Education › OSS Deep Dives › Stage 2: MLOps platforms

MLflow: tracking, registry and GenAI

Runs, experiments, artifacts and the tracking server; the model registry with aliases; tracing and evaluation for LLM apps.

Intermediate ~30 min read Module 4 of 10

MLflow started as experiment tracking for data scientists and has grown into a general AI engineering platform: tracking and a model registry for classical models, and tracing, evaluation and a prompt registry for LLM applications and agents. It is a Python package plus a server, both from mlflow/mlflow, and it runs on a laptop with one command. This lesson covers the MLflow 3 data model, how to run the server properly for a team, promoting models with aliases, and the GenAI features you will reach for when an LLM app misbehaves.

After this module you can
  • Log parameters, metrics and models to an MLflow tracking server
  • Run a team MLflow server with a database backend and object-storage artifacts
  • Register model versions and promote them with aliases instead of stages
  • Trace an LLM application and evaluate it with built-in and custom scorers
  • Version prompts in the prompt registry and load them by URI

The data model: experiments, runs, models

An experiment groups related work, such as "churn model". A run is one execution inside it, recording parameters (inputs you chose), metrics (numbers you measured, optionally per step), tags, and artifacts (files such as plots or a dataset sample). MLflow 3 adds the LoggedModel as a first-class object: a model can be logged with a name and no active run, and later runs, evaluations and traces link back to it.

Track a training run and log the model
python
import mlflow
from sklearn.datasets import load_diabetes
from sklearn.linear_model import Ridge
from sklearn.metrics import mean_squared_error

mlflow.set_tracking_uri("http://localhost:5000")
mlflow.set_experiment("diabetes")

X, y = load_diabetes(return_X_y=True)
with mlflow.start_run():
    alpha = 0.5
    model = Ridge(alpha=alpha).fit(X, y)
    mlflow.log_param("alpha", alpha)
    mlflow.log_metric("mse", mean_squared_error(y, model.predict(X)))
    mlflow.sklearn.log_model(model, name="model", registered_model_name="diabetes-ridge")

Autologging (mlflow.sklearn.autolog(), mlflow.pytorch.autolog() and friends) records parameters, metrics and the model for supported libraries without explicit calls. Models are saved with a flavor (sklearn, pytorch, transformers) plus the generic pyfunc flavor, so anything you log can be loaded with mlflow.pyfunc.load_model(uri) and called with .predict(), whatever library trained it.

Note

Upgrading from MLflow 2? log_model takes name= instead of artifact_path=, and a run is no longer required to log a model. Old code still runs with deprecation warnings, but fix it before they become errors.

Running the server for a team

mlflow server (or uvx mlflow server without installing anything) starts the tracking server and UI on port 5000. It has two storage halves. The backend store holds metadata: experiments, runs, params, metrics, registry entries. SQLite (mlflow.db in the current directory) is now the default; the older ./mlruns file store is in maintenance mode. The artifact store holds the large files: models, plots, datasets.

A shared server: Postgres for metadata, S3 for artifacts
bash
mlflow server \
  --backend-store-uri postgresql://mlflow:CHANGE_ME@db.internal:5432/mlflow \
  --artifacts-destination s3://acme-mlflow-artifacts \
  --host 0.0.0.0 \
  --port 5000
logtracemetadataproxied filesresolve aliasload versionTraining jobsruns, modelsLLM appstraces, evalsTracking serverUI, REST, registryBackend storePostgres: metadataArtifact storeS3: model filesServingmodels:/x@champion
The tracking server is stateless: metadata goes to a database, files go to object storage, and serving code finds the right model through a registry alias.
  • With --artifacts-destination, the server proxies artifact uploads and downloads, so clients need only the server URL, not cloud credentials.
  • SQLite is fine for one person; for a team use Postgres or MySQL, which handle concurrent writers and survive a pod restart.
  • The open-source server ships basic authentication and workspaces, but put it behind your SSO proxy and TLS before exposing it beyond a VPN.
  • On Kubernetes, run the server as a stateless Deployment (there is a Helm chart in the repo's charts/ folder); all state lives in the database and the bucket.

The model registry: versions and aliases

A registered model is a name, such as diabetes-ridge, holding numbered versions. Each version points at a logged model and remembers which run produced it, so you can always answer "what data and parameters made the thing in production?"

Promote with aliases: mutable, named pointers to one version, such as champion or challenger. Your serving code loads models:/diabetes-ridge@champion; promoting a new version is a single API call that moves the alias, and rolling back moves it back. The older fixed stages (Staging, Production) are deprecated in favour of aliases and tags.

Promote version 7 and load whatever champion points at
python
import mlflow
from mlflow import MlflowClient

client = MlflowClient()
client.set_registered_model_alias("diabetes-ridge", "champion", 7)
client.set_model_version_tag("diabetes-ridge", "7", "validated_by", "ci")

model = mlflow.pyfunc.load_model("models:/diabetes-ridge@champion")

To serve, mlflow models serve -m models:/diabetes-ridge@champion -p 8080 starts a local REST endpoint, and mlflow models build-docker packages a model into an image you can run anywhere, including KServe.

GenAI: tracing, evaluation and prompts

For LLM applications the questions change: not "what was the loss?" but "what did the agent retrieve, which tool did it call, why was the answer wrong, and did my prompt change make things better?" MLflow answers with traces: a tree of spans per request, recording inputs, outputs, latency and token usage. One line, such as mlflow.openai.autolog(), instruments a supported client library; the @mlflow.trace decorator instruments your own functions. Traces are OpenTelemetry-compatible.

Trace an app and evaluate it on a small dataset
python
import mlflow
from mlflow.genai import scorer
from mlflow.genai.scorers import Correctness, Guidelines


@mlflow.trace
def answer(question: str) -> str:
    return call_llm(f"Answer briefly: {question}")  # your model call


@scorer
def is_short(outputs: str) -> bool:
    return len(outputs.split()) <= 30


data = [
    {"inputs": {"question": "What does SLO stand for?"},
     "expectations": {"expected_response": "Service level objective"}},
]
mlflow.genai.evaluate(
    data=data,
    predict_fn=answer,
    scorers=[Correctness(), Guidelines(name="plain", guidelines="No jargon."), is_short],
)

Correctness and Guidelines are LLM-judge scorers: they ask a judge model, which you configure, to grade each output. Custom @scorer functions are plain code and cost nothing to run. Every evaluation run is stored with its traces, so you can open a failing example and see exactly which step went wrong.

The prompt registry gives prompts the same treatment as models: mlflow.genai.register_prompt(name=..., template=...) creates a new version on each call, mlflow.genai.load_prompt("prompts:/summarize/3") loads one, and aliases work here too, so a prompt change can be reviewed, evaluated and rolled back without a code deploy.

Hands-on practice

Track, register, promote, and evaluate

  1. Run pip install mlflow scikit-learn, then start a server with mlflow server --port 5000 and open the UI.
  2. Run the training script from this lesson three times with alpha values 0.1, 0.5 and 2.0, and compare the runs side by side in the UI.
  3. In the registry, check that diabetes-ridge has three versions; set the champion alias on the best one with MlflowClient.
  4. Serve it with mlflow models serve -m models:/diabetes-ridge@champion -p 8080 --env-manager local and send it a request with curl.
  5. Move champion to another version, restart the server, and confirm the predictions change without any code change.
  6. Wrap any function in @mlflow.trace, call it a few times, and inspect the spans in the Traces tab.
  7. Write one custom @scorer and run mlflow.genai.evaluate on a five-row dataset; open a failing row's trace.
Cheat sheet

MLflow: tracking, registry and GenAI — at a glance

Main things to focus on

  • Experiment > run > params, metrics, artifacts; MLflow 3 adds LoggedModel as a first-class object.
  • Backend store holds metadata (database), artifact store holds files (object storage).
  • Promote with aliases (models:/name@champion), not deprecated stages.
  • Every model loads as pyfunc and serves through the same predict interface.
  • Traces explain LLM failures; evaluation with scorers measures whether a change helped.
  • Version prompts in the registry so prompt changes are reviewable and reversible.

Tracking

mlflow.set_tracking_uri("http://host:5000")Point the client at a server
mlflow.set_experiment("name")Create or select an experiment
with mlflow.start_run(): ...Open a run; params and metrics attach to it
mlflow.log_param / log_metric / log_artifactRecord inputs, numbers and files
mlflow.sklearn.autolog()Log everything automatically for a library

Models and registry

mlflow.sklearn.log_model(m, name="model", registered_model_name="x")Log and register in one call
client.set_registered_model_alias("x", "champion", 7)Point an alias at a version
mlflow.pyfunc.load_model("models:/x@champion")Load by alias, version or run URI
mlflow models serve -m models:/x@champion -p 8080Local REST scoring server
mlflow models build-docker -m models:/x/7 -n img:tagPackage a model as a container image

Server

mlflow server --port 5000Local server, SQLite backend by default
--backend-store-uri postgresql://...Shared metadata database
--artifacts-destination s3://bucketProxied artifact storage

GenAI

@mlflow.traceRecord a function as a span in a trace
mlflow.openai.autolog()Trace a supported client library automatically
mlflow.genai.evaluate(data=, predict_fn=, scorers=[...])Score an app on a dataset
@scorer def name(outputs) -> boolCustom, code-based scorer
mlflow.genai.load_prompt("prompts:/name/3")Load a versioned prompt

Common pitfalls

  • Running a team server on SQLite inside a container with no volume, and losing every run on restart.
  • Hard-coding models:/x/7 in serving code, so every promotion needs a deploy.
  • Logging huge artifacts on every step and filling the bucket.
  • Judging an LLM change by reading three outputs instead of running an evaluation.
  • Exposing the tracking server publicly with no authentication in front of it.
Quiz

Check your understanding

5 questions · 4 to pass · answers are explained as you go. Your best score is saved on this device only.

Progress and quiz scores are saved in this browser only. Back up or restore on the hub.

Was this lesson useful? Tell me what to improve →