部署 Autopilot 模型进行实时推理 - 亚马逊 SageMaker AI

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

部署 Autopilot 模型进行实时推理

训练完 Amazon SageMaker Autopilot 模型后,您可以设置一个端点,以交互方式获取预测结果。下一节将介绍将模型部署到 SageMaker AI 实时推理端点的步骤,以便从模型中获取预测结果。

实时推理

实时推理非常适合有实时、交互式、低延迟要求的推理工作负载。此部分演示如何使用实时推理,以交互方式从模型获取预测。

您可以使用 SageMaker API,手动部署在 Autopilot 实验中生成最佳验证指标的模型,如下所示。

或者,当您创建 Autopilot 实验时,也可选择自动部署选项。有关设置模型自动部署的信息,请参阅请求参数 CreateAutoMLJobV2 中的 ModelDeployConfig。这将自动创建一个端点。

注意

为避免产生不必要的费用,您可以删除从模型部署中创建的不需要端点和资源。有关按区域列出的实例定价的信息,请参阅 Amazon SageMaker 定价

  1. 获取候选容器定义

    InferenceContainers 获取候选容器定义。用于推理的容器定义是指专为部署和运行经训练 SageMaker AI 模型以进行预测而设计的容器化环境。

    以下 AWS CLI 命令示例使用 DescribeAutoMLJobV2 API 来获取最佳候选模型的定义。

    aws sagemaker describe-auto-ml-job-v2 --auto-ml-job-name job-name --region region
  2. 列出候选项

    以下 AWS CLI 命令示例使用 ListCandidatesForAutoMLJob API 列出所有候选模型。

    aws sagemaker list-candidates-for-auto-ml-job --auto-ml-job-name <job-name> --region <region>
  3. 创建 SageMaker AI 模型

    使用前面步骤中的容器定义以及您选择的候选模型,通过 CreateModel API 创建 SageMaker AI 模型。请参阅以下 AWS CLI 命令示例。

    aws sagemaker create-model --model-name '<your-candidate-name>' \ --containers ['<container-definition1>, <container-definition2>, <container-definition3>]' \ --execution-role-arn '<execution-role-arn>' --region '<region>
  4. 创建端点配置

    以下 AWS CLI 命令示例使用 CreateEndpointConfig API 创建端点配置。

    aws sagemaker create-endpoint-config --endpoint-config-name '<your-endpoint-config-name>' \ --production-variants '<list-of-production-variants>' \ --region '<region>'
  5. 创建端点

    以下 AWS CLI 示例使用 CreateEndpoint API 来创建端点。

    aws sagemaker create-endpoint --endpoint-name '<your-endpoint-name>' \ --endpoint-config-name '<endpoint-config-name-you-just-created>' \ --region '<region>'

    使用 DescribeEndpoint API 检查您的端点部署进度。请参阅以下 AWS CLI 命令示例。

    aws sagemaker describe-endpoint —endpoint-name '<endpoint-name>' —region <region>

    EndpointStatus 更改为 InService 后,端点即可用于实时推理。

  6. 调用端点

    以下命令结构调用端点以进行实时推理。

    aws sagemaker invoke-endpoint --endpoint-name '<endpoint-name>' \ --region '<region>' --body '<your-data>' [--content-type] '<content-type>' <outfile>