List model versions
This example demonstrates how you can use the MLOps Python client to list all the model versions for a given registered model in the external model registry using the ExternalRegisteredModelVersionService of the MLOps API.
- Ensure that the external model registry is configured.
- You will need the values for the following constants in order to successfully carry out the task. Contact your administrator to obtain deployment specific values.
| Constant | Value | Description |
|---|---|---|
MLOPS_API_URL | Usually: https://api.mlops.my.domain | Defines the URL for the MLOps Gateway component. |
TOKEN_ENDPOINT_URL | https://mlops.keycloak.domain/auth/realms/[fill-in-realm-name]/protocol/openid-connect/token | Defines the token endpoint URL of the Identity Provider. This uses Keycloak as the Identity Provider. Keycloak Realm should be provided. |
REFRESH_TOKEN | <your-refresh-token> | Defines the user's refresh token. |
CLIENT_ID | <your-client-id> | Sets the client id for authentication. This is the client you will be using to connect to MLOps. |
CLIENT_SECRET | <your-client-secret> | Sets the client secret. |
REGISTERED_MODEL_NAME | <model-name> | Provide the registered model name in the external model registry for which you want to list the versions. |
The following steps demonstrate how you can use the MLOps Python client to list all the model versions for a given registered model in the external model registry.
-
Change the values of the following constants in your
ListModelVersions.pyfile as given in the preceding data table.ListModelVersions.py### ConstantsMLOPS_API_URL = "https://api.mlops.my.domain"TOKEN_ENDPOINT_URL="https://mlops.keycloak.domain/auth/realms/[fill-in-realm-name]/protocol/openid-connect/token"REFRESH_TOKEN="<your-refresh-token>"CLIENT_ID="<your-mlops-client>"CLIENT_SECRET = "<your-client-secret>"REGISTERED_MODEL_NAME = "<model-name>" -
Run the
ListModelVersions.pyfile.python3 ListModelVersions.py -
This lists all the model versions for the registered model name you have specified.
- Sample response
{"externalRegisteredModelVersions" : [ {"sourceKey" : "sourceKey","updatedTime" : "2000-01-23T04:56:07.000+00:00","statusDescription" : "statusDescription","sourceCreatedBy" : "sourceCreatedBy","adapterModelVersionId" : "adapterModelVersionId","createdBy" : "createdBy","artefactId" : "artefactId","createdTime" : "2000-01-23T04:56:07.000+00:00","mlflowStage" : "mlflowStage","version" : "version"}, {"sourceKey" : "sourceKey","updatedTime" : "2000-01-23T04:56:07.000+00:00","statusDescription" : "statusDescription","sourceCreatedBy" : "sourceCreatedBy","adapterModelVersionId" : "adapterModelVersionId","createdBy" : "createdBy","artefactId" : "artefactId","createdTime" : "2000-01-23T04:56:07.000+00:00","mlflowStage" : "mlflowStage","version" : "version"} ],"paging" : {"nextPageToken" : "nextPageToken"}}
Example walkthrough
This section provides a walkthrough of the ListModelVersions.py file.
-
List the model versions for the given registered model name by calling the
ListRegisteredModelVersionsForModelendpoint of theExternalRegisteredModelVersionService.ListModelVersions.pydef _form_list_model_version_request(model_name:str):return mlops.ModelregistryListRegisteredModelVersionsForModelRequest(source_key=model_name)def _list_all_versions_for_model(mlops_client: mlops.Client, model_name: str):return mlops_client.external_registry.external_registered_model_version_service.list_registered_model_versions_for_model(_form_list_model_version_request(model_name)) -
In the main function, set up the token provider using an existing refresh token and client secret, and then set up the MLOps client.
-
Call the
_list_all_versions_for_modelfunction with theREGISTERED_MODEL_NAMEdefined at the beginning of the script.ListModelVersions.pyversion_list = _list_all_versions_for_model(mlops_client, REGISTERED_MODEL_NAME)print(version_list)
- Submit and view feedback for this page
- Send feedback about H2O MLOps to cloud-feedback@h2o.ai