| SandishKumarHN | 9fedf41 | 2024-05-08 01:52:53 +0000 | [diff] [blame] | 1 | # syntax=docker/dockerfile:1 |
| 2 | |
| 3 | # NOTE: Building this image require's docker version >= 23.0. |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 4 | # |
| SandishKumarHN | 9fedf41 | 2024-05-08 01:52:53 +0000 | [diff] [blame] | 5 | # For reference: |
| 6 | # - https://docs.docker.com/build/dockerfile/frontend/#stable-channel |
| 7 | |
| Bryant Biggs | 844bfbb | 2024-03-12 21:43:21 +0000 | [diff] [blame] | 8 | ARG BASE_IMAGE=ubuntu:22.04 |
| 9 | ARG PYTHON_VERSION=3.11 |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 10 | |
| 11 | FROM ${BASE_IMAGE} as dev-base |
| Ron Green | 1c52666 | 2023-03-01 02:39:56 +0000 | [diff] [blame] | 12 | 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] | 13 | build-essential \ |
| 14 | ca-certificates \ |
| 15 | ccache \ |
| 16 | cmake \ |
| 17 | curl \ |
| 18 | git \ |
| 19 | libjpeg-dev \ |
| 20 | libpng-dev && \ |
| 21 | rm -rf /var/lib/apt/lists/* |
| 22 | RUN /usr/sbin/update-ccache-symlinks |
| 23 | RUN mkdir /opt/ccache && ccache --set-config=cache_dir=/opt/ccache |
| 24 | ENV PATH /opt/conda/bin:$PATH |
| 25 | |
| 26 | FROM dev-base as conda |
| Bryant Biggs | 844bfbb | 2024-03-12 21:43:21 +0000 | [diff] [blame] | 27 | ARG PYTHON_VERSION=3.11 |
| Eli Uriegas | 1b43771 | 2022-08-16 13:07:16 -0700 | [diff] [blame] | 28 | # Automatically set by buildx |
| 29 | ARG TARGETPLATFORM |
| 30 | # translating Docker's TARGETPLATFORM into miniconda arches |
| 31 | RUN case ${TARGETPLATFORM} in \ |
| 32 | "linux/arm64") MINICONDA_ARCH=aarch64 ;; \ |
| 33 | *) MINICONDA_ARCH=x86_64 ;; \ |
| 34 | esac && \ |
| pytorchbot | 920c023 | 2024-08-26 14:03:09 -0700 | [diff] [blame] | 35 | curl -fsSL -v -o ~/miniconda.sh -O "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-${MINICONDA_ARCH}.sh" |
| Nikita Shulga | b35c033 | 2022-06-25 02:14:46 +0000 | [diff] [blame] | 36 | COPY requirements.txt . |
| VRShard | bf1ff49 | 2023-01-24 22:54:22 +0000 | [diff] [blame] | 37 | # 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] | 38 | RUN chmod +x ~/miniconda.sh && \ |
| VRShard | bf1ff49 | 2023-01-24 22:54:22 +0000 | [diff] [blame] | 39 | bash ~/miniconda.sh -b -p /opt/conda && \ |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 40 | rm ~/miniconda.sh && \ |
| Nikita Shulga | b35c033 | 2022-06-25 02:14:46 +0000 | [diff] [blame] | 41 | /opt/conda/bin/conda install -y python=${PYTHON_VERSION} cmake conda-build pyyaml numpy ipython && \ |
| 42 | /opt/conda/bin/python -mpip install -r requirements.txt && \ |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 43 | /opt/conda/bin/conda clean -ya |
| 44 | |
| 45 | FROM dev-base as submodule-update |
| 46 | WORKDIR /opt/pytorch |
| 47 | COPY . . |
| atalman | 3bd37ff | 2022-12-20 02:17:02 +0000 | [diff] [blame] | 48 | RUN git submodule update --init --recursive |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 49 | |
| 50 | FROM conda as build |
| Kristoffer Carlson | e762cce | 2023-05-10 17:44:26 +0000 | [diff] [blame] | 51 | ARG CMAKE_VARS |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 52 | WORKDIR /opt/pytorch |
| 53 | COPY --from=conda /opt/conda /opt/conda |
| 54 | COPY --from=submodule-update /opt/pytorch /opt/pytorch |
| Wei Chen | df3a64f | 2023-07-13 20:20:24 +0000 | [diff] [blame] | 55 | RUN make triton |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 56 | RUN --mount=type=cache,target=/opt/ccache \ |
| Kristoffer Carlson | e762cce | 2023-05-10 17:44:26 +0000 | [diff] [blame] | 57 | export eval ${CMAKE_VARS} && \ |
| Bryant Biggs | 844bfbb | 2024-03-12 21:43:21 +0000 | [diff] [blame] | 58 | TORCH_CUDA_ARCH_LIST="7.0 7.2 7.5 8.0 8.6 8.7 8.9 9.0 9.0a" TORCH_NVCC_FLAGS="-Xfatbin -compress-all" \ |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 59 | CMAKE_PREFIX_PATH="$(dirname $(which conda))/../" \ |
| 60 | python setup.py install |
| 61 | |
| 62 | FROM conda as conda-installs |
| Bryant Biggs | 844bfbb | 2024-03-12 21:43:21 +0000 | [diff] [blame] | 63 | ARG PYTHON_VERSION=3.11 |
| pytorchbot | 920c023 | 2024-08-26 14:03:09 -0700 | [diff] [blame] | 64 | ARG CUDA_PATH=cu121 |
| Eli Uriegas | 474fe7d | 2021-03-05 14:41:43 -0800 | [diff] [blame] | 65 | ARG CUDA_CHANNEL=nvidia |
| pytorchbot | 920c023 | 2024-08-26 14:03:09 -0700 | [diff] [blame] | 66 | ARG INSTALL_CHANNEL=whl/nightly |
| Eli Uriegas | 1b43771 | 2022-08-16 13:07:16 -0700 | [diff] [blame] | 67 | # Automatically set by buildx |
| atalman | 8be4104 | 2024-05-10 01:43:59 +0000 | [diff] [blame] | 68 | RUN /opt/conda/bin/conda update -y -n base -c defaults conda |
| pytorchbot | 920c023 | 2024-08-26 14:03:09 -0700 | [diff] [blame] | 69 | RUN /opt/conda/bin/conda install -y python=${PYTHON_VERSION} |
| atalman | 8be4104 | 2024-05-10 01:43:59 +0000 | [diff] [blame] | 70 | |
| Eli Uriegas | 1b43771 | 2022-08-16 13:07:16 -0700 | [diff] [blame] | 71 | ARG TARGETPLATFORM |
| Andrey Talman | ab8fbd2 | 2022-10-28 19:55:31 +0000 | [diff] [blame] | 72 | |
| pytorchbot | 920c023 | 2024-08-26 14:03:09 -0700 | [diff] [blame] | 73 | # INSTALL_CHANNEL whl - release, whl/nightly - nightly, whle/test - test channels |
| Eli Uriegas | 1b43771 | 2022-08-16 13:07:16 -0700 | [diff] [blame] | 74 | RUN case ${TARGETPLATFORM} in \ |
| atalman | 6ca964b | 2023-09-21 17:07:45 +0000 | [diff] [blame] | 75 | "linux/arm64") pip install --extra-index-url https://download.pytorch.org/whl/cpu/ torch torchvision torchaudio ;; \ |
| pytorchbot | 920c023 | 2024-08-26 14:03:09 -0700 | [diff] [blame] | 76 | *) pip install --index-url https://download.pytorch.org/${INSTALL_CHANNEL}/${CUDA_PATH#.}/ torch torchvision torchaudio ;; \ |
| Eli Uriegas | 1b43771 | 2022-08-16 13:07:16 -0700 | [diff] [blame] | 77 | esac && \ |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 78 | /opt/conda/bin/conda clean -ya |
| Eli Uriegas | e2ffdf4 | 2020-09-28 09:50:48 -0700 | [diff] [blame] | 79 | RUN /opt/conda/bin/pip install torchelastic |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 80 | |
| 81 | FROM ${BASE_IMAGE} as official |
| Felix Abecassis | 0c3bae6 | 2021-01-07 14:11:01 -0800 | [diff] [blame] | 82 | ARG PYTORCH_VERSION |
| Nikita Shulga | c6cba18 | 2022-12-16 06:35:40 +0000 | [diff] [blame] | 83 | ARG TRITON_VERSION |
| 84 | ARG TARGETPLATFORM |
| 85 | ARG CUDA_VERSION |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 86 | LABEL com.nvidia.volumes.needed="nvidia_driver" |
| Ron Green | 1c52666 | 2023-03-01 02:39:56 +0000 | [diff] [blame] | 87 | 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] | 88 | ca-certificates \ |
| 89 | libjpeg-dev \ |
| Ron Green | 1c52666 | 2023-03-01 02:39:56 +0000 | [diff] [blame] | 90 | libpng-dev \ |
| 91 | && rm -rf /var/lib/apt/lists/* |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 92 | COPY --from=conda-installs /opt/conda /opt/conda |
| Nikita Shulga | c6cba18 | 2022-12-16 06:35:40 +0000 | [diff] [blame] | 93 | RUN if test -n "${TRITON_VERSION}" -a "${TARGETPLATFORM}" != "linux/arm64"; then \ |
| Ron Green | 1c52666 | 2023-03-01 02:39:56 +0000 | [diff] [blame] | 94 | DEBIAN_FRONTEND=noninteractive apt install -y --no-install-recommends gcc; \ |
| 95 | rm -rf /var/lib/apt/lists/*; \ |
| Nikita Shulga | c6cba18 | 2022-12-16 06:35:40 +0000 | [diff] [blame] | 96 | fi |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 97 | ENV PATH /opt/conda/bin:$PATH |
| 98 | ENV NVIDIA_VISIBLE_DEVICES all |
| 99 | ENV NVIDIA_DRIVER_CAPABILITIES compute,utility |
| 100 | ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64 |
| bhack | 5bc896e | 2024-01-11 18:10:14 +0000 | [diff] [blame] | 101 | ENV PATH /usr/local/nvidia/bin:/usr/local/cuda/bin:$PATH |
| Felix Abecassis | 0c3bae6 | 2021-01-07 14:11:01 -0800 | [diff] [blame] | 102 | ENV PYTORCH_VERSION ${PYTORCH_VERSION} |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 103 | WORKDIR /workspace |
| 104 | |
| 105 | FROM official as dev |
| 106 | # Should override the already installed version from the official-image stage |
| 107 | COPY --from=build /opt/conda /opt/conda |