쿠키 기본 설정 선택

당사는 사이트와 서비스를 제공하는 데 필요한 필수 쿠키 및 유사한 도구를 사용합니다. 고객이 사이트를 어떻게 사용하는지 파악하고 개선할 수 있도록 성능 쿠키를 사용해 익명의 통계를 수집합니다. 필수 쿠키는 비활성화할 수 없지만 '사용자 지정' 또는 ‘거부’를 클릭하여 성능 쿠키를 거부할 수 있습니다.

사용자가 동의하는 경우 AWS와 승인된 제3자도 쿠키를 사용하여 유용한 사이트 기능을 제공하고, 사용자의 기본 설정을 기억하고, 관련 광고를 비롯한 관련 콘텐츠를 표시합니다. 필수가 아닌 모든 쿠키를 수락하거나 거부하려면 ‘수락’ 또는 ‘거부’를 클릭하세요. 더 자세한 내용을 선택하려면 ‘사용자 정의’를 클릭하세요.

SageMaker Python SDK에서 PyTorch 프레임워크 추정기 사용

포커스 모드
SageMaker Python SDK에서 PyTorch 프레임워크 추정기 사용 - Amazon SageMaker AI

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

distribution 인수를 SageMaker AI 프레임워크 예측기 PyTorch 또는에 추가하여 분산 훈련을 시작할 수 있습니다TensorFlow. 자세한 내용은 다음 선택 항목에서 SageMaker AI 분산 데이터 병렬 처리(SMDDP) 라이브러리에서 지원하는 프레임워크 중 하나를 선택합니다.

PyTorch

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와 SMDDP AllGather는 현재 상호 호환되지 않습니다.

  • SMDDP AllReduce는 기본적으로 mpirun 기반 런처인 smdistributed 또는 pytorchddp를 사용할 때 활성화되며 NCCL AllGather가 사용됩니다.

  • SMDDP AllGathertorch_distributed 시작 관리자를 사용할 때 기본적으로 활성화되며 AllReduce는 NCCL로 돌아갑니다.

  • SMDDP AllGather는 다음과 같이 설정된 추가 환경 변수와 함께 mpirun 기반 시작 관리자를 사용할 때 활성화할 수도 있습니다.

    export SMDATAPARALLEL_OPTIMIZE_SDP=true
TensorFlow
중요

SMDDP 라이브러리는 TensorFlow에 대한 지원을 중단했으며 v2.11.0 이후 TensorFlow용 DLC에서 더 이상 사용할 수 없습니다. SMDDP 라이브러리가 설치된 이전 TensorFlow DLC를 찾으려면 TensorFlow(사용되지 않음) 섹션을 참조하세요.

from sagemaker.tensorflow import TensorFlow tf_estimator = TensorFlow( base_job_name = "training_job_name_prefix", entry_point="adapted-training-script.py", role="SageMakerRole", framework_version="2.11.0", py_version="py38",     # 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.24xlargeml.p3dn.24xlarge, and ml.p3.16xlarge instance_type="ml.p3.16xlarge",     # Training using the SageMaker AI data parallel distributed training strategy distribution={ "smdistributed": { "dataparallel": { "enabled": True } } } ) tf_estimator.fit("s3://bucket/path/to/training/data")

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와 SMDDP AllGather는 현재 상호 호환되지 않습니다.

  • SMDDP AllReduce는 기본적으로 mpirun 기반 런처인 smdistributed 또는 pytorchddp를 사용할 때 활성화되며 NCCL AllGather가 사용됩니다.

  • SMDDP AllGathertorch_distributed 시작 관리자를 사용할 때 기본적으로 활성화되며 AllReduce는 NCCL로 돌아갑니다.

  • SMDDP AllGather는 다음과 같이 설정된 추가 환경 변수와 함께 mpirun 기반 시작 관리자를 사용할 때 활성화할 수도 있습니다.

    export SMDATAPARALLEL_OPTIMIZE_SDP=true
프라이버시사이트 이용 약관쿠키 기본 설정
© 2025, Amazon Web Services, Inc. 또는 계열사. All rights reserved.