Skip to content

Operations

Interfaces

Users can access the model registry using two available interfaces:

  • The dashboard (i.e. web console)
  • APIs (i.e. the Python SDK) in a notebook or pipeline

Info

For additional details about the mlflow model registry.


Authentication

Rafay's turnkey integration with the MLflow model registry provides users with a seamless access experience. Once the user is logged into their Kubeflow workspace, they are automatically authenticated to the integrated model registry as well. They just need to click on "MLflow" in the dashboard menu to access the model registry.

For programmatic access via a notebook or a pipeline, users need to ensure that they set the MLflow Tracking Server URI before trying to access the registry. An illustrative example is shown below.

# Set MLflow Tracking Server URL
mlflow.set_tracking_uri("http://mlflow-tracking.mlflow.svc.cluster.local:80")

Note

In this Getting Started guide, notice that the Kubeflow pipeline can the integrated model registry to register and use the model without having to deal with any credentials.


Register Model

Although the typical workflow is to register a model programmatically, users can also do this using the web console (UI). The high level steps are as follows:

  1. Import mlflow and necessary libraries

    • import mlflow
    • import mlflow.sklearn (if using scikit-learn)
  2. Set tracking URI (optional)

  3. Start an MLflow run

    • mlflow.start_run()
  4. Train your model (e.g., a sklearn model)

    • Train the model on your dataset
    • model = train_model_function(data)
  5. Log model parameters and metrics

    • mlflow.log_param("parameter_name", parameter_value)
    • mlflow.log_metric("metric_name", metric_value)
  6. Log the model

    • mlflow.sklearn.log_model(model, artifact_path="models")
  7. Register the model in MLflow registry

    • model_uri = "runs://models"
    • mlflow.register_model(model_uri=model_uri, name="my_model_name")
  8. Promote model to Staging or Production (optional)

    • client = MlflowClient()
    • client.transition_model_version_stage(name="my_model_name", version=1, stage="Staging")
  9. End the MLflow run

    • mlflow.end_run()

View/List Models

The typical use case to list/view a model and its details is via the web console/UI. Once a user logs into their workspace, they just need to click on the MLFlow menu on the bottom left to view the integrated model registry. In MLflow, users have two primary approaches to view models and associated details.

By Experiments

Click on the "Experiments" tab to view the models organized by experiments. An illustrative example is shown below.

By Experiments

By Models

Click on the "Models" tab to view by models. An illustrative example is shown below.

By Models

Users that wish to list models programmatically can do so using the MLflow SDK. Shown below is example code that you can use the list ALL models and high level details from a notebook.

import mlflow
from mlflow.tracking import MlflowClient

# Set MLflow Tracking Server URL
mlflow.set_tracking_uri("http://mlflow-tracking.mlflow.svc.cluster.local:80")

# Create an MLflow client
client = MlflowClient()

# Retrieve registered models
data = client.search_registered_models()

models = []
for model in data:
    models.append(model.name)
    print(f"Model Name: {model.name}")

# Process versions of each model
for model_name in models:
    model_versions = {"name": model_name}
    data = client.search_model_versions(filter_string=f"name='{model_name}'", order_by=["version_number DESC"])
    versions = list(map(lambda x: dict(x), data))
    model_versions["latest_versions"] = versions
    for version in versions:
        print(f" - Version: {version['version']}, Stage: {version['current_stage']}, Run ID: {version['run_id']}")

When you run this in a notebook, you should see output like the following:

Model Name: mlflow_metrics
Model Name: SklearnLogisticRegression
Model Name: tensorboard_metrics
 - Version: 3, Stage: None, Run ID: 
 - Version: 2, Stage: None, Run ID: 
 - Version: 1, Stage: None, Run ID: 
 - Version: 44, Stage: None, Run ID: a48da172377f4f3a9722579aba8181f5
 - Version: 43, Stage: None, Run ID: a48da172377f4f3a9722579aba8181f5
 - Version: 42, Stage: None, Run ID: 66cb0ab846294ddd9b7ee9902b6e03fc
 - Version: 41, Stage: None, Run ID: 66cb0ab846294ddd9b7ee9902b6e03fc
 ...