SageMaker Model Registry - how to set the Stage column of a Model Package?

1

Each version of a model (i.e. versioned Model Package) in a Model Package Group in SageMaker Model Registry has some metadata attached to it. You can see its Status, Short description, Modified by as well as Stage it is currently deployed on.

This can be seen in the docs here on the screenshot below the 5. point on that list.

My question is - how do we explicitly (or implictly) set the Stage of a given Model Package? I know that changing the approval status can be done by calling update_model_package method. What about the Stage?

It magically happens when we use provided MLOps templates, but even after a thorough browsing of every generated file (SM Pipelines, CodePipeline, CodeBuild etc.) I could not find the exact API call. It probably has something to do with the sagemaker:deployment-stage Tag but setting it up on Endpoint, Endpoint Config or Model (the old construct of pre-2020 SageMaker that is still used by SageMaker Inference) did not work. You can't set tags on a Model Package.

已提问 2 年前1579 查看次数
1 回答
1

You are right that the way to reference the stage is to propagate the tags all the way down to Model, EndpointConfig and Endpoint. When you do that through the MLOps template, CodeBuild and CloudFormation take care of the tagging.

You might need to create_model from the model package as well, here's a working example:

import boto3
client = boto3.client('sagemaker')

role = '<my_role_arn>'
model_package_arn = '<my_model_package_arn>'
my_tags = [
    {'Key': 'sagemaker:deployment-stage', 'Value': 'my_stage'},
    {'Key': 'sagemaker:project-id', 'Value': 'my_project_id'},
    {'Key': 'sagemaker:project-name', 'Value': 'my_project_name'},
]

client.create_model(
    ModelName='testing-stage-model',
    PrimaryContainer={
        'ModelPackageName': model_package_arn,
    },
    ExecutionRoleArn=role,
    Tags=my_tags
)

client.create_endpoint_config(
    EndpointConfigName='testing-stage-endpoint-config',
    ProductionVariants=[
        {
            'VariantName': 'AllTraffic',
            'ModelName': 'testing-stage-model',
            'InitialInstanceCount': 1,
            'InstanceType': 'ml.t2.medium',
        },
    ],
    Tags=my_tags
)

client.create_endpoint(
    EndpointName='testing-stage-endpoint',
    EndpointConfigName='testing-stage-endpoint-config',
    Tags=my_tags
)
已回答 2 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则