SageMaker AI 예측기를 사용하여 훈련 작업 실행 - Amazon SageMaker AI

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

SageMaker AI 예측기를 사용하여 훈련 작업 실행

SageMaker Python SDK의 예측기를 사용하여 SageMaker 훈련 작업의 구성 및 실행을 처리할 수도 있습니다. 다음 코드 예제에서는 프라이빗 Docker 레지스트리의 이미지를 사용해 예측기를 구성하고 실행하는 방법을 보여줍니다.

  1. 다음 코드 예제와 같이 필수 라이브러리와 종속성을 가져오세요.

    import boto3 import sagemaker from sagemaker.estimator import Estimator session = sagemaker.Session() role = sagemaker.get_execution_role()
  2. 다음 코드 예제와 같이 훈련 작업의 VPC 구성을 위한 훈련 이미지, 보안 그룹 및 서브넷에 통합 리소스 식별자(URI)를 제공합니다.

    image_uri = "myteam.myorg.com/docker-local/my-training-image:<IMAGE-TAG>" security_groups = ["sg-0123456789abcdef0"] subnets = ["subnet-0123456789abcdef0", "subnet-0123456789abcdef0"]

    security_group_idssubnets에 대한 자세한 내용은 SageMaker Python SDK의 예측기 섹션에서 해당 파라미터 설명을 참조하세요.

    참고

    SageMaker AI는 VPC 내의 네트워크 연결을 사용하여 Docker 레지스트리의 이미지에 액세스합니다. Docker 레지스트리의 이미지를 훈련에 사용하려면 계정의 Amazon VPC에서 레지스트리에 액세스할 수 있어야 합니다.

  3. 선택적으로 Docker 레지스트리에 인증이 필요한 경우 SageMaker AI에 액세스 자격 증명을 제공하는 AWS Lambda 함수의 Amazon 리소스 이름(ARN)도 지정해야 합니다. 다음 코드 예제는 ARN을 지정하는 방법을 보여줍니다.

    training_repository_credentials_provider_arn = "arn:aws:lambda:us-west-2:1234567890:function:test"

    인증이 필요한 Docker 레지스트리에서 이미지를 사용하는 방법에 대한 자세한 내용은 아래의 훈련을 위해 위해 인증이 필요한 Docker 레지스트리 사용을 참조하세요.

  4. 다음 코드 예제와 같이 이전 단계의 코드 예제를 사용하여 예측기를 구성하세요.

    # The training repository access mode must be 'Vpc' for private docker registry jobs training_repository_access_mode = "Vpc" # Specify the instance type, instance count you want to use instance_type="ml.m5.xlarge" instance_count=1 # Specify the maximum number of seconds that a model training job can run max_run_time = 1800 # Specify the output path for the model artifacts output_path = "s3://your-output-bucket/your-output-path" estimator = Estimator( image_uri=image_uri, role=role, subnets=subnets, security_group_ids=security_groups, training_repository_access_mode=training_repository_access_mode, training_repository_credentials_provider_arn=training_repository_credentials_provider_arn, # remove this line if auth is not needed instance_type=instance_type, instance_count=instance_count, output_path=output_path, max_run=max_run_time )
  5. 다음 코드 예제와 같이 작업 이름과 입력 경로를 파라미터로 사용해 estimator.fit를 호출하여 훈련 작업을 시작합니다.

    input_path = "s3://your-input-bucket/your-input-path" job_name = "your-job-name" estimator.fit( inputs=input_path, job_name=job_name )