How to fetch a model and make predictions from the Model Registry

0

Hello! I have a model in the Sagemaker Studio Model Registry. Is there a way to do something like the following?

sm = boto3.client('sagemaker')
model = sm.fetch_model('model_group_name')
preds = model.predict(X)

I'm used to using MLFlow, where you can do

import mlflow.sklearn

sk_model = mlflow.sklearn.load_model("runs:/96771d893a5e46159d9f3b49bf9013e2/sk_models")

# use Pandas DataFrame to make predictions
pandas_df = ...
predictions = sk_model.predict(pandas_df)

I can't find an equivalent of the sm.fetch_model() function. I'm looking for something along the lines of a MLFlow equivalent. I want to do some predictions without having a model deployed.

  • A model registry in SageMaker is a catalog of models. If you'd like to predict without deploying the model, I believe the way would be to download the model from the model registry's S3 location, load the model and then predict.

asked 9 months ago505 views
1 Answer
0

SageMaker Model Registry can be used to catalog and manage different model versions. model_group_name can't be used directly from Sagemaker Model Registry. First you need to deploy the model. After deploying the model, Endpoint would be created. Then you can directly invoke the Endpoint API.

Generally at first Model You need to to create a Model group[1] << Register a Model Version using Sagemaker Model registry [2] << Update the Approval Status of a Model to approved[3] << Deploy the Model for registry[4] << Invoke the Endpoint API.

Kindly go through the below example of deploying the model and then invoking it via Endpoint API https://github.com/aws/amazon-sagemaker-examples/blob/main/serverless-inference/serverless-model-registry.ipynb

[1] https://docs.aws.amazon.com/sagemaker/latest/dg/model-registry-model-group.html [2] https://docs.aws.amazon.com/sagemaker/latest/dg/model-registry-version.html [3] https://docs.aws.amazon.com/sagemaker/latest/dg/model-registry-approve.html [4] https://docs.aws.amazon.com/sagemaker/latest/dg/model-registry-deploy.html

Yash_A
answered 9 months 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