Sub topic 13
Searching and Inspecting Registered Models
Assume you know MLflow Tracking concepts such as experiments, runs, metrics, and artifacts. This chapter uses a running MLflow tracking server and the MlflowClient API.
A registry has two main levels:
- A registered model is the named asset, such as
iris-classifier. - A model version is one registered copy of a model, with its own version number, source run, tags, description, and aliases.
Searching helps you find candidates. Inspection helps you decide which version is safe to use.
How registry objects relate
A registered model answers, “What model name exists?” A model version answers, “Which concrete artifact and validation record does this name contain?”
Search registered models
Use search_registered_models() to list model names. The client can filter and order results on the server, which is better than downloading every object and filtering locally.
from mlflow import MlflowClient
client = MlflowClient(tracking_uri="http://127.0.0.1:5000")
models = client.search_registered_models(
filter_string="name LIKE 'iris%'",
order_by=["name ASC"],
max_results=100,
)
for model in models:
print(model.name)
print(" description:", model.description or "(none)")
print(" aliases:", model.aliases)A filter string uses MLflow's registry search syntax. For example, name = 'iris-classifier' selects one registered model. name LIKE 'iris%' selects names beginning with iris.
The returned object contains model-level metadata. It does not replace inspecting individual versions.
Search model versions
Use search_model_versions() when you need versions across one or more registered models. Version filters can use fields such as name, run_id, version_number, and tags.
versions = client.search_model_versions(
filter_string="name = 'iris-classifier'",
order_by=["version_number DESC"],
max_results=100,
)
for version in versions:
print(
f"v{version.version}: run={version.run_id}, "
f"aliases={version.aliases}, status={version.status}"
)
print(" source:", version.source)
print(" tags:", version.tags)
print(" description:", version.description or "(none)")A version's source usually identifies the logged artifact location. Its run_id connects the registry record back to the tracking run, where you can inspect parameters, metrics, and other artifacts.
| Question | Object or method |
|---|---|
| Which model names exist? | `search_registered_models()` |
| What versions does a model have? | `search_model_versions()` |
| What metadata belongs to one model? | `get_registered_model()` |
| What metadata belongs to one version? | `get_model_version()` |
Inspect one version before promotion
Search results are useful for discovery, but promotion code should inspect the selected version explicitly.
model = client.get_registered_model("iris-classifier")
version = client.get_model_version("iris-classifier", "2")
print("Model:", model.name)
print("Model aliases:", model.aliases)
print("Version:", version.version)
print("Version aliases:", version.aliases)
print("Run:", version.run_id)
print("Validation status:", version.tags.get("validation_status"))
print("Description:", version.description)A common error is confusing a model-level tag with a version-level tag. Validation results normally belong to a version because each version can pass or fail independently. Read version.tags, not only model.tags, when deciding whether a particular artifact is ready.
Another common error is treating descending version order as quality order. A larger version number means it was registered later. It does not prove that the model has better metrics or passed validation.
Pagination and reliable inspection
For large registries, request bounded pages and continue with the returned page token when the client version exposes one. Do not assume that the first page contains every model or version. Also handle missing names and versions explicitly, because a concurrent deletion or permission change can make a previously discovered object unavailable.
Exercise
Why should a deployment check a version tag and alias separately instead of selecting the highest version number?
Show answer
The highest number only identifies the newest registration. The tag records validation, while the alias identifies the version currently chosen for a role such as champion.