skip to content

Registered Models & Aliases

Registered models hold numbered versions, and aliases such as @champion plus tags replace the deprecated Staging and Production stages. Interviewers ask how serving finds a version and rolls back.

on this pageshow

questions

6

In MLflow, how does passing `registered_model_name=` to `log_model` differ from calling `mlflow.register_model` later, and how are versions numbered?

level: juniorimportance: must knowfreq 34%

answer

  1. two doors into one registry
  2. register while logging, or after choosing
  3. source URI: models:/<model_id> or runs:/
  4. a counter per registered model name
  5. ModelInfo.registered_model_version

basics

~20 s

registered_model_name in log_model logs and registers in one call; mlflow.register_model registers an already-logged model later. Both create the registered model if it is missing and add the next version number under that name, starting at 1.

solid answer

~40 s

Passing `registered_model_name="room-rate-staging"` to `mlflow.sklearn.log_model` logs the model and registers it in the same call, so every training run that reaches that line becomes a new version. `mlflow.register_model(model_uri, "room-rate-staging")` registers a model you already logged, from a `models:/<model_id>` or `runs:/<run_id>/<name>` URI, which suits a pipeline that compares candidates first and registers only the winner. Either way MLflow creates the registered model when the name is new and gives the version the next integer under that name: numbering is per registered model, not global. In MLflow 3, `log_model` registers the LoggedModel it just created, so the version's `source` is `models:/<model_id>` and its `run_id` names the training run. `log_model` returns a `ModelInfo` whose `registered_model_version` holds the number; `register_model` returns the `ModelVersion`.

code

python · 18 lines
python
import mlflow

mlflow.set_tracking_uri("http://mlflow.internal.example:5000")

# Path 1: register in the same call that logs the model
with mlflow.start_run():
    info = mlflow.sklearn.log_model(
        sk_model=rate_model,
        name="room-rate",
        registered_model_name="room-rate-staging",
    )
print(info.registered_model_version)  # next number under room-rate-staging

# Path 2: log only, compare candidates, register the winner afterwards
with mlflow.start_run():
    cand = mlflow.sklearn.log_model(sk_model=candidate_model, name="room-rate")
mv = mlflow.register_model(f"models:/{cand.model_id}", "room-rate-staging")
print(mv.version, mv.run_id, mv.source)

go deeper

for a junior

Know both ways to register: the registered_model_name argument while logging, and mlflow.register_model afterwards. Say that versions count from 1 under each registered model name.

for a middle

Explain what each path returns, that both create the registered model if missing, and that create_registered_model alone raises on an existing name.

for a senior

Choose the path for the pipeline: register every run or only the chosen candidate. Name what a version records about its source, and what changed in MLflow 3 with LoggedModel.

for a principal

Weigh registry hygiene against traceability: registering every run fills the version list, registering only winners hides rejected candidates from the registry view.

## Registered models and versions The **MLflow Model Registry** stores named **registered models**. Each registered model holds numbered **model versions**, and each version points at the files of one logged model. The registered model also carries aliases, tags and a description. On a self-hosted server the registry needs a database-backed backend store, which is what the docs require before the registry UI or API will work. A pricing team that retrains a nightly room-rate model has to decide *when* a trained model enters the registry. MLflow offers two everyday paths, plus a lower-level client pair. ## The two everyday paths 1. **Register while logging.** Pass `registered_model_name=` to any flavor's `log_model`, for example `mlflow.sklearn.log_model(sk_model=model, name="room-rate", registered_model_name="room-rate-staging")`. The model is logged and a version is created in the same call. 2. **Register afterwards.** Log without registering, compare candidates, then call `mlflow.register_model(model_uri, name)` on the one you keep. `model_uri` can be `models:/<model_id>` (the LoggedModel returned by `log_model`), `runs:/<run_id>/<name>`, an existing `models:/<name>/<version>`, or a local path written by `save_model`. The lower-level pair is `MlflowClient.create_registered_model(name)` followed by `create_model_version(name, source, run_id)`. Unlike the two paths above, `create_registered_model` raises an `MlflowException` when the name already exists. | | `registered_model_name=` in `log_model` | `mlflow.register_model` | |---|---|---| | When it registers | in the logging call | whenever you call it | | What it registers | the LoggedModel just created | any model URI you pass | | What it returns | `ModelInfo` with `registered_model_version` | the `ModelVersion` object | | Fits | every run should become a version | only a chosen candidate should | Both paths create the registered model if the name is new and otherwise add a version to it. Both wait for the version to reach `READY`; `await_registration_for` defaults to 300 seconds. ## How version numbers are assigned - Numbers are **per registered model**: `room-rate-staging` and `room-rate-prod` count independently, each from **1**. - On the database-backed store the next number is the highest existing version under that name plus one. A deleted version is kept as a soft-deleted row, so its number is never handed out again and later versions are not renumbered. - Registering the same logged model twice creates two versions with two numbers; the registry does not deduplicate by content. ## What a version links back to A **model version** records where it came from: - **`run_id`**: the training run. When you register from `models:/<model_id>`, the store fills it from the LoggedModel's source run. - **`source`**: the URI the version was registered from. In MLflow 3, `log_model` registers `models:/<model_id>`, so `source` names the **LoggedModel**, the first-class model entity MLflow 3 introduced. - **`run_link`** and **description**, where set. In MLflow 3 a model's files live under the logged model rather than among the run's artifacts. `register_model("runs:/<run_id>/room-rate", ...)` still works: finding no model files at that run path, MLflow looks up the logged model named `room-rate` from that run, registers `models:/<model_id>` instead and logs a warning. How a platform walks from an old version back to everything needed to rebuild it is a separate design subject; the registry's part is these fields. ## What registration does not do Registering is bookkeeping, and interviewers like candidates who know its limits: - **It does not copy the model files.** On the database-backed store a version registered from `models:/<model_id>` records the LoggedModel's artifact location; the files stay where `log_model` wrote them. - **It does not make anything live.** A new version carries no alias, so `models:/room-rate-prod@champion` keeps resolving to whatever it named before. Promotion is a separate alias move. - **It does not judge the model.** Nothing compares the new version with earlier ones; whether it is better is decided by your evaluation, and recorded with tags. - **It does not check the name's history.** Registering into an existing name simply adds a version; nothing warns that a teammate's pipeline writes there too. ## Choosing between the paths - Use **`registered_model_name=`** when every successful training run should become a candidate version, and a later check decides which version gets an alias. - Use **`mlflow.register_model`** when a sweep produces many logged models and only the winner belongs in the registry, which keeps the version list short. - Pass `tags=` to `register_model` to record facts at registration time, such as the training data snapshot. ## Mistakes interviewers listen for - Treating version numbers as global, or expecting a deleted number to be reused. - Calling `create_registered_model` in a training job and crashing on the second night because the name exists. - In MLflow 3, building a model path from `mlflow.get_artifact_uri("room-rate")`: model files are no longer run artifacts, so that load fails. Use `ModelInfo.model_uri` or `models:/<model_id>`. - Writing `artifact_path=` in new code: MLflow 3 logs "`artifact_path` is deprecated. Please use `name` instead."

  • What happens if `mlflow.register_model` gets `runs:/<run_id>/room-rate` for a model logged with MLflow 3?
    MLflow 3 stores model files under the LoggedModel, not the run's artifacts. Finding no `MLmodel` file at that run path, `register_model` looks for a logged model named `room-rate` from that run and registers `models:/<model_id>` instead, with a warning. If the run logged several such models it takes the one logged at the largest step, and it raises if none exists.
  • Version 3 of `room-rate-staging` is deleted. What number does the next registration get?
    The highest number ever used plus one. On the database-backed store a deleted version stays as a soft-deleted row, so the next version after 1-6 is still 7, number 3 is not reused, and versions 4-6 keep their numbers.

  • Version numbers are global across the registry, so each model's versions skip numbers.
  • Registering under an existing name fails, so every run needs a fresh registered model name.
  • registered_model_name and register_model create different kinds of registry objects.
  • A registered version is detached from the run that trained it.
  • In MLflow 3 you load a just-logged model from mlflow.get_artifact_uri of the run.

Assumes MLflow 3.16; since MLflow 3, log_model takes name= and registers the LoggedModel it creates (models:/<model_id>), with artifact_path= deprecated.

open as a page

In the MLflow Model Registry, how do aliases such as `@champion` promote and roll back a `room-rate-prod` model version?

level: middleimportance: must knowfreq 22%

basics

~20 s

MlflowClient.set_registered_model_alias(name, alias, version) points an alias such as champion at exactly one version; calling it again moves the alias, so promotion and rollback are the same call with a different version. A version may carry several aliases.

open as a page

A long-running pricing service loaded `models:/room-rate-prod@champion` from the MLflow registry; after on-call moves `champion` back a version, why does it still score with the newer one?

level: seniorimportance: should knowfreq 9%

basics

~20 s

An MLflow alias is resolved when the URI is loaded: load_model asks which version champion names, downloads it and keeps that object. Moving the alias changes only what the next load gets, so the service must reload or restart.

open as a page

In MLflow, what does `MlflowClient.copy_model_version` create when promoting `room-rate-staging@candidate` into a separate `room-rate-prod` registered model?

level: middleimportance: nice to knowfreq 5%

basics

~20 s

copy_model_version resolves the models:/ source to one version and adds a new version to the destination, creating that registered model if needed. The copy gets the destination's next number and keeps the source's tags, description and run, but no aliases.

open as a page

Code written for MLflow 2.x calls `transition_model_version_stage` and loads `models:/room-rate/Production`; what replaces each when moving to MLflow 3.16?

level: seniorimportance: nice to knowfreq 6%

basics

~20 s

Registry stages have been deprecated since MLflow 2.9.0 and still are in 3.16. Replace the Production stage with an alias such as champion loaded by models:/name@champion, stage-as-status with model version tags, and stage-as-environment with separate registered models.

open as a page