本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用 Boto3 部署编译模型
你必须满足先决条件部分是否使用编译模型Amazon SDK for Python (Boto3)、Amazon CLI,或者亚马逊 SageMaker 控制台。按照以下步骤创建和部署 SageMaker 使用新编译模型适用于 Python 的 Amazon Web Services 开发工具包 (Boto3)
主题
部署模型
在你满意之后先决条件,使用create_model
、create_enpoint_config
, 和create_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)
这些区域有:AmazonSageMakerFullAccess
和AmazonS3ReadOnlyAccess
策略必须附加到AmazonSageMaker-ExecutionRole
IAM 角色。
对于的完整语法create_model
、create_endpoint_config
, 和create_endpoint
API,请参阅create_model
create_endpoint_config
create_endpoint
如果您没有使用 SageMaker 训练模型,请指定以下环境变量:
如果您使用 SageMaker 训练模型,请指定环境变量SAGEMAKER_SUBMIT_DIRECTORY
作为包含训练脚本的完整 Amazon S3 存储桶 URI。