|
| 1 | +# 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 | +# |
| 8 | +# For reference: |
| 9 | +# https://docs.docker.com/develop/develop-images/build_enhancements/ |
| 10 | +ARG BASE_IMAGE=ubuntu:18.04 |
| 11 | +ARG PYTHON_VERSION=3.7 |
| 12 | + |
| 13 | +FROM ${BASE_IMAGE} as dev-base |
| 14 | +RUN --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/* |
| 25 | +RUN /usr/sbin/update-ccache-symlinks |
| 26 | +RUN mkdir /opt/ccache && ccache --set-config=cache_dir=/opt/ccache |
| 27 | +ENV PATH /opt/conda/bin:$PATH |
| 28 | + |
| 29 | +FROM dev-base as conda |
| 30 | +RUN curl -v -o ~/miniconda.sh -O https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ |
| 31 | + chmod +x ~/miniconda.sh && \ |
| 32 | + ~/miniconda.sh -b -p /opt/conda && \ |
| 33 | + rm ~/miniconda.sh && \ |
| 34 | + /opt/conda/bin/conda install -y python=${PYTHON_VERSION} conda-build pyyaml numpy ipython&& \ |
| 35 | + /opt/conda/bin/conda clean -ya |
| 36 | + |
| 37 | +FROM dev-base as submodule-update |
| 38 | +WORKDIR /opt/pytorch |
| 39 | +COPY . . |
| 40 | +RUN git submodule update --init --recursive |
| 41 | + |
| 42 | +FROM conda as build |
| 43 | +WORKDIR /opt/pytorch |
| 44 | +COPY --from=conda /opt/conda /opt/conda |
| 45 | +COPY --from=submodule-update /opt/pytorch /opt/pytorch |
| 46 | +RUN --mount=type=cache,target=/opt/ccache \ |
| 47 | + TORCH_CUDA_ARCH_LIST="3.5 5.2 6.0 6.1 7.0+PTX" TORCH_NVCC_FLAGS="-Xfatbin -compress-all" \ |
| 48 | + CMAKE_PREFIX_PATH="$(dirname $(which conda))/../" \ |
| 49 | + python setup.py install |
| 50 | + |
| 51 | +FROM conda as conda-installs |
| 52 | +ARG INSTALL_CHANNEL=pytorch-nightly |
| 53 | +RUN /opt/conda/bin/conda install -c "${INSTALL_CHANNEL}" -y pytorch torchvision && \ |
| 54 | + /opt/conda/bin/conda clean -ya |
| 55 | + |
| 56 | +FROM ${BASE_IMAGE} as official |
| 57 | +LABEL com.nvidia.volumes.needed="nvidia_driver" |
| 58 | +RUN --mount=type=cache,id=apt-final,target=/var/cache/apt \ |
| 59 | + apt-get update && apt-get install -y --no-install-recommends \ |
| 60 | + ca-certificates \ |
| 61 | + libjpeg-dev \ |
| 62 | + libpng-dev && \ |
| 63 | + rm -rf /var/lib/apt/lists/* |
| 64 | +COPY --from=conda-installs /opt/conda /opt/conda |
| 65 | +ENV PATH /opt/conda/bin:$PATH |
| 66 | +ENV NVIDIA_VISIBLE_DEVICES all |
| 67 | +ENV NVIDIA_DRIVER_CAPABILITIES compute,utility |
| 68 | +ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64 |
| 69 | +WORKDIR /workspace |
| 70 | + |
| 71 | +FROM official as dev |
| 72 | +# Should override the already installed version from the official-image stage |
| 73 | +COPY --from=build /opt/conda /opt/conda |
0 commit comments