@@ -114,8 +114,11 @@ USER ${USER}
114114# "fatal: detected dubious ownership" for `/tmp`
115115WORKDIR /tmp/fms-hf-tuning
116116
117+ # Install poetry and its dependencies inside an isolated virtual environment which we
118+ # will not copy into the release-base layer
117119RUN --mount=type=cache,target=/home/${USER}/.cache/pip,uid=${USER_UID} \
118- python -m pip install --user wheel packaging poetry poetry-plugin-export
120+ python -m venv venv /tmp/isolated && \
121+ /tmp/isolated/bin/pip install poetry poetry-plugin-export
119122
120123COPY --chown=${USER}:root tuning tuning
121124COPY --chown=${USER}:root .git .git
@@ -126,15 +129,21 @@ COPY README.md README.md
126129# Install using poetry if PyPi wheel_version is empty else download the wheel from PyPi
127130RUN --mount=type=cache,target=/home/${USER}/.cache/pip,uid=${USER_UID} \
128131 if [[ -z "${WHEEL_VERSION}" ]]; then \
129- # Extract requirements from poetry and install them in ~/.local
130- python -m pip install --user --requirement <(python -m poetry export --format requirements.txt) && \
132+ # Extract requirements from poetry and install them in ~/.local \
133+ python -m pip install --user --requirement <(/tmp/isolated/bin/ poetry export --format requirements.txt) && \
131134 # Next install the package with flash-attn \
132- python -m pip install --user ".[flash-attn]" ; \
135+ python -m pip install --user ".[flash-attn]" ; \
133136 else \
134- # This will use whatever dependency versions satisfy the pyproject.toml constraints
135- python -m pip install --user "fms-hf-tuning[flash-attn]==${WHEEL_VERSION}" ; \
136- fi && \
137- python -m pip uninstall wheel -y
137+ # This will use whatever dependencies versions satisfy the pyproject.toml constraints \
138+ # but they won't necessarily be the exact same versions as present in poetry.lock \
139+ # First, install fms-hf-tuning first to get its dependencies which include torch. \
140+ # Then install with the flash-attn group as the latter expects torch to be present \
141+ python -m pip install --user "fms-hf-tuning==${WHEEL_VERSION}" && \
142+ python -m pip install --user "fms-hf-tuning[flash-attn]==${WHEEL_VERSION}" && \
143+ python -m pip uninstall wheel build -y ; \
144+ fi
145+
146+ RUN python -m pip freeze
138147
139148# # Final image ################################################
140149FROM release-base as release
0 commit comments