blob: 7bac648be90e6cc0df8e066d28f7162c536f3d4c [file] [log] [blame]
SandishKumarHN9fedf412024-05-08 01:52:53 +00001# syntax=docker/dockerfile:1
2
3# NOTE: Building this image require's docker version >= 23.0.
Eli Uriegasf0c85572020-01-24 10:24:46 -08004#
SandishKumarHN9fedf412024-05-08 01:52:53 +00005# For reference:
6# - https://docs.docker.com/build/dockerfile/frontend/#stable-channel
7
Bryant Biggs844bfbb2024-03-12 21:43:21 +00008ARG BASE_IMAGE=ubuntu:22.04
9ARG PYTHON_VERSION=3.11
Eli Uriegasf0c85572020-01-24 10:24:46 -080010
11FROM ${BASE_IMAGE} as dev-base
Ron Green1c526662023-03-01 02:39:56 +000012RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
Eli Uriegasf0c85572020-01-24 10:24:46 -080013 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/*
22RUN /usr/sbin/update-ccache-symlinks
23RUN mkdir /opt/ccache && ccache --set-config=cache_dir=/opt/ccache
24ENV PATH /opt/conda/bin:$PATH
25
26FROM dev-base as conda
Bryant Biggs844bfbb2024-03-12 21:43:21 +000027ARG PYTHON_VERSION=3.11
Eli Uriegas1b437712022-08-16 13:07:16 -070028# Automatically set by buildx
29ARG TARGETPLATFORM
30# translating Docker's TARGETPLATFORM into miniconda arches
31RUN case ${TARGETPLATFORM} in \
32 "linux/arm64") MINICONDA_ARCH=aarch64 ;; \
33 *) MINICONDA_ARCH=x86_64 ;; \
34 esac && \
pytorchbot920c0232024-08-26 14:03:09 -070035 curl -fsSL -v -o ~/miniconda.sh -O "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-${MINICONDA_ARCH}.sh"
Nikita Shulgab35c0332022-06-25 02:14:46 +000036COPY requirements.txt .
VRShardbf1ff492023-01-24 22:54:22 +000037# Manually invoke bash on miniconda script per https://github.com/conda/conda/issues/10431
Eli Uriegas1b437712022-08-16 13:07:16 -070038RUN chmod +x ~/miniconda.sh && \
VRShardbf1ff492023-01-24 22:54:22 +000039 bash ~/miniconda.sh -b -p /opt/conda && \
Eli Uriegasf0c85572020-01-24 10:24:46 -080040 rm ~/miniconda.sh && \
Nikita Shulgab35c0332022-06-25 02:14:46 +000041 /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 Uriegasf0c85572020-01-24 10:24:46 -080043 /opt/conda/bin/conda clean -ya
44
45FROM dev-base as submodule-update
46WORKDIR /opt/pytorch
47COPY . .
atalman3bd37ff2022-12-20 02:17:02 +000048RUN git submodule update --init --recursive
Eli Uriegasf0c85572020-01-24 10:24:46 -080049
50FROM conda as build
Kristoffer Carlsone762cce2023-05-10 17:44:26 +000051ARG CMAKE_VARS
Eli Uriegasf0c85572020-01-24 10:24:46 -080052WORKDIR /opt/pytorch
53COPY --from=conda /opt/conda /opt/conda
54COPY --from=submodule-update /opt/pytorch /opt/pytorch
Wei Chendf3a64f2023-07-13 20:20:24 +000055RUN make triton
Eli Uriegasf0c85572020-01-24 10:24:46 -080056RUN --mount=type=cache,target=/opt/ccache \
Kristoffer Carlsone762cce2023-05-10 17:44:26 +000057 export eval ${CMAKE_VARS} && \
Bryant Biggs844bfbb2024-03-12 21:43:21 +000058 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 Uriegasf0c85572020-01-24 10:24:46 -080059 CMAKE_PREFIX_PATH="$(dirname $(which conda))/../" \
60 python setup.py install
61
62FROM conda as conda-installs
Bryant Biggs844bfbb2024-03-12 21:43:21 +000063ARG PYTHON_VERSION=3.11
pytorchbot920c0232024-08-26 14:03:09 -070064ARG CUDA_PATH=cu121
Eli Uriegas474fe7d2021-03-05 14:41:43 -080065ARG CUDA_CHANNEL=nvidia
pytorchbot920c0232024-08-26 14:03:09 -070066ARG INSTALL_CHANNEL=whl/nightly
Eli Uriegas1b437712022-08-16 13:07:16 -070067# Automatically set by buildx
atalman8be41042024-05-10 01:43:59 +000068RUN /opt/conda/bin/conda update -y -n base -c defaults conda
pytorchbot920c0232024-08-26 14:03:09 -070069RUN /opt/conda/bin/conda install -y python=${PYTHON_VERSION}
atalman8be41042024-05-10 01:43:59 +000070
Eli Uriegas1b437712022-08-16 13:07:16 -070071ARG TARGETPLATFORM
Andrey Talmanab8fbd22022-10-28 19:55:31 +000072
pytorchbot920c0232024-08-26 14:03:09 -070073# INSTALL_CHANNEL whl - release, whl/nightly - nightly, whle/test - test channels
Eli Uriegas1b437712022-08-16 13:07:16 -070074RUN case ${TARGETPLATFORM} in \
atalman6ca964b2023-09-21 17:07:45 +000075 "linux/arm64") pip install --extra-index-url https://download.pytorch.org/whl/cpu/ torch torchvision torchaudio ;; \
pytorchbot920c0232024-08-26 14:03:09 -070076 *) pip install --index-url https://download.pytorch.org/${INSTALL_CHANNEL}/${CUDA_PATH#.}/ torch torchvision torchaudio ;; \
Eli Uriegas1b437712022-08-16 13:07:16 -070077 esac && \
Eli Uriegasf0c85572020-01-24 10:24:46 -080078 /opt/conda/bin/conda clean -ya
Eli Uriegase2ffdf42020-09-28 09:50:48 -070079RUN /opt/conda/bin/pip install torchelastic
Eli Uriegasf0c85572020-01-24 10:24:46 -080080
81FROM ${BASE_IMAGE} as official
Felix Abecassis0c3bae62021-01-07 14:11:01 -080082ARG PYTORCH_VERSION
Nikita Shulgac6cba182022-12-16 06:35:40 +000083ARG TRITON_VERSION
84ARG TARGETPLATFORM
85ARG CUDA_VERSION
Eli Uriegasf0c85572020-01-24 10:24:46 -080086LABEL com.nvidia.volumes.needed="nvidia_driver"
Ron Green1c526662023-03-01 02:39:56 +000087RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
Eli Uriegasf0c85572020-01-24 10:24:46 -080088 ca-certificates \
89 libjpeg-dev \
Ron Green1c526662023-03-01 02:39:56 +000090 libpng-dev \
91 && rm -rf /var/lib/apt/lists/*
Eli Uriegasf0c85572020-01-24 10:24:46 -080092COPY --from=conda-installs /opt/conda /opt/conda
Nikita Shulgac6cba182022-12-16 06:35:40 +000093RUN if test -n "${TRITON_VERSION}" -a "${TARGETPLATFORM}" != "linux/arm64"; then \
Ron Green1c526662023-03-01 02:39:56 +000094 DEBIAN_FRONTEND=noninteractive apt install -y --no-install-recommends gcc; \
95 rm -rf /var/lib/apt/lists/*; \
Nikita Shulgac6cba182022-12-16 06:35:40 +000096 fi
Eli Uriegasf0c85572020-01-24 10:24:46 -080097ENV PATH /opt/conda/bin:$PATH
98ENV NVIDIA_VISIBLE_DEVICES all
99ENV NVIDIA_DRIVER_CAPABILITIES compute,utility
100ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64
bhack5bc896e2024-01-11 18:10:14 +0000101ENV PATH /usr/local/nvidia/bin:/usr/local/cuda/bin:$PATH
Felix Abecassis0c3bae62021-01-07 14:11:01 -0800102ENV PYTORCH_VERSION ${PYTORCH_VERSION}
Eli Uriegasf0c85572020-01-24 10:24:46 -0800103WORKDIR /workspace
104
105FROM official as dev
106# Should override the already installed version from the official-image stage
107COPY --from=build /opt/conda /opt/conda