Zum Inhalt springen

Lektion 3 · Getting Started

Runs, Experiments and Stores

Understand MLflow experiments, runs, logged models, the backend store and the artifact store, and see how a tracking client connects to each of them.

MLflow has a few core nouns. Once you know them, the API and the web interface become much easier to read. This lesson defines each one and shows where its data lives.

Experiments and runs

An experiment is a named container for work on one task, such as churn-model or support-bot. A run is one execution of your code inside an experiment: one training job, one tuning trial or one evaluation.

A run has an ID, a name, a status, start and end times, and the data you log:

  • Parameters: inputs you chose, such as a learning rate.
  • Metrics: numeric results, such as accuracy. A metric can be recorded many times, at different steps.
  • Tags: free labels, such as who ran it or which data version it used.
  • Artifacts: files, such as plots, reports or serialized models.

In MLflow 3, a trained model can also be tracked as a logged model, with its own ID and metadata. You refer to it with a URI of the form models:/<model_id>. Older code used paths inside a run, so check which style an example uses.

Two stores

MLflow keeps two different kinds of data:

Store Holds Typical choices
Backend store Run metadata: IDs, params, metrics, tags SQLite locally; a database such as PostgreSQL for teams
Artifact store Larger files: models, images, data files A local folder, or object storage such as Amazon S3 or Azure Blob Storage

The split makes sense. A database is good at searching many small values. File storage is good at holding large files cheaply.

flowchart LR
  A["Your script"] --> B["Tracking client"]
  B --> C[("Backend store<br/>metadata")]
  B --> D[("Artifact store<br/>files")]
  E["Web UI"] --> C
  E --> D

A simplified view. With a tracking server in the middle, the client can send requests to the server, which talks to the stores.

Three common setups

  1. Solo, local. Everything is on your laptop: a SQLite file and a folder for artifacts.
  2. Solo with a local server. You start mlflow server and point your scripts at its address.
  3. Team server. A shared server uses a database server and shared file storage. Everyone logs to one URL.

Managed services run the server for you and add their own login and access rules.

Metadata as tables

The next block is a stand-in: a tiny SQL database with a made-up layout. The real database schema of MLflow is different, and you should read data through the API instead of querying it. The point is to see why a database suits metadata.

SQL Stand-in: run metadata in a database (not MLflow's schema)

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

Notice that parameter values are stored as text, while metric values are numbers. MLflow also treats parameters as strings when you search, which matters in the searching lesson. If SQL is new to you, see the SQL tutorial.

Reading a run in code

After logging, you can read a run back with the client:

Python
from mlflow import MlflowClient

client = MlflowClient(tracking_uri="sqlite:///mlflow.db")
experiment = client.get_experiment_by_name("first-steps")

for run in client.search_runs([experiment.experiment_id]):
    print(run.info.run_id, run.info.status)
    print(run.data.params, run.data.metrics, run.data.tags.get("stage"))

The object has two main parts: run.info for identity and status, and run.data for what you logged. In run.data.metrics you see one latest value for each metric. Use client.get_metric_history when you need every step.

Naming that scales

  • Name experiments after the question, not after a person: churn-prediction, not maria-tests.
  • Give runs short, readable names, or let MLflow generate them and rely on tags.
  • Agree on a few required tags in your team, such as data_version and owner.
  • Create a new experiment when the target or the evaluation data changes in a way that makes old scores incomparable.

Do not put runs measured on different test data in one list and compare their scores as if they were equal. Record the data version on every run.

What a run looks like after training

It helps to picture one finished run of a churn model:

Item Example value
Experiment churn-prediction
Run name forest-depth-6
Status Finished
Parameters model=forest, max_depth=6, seed=42
Metrics val_f1, train_f1
Tags data_version=7, owner=ana
Artifacts features.json, a plot, the model

All values here are invented. If a teammate opens this run, they can answer what was tried, on which data, how well it did and where the model is.

Status and failures

A run is marked as running, finished, failed or killed, depending on how it ended. A run can stay "running" if a process is stopped abruptly and never closes it. When you list runs, remember that unfinished or failed ones may have partial data. Filter them out before you pick a winner, but do not delete them at once: they show which settings crash.

Where to put a team server's data

For a team, decide these before the first run:

  1. Database. Who maintains it and backs it up?
  2. File storage. Which bucket or share, with which access rules?
  3. Address. What URL do scripts use?
  4. Retention. How long are runs and artifacts kept?

Changing storage later is possible but takes planning, because existing runs record where their artifacts live. A short written decision at the start saves painful migration work.

Concepts to keep separate

New users often mix up three things:

  • A run records an event that happened.
  • A logged model is an artifact with its own identity, created during work.
  • A registered model is a named entry that you manage for use by others.

You can have thousands of runs, many logged models and only a handful of registered models. Later chapters cover each of the last two.

Check your understanding

Quick check · 3 questions

of 3 answered You scored / 3 · perfect!

  1. 1. What does the artifact store hold?

    Files go to the artifact store; small searchable metadata goes to the backend store.
  2. 2. What is an experiment?

    An experiment groups related runs; one execution is a run.
  3. 3. When should you consider a new experiment?

    Mixing incomparable scores in one place leads to wrong conclusions.

Summary

  • Experiments group runs; runs hold params, metrics, tags and artifacts.
  • The backend store keeps metadata; the artifact store keeps files.
  • Setups range from one SQLite file to a shared team server.
  • Read data with the API rather than the database tables.

Next: Log Parameters and Metrics

Dein Fortschritt wird in diesem Browser gespeichert. Kein Konto nötig.