Skip to main content

Fixed: MLflow Doesn't Link Evaluation Metrics to the Model When You Evaluate a Registered Model Version

· 9 min read
Jagdish Kumawat
Founder @ Dewiride

I evaluated a registered model version with mlflow.models.evaluate, using its registry address, models:/tumour-evaluation/1. The evaluation run got its metrics, but the logged model behind the version said Metrics (0). MLflow 3.18.0's open-source registry doesn't store which logged model a version holds, so evaluate couldn't link the metrics; evaluating the version's source, models:/<model ID>, fixed it.

What I Was Doing​

I was building the promote command of Part 8 of the MLflow series, which evaluates a new model version with a quality gate before it replaces the one in use. Here is the same step on its own: a logistic regression on scikit-learn's breast cancer data, logged and registered as tumour-evaluation version 1, then evaluated through its registry address:

evaluate_version.py
import mlflow
from mlflow import MlflowClient
from sklearn.datasets import load_breast_cancer
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler

mlflow.set_tracking_uri("http://127.0.0.1:8080")
mlflow.set_experiment("evaluate-version-example")
client = MlflowClient()
name = "tumour-evaluation"

X, y = load_breast_cancer(return_X_y=True, as_frame=True)
y = y == 0 # True when the tumour is malignant
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=0)
model = make_pipeline(StandardScaler(), LogisticRegression()).fit(X_train, y_train)
with mlflow.start_run(run_name="train"):
mlflow.sklearn.log_model(model, name="model", registered_model_name=name, input_example=X_train.head(3))

with mlflow.start_run(run_name="evaluate-version-1"):
result = mlflow.models.evaluate(
f"models:/{name}/1",
X_test.assign(malignant=y_test),
targets="malignant",
model_type="classifier",
evaluator_config={"log_model_explainability": False},
)
print("ROC AUC:", round(result.metrics["roc_auc"], 4))

version = client.get_model_version(name, "1")
logged_model = mlflow.get_logged_model(version.source.removeprefix("models:/"))
print("Metrics on the logged model:", sorted({m.key for m in logged_model.metrics}))
Terminal
uv run python evaluate_version.py

What I Expected​

The metrics on the evaluation run, and the same metrics on the logged model behind version 1, with the dataset they were measured on. That's what mlflow.models.evaluate does when it gets a model's own address, models:/<model ID>, as in How to See an Evaluation's Metrics and Plots in the MLflow UI.

What I Got​

Output (last lines)
🏃 View run evaluate-version-1 at: http://127.0.0.1:8080/#/experiments/24/runs/f67d3545a948460b987a8c9fadd99977
🧪 View experiment at: http://127.0.0.1:8080/#/experiments/24
ROC AUC: 0.9914
Metrics on the logged model: []

The end of the output in a terminal: the evaluate-version-1 run's link, ROC AUC 0.9914, and Metrics on the logged model followed by an empty list.

The evaluation worked, with a ROC AUC of 0.9914, but the logged model has no metrics. Its page in the MLflow UI agrees:

The logged model's page in the MLflow UI: Metrics (0) with No metrics recorded, Parameters (0), and only the train run under Runs; on the right, Datasets used None and Model versions tumour-evaluation v1.

Metrics (0), no dataset, and only the training run: the evaluation isn't linked to the model at all.

What I Checked​

What the version records. A short script prints the version's source and its model_id:

check_version.py
import mlflow
from mlflow import MlflowClient

mlflow.set_tracking_uri("http://127.0.0.1:8080")
version = MlflowClient().get_model_version("tumour-evaluation", "1")
print("source: ", version.source)
print("model_id:", version.model_id)
Terminal
uv run python check_version.py
Output
source: models:/m-81517773c84e455c85f726bb59a063e8
model_id: None

The version knows its logged model through source, but its model_id is empty.

How evaluate finds the model. The reference for mlflow.models.evaluate says of its model_id argument: "The ID of the MLflow LoggedModel or Model Version to which the evaluation results (e.g. metrics and traces) will be linked. If model_id is not specified but model is specified, the ID from model will be used." In MLflow 3.18.0, that ID comes from _parse_model_id_if_present in mlflow/store/artifact/utils/models.py: a models:/<model ID> address carries it, and for models:/<name>/<version> the function asks the registry for the version and returns its model_id.

What the registry stores. The open-source registry keeps its versions in a SQL table, defined in mlflow/store/model_registry/dbmodels/models.py, and that table has no column for a model ID. So every version comes back with model_id set to None, and the logged model is only in source.

Why It Happens​

models:/tumour-evaluation/1 gives evaluate a name and a version number. To link the metrics, it asks the registry which logged model that version holds, and an open-source MLflow server answers None. With no model ID, the metrics stay on the evaluation run only. I reported it to MLflow as issue #28119.

The Fix​

Evaluate the logged model the version was registered from: its source, which is a models:/<model ID> address. Only the model address changes; the version is loaded from the same files either way:

The fixed script in a macOS-style code window: the version fetched with get_model_version, and mlflow.models.evaluate given version.source instead of the registry address.

evaluate_version_source.py
import mlflow
from mlflow import MlflowClient
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split

mlflow.set_tracking_uri("http://127.0.0.1:8080")
mlflow.set_experiment("evaluate-version-example")
client = MlflowClient()
name = "tumour-evaluation"

X, y = load_breast_cancer(return_X_y=True, as_frame=True)
y = y == 0 # True when the tumour is malignant
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=0)

# The version's source is the logged model it was registered from: models:/<model ID>.
version = client.get_model_version(name, "1")
with mlflow.start_run(run_name="evaluate-version-1-source"):
result = mlflow.models.evaluate(
version.source,
X_test.assign(malignant=y_test),
targets="malignant",
model_type="classifier",
evaluator_config={"log_model_explainability": False},
)
print("ROC AUC:", round(result.metrics["roc_auc"], 4))

logged_model = mlflow.get_logged_model(version.source.removeprefix("models:/"))
print("Metrics on the logged model:", sorted({m.key for m in logged_model.metrics}))

It splits the data the same way, with random_state=0, so it evaluates on the same 143 test tumours.

After the Fix​

Terminal
uv run python evaluate_version_source.py
Output (last lines)
🏃 View run evaluate-version-1-source at: http://127.0.0.1:8080/#/experiments/24/runs/4e7c5ff2064a47398907d3c133e3ff88
🧪 View experiment at: http://127.0.0.1:8080/#/experiments/24
ROC AUC: 0.9914
Metrics on the logged model: ['accuracy_score', 'example_count', 'f1_score', 'false_negatives', 'false_positives', 'log_loss', 'precision_recall_auc', 'precision_score', 'recall_score', 'roc_auc', 'score', 'true_negatives', 'true_positives']

The end of the fixed script's output in a terminal: the evaluate-version-1-source run's link, ROC AUC 0.9914, and the thirteen metric names now on the logged model, from accuracy_score to true_positives.

Same ROC AUC, and all thirteen metrics now sit on the logged model. Its page lists them with the dataset and the run that measured them:

The same logged model's page after the fix: Metrics (26), each row with the dataset and the evaluate-version-1-source run, such as true_negatives 87 and false_positives 3; Datasets used now lists the dataset, and Model versions still shows tumour-evaluation v1.

The page counts 26 because MLflow 3.18.0's evaluate writes each of the 13 metrics twice when it links them to a model, as How to See an Evaluation's Metrics and Plots in the MLflow UI explains; the values are the same.

Common Mistakes​

MistakeWhat happensDo this instead
Evaluating models:/<name>/<version> and checking the model's pageThe page shows no evaluation metricsEvaluate the version's source
Reading version.model_id to find the logged modelIt's None on an open-source MLflow serverRead version.source

Troubleshooting​

SymptomLikely causeFix
A logged model says Metrics (0) after an evaluationThe evaluation got a registry addressEvaluate version.source
version.model_id is NoneThe open-source registry doesn't store itUse version.source, which holds models:/<model ID>

FAQ​

Are the metrics from the first evaluation lost?​

No: they're on the evaluate-version-1 run, where the run's page lists them. Only the link to the model is missing.

No. In MLflow 3.18.0 an alias address doesn't link the metrics either. Evaluate the source of the version the alias points to.

The reference documents the model_id argument quoted above, which names the model to link the results to. Evaluating the version's source needs no extra argument, so that's what I used.

Conclusion​

mlflow.models.evaluate("models:/tumour-evaluation/1", ...) logged its metrics to the run only, because an open-source MLflow 3.18.0 registry returns model_id as None for every version, and evaluate takes the model ID from there. Evaluating the version's source, the models:/<model ID> address of the logged model it was registered from, linked all thirteen metrics to that model.

Additional Resources​