In MLflow, what does `MlflowClient.copy_model_version` create when promoting `room-rate-staging@candidate` into a separate `room-rate-prod` registered model?
answer
- promotion between registered models
- source must use the models:/ scheme
- next number in the destination
- tags, description and run travel
- aliases stay behind
basics
~20 scopy_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.
solid answer
~40 s`client.copy_model_version("models:/room-rate-staging@candidate", "room-rate-prod")` first resolves the source URI, which must use the `models:/` scheme (a version number or an alias), to one version. It creates `room-rate-prod` if it does not exist, then creates a new version there with the destination's next number, so staging version 21 might become prod version 5. The copy keeps the source's version tags, description, `run_id` and run link, and its `source` is recorded as `models:/room-rate-staging/21`. Aliases are not copied, because aliases belong to a registered model, so you still call `set_registered_model_alias("room-rate-prod", "champion", "5")`. The point of the pattern is separate registered models per environment, each with its own permissions; a `runs:/` source is rejected, because that is `register_model`'s job.
code
python · 12 linesfrom mlflow import MlflowClient
client = MlflowClient(tracking_uri="http://mlflow.internal.example:5000")
mv = client.copy_model_version(
src_model_uri="models:/room-rate-staging@candidate",
dst_name="room-rate-prod",
)
print(mv.version, mv.source, mv.run_id) # new number; source names the staging version
# Copying does not make it live: point the production alias at the copy
client.set_registered_model_alias("room-rate-prod", "champion", mv.version)go deeper
Recall that copy_model_version moves a version from one registered model into another, creating the destination if needed.
Explain what the copy carries: tags, description and run link travel; the version number and aliases do not.
Treat promotion as copy then alias move, reset copied validation tags when production checks again, and prefer copying by number when an alias may move mid-release.
Choose between copying versions across per-environment registered models and promoting training code into each environment, weighing artifact identity against reproducibility.
## Why copy between registered models The registry migration guide recommends expressing **environments as separate registered models**, such as `room-rate-staging` and `room-rate-prod`, so that permissions can differ: a training pipeline may write freely to staging while only a release job may change production. For simple deployments the guide names `MlflowClient.copy_model_version(src_model_uri, dst_name)` as the way to promote a version from one registered model to another. The UI offers the same operation as **Promote model** on a version's page. The alternative it recommends for mature setups is promoting **code**: each environment trains its own model into its own registered model. Copying is the lighter option when one trained artifact should move forward unchanged. ## What the call does, step by step 1. **Checks the scheme.** `src_model_uri` must be a `models:/` URI. Anything else, such as `runs:/<run_id>/room-rate`, raises "Unsupported source model URI ... only copies models stored in the 'models:/' scheme." 2. **Resolves the source** to exactly one version. `models:/room-rate-staging/21` and `models:/room-rate-staging@candidate` both work; the alias form copies whatever version `candidate` names at that moment. 3. **Creates the destination if needed.** If `room-rate-prod` does not exist it is registered; if it does, MLflow prints that it is creating a new version. 4. **Creates a new version** in the destination with the destination's **next number**. ## What travels and what does not | Field | Carried to the copy? | Notes | |---|---|---| | version number | no | the destination assigns its own next number | | model version tags | yes | `validation_status` and similar come along | | description | yes | | | `run_id` and run link | yes | the copy still points at the training run | | `source` | rewritten | recorded as `models:/room-rate-staging/21` | | aliases | no | aliases belong to the source registered model | | registered model tags | no | the destination keeps its own model-level tags | On the open-source database-backed store the copy also resolves where the source version's files live and records that location; it references the same model files rather than retraining or re-logging anything. ## Promotion as two calls Copying does not make the new version live. A complete promotion is: ```python from mlflow import MlflowClient client = MlflowClient() mv = client.copy_model_version("models:/room-rate-staging@candidate", "room-rate-prod") client.set_registered_model_alias("room-rate-prod", "champion", mv.version) ``` Between the two calls the production registered model has a new version that nothing loads yet, which is a natural place for a production-side check. Consumers of `models:/room-rate-prod@champion` see the change only at their next load. ## Copy against register_model - **`copy_model_version`** accepts only `models:/` sources and carries the source version's tags, description, run id and run link. - **`mlflow.register_model`** accepts any model URI, including `runs:/` and `models:/<model_id>`, and sets only the tags you pass. - **Both** create the destination registered model when it is missing and give the new version the destination's next number. - Use the copy when the version already passed through staging and its record should travel with it; use registration when a model enters the registry for the first time. ## Things to watch - **Number confusion.** Staging version 21 and prod version 5 are the same build. Record the mapping, for example with a tag on the copy naming the source version, or read the copy's `source` field. - **Copied tags may lie.** A `validation_status=passed` set in staging arrives on the prod copy. If production runs its own checks, reset or rename that tag after copying. - **Alias drift during the copy.** Copying by `@candidate` resolves the alias once. If someone moves `candidate` mid-release, re-running the script copies a different version; copying by number avoids that. - **Who may run it.** The split only helps if the release job, not every training job, holds write permission on `room-rate-prod`; that is the server's authentication setup, not something the call checks for you.
- Why does the copy not keep the staging version number?Version numbers are per registered model. `room-rate-prod` has its own counter, so the copy takes the next number there. The link back is the copy's `source`, recorded as `models:/room-rate-staging/<version>`, plus its `run_id`, which still names the training run.
- What is the difference between `copy_model_version` and `mlflow.register_model("models:/room-rate-staging/21", "room-rate-prod")`?Both can create a prod version from a staging version. `copy_model_version` also carries the source version's tags, description and run link and accepts only `models:/` sources; `register_model` takes any model URI, including `runs:/` and `models:/<model_id>`, and sets only the tags you pass it.
- copy_model_version keeps the same version number in the destination.
- Copying a version also copies its aliases, so champion arrives with it.
- copy_model_version accepts a runs:/ URI to promote straight from a training run.
- The copy fails unless the destination registered model already exists.
- After copying, consumers of the prod alias immediately load the new version.