blob: cea0fcb9ff04eff9a37b0c25a42f799a4bbe1ca3 [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
14RUN --mount=type=cache,id=apt-dev,target=/var/cache/apt \
15 apt-get update && apt-get install -y --no-install-recommends \
16 build-essential \
17 ca-certificates \
18 ccache \
19 cmake \
20 curl \
21 git \
22 libjpeg-dev \
23 libpng-dev && \
24 rm -rf /var/lib/apt/lists/*
25RUN /usr/sbin/update-ccache-symlinks
26RUN mkdir /opt/ccache && ccache --set-config=cache_dir=/opt/ccache
27ENV PATH /opt/conda/bin:$PATH
28
29FROM dev-base as conda
Eli Uriegas0d6c9002020-11-17 11:47:18 -080030ARG PYTHON_VERSION=3.8
Eli Uriegas305444a2020-05-07 09:55:56 -070031RUN curl -fsSL -v -o ~/miniconda.sh -O https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \
Eli Uriegasf0c85572020-01-24 10:24:46 -080032 chmod +x ~/miniconda.sh && \
33 ~/miniconda.sh -b -p /opt/conda && \
34 rm ~/miniconda.sh && \
35 /opt/conda/bin/conda install -y python=${PYTHON_VERSION} conda-build pyyaml numpy ipython&& \
36 /opt/conda/bin/conda clean -ya
37
38FROM dev-base as submodule-update
39WORKDIR /opt/pytorch
40COPY . .
41RUN git submodule update --init --recursive
42
43FROM conda as build
44WORKDIR /opt/pytorch
45COPY --from=conda /opt/conda /opt/conda
46COPY --from=submodule-update /opt/pytorch /opt/pytorch
47RUN --mount=type=cache,target=/opt/ccache \
Tim Nieradzik99242ec2020-09-23 11:36:33 -070048 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 -080049 CMAKE_PREFIX_PATH="$(dirname $(which conda))/../" \
50 python setup.py install
51
52FROM conda as conda-installs
Eli Uriegas0d6c9002020-11-17 11:47:18 -080053ARG PYTHON_VERSION=3.8
Eli Uriegas474fe7d2021-03-05 14:41:43 -080054ARG CUDA_VERSION=11.1
55ARG CUDA_CHANNEL=nvidia
Eli Uriegasf0c85572020-01-24 10:24:46 -080056ARG INSTALL_CHANNEL=pytorch-nightly
Eli Uriegas1dd4f432020-11-19 09:59:00 -080057ENV CONDA_OVERRIDE_CUDA=${CUDA_VERSION}
Xu Zhao03e82f72021-02-10 10:43:22 -080058RUN /opt/conda/bin/conda install -c "${INSTALL_CHANNEL}" -c "${CUDA_CHANNEL}" -y python=${PYTHON_VERSION} pytorch torchvision torchtext "cudatoolkit=${CUDA_VERSION}" && \
Eli Uriegasf0c85572020-01-24 10:24:46 -080059 /opt/conda/bin/conda clean -ya
Eli Uriegase2ffdf42020-09-28 09:50:48 -070060RUN /opt/conda/bin/pip install torchelastic
Eli Uriegasf0c85572020-01-24 10:24:46 -080061
62FROM ${BASE_IMAGE} as official
Felix Abecassis0c3bae62021-01-07 14:11:01 -080063ARG PYTORCH_VERSION
Eli Uriegasf0c85572020-01-24 10:24:46 -080064LABEL com.nvidia.volumes.needed="nvidia_driver"
65RUN --mount=type=cache,id=apt-final,target=/var/cache/apt \
66 apt-get update && apt-get install -y --no-install-recommends \
67 ca-certificates \
68 libjpeg-dev \
69 libpng-dev && \
70 rm -rf /var/lib/apt/lists/*
71COPY --from=conda-installs /opt/conda /opt/conda
72ENV PATH /opt/conda/bin:$PATH
73ENV NVIDIA_VISIBLE_DEVICES all
74ENV NVIDIA_DRIVER_CAPABILITIES compute,utility
75ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64
Felix Abecassis0c3bae62021-01-07 14:11:01 -080076ENV PYTORCH_VERSION ${PYTORCH_VERSION}
Eli Uriegasf0c85572020-01-24 10:24:46 -080077WORKDIR /workspace
78
79FROM official as dev
80# Should override the already installed version from the official-image stage
81COPY --from=build /opt/conda /opt/conda