本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
第 2 步:启动 SageMaker 使用分布式培训 Job SageMaker Python 开发工具包
在中运行你的改编脚本第 1 步:修改您自己的训练脚本,首先使用准备好的训练脚本和分布式训练配置参数创建 SageMaker 框架或通用估计器对象。您可以在任何类型的中使用库 SageMaker 环境和 Web IDE,例如SageMaker 笔记本实例和SageMaker Studio.
使用高级别SageMaker Python 开发工具
-
如果您想在 SageMaker 中快速采用分布式培训作业,请配置 SageMaker PyTorch
要么TensorFlow 框架估算器类。框架估算器会拿起你的训练脚本并自动匹配预构建 PyTorch 要么 TensorFlow Deep Learning Containers (DLC) ,给定指定的值 framework_version参数。 -
如果要扩展其中一个预构建的容器或构建自定义容器以使用 SageMaker 创建自己的机器学习环境,请使用 SageMaker 通用的
Estimator类,并指定 Amazon Elastic Container Registry (Amazon ECR) 中托管的自定义 Docker 容器的映像 URI。
您的训练数据集应存储在 Amazon S3 中或Amazon FSx for Lustre中的Amazon Web Services 区域你正在开始训练工作。如果你使用 Jupyter 笔记本电脑,你应该有 SageMaker 笔记本实例或 SageMaker Studio 应用程序在同一个中运行Amazon Web Services 区域. 有关存储训练数据的更多信息,请参阅SageMaker Python SDK 数据输入
我们强烈建议您使用适用 Amazon FSx for Lustre,而不是 Amazon S3,以提高训练绩效。与 Amazon S3 相比,Amazon FSx 的吞吐量更高,延迟更低。
选择以下主题之一,了解有关如何运行 TensorFlow 或 PyTorch 训练脚本。启动培训作业后,您可以使用以下方法监视系统利用率和建模性能。亚马逊SageMakerDebugger (调试程序)或 Amazon CloudWatch。
当您按照以下主题中的说明了解有关技术细节的更多信息时,我们还建议您尝试亚马逊 SageMaker 分布式训练记本示例开始使用。
主题
使用 SageMaker 框架估算器对于 PyTorch TensorFlow
您可以激活 SageMaker 分布式数据 parallel 库distribution中的策略SageMaker 框架估算器类
的以下两个参数 SageMaker 需要框架估算器才能激活 SageMaker 数据并行。
distribution(dict):包含有关如何运行分布式训练的信息的字典(默认值:None)。
-
使用
smdistributed.dataparallel作为分发策略,请按以下代码所示配置字典:distribution = { "smdistributed": { "dataparallel": { "enabled": True } } }
-
custom_mpi_options(str)(可选):自定义 MPI 选项。下面是说明定义时如何使用此参数的示例。distribution. 要了解更多信息,请参阅 自定义 MPI 选项。distribution = { "smdistributed": { "dataparallel": { "enabled": True, "custom_mpi_options": "-verbose -x NCCL_DEBUG=VERSION" } } }
instance_type(str): 要使用的 Amazon EC2 实例的类型。
-
如果使用
smdistributed和dataparallel分配策略,您必须使用以下实例类型之一:ml.p4d.24xlarge、ml.p3dn.24xlarge,以及ml.p3.16xlarge. 为获得最佳性能,我们建议您使用启用 EFA 的实例,ml.p3dn.24xlarge和ml.p4d.24xlarge.
使用 SageMaker 用于扩展预构建容器的通用估计器
您可以自定义 SageMaker 预构建的容器或扩展,以满足预构建的算法或模型的任何其他功能要求 SageMaker Docker 镜像不支持。有关如何扩展预构建的容器的示例,请参阅扩展预构建的容器.
要扩展预构建的容器或调整自己的容器以使用库,必须使用中列出的其中一个映像支持的框架.
从 TensorFlow 2.4.1 和 PyTorch 1.8.1,框架 DLC 支持启用 EFA 的实例类型 (ml.p3dn.24xlarge、ml.p4d.24xlarge)。我们建议您使用包含 DLC 映像 TensorFlow 2.4.1 或更高版本 PyTorch 1.8.1 或更高版本。
例如,如果你使用 PyTorch,你的 Dockerfile 应该包含FROM类似于以下内容:
# SageMaker PyTorch image FROM 763104351884.dkr.ecr.<aws-region>.amazonaws.com/pytorch-training:<image-tag>ENV PATH="/opt/ml/code:${PATH}" # this environment variable is used by the SageMaker PyTorch container to determine our user code directory. ENV SAGEMAKER_SUBMIT_DIRECTORY /opt/ml/code # /opt/ml and all subdirectories are utilized by SageMaker, use the /code subdirectory to store your user code. COPY cifar10.py /opt/ml/code/cifar10.py # Defines cifar10.py as script entrypoint ENV SAGEMAKER_PROGRAM cifar10.py
您可以进一步自定义自己的 Docker 容器以使用 SageMaker 使用SageMaker 培训工具包
使用创建自己的 Docker 容器 SageMaker 分布式数据并行库
要构建自己的 Docker 容器进行训练并使用 SageMaker data parallel 库,必须包含正确的依赖关系和的二进制文件 SageMaker Dockerfile 中的分布式 parallel 库。本节提供了有关如何使用数据 parallel 库在 SageMaker 中使用分布式训练创建一个完整的 Dockerfile 的说明,其中包含最少的依赖关系集。
这个自定义 Docker 选项带 SageMaker 数据 parallel 库作为二进制文件仅适用于 PyTorch。
使用 SageMaker 培训工具包和数据 parallel 库
-
从中的 Docker 镜像开始NVIDIA CUDA
. 使用包含 CUDA 运行时和开发工具(标头和库)的 CUDNN 开发人员版本从PyTorch 源代码 . FROM nvidia/cuda:11.3.1-cudnn8-devel-ubuntu20.04提示 官方Amazon深度学习容器 (DLC) 映像是从NVIDIA CUDA 基本映像
. 如果要在遵循其余说明的同时使用预构建的 DLC 映像作为参考,请参阅Amazon用于的 Deep Learning Containers PyTorch Dockerfile . -
添加以下参数以指定的版本 PyTorch 和其他软件包。另外,Amazon S3 明指向 SageMaker 数据 parallel 库和其他要使用的软件Amazon资源,例如 Amazon S3 插件。
要使用以下代码示例中提供的版本以外的第三方库版本,我们建议您查看的官方 DockerfileAmazonPyTorch 的深度学习容器
查找经过测试、兼容且适合您的应用程序的版本。 查找适用于
SMDATAPARALLEL_BINARY参数,请参见查找表支持的框架.ARG PYTORCH_VERSION=1.10.2ARG PYTHON_SHORT_VERSION=3.8ARG EFA_VERSION=1.14.1ARG SMDATAPARALLEL_BINARY=https://smdataparallel.s3.amazonaws.com/binary/pytorch/${PYTORCH_VERSION}/cu113/2022-02-18/smdistributed_dataparallel-1.4.0-cp38-cp38-linux_x86_64.whlARG 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 ARG CONDA_PREFIX="/opt/conda" ARG BRANCH_OFI=1.1.3-aws -
设置以下环境变量以正确构建 SageMaker 训练组件并运行数据 parallel 库。在后续步骤中,您可以将这些变量用于组件。
# Set ENV variables required to build PyTorch ENV TORCH_CUDA_ARCH_LIST="7.0+PTX 8.0" ENV TORCH_NVCC_FLAGS="-Xfatbin -compress-all" ENV NCCL_VERSION=2.10.3 # Add OpenMPI to the path. ENV PATH /opt/amazon/openmpi/bin:$PATH # Add Conda to path ENV PATH $CONDA_PREFIX/bin:$PATH # Set this enviroment variable for SageMaker to launch SMDDP correctly. ENV SAGEMAKER_TRAINING_MODULE=sagemaker_pytorch_container.training:main # Add enviroment variable for processes to be able to call fork() ENV RDMAV_FORK_SAFE=1 # Indicate the container type ENV DLC_CONTAINER_TYPE=training # Add EFA and SMDDP to LD library path ENV LD_LIBRARY_PATH="/opt/conda/lib/python${PYTHON_SHORT_VERSION}/site-packages/smdistributed/dataparallel/lib:$LD_LIBRARY_PATH" ENV LD_LIBRARY_PATH=/opt/amazon/efa/lib/:$LD_LIBRARY_PATH -
安装或更新
curl、wget, 和git在后续步骤中下载和构建软件包。RUN --mount=type=cache,id=apt-final,target=/var/cache/apt \ apt-get update && apt-get install -y --no-install-recommends \ curl \ wget \ git \ && rm -rf /var/lib/apt/lists/* -
安装EFA Elastic Fabric Adapter (EFA)适用于 Amazon EC2 网络通信的软件。
RUN DEBIAN_FRONTEND=noninteractive apt-get update RUN mkdir /tmp/efa \ && cd /tmp/efa \ && curl --silent -O https://efa-installer.amazonaws.com/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 /tmp/efa -
安装Conda
来处理软件包管理。 RUN curl -fsSL -v -o ~/miniconda.sh -O https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ chmod +x ~/miniconda.sh && \ ~/miniconda.sh -b -p $CONDA_PREFIX && \ rm ~/miniconda.sh && \ $CONDA_PREFIX/bin/conda install -y python=${PYTHON_SHORT_VERSION} conda-build pyyaml numpy ipython && \ $CONDA_PREFIX/bin/conda clean -ya -
获取、构建和安装 PyTorch 以及它的依赖关系。我们建源代码中的 PyTorch
因为我们需要控制 NCCL 版本才能保证与AmazonOFI NCCL 插件 . -
按照中的步骤操作PyTorch 官方 Dockerfile
,安装构建依赖关系并设置ccache 以加快重新编译速度。 RUN DEBIAN_FRONTEND=noninteractive \ apt-get install -y --no-install-recommends \ build-essential \ ca-certificates \ ccache \ cmake \ git \ libjpeg-dev \ libpng-dev \ && rm -rf /var/lib/apt/lists/* # Setup ccache RUN /usr/sbin/update-ccache-symlinks RUN mkdir /opt/ccache && ccache --set-config=cache_dir=/opt/ccache -
# Common dependencies for PyTorch RUN conda install astunparse numpy ninja pyyaml mkl mkl-include setuptools cmake cffi typing_extensions future six requests dataclasses # Linux specific dependency for PyTorch RUN conda install -c pytorch magma-cuda113 -
RUN --mount=type=cache,target=/opt/ccache \ cd / \ && git clone --recursive https://github.com/pytorch/pytorch -b v${PYTORCH_VERSION} -
安装和构建特定的NCCL
版本。为此,请替换 PyTorch 默认 NCCL 文件夹中的内容( /pytorch/third_party/nccl) 使用来自 NVIDIA 存储库的特定 NCCL 版本。NCCL 版本是在本指南的步骤 3 中设置的。RUN cd /pytorch/third_party/nccl \ && rm -rf nccl \ && git clone https://github.com/NVIDIA/nccl.git -b v${NCCL_VERSION}-1 \ && cd nccl \ && make -j64 src.build CUDA_HOME=/usr/local/cuda NVCC_GENCODE="-gencode=arch=compute_70,code=sm_70 -gencode=arch=compute_80,code=sm_80" \ && make pkg.txz.build \ && tar -xvf build/pkg/txz/nccl_*.txz -C $CONDA_PREFIX --strip-components=1 -
构建并安装 PyTorch。完成此过程通常需要稍多时间。它使用上一步中下载的 NCCL 版本构建。
RUN cd /pytorch \ && CMAKE_PREFIX_PATH="$(dirname $(which conda))/../" \ python setup.py install \ && rm -rf /pytorch
-
-
构建和安装AmazonOFI NCCL 插件
. 此操作启用Libfabric 支持 SageMaker 数据 parallel 库。 RUN DEBIAN_FRONTEND=noninteractive apt-get update \ && apt-get install -y --no-install-recommends \ autoconf \ automake \ libtool 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=$CONDA_PREFIX \ && make \ && make install \ && rm -rf /tmp/efa-ofi-nccl -
构建和安装TorchVision
. RUN pip install --no-cache-dir -U \ packaging \ mpi4py==3.0.3 RUN cd /tmp \ && git clone https://github.com/pytorch/vision.git -b v0.9.1 \ && cd vision \ && BUILD_VERSION="0.9.1+cu111" python setup.py install \ && cd /tmp \ && rm -rf vision -
安装和配置 OpenSSH。MPI 需要 OpenSSH 才能在容器之间进行通信。允许 OpenSSH 与集装箱交谈,而不提示确认。
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 -
安装 PT S3 插件以高效访问 Amazon S3 中的数据集。
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 -
安装libboost
库. 该软件包是联网的异步 IO 功能所需的 SageMaker 数据 parallel 库。 WORKDIR / 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 -
安装以下内容 SageMaker 用于的工具 PyTorch 训练。
WORKDIR /root RUN pip install --no-cache-dir -U \ smclarify \ "sagemaker>=2,<3" \ sagemaker-experiments==0.* \ sagemaker-pytorch-training -
最后,安装 SageMaker 数据 parallel 二进制文件和其余依赖项。
RUN --mount=type=cache,id=apt-final,target=/var/cache/apt \ apt-get update && apt-get install -y --no-install-recommends \ jq \ libhwloc-dev \ libnuma1 \ libnuma-dev \ libssl1.1 \ libtool \ hwloc \ && rm -rf /var/lib/apt/lists/* RUN SMDATAPARALLEL_PT=1 pip install --no-cache-dir ${SMDATAPARALLEL_BINARY} -
创建完 Dockerfile 后,请参阅修改自己的训练容器了解如何构建 Docker 容器,将其托管在 Amazon ECR 中,然后使用 SageMaker Python 开发工具包。
以下示例代码显示了组合之前的所有代码块之后的完整 Dockerfile。
# This file creates a docker image with minimum dependencies to run SageMaker data parallel training FROM nvidia/cuda:11.3.1-cudnn8-devel-ubuntu20.04 # Set appropiate versions and location for components ARG PYTORCH_VERSION=1.10.2 ARG PYTHON_SHORT_VERSION=3.8 ARG EFA_VERSION=1.14.1 ARG SMDATAPARALLEL_BINARY=https://smdataparallel.s3.amazonaws.com/binary/pytorch/${PYTORCH_VERSION}/cu113/2022-02-18/smdistributed_dataparallel-1.4.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 ARG CONDA_PREFIX="/opt/conda" ARG BRANCH_OFI=1.1.3-aws # Set ENV variables required to build PyTorch ENV TORCH_CUDA_ARCH_LIST="3.7 5.0 7.0+PTX 8.0" ENV TORCH_NVCC_FLAGS="-Xfatbin -compress-all" ENV NCCL_VERSION=2.10.3 # Add OpenMPI to the path. ENV PATH /opt/amazon/openmpi/bin:$PATH # Add Conda to path ENV PATH $CONDA_PREFIX/bin:$PATH # Set this enviroment variable for SageMaker to launch SMDDP correctly. ENV SAGEMAKER_TRAINING_MODULE=sagemaker_pytorch_container.training:main # Add enviroment variable for processes to be able to call fork() ENV RDMAV_FORK_SAFE=1 # Indicate the container type ENV DLC_CONTAINER_TYPE=training # Add EFA and SMDDP to LD library path ENV LD_LIBRARY_PATH="/opt/conda/lib/python${PYTHON_SHORT_VERSION}/site-packages/smdistributed/dataparallel/lib:$LD_LIBRARY_PATH" ENV LD_LIBRARY_PATH=/opt/amazon/efa/lib/:$LD_LIBRARY_PATH # Install basic dependencies to download and build other dependencies RUN --mount=type=cache,id=apt-final,target=/var/cache/apt \ apt-get update && apt-get install -y --no-install-recommends \ curl \ wget \ git \ && rm -rf /var/lib/apt/lists/* # Install EFA. # This is required for SMDDP backend communication RUN DEBIAN_FRONTEND=noninteractive apt-get update RUN mkdir /tmp/efa \ && cd /tmp/efa \ && curl --silent -O https://efa-installer.amazonaws.com/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 /tmp/efa # Install Conda RUN curl -fsSL -v -o ~/miniconda.sh -O https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ chmod +x ~/miniconda.sh && \ ~/miniconda.sh -b -p $CONDA_PREFIX && \ rm ~/miniconda.sh && \ $CONDA_PREFIX/bin/conda install -y python=${PYTHON_SHORT_VERSION} conda-build pyyaml numpy ipython && \ $CONDA_PREFIX/bin/conda clean -ya # Install PyTorch. # Start with dependencies listed in official PyTorch dockerfile # https://github.com/pytorch/pytorch/blob/master/Dockerfile RUN DEBIAN_FRONTEND=noninteractive \ apt-get install -y --no-install-recommends \ build-essential \ ca-certificates \ ccache \ cmake \ git \ libjpeg-dev \ libpng-dev && \ rm -rf /var/lib/apt/lists/* # Setup ccache RUN /usr/sbin/update-ccache-symlinks RUN mkdir /opt/ccache && ccache --set-config=cache_dir=/opt/ccache # Common dependencies for PyTorch RUN conda install astunparse numpy ninja pyyaml mkl mkl-include setuptools cmake cffi typing_extensions future six requests dataclasses # Linux specific dependency for PyTorch RUN conda install -c pytorch magma-cuda113 # Clone PyTorch RUN --mount=type=cache,target=/opt/ccache \ cd / \ && git clone --recursive https://github.com/pytorch/pytorch -b v${PYTORCH_VERSION} # Note that we need to use the same NCCL version for PyTorch and OFI plugin. # To enforce that, install NCCL from source before building PT and OFI plugin. # Install NCCL. # Required for building OFI plugin (OFI requires NCCL's header files and library) RUN cd /pytorch/third_party/nccl \ && rm -rf nccl \ && git clone https://github.com/NVIDIA/nccl.git -b v${NCCL_VERSION}-1 \ && cd nccl \ && make -j64 src.build CUDA_HOME=/usr/local/cuda NVCC_GENCODE="-gencode=arch=compute_70,code=sm_70 -gencode=arch=compute_80,code=sm_80" \ && make pkg.txz.build \ && tar -xvf build/pkg/txz/nccl_*.txz -C $CONDA_PREFIX --strip-components=1 # Build and install PyTorch. RUN cd /pytorch \ && CMAKE_PREFIX_PATH="$(dirname $(which conda))/../" \ python setup.py install \ && rm -rf /pytorch RUN ccache -C # Build and install OFI plugin. \ # It is required to use libfabric. RUN DEBIAN_FRONTEND=noninteractive apt-get update \ && apt-get install -y --no-install-recommends \ autoconf \ automake \ libtool 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=$CONDA_PREFIX \ && make \ && make install \ && rm -rf /tmp/efa-ofi-nccl # Build and install Torchvision RUN pip install --no-cache-dir -U \ packaging \ mpi4py==3.0.3 RUN cd /tmp \ && git clone https://github.com/pytorch/vision.git -b v0.9.1 \ && cd vision \ && BUILD_VERSION="0.9.1+cu111" python setup.py install \ && cd /tmp \ && rm -rf vision # Install OpenSSH. # Required 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 PT S3 plugin. # Required to efficiently access datasets in Amazon S3 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 # Install libboost from source. # This package is needed for smdataparallel functionality (for networking asynchronous IO). WORKDIR / 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 # Install SageMaker PyTorch training. WORKDIR /root RUN pip install --no-cache-dir -U \ smclarify \ "sagemaker>=2,<3" \ sagemaker-experiments==0.* \ sagemaker-pytorch-training # Install SageMaker data parallel binary (SMDDP) # Start with dependencies RUN --mount=type=cache,id=apt-final,target=/var/cache/apt \ apt-get update && apt-get install -y --no-install-recommends \ jq \ libhwloc-dev \ libnuma1 \ libnuma-dev \ libssl1.1 \ libtool \ hwloc \ && rm -rf /var/lib/apt/lists/* # Install SMDDP RUN SMDATAPARALLEL_PT=1 pip install --no-cache-dir ${SMDATAPARALLEL_BINARY}
有关在 SageMaker 中为训练创建自定义 Dockerfile 的更多常规信息,请参阅使用您自己的训练算法.
如果你想扩展自定义 Dockerfile 以纳入 SageMaker 模型 parallel 库,请参阅使用创建自己的 Docker 容器 SageMaker 分布式模型并行库.