# Nvidia does not publish a TensorRT Runtime library for Ubuntu 18.04 with Cuda 10.1 support, so we stick with cuda 10.0. # https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/ FROM nvidia/cuda:10.0-base-ubuntu18.04 LABEL maintainer="Amazon AI" LABEL dlc_major_version="4" # Prevent docker build get stopped by requesting user interaction ENV DEBIAN_FRONTEND=noninteractive ENV DEBCONF_NONINTERACTIVE_SEEN=true # Python won’t try to write .pyc or .pyo files on the import of source modules ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 # See http://bugs.python.org/issue19846 ENV PYTHONIOENCODING=UTF-8 ENV LANG=C.UTF-8 ENV LC_ALL=C.UTF-8 # Specify the location of module that contains the training logic for SageMaker # https://docs.aws.amazon.com/sagemaker/latest/dg/docker-container-environmental-variables-entrypoint.html ENV SAGEMAKER_TRAINING_MODULE=sagemaker_tensorflow_container.training:main # Define framework-related package sources ARG TF_URL=https://aws-tensorflow-binaries.s3-us-west-2.amazonaws.com/tensorflow/r1.15_aws/20210225-220854/gpu/cu100/py36/tensorflow_gpu-1.15.5-cp36-cp36m-manylinux2010_x86_64.whl # 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=0.9.4 ARG PYTHON=python3 ARG PYTHON_PIP=python3-pip ARG PIP=pip3 ARG PYTHON_VERSION=3.6.13 RUN apt-get update \ && apt-get install -y --no-install-recommends --allow-unauthenticated \ ca-certificates \ cuda-command-line-tools-10-0 \ cuda-cublas-dev-10-0 \ cuda-cudart-dev-10-0 \ cuda-cufft-dev-10-0 \ cuda-curand-dev-10-0 \ cuda-cusolver-dev-10-0 \ cuda-cusparse-dev-10-0 \ curl \ emacs \ libcudnn7=7.5.1.10-1+cuda10.0 \ # TensorFlow doesn't require libnccl anymore but Open MPI still depends on it libnccl2=2.4.7-1+cuda10.0 \ libgomp1 \ libnccl-dev=2.4.7-1+cuda10.0 \ libfreetype6-dev \ libhdf5-serial-dev \ libpng-dev \ libzmq3-dev \ git \ unzip \ wget \ vim \ build-essential \ openssh-client \ openssh-server \ libssl1.1 \ openssl \ zlib1g-dev \ # Install dependent library for OpenCV libgtk2.0-dev \ # The 'apt-get install' of nvinfer-runtime-trt-repo-ubuntu1804-5.0.2-ga-cuda10.0 # adds a new list which contains libnvinfer library, so it needs another # 'apt-get update' to retrieve that list before it can actually install the # library. # We don't install libnvinfer-dev since we don't need to build against TensorRT, # and libnvinfer4 doesn't contain libnvinfer.a static library. && apt-get update && apt-get install -y --no-install-recommends --allow-unauthenticated \ nvinfer-runtime-trt-repo-ubuntu1804-5.0.2-ga-cuda10.0 \ && apt-get update && apt-get install -y --no-install-recommends --allow-unauthenticated \ libnvinfer5=5.0.2-1+cuda10.0 \ && rm /usr/lib/x86_64-linux-gnu/libnvinfer_plugin* \ && rm /usr/lib/x86_64-linux-gnu/libnvcaffe_parser* \ && rm /usr/lib/x86_64-linux-gnu/libnvparsers* \ && rm -rf /var/lib/apt/lists/* \ && mkdir -p /var/run/sshd ########################################################################### # Horovod & its dependencies ########################################################################### # Install Open MPI RUN mkdir /tmp/openmpi \ && cd /tmp/openmpi \ && curl -fSsL -O https://download.open-mpi.org/release/open-mpi/v4.0/openmpi-4.0.1.tar.gz \ && tar zxf openmpi-4.0.1.tar.gz \ && cd openmpi-4.0.1 \ && ./configure --enable-orterun-prefix-by-default \ && make -j $(nproc) all \ && make install \ && ldconfig \ && rm -rf /tmp/openmpi # Create a wrapper for OpenMPI to allow running as root by default RUN mv /usr/local/bin/mpirun /usr/local/bin/mpirun.real \ && echo '#!/bin/bash' > /usr/local/bin/mpirun \ && echo 'mpirun.real --allow-run-as-root "$@"' >> /usr/local/bin/mpirun \ && chmod a+x /usr/local/bin/mpirun # Configure OpenMPI to run good defaults: # --bind-to none --map-by slot --mca btl_tcp_if_exclude lo,docker0 RUN echo "hwloc_base_binding_policy = none" >> /usr/local/etc/openmpi-mca-params.conf \ && echo "rmaps_base_mapping_policy = slot" >> /usr/local/etc/openmpi-mca-params.conf # Set default NCCL parameters RUN echo NCCL_DEBUG=INFO >> /etc/nccl.conf ENV LD_LIBRARY_PATH=/usr/local/openmpi/lib:$LD_LIBRARY_PATH # Resolve missing libcuda.so issue RUN cp /usr/local/cuda-10.0/extras/CUPTI/lib64/libcupti* /usr/local/cuda/lib64/ ENV LD_LIBRARY_PATH=/usr/local/cuda/lib64/:$LD_LIBRARY_PATH ENV PATH=/usr/local/openmpi/bin/:$PATH ENV PATH=/usr/local/nvidia/bin:$PATH # SSH login fix. Otherwise user is kicked off after login 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 # Create SSH key. RUN 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 WORKDIR / RUN apt-get update \ && apt-get install -y --no-install-recommends \ libbz2-dev \ libc6-dev \ libffi-dev \ libgdbm-dev \ libncursesw5-dev \ libreadline-gplv2-dev \ libsqlite3-dev \ libssl-dev \ tk-dev \ # Needed for open-cv to resolve error: ImportError: libGL.so.1: cannot open shared object file: No such file or directory libgl1-mesa-glx \ && rm -rf /var/lib/apt/lists/* \ && apt-get clean RUN wget https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz \ && tar -xvf Python-$PYTHON_VERSION.tgz \ && cd Python-$PYTHON_VERSION \ && ./configure && make && make install \ && rm -rf ../Python-$PYTHON_VERSION* RUN ${PIP} --no-cache-dir install --upgrade \ pip \ setuptools # Some TF tools expect a "python" binary RUN ln -s $(which python3) /usr/local/bin/python \ && ln -s $(which pip3) /usr/bin/pip RUN pip install --no-cache-dir -U \ numpy==1.18.5 \ scipy==1.2.2 \ scikit-learn==0.20.3 \ pandas==0.24.2 \ Pillow \ keras_applications==1.0.8 \ keras_preprocessing==1.1.0 \ requests==2.22.0 \ keras==2.3.1 \ smdebug==${SMDEBUG_VERSION} \ "sagemaker>=2,<3" \ sagemaker-experiments==0.* \ mpi4py==3.0.2 \ "cryptography>=2.3" \ "sagemaker-tensorflow>=1.15,<1.16" \ "sagemaker-tensorflow-training>=10,<20" \ # Let's install TensorFlow separately in the end to avoid # the library version to be overwritten && pip install --force-reinstall --no-cache-dir -U \ ${TF_URL} \ h5py==2.9.0 \ && pip install --no-cache-dir -U \ # install PyYAML>=5.4,<5.5 to avoid conflict with latest awscli "pyYAML>=5.4,<5.5" \ "awscli<2" \ smdebug==${SMDEBUG_VERSION} # 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.9,<3" \ "opencv-python>=4.3,<5" \ "plotly>=5.1,<6" \ "seaborn>=0.11,<1" \ "numba<0.54" \ "shap>=0.39,<1" # Install Horovod, temporarily using CUDA stubs RUN ldconfig /usr/local/cuda-10.0/targets/x86_64-linux/lib/stubs \ && HOROVOD_GPU_ALLREDUCE=NCCL HOROVOD_WITH_TENSORFLOW=1 pip install --no-cache-dir \ horovod==0.19.5 \ && ldconfig # Allow OpenSSH to talk to containers without asking for confirmation RUN 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 COPY deep_learning_container.py /usr/local/bin/deep_learning_container.py RUN 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* RUN curl https://aws-dlc-licenses.s3.amazonaws.com/tensorflow/license.txt -o /license.txt CMD ["/bin/bash"]