| 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 |
| Ron Green | 1c52666 | 2023-03-01 02:39:56 +0000 | [diff] [blame^] | 14 | RUN apt-get update && DEBIAN_FRONTEND=noninteractive 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 . |
| VRShard | bf1ff49 | 2023-01-24 22:54:22 +0000 | [diff] [blame] | 39 | # Manually invoke bash on miniconda script per https://github.com/conda/conda/issues/10431 |
| Eli Uriegas | 1b43771 | 2022-08-16 13:07:16 -0700 | [diff] [blame] | 40 | RUN chmod +x ~/miniconda.sh && \ |
| VRShard | bf1ff49 | 2023-01-24 22:54:22 +0000 | [diff] [blame] | 41 | bash ~/miniconda.sh -b -p /opt/conda && \ |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 42 | rm ~/miniconda.sh && \ |
| Nikita Shulga | b35c033 | 2022-06-25 02:14:46 +0000 | [diff] [blame] | 43 | /opt/conda/bin/conda install -y python=${PYTHON_VERSION} cmake conda-build pyyaml numpy ipython && \ |
| 44 | /opt/conda/bin/python -mpip install -r requirements.txt && \ |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 45 | /opt/conda/bin/conda clean -ya |
| 46 | |
| 47 | FROM dev-base as submodule-update |
| 48 | WORKDIR /opt/pytorch |
| 49 | COPY . . |
| atalman | 3bd37ff | 2022-12-20 02:17:02 +0000 | [diff] [blame] | 50 | RUN git submodule update --init --recursive |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 51 | |
| 52 | FROM conda as build |
| 53 | WORKDIR /opt/pytorch |
| 54 | COPY --from=conda /opt/conda /opt/conda |
| 55 | COPY --from=submodule-update /opt/pytorch /opt/pytorch |
| 56 | RUN --mount=type=cache,target=/opt/ccache \ |
| Tim Nieradzik | 99242ec | 2020-09-23 11:36:33 -0700 | [diff] [blame] | 57 | 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] | 58 | CMAKE_PREFIX_PATH="$(dirname $(which conda))/../" \ |
| 59 | python setup.py install |
| 60 | |
| 61 | FROM conda as conda-installs |
| Eli Uriegas | 0d6c900 | 2020-11-17 11:47:18 -0800 | [diff] [blame] | 62 | ARG PYTHON_VERSION=3.8 |
| atalman | 40cb494 | 2023-02-14 23:10:57 +0000 | [diff] [blame] | 63 | ARG CUDA_VERSION=11.7 |
| Eli Uriegas | 474fe7d | 2021-03-05 14:41:43 -0800 | [diff] [blame] | 64 | ARG CUDA_CHANNEL=nvidia |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 65 | ARG INSTALL_CHANNEL=pytorch-nightly |
| Eli Uriegas | 1b43771 | 2022-08-16 13:07:16 -0700 | [diff] [blame] | 66 | # Automatically set by buildx |
| Andrey Talman | ab8fbd2 | 2022-10-28 19:55:31 +0000 | [diff] [blame] | 67 | RUN /opt/conda/bin/conda update -y conda |
| Eli Uriegas | 1b43771 | 2022-08-16 13:07:16 -0700 | [diff] [blame] | 68 | RUN /opt/conda/bin/conda install -c "${INSTALL_CHANNEL}" -y python=${PYTHON_VERSION} |
| 69 | ARG TARGETPLATFORM |
| Andrey Talman | ab8fbd2 | 2022-10-28 19:55:31 +0000 | [diff] [blame] | 70 | |
| atalman | 40cb494 | 2023-02-14 23:10:57 +0000 | [diff] [blame] | 71 | # On arm64 we can only install wheel packages. |
| Eli Uriegas | 1b43771 | 2022-08-16 13:07:16 -0700 | [diff] [blame] | 72 | RUN case ${TARGETPLATFORM} in \ |
| Nikita Shulga | c6cba18 | 2022-12-16 06:35:40 +0000 | [diff] [blame] | 73 | "linux/arm64") pip install --extra-index-url https://download.pytorch.org/whl/cpu/ torch torchvision torchaudio torchtext ;; \ |
| 74 | *) /opt/conda/bin/conda install -c "${INSTALL_CHANNEL}" -c "${CUDA_CHANNEL}" -y "python=${PYTHON_VERSION}" pytorch torchvision torchaudio torchtext "pytorch-cuda=$(echo $CUDA_VERSION | cut -d'.' -f 1-2)" ;; \ |
| Eli Uriegas | 1b43771 | 2022-08-16 13:07:16 -0700 | [diff] [blame] | 75 | esac && \ |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 76 | /opt/conda/bin/conda clean -ya |
| Eli Uriegas | e2ffdf4 | 2020-09-28 09:50:48 -0700 | [diff] [blame] | 77 | RUN /opt/conda/bin/pip install torchelastic |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 78 | |
| 79 | FROM ${BASE_IMAGE} as official |
| Felix Abecassis | 0c3bae6 | 2021-01-07 14:11:01 -0800 | [diff] [blame] | 80 | ARG PYTORCH_VERSION |
| Nikita Shulga | c6cba18 | 2022-12-16 06:35:40 +0000 | [diff] [blame] | 81 | ARG TRITON_VERSION |
| 82 | ARG TARGETPLATFORM |
| 83 | ARG CUDA_VERSION |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 84 | LABEL com.nvidia.volumes.needed="nvidia_driver" |
| Ron Green | 1c52666 | 2023-03-01 02:39:56 +0000 | [diff] [blame^] | 85 | RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 86 | ca-certificates \ |
| 87 | libjpeg-dev \ |
| Ron Green | 1c52666 | 2023-03-01 02:39:56 +0000 | [diff] [blame^] | 88 | libpng-dev \ |
| 89 | && rm -rf /var/lib/apt/lists/* |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 90 | COPY --from=conda-installs /opt/conda /opt/conda |
| Nikita Shulga | c6cba18 | 2022-12-16 06:35:40 +0000 | [diff] [blame] | 91 | RUN if test -n "${TRITON_VERSION}" -a "${TARGETPLATFORM}" != "linux/arm64"; then \ |
| Ron Green | 1c52666 | 2023-03-01 02:39:56 +0000 | [diff] [blame^] | 92 | DEBIAN_FRONTEND=noninteractive apt install -y --no-install-recommends gcc; \ |
| 93 | rm -rf /var/lib/apt/lists/*; \ |
| Nikita Shulga | c6cba18 | 2022-12-16 06:35:40 +0000 | [diff] [blame] | 94 | fi |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 95 | ENV PATH /opt/conda/bin:$PATH |
| 96 | ENV NVIDIA_VISIBLE_DEVICES all |
| 97 | ENV NVIDIA_DRIVER_CAPABILITIES compute,utility |
| 98 | ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64 |
| Felix Abecassis | 0c3bae6 | 2021-01-07 14:11:01 -0800 | [diff] [blame] | 99 | ENV PYTORCH_VERSION ${PYTORCH_VERSION} |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 100 | WORKDIR /workspace |
| 101 | |
| 102 | FROM official as dev |
| 103 | # Should override the already installed version from the official-image stage |
| 104 | COPY --from=build /opt/conda /opt/conda |