FROM nvidia/cuda:11.1.1-base-ubuntu20.04 LABEL maintainer="Amazon AI" LABEL dlc_major_version="1" ARG PYTHON=python3 ARG PYTHON_VERSION=3.8.10 ARG PYTHON_SHORT_VERSION=3.8 ARG CUBLAS_VERSION=11.3.0.106 ARG OPEN_MPI_PATH=/opt/amazon/openmpi ARG EFA_PATH=/opt/amazon/efa ARG CUDA_HOME=/usr/local/cuda ARG CONDA_PREFIX=/opt/conda ARG METIS=metis-5.1.0 ARG RMM_VERSION=0.15.0 # The smdebug pipeline relies for following format to perform string replace and trigger DLC pipeline for validating # the nightly builds. Therefore, while updating the smdebug version, please ensure that the format is not disturbed. ARG SMDEBUG_VERSION=1.0.9 # This arg required to stop docker build waiting for region configuration while installing tz data from ubuntu 20 ARG DEBIAN_FRONTEND=noninteractive # Python won’t try to write .pyc or .pyo files on the import of source modules # Force stdin, stdout and stderr to be totally unbuffered. Good for logging ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 ENV LD_LIBRARY_PATH="/usr/local/lib:${LD_LIBRARY_PATH}" ENV LD_LIBRARY_PATH="/opt/conda/lib:${LD_LIBRARY_PATH}" ENV PYTHONIOENCODING=UTF-8 ENV LANG=C.UTF-8 ENV LC_ALL=C.UTF-8 ENV PATH /opt/conda/bin:$PATH ENV TORCH_CUDA_ARCH_LIST="3.7 5.0 7.0+PTX 8.0" ENV TORCH_NVCC_FLAGS="-Xfatbin -compress-all" ENV CUDNN_VERSION=8.0.5.39 ENV NCCL_VERSION=2.7.8 ENV HOROVOD_VERSION=0.21.3 ENV EFA_VERSION=1.12.1 ENV OMPI_VERSION=4.1.1 ENV BRANCH_OFI=1.1.3-aws ENV DGLBACKEND=pytorch ENV CMAKE_PREFIX_PATH="$(dirname $(which conda))/../" ENV SAGEMAKER_TRAINING_MODULE=sagemaker_pytorch_container.training:main ENV MANUAL_BUILD=0 ENV RDMAV_FORK_SAFE=1 ARG PT_TRAINING_URL=https://aws-pytorch-cicd-v3-binaries.s3.us-west-2.amazonaws.com/r1.9.1_aws_v3/20210925-173424/7b75a1ebbf2ad37219e1a59da150faa89c2a455e/gpu/torch-1.9.1-cp38-cp38-manylinux1_x86_64.whl ARG PT_TORCHVISION_URL=https://aws-pytorch-cicd-v3-binaries.s3.us-west-2.amazonaws.com/r1.9.1_aws_v3/torchvision/gpu/torchvision-0.10.1%2Bcu111-cp38-cp38-manylinux1_x86_64.whl ARG SMD_MODEL_PARALLEL_URL=https://sagemaker-distributed-model-parallel.s3.us-west-2.amazonaws.com/pytorch-1.9.0/build-artifacts/2021-06-29-16-48/smdistributed_modelparallel-1.4.0-cp38-cp38-linux_x86_64.whl ARG SMDATAPARALLEL_BINARY=https://smdataparallel.s3.amazonaws.com/binary/pytorch/1.9.0/cu111/2021-08-13/smdistributed_dataparallel-1.2.0-cp38-cp38-linux_x86_64.whl ARG PT_S3_WHL_GPU=https://aws-s3-plugin.s3.us-west-2.amazonaws.com/binaries/0.0.1/1c3e69e/awsio-0.0.1-cp38-cp38-manylinux1_x86_64.whl RUN apt-get update \ # TODO: Remove systemd upgrade once it is updated in base image && apt-get -y upgrade --only-upgrade systemd \ && apt-get install -y --allow-change-held-packages --no-install-recommends \ build-essential \ ca-certificates \ cmake \ cuda-command-line-tools-11-1 \ cuda-cudart-11-1 \ cuda-libraries-11-1 \ curl \ emacs \ git \ jq \ libcublas-11-1=${CUBLAS_VERSION}-1 \ libcublas-dev-11-1=${CUBLAS_VERSION}-1 \ libcudnn8=$CUDNN_VERSION-1+cuda11.1 \ libcufft-dev-11-1 \ libcurand-dev-11-1 \ libcusolver-dev-11-1 \ libcusparse-dev-11-1 \ libglib2.0-0 \ libgl1-mesa-glx \ libsm6 \ libxext6 \ libxrender-dev \ libgomp1 \ libibverbs-dev \ libhwloc-dev \ libnuma1 \ libnuma-dev \ libssl1.1 \ libtool \ hwloc \ openssl \ python3-dev \ vim \ wget \ unzip \ zlib1g-dev \ jq \ && rm -rf /var/lib/apt/lists/* \ && apt-get clean RUN cd /tmp \ && git clone https://github.com/NVIDIA/nccl.git -b v${NCCL_VERSION}-1 \ && cd nccl \ && make -j64 src.build BUILDDIR=/usr/local \ && rm -rf /tmp/nccl # Install EFA along without AWS OPEN_MPI RUN mkdir /tmp/efa \ && cd /tmp/efa \ && curl -O https://s3-us-west-2.amazonaws.com/aws-efa-installer/aws-efa-installer-${EFA_VERSION}.tar.gz \ && tar -xf aws-efa-installer-${EFA_VERSION}.tar.gz \ && cd aws-efa-installer \ && ./efa_installer.sh -y --skip-kmod -g \ && rm -rf $OPEN_MPI_PATH \ && rm -rf /tmp/efa \ && rm -rf /tmp/aws-efa-installer-${EFA_VERSION}.tar.gz # Install OpenMPI without libfabric support RUN mkdir /tmp/openmpi && \ cd /tmp/openmpi && \ wget --quiet https://download.open-mpi.org/release/open-mpi/v4.1/openmpi-${OMPI_VERSION}.tar.gz && \ tar zxf openmpi-${OMPI_VERSION}.tar.gz && \ cd openmpi-${OMPI_VERSION} && \ ./configure --enable-orterun-prefix-by-default --prefix=$OPEN_MPI_PATH && \ make -j $(nproc) all && \ make install && \ ldconfig && \ cd / && \ rm -rf /tmp/openmpi ENV PATH="$OPEN_MPI_PATH/bin:$PATH" ENV LD_LIBRARY_PATH=$OPEN_MPI_PATH/lib/:$EFA_PATH/lib/:$LD_LIBRARY_PATH RUN ompi_info --parsable --all | grep mpi_built_with_cuda_support:value \ && curl -L -o ~/miniconda.sh https://repo.continuum.io/miniconda/Miniconda3-py38_4.10.3-Linux-x86_64.sh \ && chmod +x ~/miniconda.sh \ && ~/miniconda.sh -b -p ${CONDA_PREFIX} \ && rm ~/miniconda.sh \ && ${CONDA_PREFIX}/bin/conda install -c conda-forge \ python=$PYTHON_VERSION \ && ${CONDA_PREFIX}/bin/conda install -y \ # conda 4.10.0 requires ruamel_yaml to be installed. Currently pinned at latest. ruamel_yaml==0.15.100 \ && ${CONDA_PREFIX}/bin/conda install -y -c anaconda \ "numpy>=1.22.3" \ ipython \ mkl \ mkl-include \ cython \ typing \ future \ "pyopenssl>=17.5.0" \ && conda install -y -c dglteam dgl-cuda11.1=0.6.1 \ && ${CONDA_PREFIX}/bin/conda clean -ya # Conda installs links for libtinfo.so.6 and libtinfo.so.6.2 both # Which causes "/opt/conda/lib/libtinfo.so.6: no version information available" warning # Removing link for libtinfo.so.6. This change is needed only for ubuntu 20.04-conda, and can be reverted # once conda fixes the issue RUN rm -rf /opt/conda/lib/libtinfo.so.6 RUN ${CONDA_PREFIX}/bin/conda config --set ssl_verify False \ && pip install --upgrade pip --trusted-host pypi.org --trusted-host files.pythonhosted.org \ && ln -s ${CONDA_PREFIX}/bin/pip /usr/local/bin/pip3 RUN conda install -c pytorch magma-cuda111==2.5.2 \ && conda install -y scikit-learn \ pandas==1.2.4 \ h5py \ requests \ libgcc \ && conda clean -ya # Install libboost from source. This package is needed for smdataparallel functionality [for networking asynchronous IO]. RUN wget https://sourceforge.net/projects/boost/files/boost/1.73.0/boost_1_73_0.tar.gz/download -O boost_1_73_0.tar.gz \ && tar -xzf boost_1_73_0.tar.gz \ && cd boost_1_73_0 \ && ./bootstrap.sh \ && ./b2 threading=multi --prefix=${CONDA_PREFIX} -j 64 cxxflags=-fPIC cflags=-fPIC install || true \ && cd .. \ && rm -rf boost_1_73_0.tar.gz \ && rm -rf boost_1_73_0 \ && cd ${CONDA_PREFIX}/include/boost WORKDIR /opt/pytorch # Copy workaround script for incorrect hostname COPY changehostname.c / COPY start_with_right_hostname.sh /usr/local/bin/start_with_right_hostname.sh WORKDIR /root # Uninstall torch and torchvision before installing the custom versions from an S3 bucket RUN pip install --no-cache-dir -U \ opencv-python==4.5.2.54 \ "botocore>1.0,<2.0" \ "boto3>1.0,<2.0" \ "awscli<2" \ smdebug==${SMDEBUG_VERSION} \ smclarify \ "sagemaker==2.75.1" \ sagemaker-experiments==0.* \ sagemaker-pytorch-training \ "pyyaml>=5.4,<5.5" \ psutil \ "Pillow>=9.1.1" \ scipy \ pybind11 \ click \ mpi4py==3.0.3 \ cmake==3.18.2.post1 \ torchnet \ "cryptography>3.2" \ && pip uninstall -y torch \ && pip install --no-cache-dir -U ${PT_TRAINING_URL} \ && pip uninstall -y torchvision \ && pip install --no-deps --no-cache-dir -U ${PT_TORCHVISION_URL} # Install extra packages # numba 0.54 only works with numpy>=1.20. See https://github.com/numba/numba/issues/7339 RUN pip install --no-cache-dir -U \ "bokeh>=2.3,<3" \ "imageio==2.10.3" \ "opencv-python>=4.3,<5" \ "plotly==5.3.1" \ "seaborn>=0.11,<1" \ "numba==0.53.1" \ "shap>=0.39,<1" \ "jsii==1.43.0" \ "marshmallow==3.14.0" \ "matplotlib==3.4.3" \ "packaging==21.2" \ "pyarrow==6.0.0" \ "pyinstrument==4.0.4" \ "pyparsing==2.4.7" \ "protobuf>=3.20,<3.21" # install metis RUN rm /etc/apt/sources.list.d/* \ && wget -nv http://glaros.dtc.umn.edu/gkhome/fetch/sw/metis/${METIS}.tar.gz \ && gunzip -f ${METIS}.tar.gz \ && tar -xvf ${METIS}.tar \ && cd ${METIS} \ && apt-get update \ && make config shared=1 \ && make install \ && cd .. \ && rm -rf ${METIS}.tar* \ && rm -rf ${METIS} \ && rm -rf /var/lib/apt/lists/* \ && apt-get clean # Install RAPIDSMemoryManager. # Requires cmake>=3.14. RUN wget -nv https://github.com/rapidsai/rmm/archive/v${RMM_VERSION}.tar.gz \ && tar -xvf v${RMM_VERSION}.tar.gz \ && cd rmm-${RMM_VERSION} \ && INSTALL_PREFIX=/usr/local ./build.sh librmm \ && cd .. \ && rm -rf v${RMM_VERSION}.tar* \ && rm -rf rmm-${RMM_VERSION} # Install Nvidia Apex RUN git clone https://github.com/NVIDIA/apex.git \ && cd apex \ && pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" ./ # Configure Open MPI and configure NCCL parameters RUN mv $OPEN_MPI_PATH/bin/mpirun $OPEN_MPI_PATH/bin/mpirun.real \ && echo '#!/bin/bash' > $OPEN_MPI_PATH/bin/mpirun \ && echo 'mpirun.real --allow-run-as-root "$@"' >> $OPEN_MPI_PATH/bin/mpirun \ && chmod a+x $OPEN_MPI_PATH/bin/mpirun \ && echo "hwloc_base_binding_policy = none" >> $OPEN_MPI_PATH/etc/openmpi-mca-params.conf \ && echo "rmaps_base_mapping_policy = slot" >> $OPEN_MPI_PATH/etc/openmpi-mca-params.conf \ && echo NCCL_DEBUG=INFO >> /etc/nccl.conf \ && echo NCCL_SOCKET_IFNAME=^docker0 >> /etc/nccl.conf # Install AWS OFI NCCL plug-in RUN apt-get update && apt-get install -y autoconf RUN mkdir /tmp/efa-ofi-nccl \ && cd /tmp/efa-ofi-nccl \ && git clone https://github.com/aws/aws-ofi-nccl.git -b v${BRANCH_OFI} \ && cd aws-ofi-nccl \ && ./autogen.sh \ && ./configure --with-libfabric=/opt/amazon/efa \ --with-mpi=/opt/amazon/openmpi \ --with-cuda=/usr/local/cuda \ --with-nccl=/usr/local --prefix=/usr/local \ && make \ && make install \ && rm -rf /tmp/efa-ofi-nccl # Install OpenSSH for MPI to communicate between containers, allow OpenSSH to talk to containers without asking for confirmation RUN apt-get update \ && apt-get install -y --allow-downgrades --allow-change-held-packages --no-install-recommends \ && apt-get install -y --no-install-recommends openssh-client openssh-server \ && mkdir -p /var/run/sshd \ && cat /etc/ssh/ssh_config | grep -v StrictHostKeyChecking > /etc/ssh/ssh_config.new \ && echo " StrictHostKeyChecking no" >> /etc/ssh/ssh_config.new \ && mv /etc/ssh/ssh_config.new /etc/ssh/ssh_config \ && rm -rf /var/lib/apt/lists/* # Configure OpenSSH so that nodes can communicate with each other RUN mkdir -p /var/run/sshd && \ sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd RUN rm -rf /root/.ssh/ && \ mkdir -p /root/.ssh/ && \ ssh-keygen -q -t rsa -N '' -f /root/.ssh/id_rsa && \ cp /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys \ && printf "Host *\n StrictHostKeyChecking no\n" >> /root/.ssh/config # Install Horovod RUN pip uninstall -y horovod \ && ldconfig /usr/local/cuda-11.1/targets/x86_64-linux/lib/stubs \ && HOROVOD_GPU_ALLREDUCE=NCCL HOROVOD_CUDA_HOME=/usr/local/cuda-11.1 HOROVOD_WITH_PYTORCH=1 pip install --no-cache-dir horovod==${HOROVOD_VERSION} \ && ldconfig # Install SM Distributed Modelparallel binary RUN pip install --no-cache-dir -U ${SMD_MODEL_PARALLEL_URL} # Install SM Distributed DataParallel binary RUN SMDATAPARALLEL_PT=1 pip install --no-cache-dir ${SMDATAPARALLEL_BINARY} ENV LD_LIBRARY_PATH="/opt/conda/lib/python${PYTHON_SHORT_VERSION}/site-packages/smdistributed/dataparallel/lib:$LD_LIBRARY_PATH" # Install PT S3 plugin RUN pip install --no-cache-dir -U ${PT_S3_WHL_GPU} RUN mkdir -p /etc/pki/tls/certs && cp /etc/ssl/certs/ca-certificates.crt /etc/pki/tls/certs/ca-bundle.crt WORKDIR / COPY deep_learning_container.py /usr/local/bin/deep_learning_container.py RUN chmod +x /usr/local/bin/start_with_right_hostname.sh \ && chmod +x /usr/local/bin/deep_learning_container.py RUN HOME_DIR=/root \ && curl -o ${HOME_DIR}/oss_compliance.zip https://aws-dlinfra-utilities.s3.amazonaws.com/oss_compliance.zip \ && unzip ${HOME_DIR}/oss_compliance.zip -d ${HOME_DIR}/ \ && cp ${HOME_DIR}/oss_compliance/test/testOSSCompliance /usr/local/bin/testOSSCompliance \ && chmod +x /usr/local/bin/testOSSCompliance \ && chmod +x ${HOME_DIR}/oss_compliance/generate_oss_compliance.sh \ && ${HOME_DIR}/oss_compliance/generate_oss_compliance.sh ${HOME_DIR} ${PYTHON} \ && rm -rf ${HOME_DIR}/oss_compliance* \ && rm -rf /tmp/tmp* RUN curl -o /license.txt https://aws-dlc-licenses.s3.amazonaws.com/pytorch-1.9/license.txt # Starts framework ENTRYPOINT ["bash", "-m", "start_with_right_hostname.sh"] CMD ["/bin/bash"]