blob: e49e0a44e816bfe3ec3b8560839e7c2df2799d09 [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
Eli Uriegas1b437712022-08-16 13:07:16 -070014RUN apt-get update && 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 .
Eli Uriegas1b437712022-08-16 13:07:16 -070039RUN chmod +x ~/miniconda.sh && \
Eli Uriegasf0c85572020-01-24 10:24:46 -080040 ~/miniconda.sh -b -p /opt/conda && \
41 rm ~/miniconda.sh && \
Nikita Shulgab35c0332022-06-25 02:14:46 +000042 /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 Uriegasf0c85572020-01-24 10:24:46 -080044 /opt/conda/bin/conda clean -ya
45
46FROM dev-base as submodule-update
47WORKDIR /opt/pytorch
48COPY . .
zhouzhuojie6107cf32021-07-07 15:37:32 -070049RUN git submodule update --init --recursive --jobs 0
Eli Uriegasf0c85572020-01-24 10:24:46 -080050
51FROM conda as build
52WORKDIR /opt/pytorch
53COPY --from=conda /opt/conda /opt/conda
54COPY --from=submodule-update /opt/pytorch /opt/pytorch
55RUN --mount=type=cache,target=/opt/ccache \
Tim Nieradzik99242ec2020-09-23 11:36:33 -070056 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 -080057 CMAKE_PREFIX_PATH="$(dirname $(which conda))/../" \
58 python setup.py install
59
60FROM conda as conda-installs
Eli Uriegas0d6c9002020-11-17 11:47:18 -080061ARG PYTHON_VERSION=3.8
Andrey Talmanab8fbd22022-10-28 19:55:31 +000062ARG CUDA_VERSION=11.6
Eli Uriegas474fe7d2021-03-05 14:41:43 -080063ARG CUDA_CHANNEL=nvidia
Eli Uriegasf0c85572020-01-24 10:24:46 -080064ARG INSTALL_CHANNEL=pytorch-nightly
Eli Uriegas1b437712022-08-16 13:07:16 -070065# Automatically set by buildx
Andrey Talmanab8fbd22022-10-28 19:55:31 +000066RUN /opt/conda/bin/conda update -y conda
Eli Uriegas1b437712022-08-16 13:07:16 -070067RUN /opt/conda/bin/conda install -c "${INSTALL_CHANNEL}" -y python=${PYTHON_VERSION}
68ARG TARGETPLATFORM
Andrey Talmanab8fbd22022-10-28 19:55:31 +000069
Eli Uriegas1b437712022-08-16 13:07:16 -070070# On arm64 we can only install wheel packages
71RUN case ${TARGETPLATFORM} in \
72 "linux/arm64") pip install --extra-index-url https://download.pytorch.org/whl/cpu/ torch torchvision torchtext ;; \
Andrey Talmanab8fbd22022-10-28 19:55:31 +000073 *) /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 Uriegas1b437712022-08-16 13:07:16 -070074 esac && \
Eli Uriegasf0c85572020-01-24 10:24:46 -080075 /opt/conda/bin/conda clean -ya
Eli Uriegase2ffdf42020-09-28 09:50:48 -070076RUN /opt/conda/bin/pip install torchelastic
Eli Uriegasf0c85572020-01-24 10:24:46 -080077
78FROM ${BASE_IMAGE} as official
Felix Abecassis0c3bae62021-01-07 14:11:01 -080079ARG PYTORCH_VERSION
Eli Uriegasf0c85572020-01-24 10:24:46 -080080LABEL com.nvidia.volumes.needed="nvidia_driver"
Eli Uriegas1b437712022-08-16 13:07:16 -070081RUN apt-get update && apt-get install -y --no-install-recommends \
Eli Uriegasf0c85572020-01-24 10:24:46 -080082 ca-certificates \
83 libjpeg-dev \
84 libpng-dev && \
85 rm -rf /var/lib/apt/lists/*
86COPY --from=conda-installs /opt/conda /opt/conda
87ENV PATH /opt/conda/bin:$PATH
88ENV NVIDIA_VISIBLE_DEVICES all
89ENV NVIDIA_DRIVER_CAPABILITIES compute,utility
90ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64
Felix Abecassis0c3bae62021-01-07 14:11:01 -080091ENV PYTORCH_VERSION ${PYTORCH_VERSION}
Eli Uriegasf0c85572020-01-24 10:24:46 -080092WORKDIR /workspace
93
94FROM official as dev
95# Should override the already installed version from the official-image stage
96COPY --from=build /opt/conda /opt/conda