Sub topic 10
Rolling Back a Bad Promotion in the MLflow Model Registry
Assume you know Python, virtual environments, MLflow Tracking, and the difference between a run and an artifact. You should also understand that an MLflow model alias is a mutable name that points to one model version.
A rollback moves an alias from a bad version to an earlier known-good version. It does not retrain the model, delete the bad version, or change the model artifact. Applications that load the alias can continue using the same model URI.
When a rollback is needed
Suppose the champion alias points to version 2:
| Registered model | Version | Alias | Result |
|---|---|---|---|
| `iris-classifier` | 1 | none | Previous good model |
| `iris-classifier` | 2 | `champion` | Current model with a problem |
The problem might be a production error, a metric regression, a schema mismatch, or a failed validation check. First confirm that version 1 is actually safe to use. A rollback is a production decision, so record why it happened and who approved it.
Repoint the alias
Use MlflowClient.set_registered_model_alias to point champion at the earlier version.
import mlflow
from mlflow import MlflowClient
TRACKING_URI = "http://127.0.0.1:5000"
MODEL_NAME = "iris-classifier"
ALIAS = "champion"
GOOD_VERSION = "1"
mlflow.set_tracking_uri(TRACKING_URI)
client = MlflowClient()
# Verify that the target version exists before changing production traffic.
target = client.get_model_version(MODEL_NAME, GOOD_VERSION)
client.set_registered_model_alias(
name=MODEL_NAME,
alias=ALIAS,
version=GOOD_VERSION,
)
current = client.get_model_version_by_alias(MODEL_NAME, ALIAS)
print(f"{MODEL_NAME}@{ALIAS} now points to version {current.version}")
print(f"Target run: {target.run_id}")The registered model keeps both versions. Code that loads the alias does not need to change:
import mlflow
mlflow.set_tracking_uri("http://127.0.0.1:5000")
model = mlflow.pyfunc.load_model("models:/iris-classifier@champion")
predictions = model.predict([[5.1, 3.5, 1.4, 0.2]])
print(predictions)Code that loads models:/iris-classifier/2 still loads version 2. A version URI is pinned, so it does not follow the rollback. This difference matters when comparing old and new behavior.
Verify and document the rollback
After changing the alias, verify its destination through the registry API. Then run a smoke test against the model and check application health. Store the incident identifier, reason, validation result, and operator as model-version or registered-model tags according to your governance policy.
client.set_model_version_tag(
MODEL_NAME,
GOOD_VERSION,
"rollback_reason",
"version 2 failed production schema validation",
)
client.set_model_version_tag(
MODEL_NAME,
GOOD_VERSION,
"rollback_incident",
"INC-1042",
)Tags explain the decision, but they do not provide a transaction history by themselves. Keep alias changes in an audit system or deployment log as well.
Alias removal
If no previous version is safe, remove the alias instead of pointing it at an unverified model:
client.delete_registered_model_alias(MODEL_NAME, ALIAS)Consumers that require models:/iris-classifier@champion will then fail rather than silently serving a model you have not approved. Your serving process should handle this condition and expose a clear alert.
Common rollback errors
- Changing a version number without checking that the version exists.
- Deleting the bad version and losing evidence needed for analysis.
- Loading a fixed version URI while expecting it to follow the alias.
- Rolling back the alias but failing to restart or refresh a serving layer that cached the model.
- Allowing two deployment jobs to move the same alias at the same time.
- Treating rollback as proof that the earlier version is healthy without running a smoke test.
Exercise
Version 2 is assigned to champion, but it produces invalid output. Version 1 passed validation. What change should serving code make?
Show answer
None. Repoint champion to version 1 with set_registered_model_alias; code using models:/iris-classifier@champion continues to resolve through the alias.