How to get Model ID of the Latest Version registered in Azure Machine Learning Service Model Registry using az ml cli?

Shivapriya Katta 51 Reputation points
2022-02-03T15:53:46.503+00:00

Hello MS team,

I have registered an ML model in the AML workspace using an Azure Machine learning pipeline and triggered the main control script of the pipeline by linking the repo present in Azure DevOps to the AML workspace(using Service principal).

How do I download the latest version of the model from the AML workspace to the "Artifacts" folder in Azure DevOPs?

Any help is appreciated please.

Azure Machine Learning
Azure Machine Learning
An Azure machine learning service for building and deploying models.
2,564 questions
0 comments No comments
{count} vote

Accepted answer
  1. YutongTie-MSFT 46,566 Reputation points
    2022-02-04T00:19:45.587+00:00

    @Shivapriya Katta

    I think you are mentioning how to get the latest version of model and download the model in az ml.

    There are 2 steps, one is list the model to get the model ID you want, two is download the model.

    az ml model list
    List models in the workspace.

    az ml model list [--dataset-id]  
                     [--latest]  
                     [--model-name]  
                     [--path]  
                     [--property]  
                     [--resource-group]  
                     [--run-id]  
                     [--subscription-id]  
                     [--tag]  
                     [--workspace-name]  
                     [-v]  
    

    Optional Parameters
    --dataset-id
    If provided, will only show models with the specified dataset ID.

    --latest -l
    If provided, will only return models with the latest version.

    --model-name -n
    An optional model name to filter the list by.

    --path
    Path to a project folder. Default: current directory.

    --property
    Key/value property to add (e.g. key=value ). Multiple properties can be specified with multiple --property options.

    --resource-group -g
    Resource group corresponding to the provided workspace.

    --run-id
    If provided, will only show models with the specified Run ID.

    --subscription-id
    Specifies the subscription Id.

    --tag
    Key/value tag to add (e.g. key=value ). Multiple tags can be specified with multiple --tag options.

    --workspace-name -w
    Name of the workspace containing models to list.

    -v
    Verbosity flag.

    az ml model download
    Download a model from the workspace.

    az ml model download --model-id  
                         --target-dir  
                         [--overwrite]  
                         [--path]  
                         [--resource-group]  
                         [--subscription-id]  
                         [--workspace-name]  
                         [-v]  
    

    Required Parameters
    --model-id -i
    ID of model.

    --target-dir -t
    Target directory to download the model file to.

    Optional Parameters
    --overwrite
    Overwrite if the same name file exists in target directory.

    --path
    Path to a project folder. Default: current directory.

    --resource-group -g
    Resource group corresponding to the provided workspace.

    --subscription-id
    Specifies the subscription Id.

    --workspace-name -w
    Name of the workspace containing model to show.

    -v
    Verbosity flag.

    Hope this helps!

    Please kindly accept the answer if you feel helpful, thank you!

    Regards,
    Yutong

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Shivapriya Katta 51 Reputation points
    2022-02-04T03:33:57.637+00:00

    Thanks a lot for the response....but I am trying to get the parameter "--model-id" as a variable and pass it into the download command, trying to do something like:

    az ml model download --model-id $(az ml model list --query "[].{ID:id}[0].ID" -o tsv --name saved_model --resource-group $(rg_name) --workspace-name $(ws_name)) --target-dir ./models --resource-group $(rg_name) --workspace-name $(ws_name)

    Not working though...any idea?

    1 person found this answer helpful.
    0 comments No comments

  2. Kjetil Haukaas 5 Reputation points
    2023-03-08T11:46:30.0833333+00:00

    I got the same issue. Say the latest version is 10. I don't want to refer to 10 I want to refer to the latest.

    In MLflow you could use models:/<model-name>/latest. In Azure that would translate to azureml:template_model:latest, however that is not an option so I need to use azureml:template_model:10, but I don't want to refer to a specific version I want to refer to the latest.

    1 person found this answer helpful.