Boto3를 사용하여 컴파일된 모델 배포 - 아마존 SageMaker

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

Boto3를 사용하여 컴파일된 모델 배포

AWS SDK for Python (Boto3) AWS CLI, 또는 Amazon SageMaker 콘솔을 사용하여 모델을 컴파일한 경우 사전 요구 사항 섹션을 충족해야 합니다. 아래 단계에 따라 Python용 Amazon Web Services SDK (Boto3) 를 사용하여 SageMaker NEO 컴파일된 모델을 생성하고 배포하십시오.

모델 배포

사전 조건을 충족한 후에는, create_model, create_enpoint_configcreate_endpoint API를 사용하십시오.

다음 예시는 이러한 API를 사용하여 Neo로 컴파일된 모델을 배포하는 방법을 보여줍니다.

import boto3 client = boto3.client('sagemaker') # create sagemaker model create_model_api_response = client.create_model( ModelName='my-sagemaker-model', PrimaryContainer={ 'Image': <insert the ECR Image URI>, 'ModelDataUrl': 's3://path/to/model/artifact/model.tar.gz', 'Environment': {} }, ExecutionRoleArn='ARN for AmazonSageMaker-ExecutionRole' ) print ("create_model API response", create_model_api_response) # create sagemaker endpoint config create_endpoint_config_api_response = client.create_endpoint_config( EndpointConfigName='sagemaker-neomxnet-endpoint-configuration', ProductionVariants=[ { 'VariantName': <provide your variant name>, 'ModelName': 'my-sagemaker-model', 'InitialInstanceCount': 1, 'InstanceType': <provide your instance type here> }, ] ) print ("create_endpoint_config API response", create_endpoint_config_api_response) # create sagemaker endpoint create_endpoint_api_response = client.create_endpoint( EndpointName='provide your endpoint name', EndpointConfigName=<insert your endpoint config name>, ) print ("create_endpoint API response", create_endpoint_api_response)
참고

AmazonSageMakerFullAccessAmazonS3ReadOnlyAccess 정책은 AmazonSageMaker-ExecutionRole IAM 역할에 연결되어야 합니다.

create_model, create_endpoint_configcreate_endpoint API의 전체 구문은 각각 create_model, create_endpoint_configcreate_endpoint를 참조하십시오.

를 사용하여 SageMaker 모델을 학습시키지 않은 경우 다음 환경 변수를 지정하십시오.

MXNet and PyTorch
"Environment": { "SAGEMAKER_PROGRAM": "inference.py", "SAGEMAKER_SUBMIT_DIRECTORY": "/opt/ml/model/code", "SAGEMAKER_CONTAINER_LOG_LEVEL": "20", "SAGEMAKER_REGION": "insert your region", "MMS_DEFAULT_RESPONSE_TIMEOUT": "500" }
TensorFlow
"Environment": { "SAGEMAKER_PROGRAM": "inference.py", "SAGEMAKER_SUBMIT_DIRECTORY": "/opt/ml/model/code", "SAGEMAKER_CONTAINER_LOG_LEVEL": "20", "SAGEMAKER_REGION": "insert your region" }

를 사용하여 모델을 학습한 경우 SageMaker, 환경 변수를 교육 스크립트가 포함된 전체 Amazon S3 버킷 SAGEMAKER_SUBMIT_DIRECTORY URI로 지정하십시오.