MLflow local tracking
Quick answer
MLflow Tracking offers a client API for organizing experiments and logging run metadata and files. Local tracking can use a database URI without starting an HTTP server. The examples target documented MLflow 3.x concepts; the package is not installed here. Examples use standard-library Python unless marked native MLflow, which is syntax-checked only. ByteMind execution is unverified.
Local MLflow run (native, pending)
import mlflowfrom tempfile import TemporaryDirectoryfrom pathlib import Pathwith TemporaryDirectory() as tmp: p=Path(tmp).resolve() mlflow.set_tracking_uri("sqlite:///"+str(p/"tracking.db")) eid=mlflow.create_experiment("local-demo",artifact_location=(p/"artifacts").as_uri()) with mlflow.start_run(experiment_id=eid) as run: mlflow.log_param("alpha",2) mlflow.log_metric("val_mae",1.25) r=mlflow.get_run(run.info.run_id) print(r.data.params["alpha"],r.data.metrics["val_mae"])Expected output (NOT RUN): 2 1.25. Expected read-back; native execution pending.
How it works
The backend store holds run metadata and the artifact store holds files. Use a fresh temporary directory for this lab and explicitly set a SQLite tracking URI and a local artifact location before creating the experiment. A run context closes the run on exit, including errors. A client can read metrics, parameters and tags back by run ID. A server is optional; its HTTP API and UI introduce authentication, permissions, network exposure and operational maintenance requirements. Do not start a server in this compulsory lab. A local SQLite demonstration is not a multi-user production design. MLflow versions differ in default stores; explicitly configuring stores prevents surprising defaults. The native snippet is syntax checked only; it must be run later in an approved isolated MLflow environment. The second example is a SQLite analogy, not MLflow API behavior.
SQLite metadata analogy
import sqlite3with sqlite3.connect(":memory:") as db: db.execute("CREATE TABLE runs(id TEXT PRIMARY KEY, mae REAL)") db.execute("INSERT INTO runs VALUES (?,?)",("r1",1.25)) print(db.execute("SELECT mae FROM runs WHERE id=?",("r1",)).fetchone()[0])Expected output (locally tested): 1.25. A parameterized query retrieves the recorded metric.
Common mistakes
Never inherit an unknown remote tracking URI, log a directory wholesale, or assume a metadata database contains all artifact bytes.
Practice and next steps
Compare a metadata database backup with an artifact directory backup; explain why both are needed for restoration.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
MLflow local tracking — knowledge check
Apply mlflow local tracking to small examples and debugging scenarios.
What groups runs?
What holds metadata?
Must a local client start an HTTP server?
Why explicitly configure a URI?
Which example proves native MLflow behavior here?