本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用阴影变体测试模型
你可以使用 SageMaker Model Shadow Deployments 来创建长期运行的阴影变体,以便在将模型服务堆栈升级到生产环境之前对其进行验证。下图更详细地说明了阴影变体的工作方式。
部署阴影变体
以下代码示例显示了如何通过编程方式部署阴影变体。更换 user placeholder text
在示例中包含您自己的信息。
-
创建两个 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
" } ] ) -
创建端点配置。在配置中指定您的生产变体和阴影变体。
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
, } ] ) -
创建端点。
create_endpoint_response = sm.create_endpoint( EndpointName=
name-of-your-endpoint
, EndpointConfigName=endpoint_config_name, )