기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
distribution
인수를 SageMaker AI 프레임워크 예측기 PyTorch
TensorFlow
PyTorch 분산 훈련을 시작하는 데 다음 시작 관리자 옵션을 사용할 수 있습니다.
-
pytorchddp
-이 옵션은 SageMaker AI에서 PyTorch 분산 훈련을 실행하는 데 필요한 환경 변수를 실행mpirun
하고 설정합니다. 이 옵션을 사용하려면 다음 사전을distribution
파라미터에 전달합니다.{ "pytorchddp": { "enabled": True } }
-
torch_distributed
-이 옵션은 SageMaker AI에서 PyTorch 분산 훈련을 실행하는 데 필요한 환경 변수를 실행torchrun
하고 설정합니다. 이 옵션을 사용하려면 다음 사전을distribution
파라미터에 전달합니다.{ "torch_distributed": { "enabled": True } }
-
smdistributed
-이 옵션은를 실행mpirun
하지만 SageMaker AI에서 PyTorch 분산 훈련을 실행하는 데 필요한 환경 변수를smddprun
설정합니다.{ "smdistributed": { "dataparallel": { "enabled": True } } }
NCCL AllGather
를 SMDDP AllGather
로 교체하도록 선택한 경우 세 가지 옵션을 모두 사용할 수 있습니다. 사용 사례에 맞는 옵션을 하나 선택합니다.
NCCL AllReduce
을 SMDDP AllReduce
로 교체하기로 선택한 경우 mpirun
기반 옵션인 smdistributed
또는 pytorchddp
중 하나를 선택해야 합니다. 다음과 같이 MPI 옵션을 추가할 수도 있습니다.
{
"pytorchddp": {
"enabled": True,
"custom_mpi_options": "-verbose -x NCCL_DEBUG=VERSION"
}
}
{
"smdistributed": {
"dataparallel": {
"enabled": True,
"custom_mpi_options": "-verbose -x NCCL_DEBUG=VERSION"
}
}
}
다음 코드 샘플은 분산 훈련 옵션이 있는 PyTorch 추정기의 기본 구조를 보여줍니다.
from sagemaker.pytorch import PyTorch
pt_estimator = PyTorch(
base_job_name="training_job_name_prefix
",
source_dir="subdirectory-to-your-code
",
entry_point="adapted-training-script.py
",
role="SageMakerRole
",
py_version="py310
",
framework_version="2.0.1
",
# For running a multi-node distributed training job, specify a value greater than 1
# Example: 2,3,4,..8
instance_count=2
,
# Instance types supported by the SageMaker AI data parallel library:
# ml.p4d.24xlarge, ml.p4de.24xlarge
instance_type="ml.p4d.24xlarge
",
# Activate distributed training with SMDDP
distribution={ "pytorchddp": { "enabled": True } } # mpirun, activates SMDDP AllReduce OR AllGather
# distribution={ "torch_distributed": { "enabled": True } } # torchrun, activates SMDDP AllGather
# distribution={ "smdistributed": { "dataparallel": { "enabled": True } } } # mpirun, activates SMDDP AllReduce OR AllGather
)
pt_estimator.fit("s3://bucket/path/to/training/data
")
참고
PyTorch Lightning 및 Lightning Bolts와 같은 유틸리티 라이브러리는 SageMaker AI PyTorch DLCs. 다음 requirements.txt
파일을 생성하고 훈련 스크립트를 저장하는 소스 디렉터리에 저장합니다.
# requirements.txt
pytorch-lightning
lightning-bolts
예를 들어 트리 구조의 디렉터리는 다음과 같아야 합니다.
├──
pytorch_training_launcher_jupyter_notebook.ipynb
└── sub-folder-for-your-code ├──adapted-training-script.py
└──requirements.txt
requirements.txt
파일을 훈련 스크립트 및 작업 제출과 함께 배치할 소스 디렉터리를 지정하는 방법에 대한 자세한 내용은 Amazon SageMaker AI Python SDK 설명서의 타사 라이브러리 사용을
SMDDP 집합 작업을 활성화하고 올바른 분산 훈련 시작 관리자 옵션을 사용하기 위한 고려 사항
-
SMDDP
AllReduce
와 SMDDPAllGather
는 현재 상호 호환되지 않습니다. -
SMDDP
AllReduce
는 기본적으로mpirun
기반 런처인smdistributed
또는pytorchddp
를 사용할 때 활성화되며 NCCLAllGather
가 사용됩니다. -
SMDDP
AllGather
는torch_distributed
시작 관리자를 사용할 때 기본적으로 활성화되며AllReduce
는 NCCL로 돌아갑니다. -
SMDDP
AllGather
는 다음과 같이 설정된 추가 환경 변수와 함께mpirun
기반 시작 관리자를 사용할 때 활성화할 수도 있습니다.export SMDATAPARALLEL_OPTIMIZE_SDP=true