Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 69

MLflow Model Registry: Register and Manage Model Versions

This lesson is built with resources from youtube.com, medium.com and 1 more site.

Hello! Welcome back to our final module, Architecture for AI & Machine Learning.

In our previous lesson, we established the foundation of MLOps by learning how to use MLflow Tracking. You saw how to capture the parameters, metrics, and artifacts of each training run, creating a reproducible and auditable history of your model development. This is the first step in moving from ad-hoc experimentation to a systematic process.

Today, we'll answer the question, "What do you do with a promising model you've found through tracking?" The answer lies in promoting it to a central, managed repository. This lesson addresses the learning outcome: Register a model and manage its versions using the MLflow Model Registry. We will focus on the modern implementation within Databricks Unity Catalog, which is crucial for governance and collaboration in an enterprise setting.

1. From Tracked Run to Managed Asset: The Model Registry

After running dozens of experiments, you'll identify a model artifact from a specific run that performs best. Simply leaving it as a file within an experiment run isn't enough for production. You need a system to manage its lifecycle, from validation to deployment and eventual retirement. This is the purpose of the MLflow Model Registry.

As a software architect, you're familiar with artifact repositories like Nexus or Artifactory, which serve as the single source of truth for software builds (e.g., JAR files, Docker images). The Model Registry plays an identical role for machine learning models. It's a centralized hub for managing model versions, their stages of deployment, and associated metadata.

MLflow Tracking Server and Model Registry Workflow
This diagram illustrates the flow from the experimentation phase (MLflow Tracking) to the management phase (MLflow Model Registry). Data scientists track many experimental models, and the best ones are registered, versioned, and promoted through stages by MLOps or deployment engineers.

Centralized Governance with Unity Catalog

In modern Databricks environments, the Model Registry is integrated directly into Unity Catalog. This is a significant architectural improvement. Instead of each workspace having its own separate registry, all models are registered in Unity Catalog's three-level namespace (catalog.schema.model_name). This provides:

  • Centralized governance: A single place to manage permissions and audit access.
  • Discoverability: Models are easily discoverable across the entire organization.
  • Data Lineage: Unity Catalog can automatically track the link between the data used to train a model and the model itself.

This article provides an excellent overview of the "why" behind this shift, framing it in terms of the governance challenges that you, as an architect, are focused on solving.

Manage Databricks ML Model Lifecycle in Unity Catalog

This article from Towards Data Engineering explains the business problem that the Unity Catalog Model Registry solves.

Please read the 'Introduction' and 'Real-World Impact: Before and After' sections. Focus on how a centralized registry addresses the challenges of model governance, discoverability, and lineage in a large organization.


2. Registering a Model in Unity Catalog

Once you've identified a model artifact from a tracked run, you can register it. This creates Version 1 of a new registered model. If you later register another model with the same name, it becomes Version 2, and so on.

While you can do this through the UI, the programmatic approach is essential for building automated MLOps pipelines. The most direct way is to specify the registered_model_name when you first log the model.

Let's watch a demonstration of this in a Databricks notebook.

Explained how to use Databricks to train ML Models using MLFlow & Hyperopt

This video by Praveen Reddy Learnings shows the exact process of training a model and registering it directly into Unity Catalog in a single step. This is the core practical skill for this lesson.

Watch from 17:02 to 18:40. Pay close attention to the mlflow.register_model call and how the model then appears in the Unity Catalog explorer. Notice the three-part name used for registration, which aligns with the catalog.schema.model structure.

As you saw in the video, the registration is done using the mlflow.register_model function, specifying the run URI and a three-part name for the model in Unity Catalog.

An even more streamlined method, shown in the LINK article you read, is to include the registered_model_name directly in the mlflow.sklearn.log_model call. This combines logging and registration into one atomic operation.

# Example of logging and registering in one call
model_info = mlflow.sklearn.log_model(
    sk_model=rf_model,
    artifact_path="model",
    registered_model_name="dev.insurance.charges_predictor" # Registers the model
)

This API-driven approach is fundamental for automating the transition from an experiment to a managed asset.


3. Managing Model Versions with Aliases

Once a model is registered, you need a way to manage its lifecycle. Is it ready for testing? Is it the primary model in production? Is it an older version that should be archived?

Historically, MLflow used fixed "stages" (Staging, Production, Archived). The modern and more flexible approach, used by Unity Catalog, is aliases. An alias is simply a mutable, named pointer to a specific model version.

Common aliases include:

  • staging: A model version undergoing final testing before production.
  • champion or prod: The primary model version currently serving production traffic.
  • challenger: A candidate model being tested against the champion (e.g., in an A/B test).

This system is more flexible than stages because you can define any alias you need and assign multiple aliases to the same version.

You manage aliases using the MlflowClient API.

Manage Databricks ML Model Lifecycle in Unity Catalog

This article again provides a clear, code-first example of the modern workflow in Unity Catalog, this time focusing on aliases.

Read 'Step 4: Model Promotion Using Unity Catalog Aliases'. Notice the use of MlflowClient and the set_registered_model_alias function. This is the standard way to programmatically manage a model's lifecycle.

The key functions from MlflowClient are:

  • client.set_registered_model_alias(name, alias, version): Assigns an alias to a specific version.
  • client.delete_registered_model_alias(name, alias): Removes an alias.
  • client.get_model_version_by_alias(name, alias): Retrieves the details of the version pointed to by an alias.

This programmatic control is the engine that drives CI/CD for machine learning, allowing you to automate model promotions based on test results.

Test your understanding!

You have a registered model named prod.finance.loan_predictor. You have just finished validating Version 5 and want to promote it to production. The current production model is Version 4, which has the alias champion.

Using the MlflowClient API, write the Python code to:

  1. Assign the champion alias to Version 5.
  2. Also assign a new alias canary_20 to Version 5, indicating you want to route 20% of traffic to it for a canary release.

Assume client = MlflowClient() has already been defined.

Show answer
model_name = "prod.finance.loan_predictor"
new_version = "5"

# 1. Reassign the 'champion' alias to the new version
client.set_registered_model_alias(name=model_name, alias="champion", version=new_version)
print(f"Alias 'champion' now points to version {new_version}.")

# 2. Assign a new 'canary_20' alias to the same version
client.set_registered_model_alias(name=model_name, alias="canary_20", version=new_version)
print(f"Alias 'canary_20' also points to version {new_version}.")

This demonstrates how a single version can be referenced by multiple aliases for different deployment strategies.


4. Loading and Using Registered Models

The primary benefit of the Model Registry is creating a stable interface for downstream applications to consume models. Instead of hard-coding a path to a model file, applications can load a model by its name and an alias.

The URI formats are:

  • By version: models:/<model_name>/<version_number> (e.g., models:/dev.insurance.charges_predictor/2)
  • By alias: models:/<model_name>@<alias> (e.g., models:/dev.insurance.charges_predictor@champion)

Loading by alias is the most powerful pattern from an architectural perspective. It decouples the consuming application from the model deployment process. Your application code always asks for the champion model. MLOps engineers can update which version the champion alias points to in the Model Registry without requiring any changes or redeployments of the application itself.

Let's see the code for this in action.

Manage Databricks ML Model Lifecycle in Unity Catalog

The final step in the workflow is loading the model for inference. This section demonstrates the simple and powerful URI syntax for loading a model by its alias.

Read 'Step 5: Model Loading Using Aliases'. Note the models:/<model_name>@staging URI format. This is the key to decoupling model consumption from model versioning.

This ability to dynamically swap model versions behind a stable alias is a cornerstone of modern MLOps and continuous delivery for machine learning.


Conclusion

In this lesson, you have bridged the gap between experimentation and production-level model management. By moving from a tracked artifact to a versioned and aliased asset in the Model Registry, you've established a formal governance process for your ML models.

Key Takeaways:

  • The MLflow Model Registry, integrated into Databricks Unity Catalog, provides a centralized, governed repository for the entire ML model lifecycle.
  • Models are registered from experiment runs, creating a new version for each registration under the same model name.
  • Aliases (e.g., champion, staging) are flexible, named pointers to specific model versions that replace the older, rigid "stages."
  • Managing aliases programmatically with the MlflowClient is the foundation of automated model promotion and CI/CD for ML.
  • Loading models using the models:/<name>@<alias> URI decouples applications from model versions, enabling seamless updates and deployments.

Preview of the next lesson:
We now have a governed, versioned model available through a stable alias. But how do we actually make it available for a real-time application to use? In our next lesson, we will explore different deployment strategies as we compare architectural patterns for real-time vs. batch model inference.