本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用部署編譯的模型 AWS CLI
如果模型是使用 AWS SDK for Python (Boto3)、或 Amazon SageMaker 主控台編譯 AWS CLI,則必須符合先決條件部分。請遵循下列步驟,使用建立和部署 SageMaker 新編譯的模型。AWS CLI
主題
部署模型
在您滿足先決條件之後,請使用create-model
create-enpoint-config
、和create-endpoint
AWS CLI
指令。下列步驟說明,如何使用這些命令部署使用 Neo 編譯的模型:
建立模型
從新推論容器映像中,選取推論映像 URI,然後使用 create-model
API 建立 SageMaker 模型。您可用兩個步驟完成這項工作:
-
建立
create_model.json
檔案。在檔案中,指定模型的名稱、映像 URI、Amazon S3 儲存貯體中model.tar.gz
檔案的路徑,以及您的 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
。