| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 1 | # syntax = docker/dockerfile:experimental |
| 2 | # |
| 3 | # NOTE: To build this you will need a docker version > 18.06 with |
| 4 | # experimental enabled and DOCKER_BUILDKIT=1 |
| 5 | # |
| 6 | # If you do not use buildkit you are not going to have a good time |
| 7 | # |
| Eli Uriegas | 474fe7d | 2021-03-05 14:41:43 -0800 | [diff] [blame] | 8 | # For reference: |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 9 | # https://docs.docker.com/develop/develop-images/build_enhancements/ |
| 10 | ARG BASE_IMAGE=ubuntu:18.04 |
| Aliaksandr Ivanou | 208df1a | 2020-09-28 19:20:03 -0700 | [diff] [blame] | 11 | ARG PYTHON_VERSION=3.8 |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 12 | |
| 13 | FROM ${BASE_IMAGE} as dev-base |
| Eli Uriegas | 1b43771 | 2022-08-16 13:07:16 -0700 | [diff] [blame] | 14 | RUN apt-get update && apt-get install -y --no-install-recommends \ |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 15 | build-essential \ |
| 16 | ca-certificates \ |
| 17 | ccache \ |
| 18 | cmake \ |
| 19 | curl \ |
| 20 | git \ |
| 21 | libjpeg-dev \ |
| 22 | libpng-dev && \ |
| 23 | rm -rf /var/lib/apt/lists/* |
| 24 | RUN /usr/sbin/update-ccache-symlinks |
| 25 | RUN mkdir /opt/ccache && ccache --set-config=cache_dir=/opt/ccache |
| 26 | ENV PATH /opt/conda/bin:$PATH |
| 27 | |
| 28 | FROM dev-base as conda |
| Eli Uriegas | 0d6c900 | 2020-11-17 11:47:18 -0800 | [diff] [blame] | 29 | ARG PYTHON_VERSION=3.8 |
| Eli Uriegas | 1b43771 | 2022-08-16 13:07:16 -0700 | [diff] [blame] | 30 | # Automatically set by buildx |
| 31 | ARG TARGETPLATFORM |
| 32 | # translating Docker's TARGETPLATFORM into miniconda arches |
| 33 | RUN case ${TARGETPLATFORM} in \ |
| 34 | "linux/arm64") MINICONDA_ARCH=aarch64 ;; \ |
| 35 | *) MINICONDA_ARCH=x86_64 ;; \ |
| 36 | esac && \ |
| 37 | curl -fsSL -v -o ~/miniconda.sh -O "https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-${MINICONDA_ARCH}.sh" |
| Nikita Shulga | b35c033 | 2022-06-25 02:14:46 +0000 | [diff] [blame] | 38 | COPY requirements.txt . |
| Eli Uriegas | 1b43771 | 2022-08-16 13:07:16 -0700 | [diff] [blame] | 39 | RUN chmod +x ~/miniconda.sh && \ |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 40 | ~/miniconda.sh -b -p /opt/conda && \ |
| 41 | rm ~/miniconda.sh && \ |
| Nikita Shulga | b35c033 | 2022-06-25 02:14:46 +0000 | [diff] [blame] | 42 | /opt/conda/bin/conda install -y python=${PYTHON_VERSION} cmake conda-build pyyaml numpy ipython && \ |
| 43 | /opt/conda/bin/python -mpip install -r requirements.txt && \ |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 44 | /opt/conda/bin/conda clean -ya |
| 45 | |
| 46 | FROM dev-base as submodule-update |
| 47 | WORKDIR /opt/pytorch |
| 48 | COPY . . |
| zhouzhuojie | 6107cf3 | 2021-07-07 15:37:32 -0700 | [diff] [blame] | 49 | RUN git submodule update --init --recursive --jobs 0 |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 50 | |
| 51 | FROM conda as build |
| 52 | WORKDIR /opt/pytorch |
| 53 | COPY --from=conda /opt/conda /opt/conda |
| 54 | COPY --from=submodule-update /opt/pytorch /opt/pytorch |
| 55 | RUN --mount=type=cache,target=/opt/ccache \ |
| Tim Nieradzik | 99242ec | 2020-09-23 11:36:33 -0700 | [diff] [blame] | 56 | TORCH_CUDA_ARCH_LIST="3.5 5.2 6.0 6.1 7.0+PTX 8.0" TORCH_NVCC_FLAGS="-Xfatbin -compress-all" \ |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 57 | CMAKE_PREFIX_PATH="$(dirname $(which conda))/../" \ |
| 58 | python setup.py install |
| 59 | |
| 60 | FROM conda as conda-installs |
| Eli Uriegas | 0d6c900 | 2020-11-17 11:47:18 -0800 | [diff] [blame] | 61 | ARG PYTHON_VERSION=3.8 |
| Andrey Talman | ab8fbd2 | 2022-10-28 19:55:31 +0000 | [diff] [blame^] | 62 | ARG CUDA_VERSION=11.6 |
| Eli Uriegas | 474fe7d | 2021-03-05 14:41:43 -0800 | [diff] [blame] | 63 | ARG CUDA_CHANNEL=nvidia |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 64 | ARG INSTALL_CHANNEL=pytorch-nightly |
| Eli Uriegas | 1b43771 | 2022-08-16 13:07:16 -0700 | [diff] [blame] | 65 | # Automatically set by buildx |
| Andrey Talman | ab8fbd2 | 2022-10-28 19:55:31 +0000 | [diff] [blame^] | 66 | RUN /opt/conda/bin/conda update -y conda |
| Eli Uriegas | 1b43771 | 2022-08-16 13:07:16 -0700 | [diff] [blame] | 67 | RUN /opt/conda/bin/conda install -c "${INSTALL_CHANNEL}" -y python=${PYTHON_VERSION} |
| 68 | ARG TARGETPLATFORM |
| Andrey Talman | ab8fbd2 | 2022-10-28 19:55:31 +0000 | [diff] [blame^] | 69 | |
| Eli Uriegas | 1b43771 | 2022-08-16 13:07:16 -0700 | [diff] [blame] | 70 | # On arm64 we can only install wheel packages |
| 71 | RUN case ${TARGETPLATFORM} in \ |
| 72 | "linux/arm64") pip install --extra-index-url https://download.pytorch.org/whl/cpu/ torch torchvision torchtext ;; \ |
| Andrey Talman | ab8fbd2 | 2022-10-28 19:55:31 +0000 | [diff] [blame^] | 73 | *) /opt/conda/bin/conda install -c "${INSTALL_CHANNEL}" -c "${CUDA_CHANNEL}" -y "python=${PYTHON_VERSION}" pytorch torchvision torchtext "pytorch-cuda=$(echo $CUDA_VERSION | cut -d'.' -f 1-2)" ;; \ |
| Eli Uriegas | 1b43771 | 2022-08-16 13:07:16 -0700 | [diff] [blame] | 74 | esac && \ |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 75 | /opt/conda/bin/conda clean -ya |
| Eli Uriegas | e2ffdf4 | 2020-09-28 09:50:48 -0700 | [diff] [blame] | 76 | RUN /opt/conda/bin/pip install torchelastic |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 77 | |
| 78 | FROM ${BASE_IMAGE} as official |
| Felix Abecassis | 0c3bae6 | 2021-01-07 14:11:01 -0800 | [diff] [blame] | 79 | ARG PYTORCH_VERSION |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 80 | LABEL com.nvidia.volumes.needed="nvidia_driver" |
| Eli Uriegas | 1b43771 | 2022-08-16 13:07:16 -0700 | [diff] [blame] | 81 | RUN apt-get update && apt-get install -y --no-install-recommends \ |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 82 | ca-certificates \ |
| 83 | libjpeg-dev \ |
| 84 | libpng-dev && \ |
| 85 | rm -rf /var/lib/apt/lists/* |
| 86 | COPY --from=conda-installs /opt/conda /opt/conda |
| 87 | ENV PATH /opt/conda/bin:$PATH |
| 88 | ENV NVIDIA_VISIBLE_DEVICES all |
| 89 | ENV NVIDIA_DRIVER_CAPABILITIES compute,utility |
| 90 | ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64 |
| Felix Abecassis | 0c3bae6 | 2021-01-07 14:11:01 -0800 | [diff] [blame] | 91 | ENV PYTORCH_VERSION ${PYTORCH_VERSION} |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 92 | WORKDIR /workspace |
| 93 | |
| 94 | FROM official as dev |
| 95 | # Should override the already installed version from the official-image stage |
| 96 | COPY --from=build /opt/conda /opt/conda |