本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用 部署編譯模型 AWS CLI
如果模型是使用 或 Amazon SageMaker AI 主控台編譯的 AWS SDK for Python (Boto3) AWS CLI,您必須滿足先決條件區段。請遵循下列步驟,使用 AWS CLI 建立和部署 SageMaker Neo 編譯的模型。
主題
部署模型
在您滿足先決條件之後,請使用 create-model
、 create-enpoint-config
和 create-endpoint
AWS CLI 命令。下列步驟說明,如何使用這些命令部署使用 Neo 編譯的模型:
建立模型
從 Neo 推論容器映像中,選取推論映像 URI,然後使用 create-model
API 來建立 SageMaker AI 模型。您可用兩個步驟完成這項工作:
-
建立
create_model.json
檔案。在 檔案中,指定模型的名稱、映像 URI、Amazon S3 儲存貯體中model.tar.gz
檔案的路徑,以及 SageMaker AI 執行角色:{ "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 AI 訓練模型,請指定下列環境變數:
"Environment": { "SAGEMAKER_SUBMIT_DIRECTORY" :
"[Full S3 path for *.tar.gz file containing the training script]"
}如果您未使用 SageMaker AI 訓練模型,請指定下列環境變數:
注意
AmazonSageMakerFullAccess
和AmazonS3ReadOnlyAccess
政策必須連接到AmazonSageMaker-ExecutionRole
IAM 角色。 -
執行以下命令:
aws sagemaker create-model --cli-input-json file://create_model.json
如需
create-model
API 的完整語法,請參閱create-model
。
建立一個端點組態
建立 SageMaker AI 模型後,請使用 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
。