What breaks when an MLflow 2 training script that logs a model with artifact_path= and loads it from the run's artifacts runs on MLflow 3?
answer
- models became their own entity
- name= replaces artifact_path=
- ModelInfo.model_id
- models:/<model_id> URI
- search_logged_models order_by dicts
basics
~20 sIn MLflow 3 a logged model is a LoggedModel with its own model_id, stored outside the run's artifacts. artifact_path= still works but warns to use name=, and loading via mlflow.get_artifact_uri("model") fails; load from ModelInfo.model_uri or models:/<model_id>.
solid answer
~40 sMLflow 3 made models first-class: `log_model` creates a **LoggedModel** with its own `model_id`, and its files live under the experiment's `models/<model_id>/artifacts`, not under the run. So `artifact_path="model"` still logs, with the warning "`artifact_path` is deprecated. Please use `name` instead." (passing both is an error), but code that builds the path from the run — `mlflow.get_artifact_uri("model")`, or `list_artifacts` on the run — no longer finds the model, and the run's Artifacts tab no longer shows it. Load with the returned `ModelInfo.model_uri` or `models:/<model_id>`; `runs:/<run_id>/model` is marked deprecated in the migration guide. The model keeps a link to its source run, copies the run's params, and can carry metrics: pass `model_id=` to `log_metric`, use `step=` to log several checkpoints in one run, and rank them with `mlflow.search_logged_models`.
code
python · 15 linesimport mlflow
model = make_forecaster() # your estimator
with mlflow.start_run() as run:
for epoch in (10, 20, 30):
model = train_more(model) # your training code
info = mlflow.sklearn.log_model(model, name=f"checkpoint-{epoch}", step=epoch)
mlflow.log_metric("val_rmse", validate(model), step=epoch, model_id=info.model_id)
best = mlflow.search_logged_models(
filter_string=f"source_run_id = '{run.info.run_id}'",
order_by=[{"field_name": "metrics.val_rmse", "ascending": True}],
output_format="list",
)[0]
forecaster = mlflow.pyfunc.load_model(f"models:/{best.model_id}")go deeper
Recall that MLflow 3 logs models with name=, that each logged model gets a model_id, and that models:/<model_id> loads it.
Explain where MLflow 3 stores a model's files, what ModelInfo returns, and how a LoggedModel links to its source run, params and metrics.
Show how you would migrate a 2.x codebase: artifact_path warnings, path-building code that silently breaks, runs:/ URIs, checkpoint comparison with search_logged_models.
Weigh how a team moves many projects to model-centric tracking — upgrade order of clients and server, which URIs downstream jobs may hold, and where model IDs get recorded.
## What changed in MLflow 3 In MLflow 2.x a model was just a directory of **run artifacts**: `mlflow.sklearn.log_model(model, artifact_path="model")` wrote it under the run, and code reached it with `runs:/<run_id>/model` or a path built from the run's artifact URI. MLflow 3 made models **first-class entities**. Every `log_model` call creates a **LoggedModel** — a record in the backend store with its own **`model_id`**, name, params, tags and metrics — and stores the files under the experiment rather than the run: ``` experiments/<experiment_id>/models/<model_id>/artifacts/ ``` The migration guide is explicit: model artifacts are no longer stored as run artifacts. ## What breaks in a 2.x script | 2.x habit | Behaviour in MLflow 3.16 | Replacement | |---|---|---| | `log_model(..., artifact_path="model")` | Logs, with a warning that `artifact_path` is deprecated | `log_model(..., name="model")` | | Passing both `artifact_path` and `name` | Raises an error | Pass `name` only | | `load_model(mlflow.get_artifact_uri("model"))` | Fails: the model is not under the run's artifacts | `load_model(info.model_uri)` | | `MlflowClient().list_artifacts(run_id)` to find the model | The model directory is not listed | Look up the LoggedModel | | `runs:/<run_id>/model` | Still resolves through the model's ID (fixed in 3.13), but marked deprecated | `models:/<model_id>` | | `run_info.run_uuid` | Removed | `run_info.run_id` | `ModelInfo`, the object `log_model` returns, carries `model_id` and `model_uri`, so the most robust fix is to keep that return value instead of rebuilding a path. ## How a LoggedModel links to its run - **Source run.** Logged inside an active run, the model records it as `source_run_id`, and the run records the model as an output. `log_model` can also be called outside any run; the model then has no source run. - **Params.** The run's params are copied onto the model, so model searches can filter on `params.*`. - **Metrics.** Pass `model_id=info.model_id` (and optionally `dataset=`) to `mlflow.log_metric` to attach a metric to one model. At log time, metrics already in the run at the model's `step` are linked to it as well. - **Checkpoints.** `log_model(..., name=f"checkpoint-{epoch}", step=epoch)` inside one run produces several LoggedModels, each with its own `model_id`. ## What a LoggedModel carries - **Identity**: `model_id`, the `name` given to `log_model`, the experiment it belongs to and its creation time. - **Lineage**: `source_run_id`, plus the run's model outputs pointing back at it. - **Description**: its params and tags; `mlflow.get_logged_model(model_id)` returns the whole record as one object. - **Results**: metrics linked by `model_id`, each optionally tied to a named dataset. `mlflow.set_active_model(model_id=...)` makes later `log_metric` calls link to that model without passing `model_id` each time. When no model is active, `log_metric` falls back to the models already associated with the run. The point of the change is comparison at the right grain. In 2.x, a run that saved five checkpoints had one set of metrics and five unlabelled folders; in 3.x each checkpoint is its own object with its own metrics, so "which checkpoint was best on the validation set" is a query instead of a naming convention. ## Finding a model by its metrics `mlflow.search_logged_models` searches models, not runs: 1. `filter_string` uses `metrics.`, `params.`, `tags.` and attribute names, such as `source_run_id = '<id>'` or `metrics.val_rmse < 11.5`; string values go in single quotes. 2. `order_by` is a **list of dicts** — `[{"field_name": "metrics.val_rmse", "ascending": True}]` — not the strings `search_runs` takes. `ascending` defaults to true; an entry can also name a `dataset_name` so only that dataset's metric counts. 3. `output_format="list"` returns `LoggedModel` objects whose `model_id` loads directly through `models:/<model_id>`. ## Migrating a script - Replace `artifact_path=` with `name=` in every `log_model` call. - Keep the returned `ModelInfo` and load from `info.model_uri`. - Replace hand-built model paths and `runs:/…` URIs with `models:/<model_id>`. - Where checkpoints are compared, log the comparison metric with `model_id=` and rank with `search_logged_models`. - Find downstream jobs that hold a run-relative URI. They keep working for now, but the migration guide says that form will be removed, so move them to `models:/<model_id>` — or to a registry URI once the model is registered. - Upgrade the client and the server together; the migration guide warns that a version mismatch can behave unexpectedly, and MLflow 3 can read 2.x data but not the reverse. Registering a LoggedModel under a name with versions and aliases is a separate step, done through the model registry.
- In MLflow 3, how do you attach a validation metric to one specific checkpoint rather than the whole run?Pass the checkpoint's ID: `mlflow.log_metric("val_rmse", v, step=epoch, model_id=info.model_id)`, optionally with `dataset=` naming the evaluation data. The metric is still recorded in the run, and `search_logged_models` can then filter and order that checkpoint by it.
- Why does a model logged in MLflow 3 no longer appear in the run's Artifacts tab?Because its files are no longer run artifacts. MLflow 3 stores them under the experiment's `models/<model_id>/artifacts` and shows them on the Logged Models page; the run page keeps the link through the run's model outputs.
- artifact_path was removed from log_model, so MLflow 2 scripts crash immediately
- In MLflow 3 the model is still a folder of run artifacts under the run ID
- search_logged_models takes order_by strings like "metrics.val_rmse ASC"
- A run can hold only one logged model, so checkpoints need separate runs
- models:/<model_id> needs the model to be registered first
Assumes MLflow 3.16; LoggedModel, models:/<model_id> and name= replacing artifact_path= arrived with MLflow 3, and 2.x stored models as run artifacts.