<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Promote registered UC models using CLI in Machine Learning</title>
    <link>https://community.databricks.com/t5/machine-learning/promote-registered-uc-models-using-cli/m-p/71387#M3322</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/98261"&gt;@victorNilsson&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;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&amp;nbsp;&lt;A href="https://docs.gcp.databricks.com/en/machine-learning/manage-model-lifecycle/index.html," target="_blank" rel="noopener"&gt;https://docs.gcp.databricks.com/en/machine-learning/manage-model-lifecycle/index.html,&lt;/A&gt;&amp;nbsp;and I try to replicate the "Promote models across environments (deploy model)" steps.&lt;BR /&gt;&lt;BR /&gt;To promote our models we have been using the&amp;nbsp;&lt;SPAN&gt;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 &lt;SPAN&gt;"test_env.models.test_model" to&amp;nbsp;&lt;/SPAN&gt;"prod_env.models.test_model", but I am unable to find a suitable API call for it.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;It is possible to run python code inside a cluster to do this, e.g. using&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;but I want to handle this transition from outside databricks.&lt;BR /&gt;&lt;BR /&gt;Is there anyway that I can that I can replicate this processs using mlflow cli/databricks cli calls?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Br,&lt;BR /&gt;Victor&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Yes, you can promote registered UC models using the Databricks CLI. Here's how:&lt;/P&gt;&lt;P&gt;1. Set up the CLI:&lt;/P&gt;&lt;P&gt;Install the Databricks CLI: pip install databricks-cli&lt;BR /&gt;Configure the CLI with your workspace credentials: databricks configure --token &amp;lt;your-databricks-token&amp;gt;&lt;BR /&gt;2. Identify the models:&lt;/P&gt;&lt;P&gt;Use the databricks workspace list-models command to list models in your workspace.&lt;BR /&gt;Identify the models you want to promote and their versions.&lt;BR /&gt;3. Copy the model version:&lt;/P&gt;&lt;P&gt;Use the databricks model copy command to copy the model version between catalogs:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;databricks model copy --model-name &amp;lt;source-model-name&amp;gt; --version &amp;lt;source-version&amp;gt; --target-catalog &amp;lt;target-catalog-name&amp;gt; --target-model-name &amp;lt;target-model-name&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Set the alias:&lt;/P&gt;&lt;P&gt;Use the databricks model set-alias command to set the alias for the copied model version:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;databricks model set-alias --model-name &amp;lt;target-model-name&amp;gt; --version &amp;lt;copied-version&amp;gt; --alias &amp;lt;alias-name&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;# 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&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This approach achieves the same functionality as the Python code within a cluster, but using Databricks CLI commands for external execution.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope the information may helps you.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 03 Jun 2024 04:16:28 GMT</pubDate>
    <dc:creator>Dennisleon</dc:creator>
    <dc:date>2024-06-03T04:16:28Z</dc:date>
    <item>
      <title>Promote registered UC models using CLI</title>
      <link>https://community.databricks.com/t5/machine-learning/promote-registered-uc-models-using-cli/m-p/57438#M2851</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;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&amp;nbsp;&lt;A href="https://docs.gcp.databricks.com/en/machine-learning/manage-model-lifecycle/index.html," target="_blank"&gt;https://docs.gcp.databricks.com/en/machine-learning/manage-model-lifecycle/index.html,&lt;/A&gt;&amp;nbsp;and I try to replicate the "Promote models across environments (deploy model)" steps.&lt;BR /&gt;&lt;BR /&gt;To promote our models we have been using the&amp;nbsp;&lt;SPAN&gt;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 &lt;SPAN&gt;"test_env.models.test_model" to&amp;nbsp;&lt;/SPAN&gt;"prod_env.models.test_model", but I am unable to find a suitable API call for it.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;It is possible to run python code inside a cluster to do this, e.g. using&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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
)&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;but I want to handle this transition from outside databricks.&lt;BR /&gt;&lt;BR /&gt;Is there anyway that I can that I can replicate this processs using mlflow cli/databricks cli calls?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Br,&lt;BR /&gt;Victor&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2024 10:51:34 GMT</pubDate>
      <guid>https://community.databricks.com/t5/machine-learning/promote-registered-uc-models-using-cli/m-p/57438#M2851</guid>
      <dc:creator>victorNilsson</dc:creator>
      <dc:date>2024-01-16T10:51:34Z</dc:date>
    </item>
    <item>
      <title>Re: Promote registered UC models using CLI</title>
      <link>https://community.databricks.com/t5/machine-learning/promote-registered-uc-models-using-cli/m-p/71387#M3322</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/98261"&gt;@victorNilsson&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;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&amp;nbsp;&lt;A href="https://docs.gcp.databricks.com/en/machine-learning/manage-model-lifecycle/index.html," target="_blank" rel="noopener"&gt;https://docs.gcp.databricks.com/en/machine-learning/manage-model-lifecycle/index.html,&lt;/A&gt;&amp;nbsp;and I try to replicate the "Promote models across environments (deploy model)" steps.&lt;BR /&gt;&lt;BR /&gt;To promote our models we have been using the&amp;nbsp;&lt;SPAN&gt;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 &lt;SPAN&gt;"test_env.models.test_model" to&amp;nbsp;&lt;/SPAN&gt;"prod_env.models.test_model", but I am unable to find a suitable API call for it.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;It is possible to run python code inside a cluster to do this, e.g. using&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;but I want to handle this transition from outside databricks.&lt;BR /&gt;&lt;BR /&gt;Is there anyway that I can that I can replicate this processs using mlflow cli/databricks cli calls?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Br,&lt;BR /&gt;Victor&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Yes, you can promote registered UC models using the Databricks CLI. Here's how:&lt;/P&gt;&lt;P&gt;1. Set up the CLI:&lt;/P&gt;&lt;P&gt;Install the Databricks CLI: pip install databricks-cli&lt;BR /&gt;Configure the CLI with your workspace credentials: databricks configure --token &amp;lt;your-databricks-token&amp;gt;&lt;BR /&gt;2. Identify the models:&lt;/P&gt;&lt;P&gt;Use the databricks workspace list-models command to list models in your workspace.&lt;BR /&gt;Identify the models you want to promote and their versions.&lt;BR /&gt;3. Copy the model version:&lt;/P&gt;&lt;P&gt;Use the databricks model copy command to copy the model version between catalogs:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;databricks model copy --model-name &amp;lt;source-model-name&amp;gt; --version &amp;lt;source-version&amp;gt; --target-catalog &amp;lt;target-catalog-name&amp;gt; --target-model-name &amp;lt;target-model-name&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Set the alias:&lt;/P&gt;&lt;P&gt;Use the databricks model set-alias command to set the alias for the copied model version:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;databricks model set-alias --model-name &amp;lt;target-model-name&amp;gt; --version &amp;lt;copied-version&amp;gt; --alias &amp;lt;alias-name&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;# 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&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This approach achieves the same functionality as the Python code within a cluster, but using Databricks CLI commands for external execution.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope the information may helps you.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2024 04:16:28 GMT</pubDate>
      <guid>https://community.databricks.com/t5/machine-learning/promote-registered-uc-models-using-cli/m-p/71387#M3322</guid>
      <dc:creator>Dennisleon</dc:creator>
      <dc:date>2024-06-03T04:16:28Z</dc:date>
    </item>
  </channel>
</rss>

