blob: e5bd901a33c953719957e7a56ded4133dff6e084 [file] [log] [blame]
Eli Uriegasf0c85572020-01-24 10:24:46 -08001# 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 Uriegas474fe7d2021-03-05 14:41:43 -08008# For reference:
Eli Uriegasf0c85572020-01-24 10:24:46 -08009# https://docs.docker.com/develop/develop-images/build_enhancements/
10ARG BASE_IMAGE=ubuntu:18.04
Aliaksandr Ivanou208df1a2020-09-28 19:20:03 -070011ARG PYTHON_VERSION=3.8
Eli Uriegasf0c85572020-01-24 10:24:46 -080012
13FROM ${BASE_IMAGE} as dev-base
Ron Green1c526662023-03-01 02:39:56 +000014RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
Eli Uriegasf0c85572020-01-24 10:24:46 -080015 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/*
24RUN /usr/sbin/update-ccache-symlinks
25RUN mkdir /opt/ccache && ccache --set-config=cache_dir=/opt/ccache
26ENV PATH /opt/conda/bin:$PATH
27
28FROM dev-base as conda
Eli Uriegas0d6c9002020-11-17 11:47:18 -080029ARG PYTHON_VERSION=3.8
Eli Uriegas1b437712022-08-16 13:07:16 -070030# Automatically set by buildx
31ARG TARGETPLATFORM
32# translating Docker's TARGETPLATFORM into miniconda arches
33RUN 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 Shulgab35c0332022-06-25 02:14:46 +000038COPY requirements.txt .
VRShardbf1ff492023-01-24 22:54:22 +000039# Manually invoke bash on miniconda script per https://github.com/conda/conda/issues/10431
Eli Uriegas1b437712022-08-16 13:07:16 -070040RUN chmod +x ~/miniconda.sh && \
VRShardbf1ff492023-01-24 22:54:22 +000041 bash ~/miniconda.sh -b -p /opt/conda && \
Eli Uriegasf0c85572020-01-24 10:24:46 -080042 rm ~/miniconda.sh && \
Nikita Shulgab35c0332022-06-25 02:14:46 +000043 /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 Uriegasf0c85572020-01-24 10:24:46 -080045 /opt/conda/bin/conda clean -ya
46
47FROM dev-base as submodule-update
48WORKDIR /opt/pytorch
49COPY . .
atalman3bd37ff2022-12-20 02:17:02 +000050RUN git submodule update --init --recursive
Eli Uriegasf0c85572020-01-24 10:24:46 -080051
52FROM conda as build
53WORKDIR /opt/pytorch
54COPY --from=conda /opt/conda /opt/conda
55COPY --from=submodule-update /opt/pytorch /opt/pytorch
56RUN --mount=type=cache,target=/opt/ccache \
Tim Nieradzik99242ec2020-09-23 11:36:33 -070057 TORCH_CUDA_ARCH_LIST="3.5 5.2 6.0 6.1 7.0+PTX 8.0" TORCH_NVCC_FLAGS="-Xfatbin -compress-all" \
Eli Uriegasf0c85572020-01-24 10:24:46 -080058 CMAKE_PREFIX_PATH="$(dirname $(which conda))/../" \
59 python setup.py install
60
61FROM conda as conda-installs
Eli Uriegas0d6c9002020-11-17 11:47:18 -080062ARG PYTHON_VERSION=3.8
atalman40cb4942023-02-14 23:10:57 +000063ARG CUDA_VERSION=11.7
Eli Uriegas474fe7d2021-03-05 14:41:43 -080064ARG CUDA_CHANNEL=nvidia
Eli Uriegasf0c85572020-01-24 10:24:46 -080065ARG INSTALL_CHANNEL=pytorch-nightly
Eli Uriegas1b437712022-08-16 13:07:16 -070066# Automatically set by buildx
Andrey Talmanab8fbd22022-10-28 19:55:31 +000067RUN /opt/conda/bin/conda update -y conda
Eli Uriegas1b437712022-08-16 13:07:16 -070068RUN /opt/conda/bin/conda install -c "${INSTALL_CHANNEL}" -y python=${PYTHON_VERSION}
69ARG TARGETPLATFORM
Andrey Talmanab8fbd22022-10-28 19:55:31 +000070
atalman40cb4942023-02-14 23:10:57 +000071# On arm64 we can only install wheel packages.
Eli Uriegas1b437712022-08-16 13:07:16 -070072RUN case ${TARGETPLATFORM} in \
Nikita Shulgac6cba182022-12-16 06:35:40 +000073 "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 Uriegas1b437712022-08-16 13:07:16 -070075 esac && \
Eli Uriegasf0c85572020-01-24 10:24:46 -080076 /opt/conda/bin/conda clean -ya
Eli Uriegase2ffdf42020-09-28 09:50:48 -070077RUN /opt/conda/bin/pip install torchelastic
Eli Uriegasf0c85572020-01-24 10:24:46 -080078
79FROM ${BASE_IMAGE} as official
Felix Abecassis0c3bae62021-01-07 14:11:01 -080080ARG PYTORCH_VERSION
Nikita Shulgac6cba182022-12-16 06:35:40 +000081ARG TRITON_VERSION
82ARG TARGETPLATFORM
83ARG CUDA_VERSION
Eli Uriegasf0c85572020-01-24 10:24:46 -080084LABEL com.nvidia.volumes.needed="nvidia_driver"
Ron Green1c526662023-03-01 02:39:56 +000085RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
Eli Uriegasf0c85572020-01-24 10:24:46 -080086 ca-certificates \
87 libjpeg-dev \
Ron Green1c526662023-03-01 02:39:56 +000088 libpng-dev \
89 && rm -rf /var/lib/apt/lists/*
Eli Uriegasf0c85572020-01-24 10:24:46 -080090COPY --from=conda-installs /opt/conda /opt/conda
Nikita Shulgac6cba182022-12-16 06:35:40 +000091RUN if test -n "${TRITON_VERSION}" -a "${TARGETPLATFORM}" != "linux/arm64"; then \
Ron Green1c526662023-03-01 02:39:56 +000092 DEBIAN_FRONTEND=noninteractive apt install -y --no-install-recommends gcc; \
93 rm -rf /var/lib/apt/lists/*; \
Nikita Shulgac6cba182022-12-16 06:35:40 +000094 fi
Eli Uriegasf0c85572020-01-24 10:24:46 -080095ENV PATH /opt/conda/bin:$PATH
96ENV NVIDIA_VISIBLE_DEVICES all
97ENV NVIDIA_DRIVER_CAPABILITIES compute,utility
98ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64
Felix Abecassis0c3bae62021-01-07 14:11:01 -080099ENV PYTORCH_VERSION ${PYTORCH_VERSION}
Eli Uriegasf0c85572020-01-24 10:24:46 -0800100WORKDIR /workspace
101
102FROM official as dev
103# Should override the already installed version from the official-image stage
104COPY --from=build /opt/conda /opt/conda