| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 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 | # |
| Eli Uriegas | 474fe7d | 2021-03-05 14:41:43 -0800 | [diff] [blame^] | 8 | # For reference: |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 9 | # https://docs.docker.com/develop/develop-images/build_enhancements/ |
| 10 | ARG BASE_IMAGE=ubuntu:18.04 |
| Aliaksandr Ivanou | 208df1a | 2020-09-28 19:20:03 -0700 | [diff] [blame] | 11 | ARG PYTHON_VERSION=3.8 |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 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 |
| Eli Uriegas | 0d6c900 | 2020-11-17 11:47:18 -0800 | [diff] [blame] | 30 | ARG PYTHON_VERSION=3.8 |
| Eli Uriegas | 305444a | 2020-05-07 09:55:56 -0700 | [diff] [blame] | 31 | RUN curl -fsSL -v -o ~/miniconda.sh -O https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 32 | 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 | |
| 38 | FROM dev-base as submodule-update |
| 39 | WORKDIR /opt/pytorch |
| 40 | COPY . . |
| 41 | RUN git submodule update --init --recursive |
| 42 | |
| 43 | FROM conda as build |
| 44 | WORKDIR /opt/pytorch |
| 45 | COPY --from=conda /opt/conda /opt/conda |
| 46 | COPY --from=submodule-update /opt/pytorch /opt/pytorch |
| 47 | RUN --mount=type=cache,target=/opt/ccache \ |
| Tim Nieradzik | 99242ec | 2020-09-23 11:36:33 -0700 | [diff] [blame] | 48 | TORCH_CUDA_ARCH_LIST="3.5 5.2 6.0 6.1 7.0+PTX 8.0" TORCH_NVCC_FLAGS="-Xfatbin -compress-all" \ |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 49 | CMAKE_PREFIX_PATH="$(dirname $(which conda))/../" \ |
| 50 | python setup.py install |
| 51 | |
| 52 | FROM conda as conda-installs |
| Eli Uriegas | 0d6c900 | 2020-11-17 11:47:18 -0800 | [diff] [blame] | 53 | ARG PYTHON_VERSION=3.8 |
| Eli Uriegas | 474fe7d | 2021-03-05 14:41:43 -0800 | [diff] [blame^] | 54 | ARG CUDA_VERSION=11.1 |
| 55 | ARG CUDA_CHANNEL=nvidia |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 56 | ARG INSTALL_CHANNEL=pytorch-nightly |
| Eli Uriegas | 1dd4f43 | 2020-11-19 09:59:00 -0800 | [diff] [blame] | 57 | ENV CONDA_OVERRIDE_CUDA=${CUDA_VERSION} |
| Xu Zhao | 03e82f7 | 2021-02-10 10:43:22 -0800 | [diff] [blame] | 58 | RUN /opt/conda/bin/conda install -c "${INSTALL_CHANNEL}" -c "${CUDA_CHANNEL}" -y python=${PYTHON_VERSION} pytorch torchvision torchtext "cudatoolkit=${CUDA_VERSION}" && \ |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 59 | /opt/conda/bin/conda clean -ya |
| Eli Uriegas | e2ffdf4 | 2020-09-28 09:50:48 -0700 | [diff] [blame] | 60 | RUN /opt/conda/bin/pip install torchelastic |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 61 | |
| 62 | FROM ${BASE_IMAGE} as official |
| Felix Abecassis | 0c3bae6 | 2021-01-07 14:11:01 -0800 | [diff] [blame] | 63 | ARG PYTORCH_VERSION |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 64 | LABEL com.nvidia.volumes.needed="nvidia_driver" |
| 65 | RUN --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/* |
| 71 | COPY --from=conda-installs /opt/conda /opt/conda |
| 72 | ENV PATH /opt/conda/bin:$PATH |
| 73 | ENV NVIDIA_VISIBLE_DEVICES all |
| 74 | ENV NVIDIA_DRIVER_CAPABILITIES compute,utility |
| 75 | ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64 |
| Felix Abecassis | 0c3bae6 | 2021-01-07 14:11:01 -0800 | [diff] [blame] | 76 | ENV PYTORCH_VERSION ${PYTORCH_VERSION} |
| Eli Uriegas | f0c8557 | 2020-01-24 10:24:46 -0800 | [diff] [blame] | 77 | WORKDIR /workspace |
| 78 | |
| 79 | FROM official as dev |
| 80 | # Should override the already installed version from the official-image stage |
| 81 | COPY --from=build /opt/conda /opt/conda |