cancel
Showing results for 
Search instead for 
Did you mean: 
Machine Learning
Dive into the world of machine learning on the Databricks platform. Explore discussions on algorithms, model training, deployment, and more. Connect with ML enthusiasts and experts.
cancel
Showing results for 
Search instead for 
Did you mean: 

Promote registered UC models using CLI

victorNilsson
New Contributor II

Hi,

I am currently transitioning some of our MLops workflows to use models registered in Unity Catalog (UC) instead of the "normal" model registry. I am trying to follow the instructions on https://docs.gcp.databricks.com/en/machine-learning/manage-model-lifecycle/index.html, and I try to replicate the "Promote models across environments (deploy model)" steps.

To promote our models we have been using the mlflow/model-versions/transition-stage REST API endpoint to move models between stages. A similar approach could be done by using model aliases in UC for which there are API endpoints for. Though the recommendations seems to be to promote models by moving them between environment catalogs instead, e.g. move from "test_env.models.test_model" to "prod_env.models.test_model", but I am unable to find a suitable API call for it. 

It is possible to run python code inside a cluster to do this, e.g. using

import mlflow

mlflow.set_registry_uri("databricks-uc")

environment_from = "test_env.models.test_model"
environment_to = "prod_env.models.test_model"
alias = "production"

client = mlflow.tracking.MlflowClient()
copied_model_version = client.copy_model_version(
    src_model_uri = f"models:/{environment_from}@{alias}",
    dst_name = environment_to,
)
client.set_registered_model_alias(
    name=environment_to,
    alias=alias,
    version=copied_model_version.version
)

but I want to handle this transition from outside databricks.

Is there anyway that I can that I can replicate this processs using mlflow cli/databricks cli calls?

Br,
Victor

1 REPLY 1

Dennisleon
New Contributor II

@victorNilsson wrote:

Hi,

I am currently transitioning some of our MLops workflows to use models registered in Unity Catalog (UC) instead of the "normal" model registry. I am trying to follow the instructions on https://docs.gcp.databricks.com/en/machine-learning/manage-model-lifecycle/index.html, and I try to replicate the "Promote models across environments (deploy model)" steps.

To promote our models we have been using the mlflow/model-versions/transition-stage REST API endpoint to move models between stages. A similar approach could be done by using model aliases in UC for which there are API endpoints for. Though the recommendations seems to be to promote models by moving them between environment catalogs instead, e.g. move from "test_env.models.test_model" to "prod_env.models.test_model", but I am unable to find a suitable API call for it. 

It is possible to run python code inside a cluster to do this, e.g. using

 

import mlflow

mlflow.set_registry_uri("databricks-uc")

environment_from = "test_env.models.test_model"
environment_to = "prod_env.models.test_model"
alias = "production"

client = mlflow.tracking.MlflowClient()
copied_model_version = client.copy_model_version(
    src_model_uri = f"models:/{environment_from}@{alias}",
    dst_name = environment_to,
)
client.set_registered_model_alias(
    name=environment_to,
    alias=alias,
    version=copied_model_version.version
)

 

but I want to handle this transition from outside databricks.

Is there anyway that I can that I can replicate this processs using mlflow cli/databricks cli calls?

Br,
Victor


Hello,

Yes, you can promote registered UC models using the Databricks CLI. Here's how:

1. Set up the CLI:

Install the Databricks CLI: pip install databricks-cli
Configure the CLI with your workspace credentials: databricks configure --token <your-databricks-token>
2. Identify the models:

Use the databricks workspace list-models command to list models in your workspace.
Identify the models you want to promote and their versions.
3. Copy the model version:

Use the databricks model copy command to copy the model version between catalogs:

 

databricks model copy --model-name <source-model-name> --version <source-version> --target-catalog <target-catalog-name> --target-model-name <target-model-name>

 

Set the alias:

Use the databricks model set-alias command to set the alias for the copied model version:

 

databricks model set-alias --model-name <target-model-name> --version <copied-version> --alias <alias-name>

 

Example: 

 

# Copy model version "1" of "test_model" from "test_env" to "prod_env" with alias "production"
databricks model copy --model-name test_model --version 1 --target-catalog prod_env --target-model-name test_model
databricks model set-alias --model-name prod_env.models.test_model --version 1 --alias production

 

This approach achieves the same functionality as the Python code within a cluster, but using Databricks CLI commands for external execution. 

I hope the information may helps you. 

 

 

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!