Sub topic 7
Aliases: Named Pointers to Model Versions
Assume you know MLflow runs, logged model artifacts, and registered model versions. This chapter focuses on aliases: stable names that point to specific versions in the Model Registry.
Why aliases matter
A model version has an immutable version number, such as 1 or 2. A serving application can load that exact version:
mlflow.pyfunc.load_model("models:/iris-classifier/2")This is predictable, but changing the deployed model requires changing application configuration or code.
An alias adds a movable name, such as champion, to a version. The application loads the alias instead:
mlflow.pyfunc.load_model("models:/iris-classifier@champion")When the champion alias moves from version 1 to version 2, the application code stays the same. The registry becomes the location where the active model choice is recorded.
An alias belongs to one registered model and points to one model version at a time.
Assigning and moving an alias
Use MlflowClient to assign an alias. The version can be supplied as a string or converted from an integer.
from mlflow import MlflowClient
client = MlflowClient(tracking_uri="http://127.0.0.1:5000")
model_name = "iris-classifier"
# Promote version 2.
client.set_registered_model_alias(
name=model_name,
alias="champion",
version="2",
)
# Read back the version selected by the alias.
selected = client.get_model_version_by_alias(
name=model_name,
alias="champion",
)
print(f"{selected.name} version {selected.version} is champion")If champion already points to version 1, setting it to version 2 moves the pointer. The old version remains registered and its artifacts remain available. The alias change does not retrain, copy, or modify the model artifact.
Use different aliases for different operational roles. For example:
candidatecan identify a version under validation.championcan identify the version used for production inference.shadowcan identify a version receiving comparison traffic.
These names are conventions. MLflow does not decide whether a version is safe to promote. Your validation process must make that decision.
>``callout warning > Treat alias changes as deployment changes. Restrict permission to move production aliases, record who approved the change, and keep validation evidence in version tags or an external release system. >``
Loading by alias
Serving code can load the alias URI without knowing the current version:
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)The @champion form resolves the current alias target when the model is loaded. A long-running service may continue using the model object it already loaded. Moving the alias does not automatically replace that in-memory object. Restart or reload the service according to your deployment process.
Use a version URI when reproducibility requires a fixed target:
pinned = mlflow.pyfunc.load_model("models:/iris-classifier/1")Use an alias when deployment should follow a controlled promotion. Use a version number for audits, experiments, and rollback verification.
Exercise
What changes when the champion alias moves from version 1 to version 2?
Show answer
A new load using models:/iris-classifier@champion resolves to version 2, while the registered versions, their artifacts, and already loaded model objects do not change.