The registry decouples deployment from training: services load 'the champion' while you swap versions behind it.
The Model Registry gives logged models a registered model name and auto-incrementing versions. Register either while logging (log_model(..., registered_model_name="churn")) or afterwards:
mv = mlflow.register_model(info.model_uri, "churn")Each version links back to the run and logged model that produced it, preserving lineage.
To mark which version is used where, assign aliases: mutable named pointers such as champion, challenger or staging:
client.set_registered_model_alias("churn", "champion", mv.version)
model = mlflow.pyfunc.load_model("models:/churn@champion")Promoting a new model is just moving the alias; rolling back is moving it back. No consumer code changes. The older stages (Staging, Production) are deprecated in favour of aliases and tags.
Other useful operations on MlflowClient:
set_model_version_tagfor metadata likevalidation_status=passed.get_model_version_by_alias,search_model_versions("name='churn'").- Descriptions on models and versions for documentation.
For separate dev and prod environments, a common pattern is one registry per environment (or names prefixed by environment) and copying approved versions across with client.copy_model_version.
Example
import mlflow
from mlflow import MlflowClient
from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression
X, y = load_iris(return_X_y=True, as_frame=True)
client = MlflowClient()
versions = []
for C in [0.1, 1.0]:
with mlflow.start_run():
m = LogisticRegression(C=C, max_iter=1000).fit(X, y)
info = mlflow.sklearn.log_model(m, name="clf", input_example=X.head(2))
versions.append(mlflow.register_model(info.model_uri, "iris-clf").version)
client.set_registered_model_alias("iris-clf", "champion", versions[-1])
client.set_model_version_tag("iris-clf", versions[-1], "validated", "true")
champ = mlflow.pyfunc.load_model("models:/iris-clf@champion")
print(champ.predict(X.head(3))) # [0 0 0]
mv = client.get_model_version_by_alias("iris-clf", "champion")
print(mv.version == versions[-1], mv.tags) # True {'validated': 'true'}Remember
- Registered models have versions linked to the runs that produced them
- Aliases (e.g. @champion) are movable pointers; load with
models:/name@alias - Promote or roll back by moving an alias; stages are deprecated
Watch out for
- Hard-coding a version number in serving code, which forces a redeploy for every model update.