Sub topic 12
Why stages are deprecated and how to migrate
Prerequisites: you should know basic Python, virtual environments, MLflow runs and artifacts, and how to train a simple scikit-learn model. This chapter assumes that a registered model already contains at least one model version.
Why registry stages are deprecated
Older MLflow workflows placed each model version in a registry stage such as Staging, Production, or Archived. A version could occupy only one stage at a time. Application code commonly loaded a stage with a URI such as models:/iris-classifier/Production.
MLflow deprecated model stages in version 2.9.0. Stages combine several different decisions into one fixed workflow. They also assume that every organization has the same lifecycle: staging, production, and archive. Modern workflows often use several environments, approval states, or serving roles instead.
An alias is a named, mutable pointer to one model version. For example, champion can point to version 7 today and version 8 after a successful promotion. A registered model can have several aliases, and a version can have more than one alias.
Mapping stages to aliases
Choose alias names that describe a role, not an MLflow stage. A common migration is:
Productionbecomeschampion.Stagingbecomescandidateorvalidation.Archivedbecomes no alias. Keep the version for history, and record its status with tags or a description.
The alias is not a copy of the model. It changes only registry metadata. The model artifact remains in the run that produced it.
Migrating code
Replace a stage transition with an alias assignment. Replace a stage URI with an alias URI.
import mlflow
from mlflow import MlflowClient
mlflow.set_tracking_uri("http://127.0.0.1:5000")
client = MlflowClient()
model_name = "iris-classifier"
validated_version = "8"
# Replacement for moving version 8 to the Production stage.
client.set_registered_model_alias(
model_name,
"champion",
validated_version,
)
# Verify the pointer before changing serving configuration.
champion = client.get_model_version_by_alias(model_name, "champion")
print(f"champion points to version {champion.version}")
# Serving code follows the alias after later promotions.
model = mlflow.pyfunc.load_model(
f"models:/{model_name}@champion"
)The old stage-based operation, transition_model_version_stage, should not be the basis of new automation. During migration, keep the old and new paths separate. Update deployment code, scheduled jobs, notebooks, and monitoring jobs so that they all use the alias.
Operational gotchas
First, moving an alias is a promotion operation, not validation. Your pipeline should run tests, inspect model-version tags, and require approval before calling set_registered_model_alias.
Second, aliases are shared registry state. Two pipelines promoting at the same time can move champion unexpectedly. Serialize promotions or check the current alias target before updating it.
Third, all clients must use a registry server that supports aliases and must point to the same tracking URI. A local file store or an older MLflow server can cause confusing compatibility errors.
Finally, rollback is another alias update. Point champion at the last known-good version, verify the loaded model, and retain the failed version with a tag such as promotion_status=rolled_back. Do not delete it merely to hide the incident.
Exercise
A service currently loads models:/iris-classifier/Production. Version 9 passed validation, while version 8 is still serving. What two changes migrate the service to aliases?
Show answer
Assign the champion alias to version 9 with MlflowClient.setregisteredmodel_alias, then change the service URI to models:/iris-classifier@champion. The service can roll back by repointing champion to version 8.