쿠키 기본 설정 선택

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

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

SageMaker 훈련 컴파일러로 TensorFlow 훈련 작업 실행

포커스 모드
SageMaker 훈련 컴파일러로 TensorFlow 훈련 작업 실행 - Amazon SageMaker AI

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

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

SageMaker AI 인터페이스를 사용하여 SageMaker 훈련 컴파일러: Amazon SageMaker Studio Classic, Amazon SageMaker 노트북 인스턴스 AWS SDK for Python (Boto3)및를 사용하여 훈련 작업을 실행할 수 있습니다 AWS Command Line Interface.

SageMaker Python SDK 사용하기

SageMaker 훈련 컴파일러를 켜려면 SageMaker AI TensorFlow 또는 Hugging Face 예측기에 compiler_config 파라미터를 추가합니다. TrainingCompilerConfig 클래스를 가져와서 이 클래스의 인스턴스를 compiler_config 매개변수에 전달합니다. 다음 코드 예제는 SageMaker 훈련 컴파일러가 켜져 있는 SageMaker AI 예측기 클래스의 구조를 보여줍니다.

작은 정보

TensorFlow 및 Transformer 라이브러리에서 제공하는 사전 구축된 모델을 시작하려면 테스트 완료 모델의 참조 표에 나와 있는 배치 크기를 사용해 보세요.

참고

TensorFlow용 SageMaker 훈련 컴파일러는 SageMaker AI TensorFlowHugging Face 프레임워크 예측기를 통해 사용할 수 있습니다.

사용 사례에 맞는 정보는 다음 옵션 중 하나를 참조하세요.

TensorFlow
from sagemaker.tensorflow import TensorFlow, TrainingCompilerConfig # the original max batch size that can fit into GPU memory without compiler batch_size_native=12 learning_rate_native=float('5e-5') # an updated max batch size that can fit into GPU memory with compiler batch_size=64 # update the global learning rate learning_rate=learning_rate_native/batch_size_native*batch_size hyperparameters={ "n_gpus": 1, "batch_size": batch_size, "learning_rate": learning_rate } tensorflow_estimator=TensorFlow( entry_point='train.py', instance_count=1, instance_type='ml.p3.2xlarge', framework_version='2.9.1', hyperparameters=hyperparameters, compiler_config=TrainingCompilerConfig(), disable_profiler=True, debugger_hook_config=False ) tensorflow_estimator.fit()

훈련 스크립트를 준비하려면 다음 페이지를 참고하세요.

Hugging Face Estimator with TensorFlow
from sagemaker.huggingface import HuggingFace, TrainingCompilerConfig # the original max batch size that can fit into GPU memory without compiler batch_size_native=12 learning_rate_native=float('5e-5') # an updated max batch size that can fit into GPU memory with compiler batch_size=64 # update the global learning rate learning_rate=learning_rate_native/batch_size_native*batch_size hyperparameters={ "n_gpus": 1, "batch_size": batch_size, "learning_rate": learning_rate } tensorflow_huggingface_estimator=HuggingFace( entry_point='train.py', instance_count=1, instance_type='ml.p3.2xlarge', transformers_version='4.21.1', tensorflow_version='2.6.3', hyperparameters=hyperparameters, compiler_config=TrainingCompilerConfig(), disable_profiler=True, debugger_hook_config=False ) tensorflow_huggingface_estimator.fit()

훈련 스크립트를 준비하려면 다음 페이지를 참고하세요.

TensorFlow
from sagemaker.tensorflow import TensorFlow, TrainingCompilerConfig # the original max batch size that can fit into GPU memory without compiler batch_size_native=12 learning_rate_native=float('5e-5') # an updated max batch size that can fit into GPU memory with compiler batch_size=64 # update the global learning rate learning_rate=learning_rate_native/batch_size_native*batch_size hyperparameters={ "n_gpus": 1, "batch_size": batch_size, "learning_rate": learning_rate } tensorflow_estimator=TensorFlow( entry_point='train.py', instance_count=1, instance_type='ml.p3.2xlarge', framework_version='2.9.1', hyperparameters=hyperparameters, compiler_config=TrainingCompilerConfig(), disable_profiler=True, debugger_hook_config=False ) tensorflow_estimator.fit()

훈련 스크립트를 준비하려면 다음 페이지를 참고하세요.

Hugging Face Estimator with TensorFlow
from sagemaker.huggingface import HuggingFace, TrainingCompilerConfig # the original max batch size that can fit into GPU memory without compiler batch_size_native=12 learning_rate_native=float('5e-5') # an updated max batch size that can fit into GPU memory with compiler batch_size=64 # update the global learning rate learning_rate=learning_rate_native/batch_size_native*batch_size hyperparameters={ "n_gpus": 1, "batch_size": batch_size, "learning_rate": learning_rate } tensorflow_huggingface_estimator=HuggingFace( entry_point='train.py', instance_count=1, instance_type='ml.p3.2xlarge', transformers_version='4.21.1', tensorflow_version='2.6.3', hyperparameters=hyperparameters, compiler_config=TrainingCompilerConfig(), disable_profiler=True, debugger_hook_config=False ) tensorflow_huggingface_estimator.fit()

훈련 스크립트를 준비하려면 다음 페이지를 참고하세요.

from sagemaker.tensorflow import TensorFlow, TrainingCompilerConfig # the original max batch size that can fit into GPU memory without compiler batch_size_native=12 learning_rate_native=float('5e-5') # an updated max batch size that can fit into GPU memory with compiler batch_size=64 # update the global learning rate learning_rate=learning_rate_native/batch_size_native*batch_size hyperparameters={ "n_gpus": 1, "batch_size": batch_size, "learning_rate": learning_rate } tensorflow_estimator=TensorFlow( entry_point='train.py', instance_count=1, instance_type='ml.p3.2xlarge', framework_version='2.9.1', hyperparameters=hyperparameters, compiler_config=TrainingCompilerConfig(), disable_profiler=True, debugger_hook_config=False ) tensorflow_estimator.fit()

훈련 스크립트를 준비하려면 다음 페이지를 참고하세요.

Hugging Face Estimator with TensorFlow
from sagemaker.huggingface import HuggingFace, TrainingCompilerConfig # choose an instance type, specify the number of instances you want to use, # and set the num_gpus variable the number of GPUs per instance. instance_count=1 instance_type='ml.p3.8xlarge' num_gpus=4 # the original max batch size that can fit to GPU memory without compiler batch_size_native=16 learning_rate_native=float('5e-5') # an updated max batch size that can fit to GPU memory with compiler batch_size=26 # update learning rate learning_rate=learning_rate_native/batch_size_native*batch_size*num_gpus*instance_count hyperparameters={ "n_gpus": num_gpus, "batch_size": batch_size, "learning_rate": learning_rate } tensorflow_huggingface_estimator=HuggingFace( entry_point='train.py', instance_count=instance_count, instance_type=instance_type, transformers_version='4.21.1', tensorflow_version='2.6.3', hyperparameters=hyperparameters, compiler_config=TrainingCompilerConfig(), disable_profiler=True, debugger_hook_config=False ) tensorflow_huggingface_estimator.fit()
작은 정보

훈련 스크립트를 준비하려면 다음 페이지를 참조하세요.

Hugging Face Estimator with TensorFlow
from sagemaker.huggingface import HuggingFace, TrainingCompilerConfig # choose an instance type, specify the number of instances you want to use, # and set the num_gpus variable the number of GPUs per instance. instance_count=1 instance_type='ml.p3.8xlarge' num_gpus=4 # the original max batch size that can fit to GPU memory without compiler batch_size_native=16 learning_rate_native=float('5e-5') # an updated max batch size that can fit to GPU memory with compiler batch_size=26 # update learning rate learning_rate=learning_rate_native/batch_size_native*batch_size*num_gpus*instance_count hyperparameters={ "n_gpus": num_gpus, "batch_size": batch_size, "learning_rate": learning_rate } tensorflow_huggingface_estimator=HuggingFace( entry_point='train.py', instance_count=instance_count, instance_type=instance_type, transformers_version='4.21.1', tensorflow_version='2.6.3', hyperparameters=hyperparameters, compiler_config=TrainingCompilerConfig(), disable_profiler=True, debugger_hook_config=False ) tensorflow_huggingface_estimator.fit()
작은 정보

훈련 스크립트를 준비하려면 다음 페이지를 참조하세요.

from sagemaker.huggingface import HuggingFace, TrainingCompilerConfig # choose an instance type, specify the number of instances you want to use, # and set the num_gpus variable the number of GPUs per instance. instance_count=1 instance_type='ml.p3.8xlarge' num_gpus=4 # the original max batch size that can fit to GPU memory without compiler batch_size_native=16 learning_rate_native=float('5e-5') # an updated max batch size that can fit to GPU memory with compiler batch_size=26 # update learning rate learning_rate=learning_rate_native/batch_size_native*batch_size*num_gpus*instance_count hyperparameters={ "n_gpus": num_gpus, "batch_size": batch_size, "learning_rate": learning_rate } tensorflow_huggingface_estimator=HuggingFace( entry_point='train.py', instance_count=instance_count, instance_type=instance_type, transformers_version='4.21.1', tensorflow_version='2.6.3', hyperparameters=hyperparameters, compiler_config=TrainingCompilerConfig(), disable_profiler=True, debugger_hook_config=False ) tensorflow_huggingface_estimator.fit()
작은 정보

훈련 스크립트를 준비하려면 다음 페이지를 참조하세요.

다음 목록은 컴파일러로 SageMaker 훈련 작업을 실행하는 데 필요한 최소 파라미터 세트입니다.

참고

SageMaker AI Hugging Face 예측기를 사용하는 경우 SageMaker 훈련 컴파일러를 활성화하려면 transformers_version, tensorflow_versionhyperparameters, 및 compiler_config 파라미터를 지정해야 합니다. image_uri은(는) 지원되는 프레임워크에 나열된 Training Compiler 통합 딥 러닝 컨테이너를 수동으로 지정하는 데 사용할 수 없습니다.

  • entry_point(str) - 필수 사항. 훈련 스크립트의 파일 이름을 지정하세요.

  • instance_count(int) - 필수. 인스턴스 수를 지정하세요.

  • instance_type(str) - 필수 사항. 인스턴스 유형을 지정하세요.

  • transformers_version (str) - SageMaker AI Hugging Face 예측기를 사용하는 경우에만 필요합니다. SageMaker Training Compiler가 지원하는 Hugging Face Transformers 라이브러리 버전을 지정하세요. 사용 가능한 버전을 확인하려면 지원되는 프레임워크을(를) 참조하세요.

  • framework_version 또는 tensorflow_version(str) - 필수. SageMaker 훈련 컴파일러가 지원하는 TensorFlow 버전을 지정합니다. 사용 가능한 버전을 찾으려면 지원되는 프레임워크을 참조하세요.

    참고

    SageMaker AI TensorFlow 예측기를 사용하는 경우를 지정해야 합니다framework_version.

    SageMaker AI Hugging Face 예측기를 사용할 때는 transformers_version 및를 모두 지정해야 합니다tensorflow_version.

  • hyperparameters(dict) - 선택 사항. 훈련 작업에 사용할 하이퍼파라미터(예: n_gpus, batch_size, learning_rate)를 지정하세요. SageMaker Training Compiler를 활성화할 경우, 배치 크기를 늘려 보고 그에 따라 학습률을 조정하세요. 컴파일러를 사용하고 배치 크기를 조정하여 훈련 속도를 개선하는 사례 연구를 찾으려면 테스트 완료 모델SageMaker 훈련 컴파일러 예제 노트북 및 블로그을 참조하세요.

  • compiler_config(TrainingCompilerConfig 객체) - 필수. 이 매개변수를 포함하여 SageMaker 훈련 컴파일러를 설정합니다. 다음은 TrainingCompilerConfig 클래스의 파라미터입니다.

    • enabled(bool) - 선택 사항. SageMaker Training Compiler를 켜거나 끄려면 True 또는 False을(를) 지정하세요. 기본값은 True입니다.

    • debug(bool) - 선택 사항. 컴파일러 가속 훈련 작업의 자세한 훈련 로그를 수신하려면 이 파라미터를 True(으)로 변경하세요. 다만 추가 로깅으로 인해 오버헤드가 추가되어 컴파일된 훈련 작업이 느려질 수 있습니다. 기본값은 False입니다.

주의

SageMaker Debugger를 켜면 SageMaker 훈련 컴파일러의 성능에 영향을 미칠 수 있습니다. SageMaker Training Compiler를 실행할 때는 그 성능에 영향을 미치지 않도록 Debugger를 끄는 것이 좋습니다. 자세한 내용은 고려 사항을 참조하세요. Debugger 기능을 끄려면 다음 2가지 인수를 예측기에 추가하세요.

disable_profiler=True, debugger_hook_config=False

컴파일러를 이용한 훈련 작업이 시작되면 작업 초기화 단계에서 다음과 같은 로그를 받게 됩니다.

  • TrainingCompilerConfig(debug=False) 포함

    Found configuration for Training Compiler Configuring SM Training Compiler...
  • TrainingCompilerConfig(debug=True) 포함

    Found configuration for Training Compiler Configuring SM Training Compiler... Training Compiler set to debug mode

SageMaker AI Python SDK 사용 및 SageMaker AI 프레임워크 딥 러닝 컨테이너 확장

AWS TensorFlow용 딥 러닝 컨테이너(DLC)는 오픈 소스 TensorFlow 프레임워크에 대한 변경 사항이 포함된 TensorFlow의 조정된 버전을 사용합니다. SageMaker AI 프레임워크 딥 러닝 컨테이너는 기본 AWS 인프라 및 Amazon SageMaker AI에 최적화되어 있습니다. SageMaker 훈련 컴파일러 통합은 DLC 사용의 이점을 활용하여 네이티브 TensorFlow에 비해 더 많은 성능 개선을 제공합니다. 또한, DLC 이미지를 확장하여 사용자 지정 훈련 컨테이너를 만들 수 있습니다.

참고

이 Docker 사용자 지정 기능은 현재 TensorFlow에서만 사용할 수 있습니다.

사용 사례에 맞게 SageMaker AI TensorFlow DLCs를 확장하고 사용자 지정하려면 다음 지침을 사용합니다.

Dockerfile 생성

다음 Dockerfile 템플릿을 사용하여 SageMaker AI TensorFlow DLC를 확장합니다. SageMaker AI TensorFlow DLC 이미지를 Docker 컨테이너의 기본 이미지로 사용해야 합니다. SageMaker AI TensorFlow DLC 이미지 URIs 찾으려면 지원되는 프레임워크를 참조하세요.

# SageMaker AI TensorFlow Deep Learning Container image FROM 763104351884.dkr.ecr.<aws-region>.amazonaws.com/tensorflow-training:<image-tag> ENV PATH="/opt/ml/code:${PATH}" # This environment variable is used by the SageMaker AI container # to determine user code directory. ENV SAGEMAKER_SUBMIT_DIRECTORY /opt/ml/code # Add more code lines to customize for your use-case ...

자세한 내용은 2단계: Dockerfile 및 Python 훈련 스크립트 생성 및 업로드를 참조하세요.

SageMaker AI 프레임워크 DLCs.

  • SageMaker AI 컨테이너에서 TensorFlow 패키지 버전을 명시적으로 제거하거나 변경하지 마세요. 이렇게 하면 AWS 최적화된 TensorFlow 패키지가 오픈 소스 TensorFlow 패키지로 덮어쓰기되어 성능이 저하될 수 있습니다.

  • 특정 TensorFlow 버전 또는 플레이버를 종속성으로 가지고 있는 패키지를 주의하세요. 이러한 패키지는 AWS 최적화 TensorFlow를 묵시적으로 제거하고 오픈 소스 TensorFlow 패키지를 설치할 수 있습니다.

예를 들어 tensorflow/modelstensorflow/text 라이브러리가 오픈 소스 TensorFlow 재설치를 항상 시도하려는 문제가 있다고 알려져 있습니다. 사용 사례에 맞는 특정 버전을 선택하기 위해 이러한 라이브러리를 설치해야 하는 경우 v2.9 이상용 SageMaker AI TensorFlow DLC Dockerfiles를 살펴보는 것이 좋습니다. Dockerfile의 경로는 일반적으로 다음과 같은 형식(tensorflow/training/docker/<tensorflow-version>/py3/<cuda-version>/Dockerfile.gpu)입니다. Dockerfiles에서 AWS 관리형 TensorFlow 바이너리(TF_URL환경 변수에 지정됨) 및 기타 종속성을 순서대로 다시 설치할 코드 줄을 찾아야 합니다. 재설치 섹션은 다음 예제와 같아야 합니다.

# tf-models does not respect existing installations of TensorFlow # and always installs open source TensorFlow RUN pip3 install --no-cache-dir -U \ tf-models-official==x.y.z RUN pip3 uninstall -y tensorflow tensorflow-gpu \ ; pip3 install --no-cache-dir -U \ ${TF_URL} \ tensorflow-io==x.y.z \ tensorflow-datasets==x.y.z

구축하고 ECR로 푸시

Docker 컨테이너를 빌드하고 Amazon ECR에 푸시하려면, 다음 링크의 지침을 따르세요.

SageMaker Python SDK 예측기를 사용하여 실행

평소와 같이 SageMaker AI TensorFlow 프레임워크 예측기를 사용합니다. Amazon ECR에서 호스팅한 새 컨테이너를 사용하도록 image_uri를 지정해야 합니다.

import sagemaker, boto3 from sagemaker import get_execution_role from sagemaker.tensorflow import TensorFlow, TrainingCompilerConfig account_id = boto3.client('sts').get_caller_identity().get('Account') ecr_repository = 'tf-custom-container-test' tag = ':latest' region = boto3.session.Session().region_name uri_suffix = 'amazonaws.com' byoc_image_uri = '{}.dkr.ecr.{}.{}/{}'.format( account_id, region, uri_suffix, ecr_repository + tag ) byoc_image_uri # This should return something like # 111122223333.dkr.ecr.us-east-2.amazonaws.com/tf-custom-container-test:latest estimator = TensorFlow( image_uri=image_uri, role=get_execution_role(), base_job_name='tf-custom-container-test-job', instance_count=1, instance_type='ml.p3.8xlarge' compiler_config=TrainingCompilerConfig(), disable_profiler=True, debugger_hook_config=False ) # Start training estimator.fit()

SageMaker AI CreateTrainingJob API 작업을 사용하여 SageMaker 훈련 컴파일러 활성화

SageMaker 훈련 컴파일러 구성 옵션은 CreateTrainingJob API 작업에 대해 요청 구문의 AlgorithmSpecificationHyperParameters 필드를 통해 지정해야 합니다.

"AlgorithmSpecification": { "TrainingImage": "<sagemaker-training-compiler-enabled-dlc-image>" }, "HyperParameters": { "sagemaker_training_compiler_enabled": "true", "sagemaker_training_compiler_debug_mode": "false" }

SageMaker Training Compiler가 구현된 딥 러닝 컨테이너 이미지 URI의 전체 목록을 확인하려면 지원되는 프레임워크을(를) 참조하세요.

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