ARG PYTHON=python3 ARG PYTHON_VERSION=3.10.8 ARG MAMBA_VERSION=22.11.1-4 ARG PYTORCH_VERSION_EC2=2.0.1 ARG PYTORCH_VERSION_SM=2.0.0 FROM ubuntu:20.04 AS base_image ENV DEBIAN_FRONTEND=noninteractive \ 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" ARG PYTHON ARG PYTHON_VERSION ARG OPEN_MPI_VERSION=4.1.5 ARG MAMBA_VERSION # 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 PYTHONIOENCODING=UTF-8 ENV LANG=C.UTF-8 ENV LC_ALL=C.UTF-8 ENV LD_LIBRARY_PATH="/usr/local/lib:${LD_LIBRARY_PATH}" ENV LD_LIBRARY_PATH="/opt/conda/lib:${LD_LIBRARY_PATH}" ENV PATH=/opt/conda/bin:$PATH ENV DGLBACKEND=pytorch ENV DLC_CONTAINER_TYPE=training WORKDIR / 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 --no-install-recommends \ build-essential \ ca-certificates \ cmake \ curl \ emacs \ git \ jq \ libcurl4-openssl-dev \ libglib2.0-0 \ libgl1-mesa-glx \ libsm6 \ libssl-dev \ libxext6 \ libxrender-dev \ software-properties-common \ unzip \ vim \ wget \ zlib1g-dev \ && rm -rf /var/lib/apt/lists/* \ && apt-get clean # Install Open MPI RUN wget https://www.open-mpi.org/software/ompi/v4.1/downloads/openmpi-$OPEN_MPI_VERSION.tar.gz \ && gunzip -c openmpi-$OPEN_MPI_VERSION.tar.gz | tar xf - \ && cd openmpi-$OPEN_MPI_VERSION \ && ./configure --prefix=/home/.openmpi \ && make all install \ && cd .. \ && rm openmpi-$OPEN_MPI_VERSION.tar.gz \ && rm -rf openmpi-$OPEN_MPI_VERSION # 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 --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/* \ && apt-get clean # 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 # for conda ssl verification ENV REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt RUN curl -L -o ~/mambaforge.sh https://github.com/conda-forge/miniforge/releases/download/${MAMBA_VERSION}/Mambaforge-${MAMBA_VERSION}-Linux-x86_64.sh \ && chmod +x ~/mambaforge.sh \ && ~/mambaforge.sh -b -p /opt/conda \ && rm ~/mambaforge.sh # install core conda dependency packages (and pin essential packages) RUN /opt/conda/bin/mamba install -y --override-channels \ -c conda-forge \ conda=23.1.0 \ "cryptography>39.0.0" \ cmake \ requests \ pyopenssl \ python=$PYTHON_VERSION \ cython \ # force conda to install h5py with openmpi build, not mpich (rubik error) # https://anaconda.org/conda-forge/h5py/files?page=2 "mpi4py>=3.1.4,<3.2" \ mpi4py \ h5py \ mkl \ mkl-include \ parso \ typing \ # Below 2 are included in miniconda base, but not mamba so need to install conda-content-trust \ charset-normalizer \ packaging \ opencv \ awscli \ boto3 \ pybind11 \ pyyaml \ scipy \ click \ psutil \ ipython \ # Adding package for studio kernels ipykernel \ && /opt/conda/bin/mamba install -y -c dglteam dgl \ && /opt/conda/bin/mamba clean -afy RUN curl -o /license.txt https://aws-dlc-licenses.s3.amazonaws.com/pytorch-2.0/license.txt # The ENV variables declared below are changed in the previous section # Grouping these ENV variables in the first section causes # ompi_info to fail. This is only observed in CPU containers ENV PATH="/home/.openmpi/bin:$PATH" ENV LD_LIBRARY_PATH="/home/.openmpi/lib/:$LD_LIBRARY_PATH" RUN ompi_info --parsable --all | grep mpi_built_with_cuda_support:value # needed by torchdata RUN mkdir -p /etc/pki/tls/certs && cp /etc/ssl/certs/ca-certificates.crt /etc/pki/tls/certs/ca-bundle.crt # Removing the cache as it is needed for security verification RUN rm -rf /root/.cache | true ######################################################## # _____ ____ ____ ___ # | ____/ ___|___ \ |_ _|_ __ ___ __ _ __ _ ___ # | _|| | __) | | || '_ ` _ \ / _` |/ _` |/ _ \ # | |__| |___ / __/ | || | | | | | (_| | (_| | __/ # |_____\____|_____| |___|_| |_| |_|\__,_|\__, |\___| # |___/ # ____ _ # | _ \ ___ ___(_)_ __ ___ # | |_) / _ \/ __| | '_ \ / _ \ # | _ < __/ (__| | |_) | __/ # |_| \_\___|\___|_| .__/ \___| # |_| ######################################################## FROM common AS ec2 ARG PYTHON # PyTorch Binaries ARG PT_EC2_TRAINING_URL ARG PT_TORCHVISION_URL ARG PT_TORCHAUDIO_URL ARG PT_TORCHDATA_URL # Install ec2 AWS-PyTorch RUN /opt/conda/bin/mamba install -y pytorch=${PYTORCH_VERSION_EC2} \ torchvision torchaudio torchtext cpuonly \ --override-channels \ -c https://aws-ml-conda-ec2.s3.us-west-2.amazonaws.com \ -c conda-forge # Patches RUN pip install "pillow>=9.5" RUN /opt/conda/bin/mamba install -y -c conda-forge \ "requests>=2.31.0" # install fastai (depends on PyTorch) RUN /opt/conda/bin/mamba install -y -c conda-forge \ # needed by fastai.distributed accelerate \ && /opt/conda/bin/mamba install -y -c fastai fastai \ # fastai conda strictly depends on dataclasses && pip uninstall -y dataclasses 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* # Removing the cache as it is needed for security verification RUN rm -rf /root/.cache | true # Starts framework CMD ["/bin/bash"] ################################################################# # ____ __ __ _ # / ___| __ _ __ _ ___| \/ | __ _| | _____ _ __ # \___ \ / _` |/ _` |/ _ \ |\/| |/ _` | |/ / _ \ '__| # ___) | (_| | (_| | __/ | | | (_| | < __/ | # |____/ \__,_|\__, |\___|_| |_|\__,_|_|\_\___|_| # |___/ # ___ ____ _ # |_ _|_ __ ___ __ _ __ _ ___ | _ \ ___ ___(_)_ __ ___ # | || '_ ` _ \ / _` |/ _` |/ _ \ | |_) / _ \/ __| | '_ \ / _ \ # | || | | | | | (_| | (_| | __/ | _ < __/ (__| | |_) | __/ # |___|_| |_| |_|\__,_|\__, |\___| |_| \_\___|\___|_| .__/ \___| # |___/ |_| ################################################################# FROM common AS sagemaker LABEL maintainer="Amazon AI" LABEL dlc_major_version="1" ARG PYTHON # 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.34 ENV SAGEMAKER_TRAINING_MODULE=sagemaker_pytorch_container.training:main ARG PT_SM_TRAINING_URL ARG PT_TORCHVISION_URL ARG PT_TORCHAUDIO_URL ARG PT_TORCHDATA_URL # Install SM AWS-PyTorch (force remove will increase the docker image size drastically) RUN /opt/conda/bin/mamba install -y pytorch=${PYTORCH_VERSION_SM} \ torchvision torchaudio torchtext cpuonly \ --override-channels \ -c https://aws-ml-conda-pre-prod-ec2.s3.us-west-2.amazonaws.com \ -c conda-forge # install fastai (depends on PyTorch) RUN /opt/conda/bin/mamba install -y -c conda-forge \ # needed by fastai.distributed accelerate \ && /opt/conda/bin/mamba install -y -c fastai fastai \ # fastai conda strictly depends on dataclasses && pip uninstall -y dataclasses WORKDIR / # Copy workaround script for incorrect hostname COPY changehostname.c / COPY start_with_right_hostname.sh /usr/local/bin/start_with_right_hostname.sh RUN chmod +x /usr/local/bin/start_with_right_hostname.sh RUN pip install --no-cache-dir --upgrade pip --trusted-host pypi.org --trusted-host files.pythonhosted.org \ && pip install --no-cache-dir -U \ # disable smdebug pip install until available stable smdebug releases # smdebug==${SMDEBUG_VERSION} \ smclarify \ "sagemaker>=2,<3" \ "sagemaker-experiments<1" \ sagemaker-pytorch-training # Install smdebug from source RUN cd /tmp \ && git clone https://github.com/awslabs/sagemaker-debugger --depth 1 --single-branch --branch ${SMDEBUG_VERSION} \ && cd sagemaker-debugger \ && pip install . \ && rm -rf /tmp/* # Install extra packages RUN /opt/conda/bin/mamba install -y -c conda-forge \ bokeh \ imageio \ numba \ pandas \ plotly \ scikit-learn \ seaborn \ shap \ && /opt/conda/bin/mamba clean -afy # Patches RUN pip install "pillow>=9.5" RUN /opt/conda/bin/mamba install -y -c conda-forge \ "requests>=2.31.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* \ && rm -rf /tmp/tmp* # Removing the cache as it is needed for security verification RUN rm -rf /root/.cache | true ENTRYPOINT ["bash", "-m", "start_with_right_hostname.sh"] CMD ["/bin/bash"]