本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用 部署已编译的模型 AWS CLI
如果已使用 、 或 控制台编译模型适用于 Python (Boto3) 的 AWS 软件开发工具包,则必须满足AWS CLI先决条件Amazon SageMaker部分。按照以下步骤,使用 创建和部署 SageMaker Neo AWS CLI 编译的模型。
主题
部署模型
在满足先决条件后,请使用 create-model
、 create-enpoint-config
和 create-endpoint
AWS CLI 命令。以下步骤介绍如何使用以下命令部署使用 Neo 编译的模型:
创建模型
从 Neo Inference Container Images (Neo 推理容器映像) 中,选择推理映像 URI,然后使用 create-model
API 创建SageMaker模型。您可以通过两个步骤完成此操作:
-
创建
create_model.json
文件。在 文件中,指定模型的名称、映像 URI、model.tar.gz
存储桶中Amazon S3文件的路径以及您的 SageMaker 执行角色:{ "ModelName":
"insert model name"
, "PrimaryContainer": { "Image":"insert the ECR Image URI"
, "ModelDataUrl":"insert S3 archive URL"
, "Environment": {"See details below"
} }, "ExecutionRoleArn":"ARN for AmazonSageMaker-ExecutionRole"
}如果您使用 训练了模型SageMaker,请指定以下环境变量:
"Environment": { "SAGEMAKER_SUBMIT_DIRECTORY" :
"[Full S3 path for *.tar.gz file containing the training script]"
}如果您未使用 训练模型SageMaker,请指定以下环境变量:
注意 AmazonSageMakerFullAccess
和AmazonS3ReadOnlyAccess
策略必须附加到AmazonSageMaker-ExecutionRole
IAM角色。 -
运行以下命令:
aws sagemaker create-model --cli-input-json file://create_model.json
有关
create-model
API 的完整语法,请参阅create-model
。
创建终端节点配置
创建SageMaker模型后,使用 create-endpoint-config
API 创建终端节点配置。为此,请使用终端节点配置规范创建 JSON 文件。例如,您可以使用以下代码模板并将其另存为 create_config.json
:
{ "EndpointConfigName":
"<provide your endpoint config name>"
, "ProductionVariants": [ { "VariantName":"<provide your variant name>"
, "ModelName": "my-sagemaker-model", "InitialInstanceCount": 1, "InstanceType":"<provide your instance type here>"
, "InitialVariantWeight": 1.0 } ] }
现在,运行AWS CLI以下命令以创建终端节点配置:
aws sagemaker create-endpoint-config --cli-input-json file://create_config.json
有关 create-endpoint-config
API 的完整语法,请参阅 create-endpoint-config
。
创建终端节点
创建终端节点配置后,使用 create-endpoint
API 创建终端节点:
aws sagemaker create-endpoint --endpoint-name
'<provide your endpoint name>'
--endpoint-config-name'<insert your endpoint config name>'
有关 create-endpoint
API 的完整语法,请参阅 create-endpoint
。