阴影变体 - Amazon SageMaker
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

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

阴影变体

你可以使用 SageMaker Model Shadow Deployments 来创建长期运行的阴影变体,以便在将模型服务堆栈升级到生产环境之前对其进行验证。下图更详细地说明了阴影变体的工作方式。

阴影变体的详细信息。

部署阴影变体

以下代码示例显示了如何通过编程方式部署阴影变体。请将示例中的用户占位符文本替换为您自己的信息。

  1. 创建两个 SageMaker 模型:一个用于生产变体,另一个用于阴影变体。

    import boto3 from sagemaker import get_execution_role, Session aws_region = "aws-region" boto_session = boto3.Session(region_name=aws_region) sagemaker_client = boto_session.client("sagemaker") role = get_execution_role() bucket = Session(boto_session).default_bucket() model_name1 = "name-of-your-first-model" model_name2 = "name-of-your-second-model" sagemaker_client.create_model( ModelName = model_name1, ExecutionRoleArn = role, Containers=[ { "Image": "ecr-image-uri-for-first-model", "ModelDataUrl": "s3-location-of-trained-first-model" } ] ) sagemaker_client.create_model( ModelName = model_name2, ExecutionRoleArn = role, Containers=[ { "Image": "ecr-image-uri-for-second-model", "ModelDataUrl": "s3-location-of-trained-second-model" } ] )
  2. 创建端点配置。在配置中指定您的生产变体和阴影变体。

    endpoint_config_name = name-of-your-endpoint-config create_endpoint_config_response = sagemaker_client.create_endpoint_config( EndpointConfigName=endpoint_config_name, ProductionVariants=[ { "VariantName": name-of-your-production-variant, "ModelName": model_name1, "InstanceType": "ml.m5.xlarge", "InitialInstanceCount": 1, "InitialVariantWeight": 1, } ], ShadowProductionVariants=[ { "VariantName": name-of-your-shadow-variant, "ModelName": model_name2, "InstanceType": "ml.m5.xlarge", "InitialInstanceCount": 1, "InitialVariantWeight": 1, } ] )
  3. 创建端点。

    create_endpoint_response = sm.create_endpoint( EndpointName=name-of-your-endpoint, EndpointConfigName=endpoint_config_name, )