How to set model custom metadata in Sagemaker ML pipeline

0

Hi there,

I am interested in using model custom metadata. Looks like it got released recently.
https://aws.amazon.com/about-aws/whats-new/2021/12/sagemaker-model-registry-endpoint-visibility-custom-metadata-model-metrics/

Metadata can be set and read successfully via cli aws sagemaker describe-model-package --model-package-name "arn:aws:sagemaker:us-east-1:ACCOUNT:model-package/MODEL_PACKAGE_NAME/1"

aws --profile dev sagemaker describe-model-package --model-package-name "arn:aws:sagemaker:us-east-1:ACCOUNT:model-package/MODEL_PACKAGE_NAME/1" | jq .CustomerMetadataProperties { "KeyName1": "string2", "KeyName2": "string2" }

However, it is not clear how custom metadata can be set in Sagemaker ML pipeline when model is train and registered using RegisterModel

Thanks in advance.

crawlik
asked 3 years ago2306 views
3 Answers
3
Accepted Answer

Have you tried using this parameter on the RegisterModel step?

AWS
answered 3 years ago
profile picture
EXPERT
reviewed 4 months ago
  • Perfect timing. This support got added 2 days ago! Thanks for pointing to it.

1

That is correct. Figured that. Looks like one to call that API is to have LambaStep and chain it after RegisterModel step . Here is lambda implementation. Feels a bit heavy workaround for this objective. So let me know if there is a better /lighter way to achieving the same. Thanks.

sagemaker_client = client = boto3.client("sagemaker")
def lambda_handler(event, context):

    print(boto3.__version__)
    logger.info(f"Received Event: {event}")
    logger.info(f"Boto version: {boto3.__version__}")
    
    model_arn = event['model_arn']
    model_arn = 'arn:aws:sagemaker:us-east-1:ACCOUNT:model-package/model_package_name/version'
    response = client.describe_model_package(
        ModelPackageName=model_arn
    )
    help(client.update_model_package)
    response = client.update_model_package(
        ModelPackageArn=model_arn,
        ModelApprovalStatus=response['ModelApprovalStatus'],
        CustomerMetadataProperties={'string': 'string'},
    )

    return {"statusCode": 200, "body": json.dumps("Model metadata updated successfully")}
crawlik
answered 3 years ago
  • The only problem with approach getting registered model ARN in SageMaker pipelines. It is buried somewhere in RegisterModel step, but I can't seem to figure out how to extract it. However, SM Studio does access it and shows in UI as step output.

0

Hi,

You can use the UpdateModelPackage API to update custom metadata properties on an already registered model package whether it's in a pipeline or not.

AWS
answered 3 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions