2020-10-26 10:47:09 +00:00
|
|
|
# Copyright The PyTorch Lightning team.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
# Existing images:
|
2021-02-09 08:22:35 +00:00
|
|
|
# --build-arg PYTHON_VERSION=3.7 --build-arg PYTORCH_VERSION=1.8
|
|
|
|
# --build-arg PYTHON_VERSION=3.7 --build-arg PYTORCH_VERSION=1.6
|
|
|
|
# --build-arg PYTHON_VERSION=3.7 --build-arg PYTORCH_VERSION=1.5
|
|
|
|
# --build-arg PYTHON_VERSION=3.7 --build-arg PYTORCH_VERSION=1.4
|
2020-10-26 10:47:09 +00:00
|
|
|
|
|
|
|
ARG CUDNN_VERSION=8
|
|
|
|
ARG CUDA_VERSION=10.2
|
|
|
|
|
|
|
|
# FROM nvidia/cuda:${CUDA_VERSION}-devel-ubuntu20.04
|
|
|
|
FROM nvidia/cuda:${CUDA_VERSION}-cudnn${CUDNN_VERSION}-devel-ubuntu18.04
|
|
|
|
# FROM nvidia/cuda:${CUDA_VERSION}-devel-ubuntu18.04
|
|
|
|
|
|
|
|
ARG PYTHON_VERSION=3.7
|
|
|
|
ARG PYTORCH_VERSION=1.6
|
2021-02-09 08:22:35 +00:00
|
|
|
ARG CONDA_VERSION=4.9.2
|
2020-10-26 10:47:09 +00:00
|
|
|
|
|
|
|
SHELL ["/bin/bash", "-c"]
|
|
|
|
|
|
|
|
ENV PATH="$PATH:/root/.local/bin"
|
|
|
|
|
2020-11-09 14:48:24 +00:00
|
|
|
RUN apt-get update -qq && \
|
|
|
|
apt-get install -y --no-install-recommends \
|
2020-10-26 10:47:09 +00:00
|
|
|
build-essential \
|
|
|
|
cmake \
|
|
|
|
git \
|
2021-01-08 15:36:49 +00:00
|
|
|
wget \
|
2020-10-26 10:47:09 +00:00
|
|
|
curl \
|
2021-01-08 15:36:49 +00:00
|
|
|
unzip \
|
2020-10-26 10:47:09 +00:00
|
|
|
ca-certificates \
|
2021-02-17 12:15:49 +00:00
|
|
|
libopenmpi-dev \
|
2020-10-26 10:47:09 +00:00
|
|
|
&& \
|
|
|
|
|
|
|
|
# Install conda and python.
|
|
|
|
# NOTE new Conda does not forward the exit status... https://github.com/conda/conda/issues/8385
|
2021-02-09 08:22:35 +00:00
|
|
|
curl -o ~/miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-py38_${CONDA_VERSION}-Linux-x86_64.sh && \
|
2020-10-26 10:47:09 +00:00
|
|
|
chmod +x ~/miniconda.sh && \
|
|
|
|
~/miniconda.sh -b && \
|
|
|
|
rm ~/miniconda.sh && \
|
|
|
|
|
|
|
|
# Cleaning
|
|
|
|
apt-get autoremove -y && \
|
|
|
|
apt-get clean && \
|
|
|
|
rm -rf /root/.cache && \
|
|
|
|
rm -rf /var/lib/apt/lists/*
|
|
|
|
|
2021-01-29 12:27:18 +00:00
|
|
|
ENV \
|
|
|
|
PATH="/root/miniconda3/bin:$PATH" \
|
|
|
|
LD_LIBRARY_PATH="/root/miniconda3/lib:$LD_LIBRARY_PATH" \
|
|
|
|
CUDA_TOOLKIT_ROOT_DIR="/usr/local/cuda" \
|
2021-02-09 15:30:48 +00:00
|
|
|
MKL_THREADING_LAYER=GNU \
|
2021-01-29 12:27:18 +00:00
|
|
|
HOROVOD_GPU_OPERATIONS=NCCL \
|
|
|
|
HOROVOD_WITH_PYTORCH=1 \
|
|
|
|
HOROVOD_WITHOUT_TENSORFLOW=1 \
|
|
|
|
HOROVOD_WITHOUT_MXNET=1 \
|
|
|
|
HOROVOD_WITH_GLOO=1 \
|
|
|
|
HOROVOD_WITHOUT_MPI=1 \
|
|
|
|
# MAKEFLAGS="-j$(nproc)" \
|
|
|
|
MAKEFLAGS="-j1" \
|
|
|
|
TORCH_CUDA_ARCH_LIST="3.7;5.0;6.0;7.0;7.5" \
|
|
|
|
CONDA_ENV=lightning
|
|
|
|
|
2020-10-26 10:47:09 +00:00
|
|
|
COPY environment.yml environment.yml
|
|
|
|
|
|
|
|
# conda init
|
2021-02-09 08:22:35 +00:00
|
|
|
RUN conda create -y --name $CONDA_ENV python=${PYTHON_VERSION} pytorch=${PYTORCH_VERSION} cudatoolkit=${CUDA_VERSION} -c pytorch -c pytorch-test -c pytorch-nightly && \
|
2020-10-26 10:47:09 +00:00
|
|
|
conda init bash && \
|
|
|
|
# NOTE: this requires that the channel is presented in the yaml before packages
|
2021-01-06 16:59:42 +00:00
|
|
|
# replace channel to nigtly if needed, fix PT version and remove Horovod as it will be installed later
|
|
|
|
python -c "import re ; fname = 'environment.yml' ; req = re.sub(r'- python[>=]+[\d\.]+', '# - python=${PYTHON_VERSION}', open(fname).read()) ; open(fname, 'w').write(req)" && \
|
|
|
|
python -c "import re ; fname = 'environment.yml' ; req = re.sub(r'- pytorch[>=]+[\d\.]+', '# - pytorch=${PYTORCH_VERSION}', open(fname).read()) ; open(fname, 'w').write(req)" && \
|
2021-02-09 08:22:35 +00:00
|
|
|
python -c "import re ; fname = 'environment.yml' ; req = re.sub(r'- horovod[>=]+[\d\.]+', '# - horovod', open(fname).read()) ; open(fname, 'w').write(req)" && \
|
2020-10-26 10:47:09 +00:00
|
|
|
python -c "fname = 'environment.yml' ; req = open(fname).readlines() ; open(fname, 'w').writelines([ln for ln in req if 'horovod' not in ln])" && \
|
|
|
|
cat environment.yml && \
|
2021-01-06 16:59:42 +00:00
|
|
|
conda env update --name $CONDA_ENV --file environment.yml && \
|
2020-10-26 10:47:09 +00:00
|
|
|
conda clean -ya && \
|
|
|
|
rm environment.yml
|
|
|
|
|
2021-01-29 12:27:18 +00:00
|
|
|
ENV \
|
|
|
|
PATH /root/miniconda3/envs/${CONDA_ENV}/bin:$PATH \
|
|
|
|
LD_LIBRARY_PATH="/root/miniconda3/envs/${CONDA_ENV}/lib:$LD_LIBRARY_PATH" \
|
|
|
|
# if you want this environment to be the default one, uncomment the following line:
|
|
|
|
CONDA_DEFAULT_ENV=${CONDA_ENV}
|
2020-10-26 10:47:09 +00:00
|
|
|
|
|
|
|
COPY ./requirements/extra.txt requirements-extra.txt
|
|
|
|
COPY ./requirements/test.txt requirements-test.txt
|
2021-03-06 13:34:54 +00:00
|
|
|
COPY ./requirements/adjust_versions.py requirements_adjust_versions.py
|
2020-10-26 10:47:09 +00:00
|
|
|
|
|
|
|
RUN \
|
2021-02-09 08:22:35 +00:00
|
|
|
pip list | grep torch && \
|
|
|
|
python -c "import torch; print(torch.__version__)" && \
|
2021-03-06 13:34:54 +00:00
|
|
|
python requirements_adjust_versions.py requirements-extra.txt && \
|
2020-10-26 10:47:09 +00:00
|
|
|
# Install remaining requirements
|
2021-01-25 22:10:56 +00:00
|
|
|
pip install -r requirements-extra.txt --no-cache-dir && \
|
|
|
|
pip install -r requirements-test.txt --no-cache-dir && \
|
2020-10-26 10:47:09 +00:00
|
|
|
rm requirements*
|
|
|
|
|
2020-11-12 14:03:43 +00:00
|
|
|
RUN \
|
|
|
|
# install DALI, needed for examples
|
|
|
|
pip install --extra-index-url https://developer.download.nvidia.com/compute/redist nvidia-dali-cuda${CUDA_VERSION%%.*}0
|
|
|
|
|
2020-10-26 10:47:09 +00:00
|
|
|
RUN \
|
|
|
|
# install NVIDIA AMP
|
|
|
|
git clone https://github.com/NVIDIA/apex && \
|
|
|
|
pip install --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" ./apex && \
|
|
|
|
rm -rf apex
|
|
|
|
|
|
|
|
RUN \
|
|
|
|
# Show what we have
|
|
|
|
pip --version && \
|
|
|
|
conda info && \
|
|
|
|
pip list && \
|
|
|
|
python -c "import sys; assert sys.version[:3] == '$PYTHON_VERSION', sys.version" && \
|
2020-11-09 14:48:24 +00:00
|
|
|
python -c "import torch; assert torch.__version__[:3] == '$PYTORCH_VERSION', torch.__version__"
|