FROM ubuntu:20.04 AS base_image ENV DEBIAN_FRONTEND=noninteractive \ LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/local/lib" RUN apt-get update \ && apt-get upgrade -y \ && apt-get autoremove -y \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* FROM base_image AS common LABEL maintainer="Amazon AI" LABEL dlc_major_version="1" # TensorFlow major.minor version ENV TF_VERSION=2.12 # prevent stopping by user interaction ENV DEBIAN_FRONTEND noninteractive ENV DEBCONF_NONINTERACTIVE_SEEN true # Set environment variables for MKL # For more about MKL with TensorFlow see: # https://www.tensorflow.org/performance/performance_guide#tensorflow_with_intel%C2%AE_mkl_dnn ENV KMP_AFFINITY=granularity=fine,compact,1,0 ENV KMP_BLOCKTIME=1 ENV KMP_SETTINGS=0 ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 ENV PYTHONIOENCODING=UTF-8 ENV LANG=C.UTF-8 ENV LC_ALL=C.UTF-8 ARG PYTHON=python3.10 ARG PYTHON_VERSION=3.10.10 ARG PIP=pip3 ARG OMPI_VERSION=4.1.5 # To be passed to ec2 and sagemaker stages ENV PYTHON=${PYTHON} ENV PYTHON_VERSION=${PYTHON_VERSION} ENV PIP=${PIP} RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ openssh-client \ openssh-server \ ca-certificates \ curl \ emacs \ git \ libtemplate-perl \ libssl1.1 \ openssl \ unzip \ wget \ vim \ zlib1g-dev \ # Install dependent library for OpenCV libgtk2.0-dev \ && rm -rf /var/lib/apt/lists/* # Install Open MPI 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 \ && 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 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 ENV LD_LIBRARY_PATH=/usr/local/openmpi/lib:$LD_LIBRARY_PATH ENV PATH /usr/local/openmpi/bin/:$PATH # SSH login fix. Otherwise user is kicked off after login RUN 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/ \ && mkdir -p /var/run/sshd \ && 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 \ libcurl4-openssl-dev \ libffi-dev \ libgdbm-dev \ liblzma-dev \ libncursesw5-dev \ libreadline-gplv2-dev \ libsqlite3-dev \ libssl-dev \ tk-dev \ ffmpeg \ libsm6 \ libxext6 \ && 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 -j $(nproc) \ && 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 ${PYTHON}) /usr/local/bin/python \ && ln -s $(which ${PIP}) /usr/bin/pip RUN apt-get update && apt-get -y install protobuf-compiler # install PyYAML==5.1.2 to avoid conflict with latest awscli RUN ${PIP} install --no-cache-dir -U \ pybind11 \ cmake \ scipy \ Pillow \ python-dateutil \ "pyYAML>=5.4,<5.5" \ requests \ "awscli<2" \ mpi4py \ # Let's install TensorFlow separately in the end to avoid # the library version to be overwritten && ${PIP} install --no-cache-dir -U \ h5py \ absl-py \ opencv-python \ werkzeug \ psutil \ urllib3 \ "protobuf<4" ADD https://raw.githubusercontent.com/aws/deep-learning-containers/master/src/deep_learning_container.py /usr/local/bin/deep_learning_container.py RUN chmod +x /usr/local/bin/deep_learning_container.py RUN curl https://aws-dlc-licenses.s3.amazonaws.com/tensorflow-${TF_VERSION}/license.txt -o /license.txt ######################################################## # _____ ____ ____ ___ # | ____/ ___|___ \ |_ _|_ __ ___ __ _ __ _ ___ # | _|| | __) | | || '_ ` _ \ / _` |/ _` |/ _ \ # | |__| |___ / __/ | || | | | | | (_| | (_| | __/ # |_____\____|_____| |___|_| |_| |_|\__,_|\__, |\___| # |___/ # ____ _ # | _ \ ___ ___(_)_ __ ___ # | |_) / _ \/ __| | '_ \ / _ \ # | _ < __/ (__| | |_) | __/ # |_| \_\___|\___|_| .__/ \___| # |_| ######################################################## FROM common AS ec2 ARG TF_URL=https://framework-binaries.s3.us-west-2.amazonaws.com/tensorflow/r2.12_aws/cpu/2023-03-23-00-31/tensorflow_cpu-2.12.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl RUN ${PIP} install --no-cache-dir -U \ ${TF_URL} \ tensorflow-io \ tensorflow-datasets # Install Horovod with TensorFlow RUN HOROVOD_WITH_MPI=1 \ && HOROVOD_WITH_TENSORFLOW=1 HOROVOD_WITHOUT_MXNET=1 HOROVOD_WITHOUT_PYTORCH=1 \ && ${PIP} install --no-cache-dir horovod==0.27.0 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* # remove tmp files RUN rm -rf /tmp/* CMD ["/bin/bash"] ################################################################# # ____ __ __ _ # / ___| __ _ __ _ ___| \/ | __ _| | _____ _ __ # \___ \ / _` |/ _` |/ _ \ |\/| |/ _` | |/ / _ \ '__| # ___) | (_| | (_| | __/ | | | (_| | < __/ | # |____/ \__,_|\__, |\___|_| |_|\__,_|_|\_\___|_| # |___/ # ___ ____ _ # |_ _|_ __ ___ __ _ __ _ ___ | _ \ ___ ___(_)_ __ ___ # | || '_ ` _ \ / _` |/ _` |/ _ \ | |_) / _ \/ __| | '_ \ / _ \ # | || | | | | | (_| | (_| | __/ | _ < __/ (__| | |_) | __/ # |___|_| |_| |_|\__,_|\__, |\___| |_| \_\___|\___|_| .__/ \___| # |___/ |_| ################################################################# FROM common AS sagemaker LABEL maintainer="Amazon AI" LABEL dlc_major_version="1" ARG TF_URL=https://framework-binaries.s3.us-west-2.amazonaws.com/tensorflow/r2.12_aws/cpu/2023-03-23-00-31/tensorflow_cpu-2.12.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl # sagemaker-specific environment variable ENV SAGEMAKER_TRAINING_MODULE sagemaker_tensorflow_container.training:main # dependencies for opencv # these dependencies are not needed for gpu image RUN apt-get update && apt-get install -y --no-install-recommends \ libgtk2.0-dev \ && apt-get install -y -qq libkrb5-dev \ && apt-get install -y -qq libsasl2-dev libsasl2-modules \ && apt-get install -y -qq krb5-user \ && rm -rf /var/lib/apt/lists/* # https://github.com/tensorflow/models/issues/9267 # tf-models does not respect existing installations of TF and always installs open source TF RUN ${PIP} install --no-cache-dir -U \ tf-models-official==2.12.0 \ tensorflow-text==2.12.0 RUN ${PIP} uninstall -y tensorflow tensorflow-gpu \ ; ${PIP} install --no-cache-dir -U \ ${TF_URL} \ tensorflow-io \ tensorflow-datasets # Install Horovod with TensorFlow RUN HOROVOD_WITH_MPI=1 \ && HOROVOD_WITH_TENSORFLOW=1 HOROVOD_WITHOUT_MXNET=1 HOROVOD_WITHOUT_PYTORCH=1 \ && ${PIP} install --no-cache-dir horovod==0.27.0 RUN $PYTHON -m pip install --no-cache-dir -U \ numba \ bokeh \ imageio \ opencv-python \ plotly \ seaborn \ shap RUN $PYTHON -m pip install --no-cache-dir -U \ "sagemaker<3" \ sagemaker-experiments==0.* \ sagemaker-tensorflow-training \ sagemaker-training \ "sagemaker-studio-analytics-extension<1" \ "sparkmagic<1" \ "sagemaker-studio-sparkmagic-lib<1" \ smclarify # install smdebug directly the specific branch ARG SMDEBUG_TAG=1.0.33 RUN git clone https://github.com/awslabs/sagemaker-debugger.git \ && cd sagemaker-debugger \ && git checkout tags/$SMDEBUG_TAG -b $SMDEBUG_TAG \ && $PYTHON setup.py install && cd .. && rm -rf sagemaker-debugger # install sagemaker-tensorflow from source ARG SAGEMAKER_TENSORFLOW_TAG=v1.18.0 RUN git clone -b tf-2 https://github.com/aws/sagemaker-tensorflow-extensions.git \ && cd sagemaker-tensorflow-extensions \ && git checkout tags/$SAGEMAKER_TENSORFLOW_TAG -b $SAGEMAKER_TENSORFLOW_TAG \ && $PYTHON -m pip install . \ && cd .. && rm -rf sagemaker-tensorflow-extensions # Remove python kernel installed by sparkmagic RUN /usr/local/bin/jupyter-kernelspec remove -f python3 # remove tmp files RUN rm -rf /tmp/* 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* CMD ["/bin/bash"]