Skip to content

Commit 6c11e5a

Browse files
veritas9872joonhyung.lee
andauthored
Dev/update (#188)
* Change the name of the `Dockerfile` to `train.Dockerfile` and place it in the `dockerfiles` directory as it is no longer that special. * Updated $PYTHONPATH to incorporate any pre-existing values. * Added PYTHONPATH to NGC conda installation to check if it reduces the number of downloads. * Undo adding PYTHON PATH during conda installation as there is a worry that conda will uninstall existing packages. * Add code to remove pre-installed `pip` packages that should use the versions installed via `conda` instead. * Update `ruff` version. * Add `uninstalls` to `.dockerignore`. * Add `pip` package removal functionality to the NGC image. --------- Co-authored-by: joonhyung.lee <[email protected]>
1 parent 31ad7d3 commit 6c11e5a

File tree

9 files changed

+22
-13
lines changed

9 files changed

+22
-13
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
!**/*environment*.yaml
1010
!*conda-lock*.yaml
1111
!**/*conda-lock*.yaml
12+
!**/*uninstalls*.txt

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ repos:
3232

3333
# Ruff should be executed before other formatters.
3434
- repo: https://github.com/astral-sh/ruff-pre-commit
35-
rev: v0.1.8
35+
rev: v0.1.13
3636
hooks:
3737
- id: ruff
3838
args: [--exit-non-zero-on-fix]

docker-compose.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ services:
8080

8181
build:
8282
context: . # Nearly all files are ignored due to `.dockerignore` settings.
83-
target: ${TARGET_STAGE:-train} # Specify Dockerfile target build stage.
83+
target: ${TARGET_STAGE:-train} # Specify the `train.Dockerfile` target build stage.
8484
args: # Common build-time environment variables.
8585
# Even if these variables are unnecessary during the build,
8686
# they can be ignored simply by not defining them in that stage.
@@ -114,7 +114,7 @@ services:
114114
service: base
115115
build: # Options for building. Used when `--build` is called in `docker compose`.
116116
# Set `TARGET_STAGE` to `train-builds` to get just the wheels in `/tmp/dist`.
117-
dockerfile: Dockerfile
117+
dockerfile: dockerfiles/train.Dockerfile
118118
args: # Equivalent to `--build-arg`.
119119
BUILD_MODE: ${BUILD_MODE:-exclude}
120120
# BUILD_TEST: 0
@@ -155,7 +155,7 @@ services:
155155
service: base
156156
build:
157157
target: ${TARGET_STAGE:-build-base} # All builds begin at `build-base`.
158-
dockerfile: Dockerfile
158+
dockerfile: dockerfiles/train.Dockerfile
159159

160160
ngc: # Service based on images from the NGC PyTorch image catalog.
161161
# https://docs.nvidia.com/deeplearning/frameworks/pytorch-release-notes/running.html

dockerfiles/ngc.Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ RUN git clone --depth 1 ${ZSHS_URL} /opt/zsh/zsh-syntax-highlighting
2222
# Copy `apt` and `conda` requirements for ngc images.
2323
COPY --link ../reqs/ngc-apt.requirements.txt /tmp/apt/requirements.txt
2424
COPY --link ../reqs/ngc-environment.yaml /tmp/env/environment.yaml
25+
COPY --link ../reqs/ngc-pip.uninstalls.txt /tmp/pip/uninstalls.txt
2526

2627
########################################################################
2728
FROM ${BASE_IMAGE} AS install-conda
@@ -110,6 +111,10 @@ RUN --mount=type=bind,from=stash,source=/tmp/apt,target=/tmp/apt \
110111
xargs -r apt-get install -y --no-install-recommends && \
111112
rm -rf /var/lib/apt/lists/*
112113

114+
# Remove pre-installed `pip` packages that should use the versions installed via `conda` instead.
115+
RUN --mount=type=bind,from=stash,source=/tmp/pip,target=/tmp/pip \
116+
python -m pip uninstall -y -r /tmp/pip/uninstalls.txt
117+
113118
########################################################################
114119
FROM train-base AS train-adduser-include
115120

@@ -208,7 +213,8 @@ ENV PATH=${PATH}:/opt/conda/bin
208213
# Configure `PYTHONPATH` to prioritize system packages over `conda` packages to
209214
# prevent conflict when `conda` installs different versions of the same package.
210215
ARG PROJECT_ROOT=/opt/project
211-
ENV PYTHONPATH=${PROJECT_ROOT}:/usr/local/lib/python3/dist-packages
216+
ENV PYTHONPATH=${PYTHONPATH:+${PYTHONPATH}:}${PROJECT_ROOT}
217+
ENV PYTHONPATH=${PYTHONPATH}:/usr/local/lib/python3/dist-packages
212218
ENV PYTHONPATH=${PYTHONPATH}:/opt/conda/lib/python3/site-packages
213219

214220
WORKDIR ${PROJECT_ROOT}

dockerfiles/simple.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,6 @@ RUN { echo "fpath+=${PURE_PATH}"; \
265265

266266
ENV PATH=/opt/conda/bin:${PATH}
267267
ARG PROJECT_ROOT=/opt/project
268-
ENV PYTHONPATH=${PROJECT_ROOT}
268+
ENV PYTHONPATH=${PROJECT_ROOT}${PYTHONPATH:+:${PYTHONPATH}}
269269
WORKDIR ${PROJECT_ROOT}
270270
CMD ["/bin/zsh"]

Dockerfile renamed to dockerfiles/train.Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ RUN --mount=type=bind,from=curl-conda,source=/tmp/conda,target=/tmp/conda \
103103

104104
########################################################################
105105
FROM install-conda AS build-base
106-
# `build-base` is the base stage for all heavy builds in the Dockerfile.
106+
# `build-base` is the base stage for all heavy builds in the train.Dockerfile.
107107

108108
# Get build requirements. Set package versions manually if compatibility issues arise.
109109
ARG BUILD_REQS=/tmp/conda/build-requirements.txt
110-
COPY --link reqs/train-conda-build.requirements.txt ${BUILD_REQS}
110+
COPY --link ../reqs/train-conda-build.requirements.txt ${BUILD_REQS}
111111

112112
# Conda packages are preferable to system packages because they
113113
# are much more likely to be the latest (and the greatest!) packages.
@@ -359,7 +359,7 @@ FROM ${BUILD_IMAGE} AS train-stash
359359

360360
# This stage prevents direct contact between the `train` stage and external files.
361361
# Other files such as `.deb` package files may also be stashed here.
362-
COPY --link reqs/train-apt.requirements.txt /tmp/apt/requirements.txt
362+
COPY --link ../reqs/train-apt.requirements.txt /tmp/apt/requirements.txt
363363

364364
########################################################################
365365
FROM ${BUILD_IMAGE} AS train-builds-include
@@ -422,7 +422,7 @@ ARG conda=/opt/conda/bin/${CONDA_MANAGER}
422422
ARG PIP_CACHE_DIR=/root/.cache/pip
423423
ARG CONDA_PKGS_DIRS=/opt/conda/pkgs
424424
ARG CONDA_ENV_FILE=/tmp/train/environment.yaml
425-
COPY --link reqs/train-environment.yaml ${CONDA_ENV_FILE}
425+
COPY --link ../reqs/train-environment.yaml ${CONDA_ENV_FILE}
426426
RUN --mount=type=cache,target=${PIP_CACHE_DIR},sharing=locked \
427427
--mount=type=cache,target=${CONDA_PKGS_DIRS},sharing=locked \
428428
find /tmp/dist -name '*.whl' | sed 's/^/ - /' >> ${CONDA_ENV_FILE} && \
@@ -566,6 +566,6 @@ RUN { echo "fpath+=${PURE_PATH}"; \
566566
ENV PATH=/opt/conda/bin:${PATH}
567567
# `PROJECT_ROOT` is where the project code will reside.
568568
ARG PROJECT_ROOT=/opt/project
569-
ENV PYTHONPATH=${PROJECT_ROOT}
569+
ENV PYTHONPATH=${PROJECT_ROOT}${PYTHONPATH:+:${PYTHONPATH}}
570570
WORKDIR ${PROJECT_ROOT}
571571
CMD ["/bin/zsh"]

reqs/ngc-pip.uninstalls.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Remove pre-installed `pip` packages that should use the versions installed via `conda` instead.
2+
dummy # Placeholder package to prevent errors durring the build.

reqs/train-environment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Packages to be installed in `Dockerfile` in `train` mode.
1+
# Packages to be installed in `train.Dockerfile` in `train` mode.
22
# PyTorch install variables are in the Docker Compose file.
33
# PyTorch and related libraries are either compiled or installed via pip
44
# to reduce dependency issues with conda and for greater flexibility.

tests/test_run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
The hit to performance from antivirus programs is nontrivial.
2020
2121
Please note that a clean installation of PyTorch on the same image
22-
as provided in the `Dockerfile` will probably not give any speedup.
22+
as provided in the `train.Dockerfile` will probably not give any speedup.
2323
Use your environment as you were using it for a fair comparison.
2424
"""
2525
import logging

0 commit comments

Comments
 (0)