You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We would like to include our Unity Catalog registered models in the Databricks Asset Bundles which is supported by the resources:registered_models:model syntax, however we run into issues when we want to modify/remove models from the bundle. In particular, if we first deploy a bundle with a registered model, run code that registers a version of that model, and then change the model name or which schema it is saved in, then when we redeploy the bundle with the new registered/model configuration it fails because it tries to delete the old registered model first, and cannot do so since it has registered versions. I don't expect the new registered model to preserve the versions of the old one, but I would like to be able to deploy the new bundle. The same issue would occur if I have a second model deployed with the bundle with registered versions that I later decide to drop from the project. I would need to delete the old model in the Unity Catalog before I could deploy the new bundle.
delete registered models that are no longer in the bundle configuration (due to removal or name change)
unbind all registered models that are no longer in the bundle configuration
provide a flag for the CLI to force delete/unbind removed registered models
Configuration
bundle.yaml
grants: &grants
grants:
- privileges:
- EXECUTE
principal: ${workspace.current_user.userName}
variables:
uc_registered_models:
type: complex
default:
main_model: ${resources.registered_models.main_model.catalog_name}.${resources.registered_models.main_model.schema_name}.${resources.registered_models.main_model.name}
resources:
registered_models:
main_model:
name: bundle_demo_model # must be all lower-case
catalog_name: [catalog]
schema_name: [schema]
comment: Registered model in Unity Catalog for the DEMO repo.
<<: *grants
jobs:
model_train:
name: Train_Model
tasks:
- task_key: training
notebook_task:
notebook_path: notebooks/train_model
base_parameters:
model_name: ${var.uc_registered_models.main_model}
experiment_path: /Users/${workspace.current_user.userName}/Bundled_Models_Demo_Experiment
source: GIT
git_source:
git_url: ${bundle.git.origin_url}
git_provider: gitHubEnterprise
git_branch: ${bundle.git.branch}
targets:
demo:
default: true
workspace:
host: [databricks host url]
Model registration notebook (notebooks/train_model.py)
# Databricks notebook source
# MAGIC %pip install mlflow-skinny[databricks]
# COMMAND ----------
from sklearn import datasets
from sklearn.ensemble import RandomForestClassifier
import mlflow
import json
# COMMAND ----------
dbutils.widgets.text("model_name", defaultValue="", label="UC Model Name")
params = dbutils.widgets.getAll()
print(json.dumps(params, indent=3))
# COMMAND ----------
mlflow.set_experiment(dbutils.widgets.get("experiment_path"))
with mlflow.start_run():
# Train a sklearn model on the iris dataset
X, y = datasets.load_iris(return_X_y=True, as_frame=True)
clf = RandomForestClassifier(max_depth=7)
clf.fit(X, y)
# Take the first row of the training dataset as the model input example.
input_example = X.iloc[[0]]
# Log the model and register it as a new version in UC.
mlflow.sklearn.log_model(
sk_model=clf,
artifact_path="model",
# The signature is automatically inferred from the input example and its predicted output.
input_example=input_example,
registered_model_name=dbutils.widgets.get("model_name"),
)
Steps to reproduce the behavior
Please list the steps required to reproduce the issue, for example:
Run databricks bundle deploy
Run databricks bundle run model_train
Change name: bundle_demo_model to name: bundle_demo_model_new
Run databricks bundle deploy
See error: Error: terraform apply: exit status 1 Error: cannot delete registered model: Function '[catalog].[schema].bundle_demo_model' is not empty. The function has 1 model versions(s)
Expected Behavior
Since we changed the model name, we would like the bundle to deploy with a registered model named bundle_demo_model_new. The old model bundle_demo_model can either be disconnected from the bundle or deleted.
Actual Behavior
The bundle deployment attempts to destroy the old registered model but since it has a version it throws an error and fails to deploy the bundle.
OS and CLI version
Databricks CLI v0.228.1
OS Sonoma 14.7 (23H124)
Is this a regression?
Not tested on previous versions.
Debug Logs
Output logs if you run the command with debug logs enabled. Example: databricks bundle deploy --log-level=debug. Redact if needed
Describe the issue
We would like to include our Unity Catalog registered models in the Databricks Asset Bundles which is supported by the
resources:registered_models:model
syntax, however we run into issues when we want to modify/remove models from the bundle. In particular, if we first deploy a bundle with a registered model, run code that registers a version of that model, and then change the model name or which schema it is saved in, then when we redeploy the bundle with the new registered/model configuration it fails because it tries to delete the old registered model first, and cannot do so since it has registered versions. I don't expect the new registered model to preserve the versions of the old one, but I would like to be able to deploy the new bundle. The same issue would occur if I have a second model deployed with the bundle with registered versions that I later decide to drop from the project. I would need to delete the old model in the Unity Catalog before I could deploy the new bundle.This is mentioned in this Databricks community thread.
Suggested fixes:
Configuration
bundle.yaml
Model registration notebook (
notebooks/train_model.py
)Steps to reproduce the behavior
Please list the steps required to reproduce the issue, for example:
databricks bundle deploy
databricks bundle run model_train
name: bundle_demo_model
toname: bundle_demo_model_new
databricks bundle deploy
Error: terraform apply: exit status 1 Error: cannot delete registered model: Function '[catalog].[schema].bundle_demo_model' is not empty. The function has 1 model versions(s)
Expected Behavior
Since we changed the model name, we would like the bundle to deploy with a registered model named
bundle_demo_model_new
. The old modelbundle_demo_model
can either be disconnected from the bundle or deleted.Actual Behavior
The bundle deployment attempts to destroy the old registered model but since it has a version it throws an error and fails to deploy the bundle.
OS and CLI version
Databricks CLI v0.228.1
OS Sonoma 14.7 (23H124)
Is this a regression?
Not tested on previous versions.
Debug Logs
Output logs if you run the command with debug logs enabled. Example: databricks bundle deploy --log-level=debug. Redact if needed
The text was updated successfully, but these errors were encountered: