跳到正文

第 14 课 · Model Registry

Aliases, Tags and Promotion

Move model versions to production safely with MLflow aliases and validation tags, plan rollbacks and understand why the old stage system is deprecated.

Once you have versions, you need a way to say which one is live. In MLflow you do this with aliases and tags, and you build a clear process around them.

Aliases

An alias is a named, movable pointer to one version. Production code loads the alias, so you can change the live model without editing that code.

Python
from mlflow import MlflowClient

client = MlflowClient()
client.set_registered_model_alias("churn-classifier", "champion", "3")
client.set_registered_model_alias("churn-classifier", "challenger", "4")

champion = client.get_model_version_by_alias("churn-classifier", "champion")
print(champion.version)

model = mlflow.pyfunc.load_model("models:/churn-classifier@champion")

A common pattern is champion and challenger: the champion serves users while the challenger is tested. To promote, move champion to the new version.

Stages are deprecated

Older tutorials move versions through stages such as Staging and Production. The official documentation says model stages are deprecated and will be removed in a future major release. Since MLflow 2.9.0, aliases and tags are the recommended replacements. For new projects, do not build on stages.

Tags for review state

Tags record facts about a version:

Python
client.set_model_version_tag("churn-classifier", "4", "validation_status", "approved")
client.set_model_version_tag("churn-classifier", "4", "approved_by", "review-board")

Tags are labels, not security. Anyone with edit rights may change them, so enforce approval with permissions and your delivery pipeline.

Separate environments

Many teams keep separate registered models per environment, such as dev-churn and prod-churn, with different permissions. MLflow offers copy_model_version to copy a version from one registered model to another:

Python
client.copy_model_version(
    src_model_uri="models:/dev-churn@candidate",
    dst_name="prod-churn",
)

A promotion gate

A gate is an automated check that must pass before the alias moves. Here is a stand-in with made-up scores. It records the previous version, so that you can roll back.

Python Stand-in: promote with a gate and roll back

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Do running services notice?

Moving an alias changes what new loads get. A service that already loaded the model keeps it in memory until it reloads or restarts. Decide how your service picks up changes: redeploy on promotion, or reload on a schedule with care. Always log the version number that served each prediction, so that you can investigate later.

Moving the champion alias is a production change. Treat it like a code deploy: require review, run automated checks, record who did it, and know how to roll back.

A practical checklist

  1. Register the candidate version.
  2. Evaluate it on a fixed dataset (evaluation lesson).
  3. Set validation_status after review.
  4. Note the current champion version.
  5. Move the alias and watch live metrics.
  6. Move it back if something goes wrong.

Naming your aliases

Keep the list of aliases short and meaningful. A common set is:

Alias Meaning
champion The version that serves users now
challenger The version being compared against the champion
previous The last champion, kept for a fast rollback

The names are only conventions. MLflow does not give special behavior to the word champion. What matters is that everyone, and every service, agrees on what each alias means.

Compare champion and challenger fairly

To compare two versions, evaluate both on the same data with the same metrics. Do not compare the old score of the champion with a new score of the challenger, because the data may have changed in between. Re-run both.

If you can, test the challenger on live traffic without showing its answers to users. This is called shadow testing: both models receive the input, only the champion answers, and you compare outputs later. It costs extra computing and may need approval if the data is sensitive. A gradual rollout, where a small share of users gets the new version, is another option, with clear criteria to stop.

Record the history of promotions

An alias only shows the current target. It does not tell you the story of past moves. Keep your own log: in your delivery pipeline, in a changelog file, or as tags on versions, such as the date a version became champion. During an incident, the question "what was live on Tuesday?" needs a quick answer.

Rollback rehearsal

A rollback plan that was never tried is only a hope. Practice it in a test environment: move the alias back, reload the service, and confirm which version answers. Check that the previous model still loads in the current environment. A rollback can fail if the old model needs packages that the service no longer has. Keep the older version and its environment information until you are sure you no longer need it.

Who is allowed to move an alias?

Decide this before the first release. In small teams, one named owner and one backup may be enough. In larger teams, let an automated pipeline move the alias after checks and a human approval, and restrict manual changes to emergencies. Whatever you choose, test that other accounts really cannot move the alias. After an emergency change, write down what happened and why, so the normal process can catch up.

Check your understanding

Quick check · 3 questions

of 3 answered You scored / 3 · perfect!

  1. 1. What is an alias in the registry?

    An alias points at one version and can be moved to another.
  2. 2. What does the official guidance say about model stages?

    Stages are deprecated and set to be removed in a future major release.
  3. 3. A running service loaded the champion an hour ago. You move the alias. What happens?

    The alias is resolved when the model is loaded.

Summary

  • Aliases such as champion mark which version to use.
  • Use tags for review state, and permissions to enforce it.
  • Stages are deprecated.
  • Gate promotions, record versions and prepare rollback.

Next: Evaluate Machine Learning Models

你的学习进度保存在此浏览器中,无需账号。