Skip to content

Commit 88f2a0b

Browse files
authored
👷 put python installs in separate stage (#46)
This puts all the final `pip install` commands and site-packages overrides into a `python-installations` stage, then the python environment from there is copied into the `server-release` stage. This should mean that the final image will not contain any intermediate python packages. Signed-off-by: Joe Runde <[email protected]>
1 parent b0b3841 commit 88f2a0b

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

.github/actions/free-up-disk-space/action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@ runs:
1212
df -h
1313
echo "Removing non-essential tools and libraries ..."
1414
sudo rm -rf /opt/ghc
15+
sudo rm -rf /usr/local/.ghcup
1516
sudo rm -rf /usr/share/dotnet
1617
# sudo rm -rf /usr/local/share/boost
1718
echo "Deleting libraries for Android (12G), CodeQL (5.3G), PowerShell (1.3G), Swift (1.7G) ..."
1819
sudo rm -rf /usr/local/lib/android
1920
sudo rm -rf "${AGENT_TOOLSDIRECTORY}/CodeQL"
2021
sudo rm -rf /usr/local/share/powershell
2122
sudo rm -rf /usr/share/swift
23+
# ref: https://github.com/jlumbroso/free-disk-space/blob/main/action.yml
24+
echo "Deleting some larger apt packages:"
25+
sudo apt-get remove -y azure-cli google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri --fix-missing || echo "::warning::The command [sudo apt-get remove -y azure-cli google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri --fix-missing] failed to complete successfully. Proceeding..."
2226
echo "Disk usage after cleanup:"
2327
df -h
2428

Dockerfile

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -285,19 +285,16 @@ FROM base as auto-gptq-cache
285285
COPY --from=auto-gptq-installer /usr/src/auto-gptq-wheel /usr/src/auto-gptq-wheel
286286

287287

288-
## Final Inference Server image ################################################
289-
FROM cuda-runtime as server-release
290-
ARG PYTHON_VERSION
291-
ARG SITE_PACKAGES=/opt/tgis/lib/python${PYTHON_VERSION}/site-packages
288+
## Full set of python installations for server release #########################
292289

293-
# Install C++ compiler (required at runtime when PT2_COMPILE is enabled)
294-
RUN dnf install -y gcc-c++ git && dnf clean all \
295-
&& useradd -u 2000 tgis -m -g 0
290+
FROM cuda-runtime as python-installations
296291

297-
SHELL ["/bin/bash", "-c"]
292+
ARG PYTHON_VERSION
293+
ARG SITE_PACKAGES=/opt/tgis/lib/python${PYTHON_VERSION}/site-packages
298294

299295
COPY --from=build /opt/tgis /opt/tgis
300296

297+
# `pip` is installed in the venv here
301298
ENV PATH=/opt/tgis/bin:$PATH
302299

303300
# Install flash attention v2 from the cache build
@@ -315,13 +312,30 @@ RUN --mount=type=bind,from=auto-gptq-cache,src=/usr/src/auto-gptq-wheel,target=/
315312
pip install /usr/src/auto-gptq-wheel/*.whl --no-cache-dir
316313

317314
# Install server
315+
# git is required to pull the fms-extras dependency
316+
RUN dnf install -y git && dnf clean all
318317
COPY proto proto
319318
COPY server server
320319
RUN cd server && make gen-server && pip install ".[accelerate, ibm-fms, onnx-gpu, quantize]" --no-cache-dir
321320

322321
# Patch codegen model changes into transformers 4.35
323322
RUN cp server/transformers_patch/modeling_codegen.py ${SITE_PACKAGES}/transformers/models/codegen/modeling_codegen.py
324323

324+
325+
## Final Inference Server image ################################################
326+
FROM cuda-runtime as server-release
327+
ARG PYTHON_VERSION
328+
ARG SITE_PACKAGES=/opt/tgis/lib/python${PYTHON_VERSION}/site-packages
329+
330+
# Install C++ compiler (required at runtime when PT2_COMPILE is enabled)
331+
RUN dnf install -y gcc-c++ && dnf clean all \
332+
&& useradd -u 2000 tgis -m -g 0
333+
334+
# Copy in the full python environment
335+
COPY --from=python-installations /opt/tgis /opt/tgis
336+
337+
ENV PATH=/opt/tgis/bin:$PATH
338+
325339
# Print a list of all installed packages and versions
326340
RUN pip list -v --disable-pip-version-check --no-python-version-warning
327341

0 commit comments

Comments
 (0)