Sub topic 11
Promoting Across Environments by Copying Model Versions
This chapter assumes you understand MLflow runs, logged model artifacts, registered models, model versions, and aliases. It also assumes that your team separates environments such as staging and production.
An alias can promote a version within one registered model. For example, iris-classifier@champion can point to version 4 in staging. Production may use a separate registered model, such as iris-classifier-prod. Copying creates a new version in that destination model while keeping the source model unchanged.
Why copy a version between registered models
Separate registered models can provide a clear boundary between environments:
iris-classifier-stagingcontains versions under testing.iris-classifier-prodcontains versions approved for production.- Production permissions can be stricter than staging permissions.
- Production code can load from its own stable model name.
The copied version receives a new version number in the destination registered model. The destination version refers to the same model content, but its registry identity belongs to the destination model.
| Promotion method | Best fit | Main consequence |
|---|---|---|
| Move an alias | One registered model with multiple consumers | The alias points to a different version |
| Copy a version | Separate staging and production models | A new destination version is created |
| Load a fixed version | Reproducible experiments or audits | The loaded version never changes automatically |
Copy a champion from staging to production
First, assign an alias to the version that passed staging validation. The alias makes the source selection readable and avoids hard-coding a staging version number in the promotion script.
from mlflow import MlflowClient
client = MlflowClient(tracking_uri="http://127.0.0.1:5000")
# The staging alias was assigned after validation.
client.set_registered_model_alias(
"iris-classifier-staging",
"champion",
"3",
)
# Copy the aliased version into the production registered model.
copied = client.copy_model_version(
src_model_uri="models:/iris-classifier-staging@champion",
dst_name="iris-classifier-prod",
comment="Approved by staging validation run",
tags={
"promotion_source": "iris-classifier-staging@champion",
"approval_status": "approved",
},
)
print(f"Created production version {copied.version}")The source URI uses the models:/ scheme. Its @champion suffix resolves the source alias before the copy occurs. The destination name is a separate registered model. If production already has versions, MLflow assigns the next available version number there.
After the copy, production serving code can use a production alias:
client.set_registered_model_alias(
"iris-classifier-prod",
"champion",
str(copied.version),
)Serving code can then load models:/iris-classifier-prod@champion. A later promotion changes the production alias, rather than requiring a code change.
Choosing a workflow
Use aliases alone when one registry contains all versions and access rules are sufficient. Use copying when staging and production need separate names, permissions, ownership, or retention policies.
Copying does not automatically prove that the model works in production. Check the model signature, dependencies, artifact access, input data contract, and security requirements. Also confirm that the destination registry can access the model artifacts.
Exercise
Staging version 3 is aliased as champion. Production currently points champion to version 2. What operation promotes staging version 3 without changing serving code?
Show answer
Copy staging's champion with copymodelversion, then assign the production model's champion alias to the newly created destination version.