Search code examples
azureazure-cliazure-machine-learning-service

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


Using Azure Machine Learning CLI extension, how do we get the Model ID for the latest version of a Model (with known model name)?

To get the entire list of Model Details with a given name the command is

az ml model list --model-name [Model_Name] --resource-group [RGP_NAME] --subscription-id [SUB_ID] --workspace-name [WS_NAME]

Running this will give a list of all the models:

[
  {
    "createdTime": "2021-03-19T07:02:03.814172+00:00",
    "framework": "Custom",
    "frameworkVersion": null,
    "id": "model:2"
    "name": "model",
    "version": 3
  },
  {
    "createdTime": "2021-03-19T06:46:34.301054+00:00",
    "framework": "Custom",
    "frameworkVersion": null,
    "id": "model:2",
    "name": "model",
    "version": 2
  },
  {
    "createdTime": "2021-03-19T06:38:56.558385+00:00",
    "framework": "Custom",
    "frameworkVersion": null,
    "id": "model:1",
    "name": "model",
    "version": 1
  }
]

The Microsoft Documentation mentions, we can use a -l parameter to get the latest version details:

az ml model list --model-name [Model_Name] --resource-group [RGP_NAME] --subscription-id [SUB_ID] --workspace-name [WS_NAME] -l

However, running this gives the following error:

ERROR: UnrecognizedArgumentError: unrecognized arguments: -l

What is the syntax to use this -l flag?


Solution

  • If we wish to obtain the model-id for the latest model, instead of using az ml model list with -l flag, using az model show will return the details for the latest model. The syntax to get a string for model-id will be:

    az ml model show --model-id $(TRN_MODEL_ID) --resource-group $(AML_TRN_RG) --subscription-id $(AML_TRN_SUB_ID) --workspace-name $(AML_TRN_WS) --query name -o tsv