Sub topic 13
What a Run Records for Reproducibility
A reproducible run lets someone else, or you in six months, answer four questions: which code ran, on which data, with which settings, in which environment. MLflow records some of this for you and leaves the rest to you. This chapter shows which parts are automatic, which parts you must add, and how to read them back.
This chapter assumes you can already create runs and log parameters, metrics, tags and models, as covered in the earlier chapters. It also assumes you have a notebook attached to compute on Databricks.
The four ingredients of reproducibility
To rerun an experiment and get a comparable result, you need:
- Code. The exact source and version that produced the run.
- Configuration. Hyperparameters, random seeds, and any other setting that changes behavior.
- Data. The training and evaluation data, or a precise reference to them.
- Environment. Library versions and the Python version.
MLflow covers these unevenly. The following diagram shows where each ingredient is stored on a run.
What is recorded automatically
Every run stores basic facts without any logging calls from you. These live in the run's info and in system tags, which are tags that start with mlflow..
| Recorded item | Where it lives | What it tells you |
|---|---|---|
| Run ID, experiment ID | `run.info` | Identity of the run |
| Start time, end time, status | `run.info` | When it ran and whether it finished, failed or was killed |
| User | tag `mlflow.user` | Who started it |
| Source | tag `mlflow.source.name` and `mlflow.source.type` | The notebook, script or job that created the run |
| Run name | tag `mlflow.runName` | The display name you set |
| Git commit | tag `mlflow.source.git.commit` | The commit, when the code was run from a Git repository |
On Databricks, runs created from a notebook or job also get Databricks-specific tags, such as the notebook path and notebook ID (mlflow.databricks.notebookPath, mlflow.databricks.notebookID). Runs started from a job carry job-related tags as well. The exact set varies by runtime and by how the run was launched, so inspect a real run in your workspace instead of assuming a list.
You can read all of this back with the client:
import mlflow
from mlflow import MlflowClient
mlflow.set_experiment("/Users/<your-email>/iris-tracking")
with mlflow.start_run(run_name="repro-demo") as run:
mlflow.log_param("C", 1.0)
mlflow.log_metric("accuracy", 0.93)
client = MlflowClient()
stored = client.get_run(run.info.run_id)
print("status:", stored.info.status)
print("started:", stored.info.start_time)
print("params:", stored.data.params)
for key, value in sorted(stored.data.tags.items()):
print(key, "=", value)Run this in a notebook and read the tag list. It shows what Databricks attached to your run, which tells you what the code ingredient looks like in your setup.
Code: tags help, but a commit is better
The source tags tell you which notebook or script produced a run, but a notebook path alone does not identify a version. Notebooks change. If you rerun a notebook after editing it, the path stays the same while the code differs.
Two practices close the gap:
- Work from a Databricks Git folder. When the code runs from a Git-backed location, MLflow can record the commit in
mlflow.source.git.commit. Pinning that commit later gives you the exact code. - Add your own tag when the automatic one is missing. For example, tag the run with a release label or a pipeline run ID.
import mlflow
with mlflow.start_run(run_name="tagged-source"):
mlflow.set_tags({
"pipeline_run_id": "nightly-2026-12-04",
"code_version": "v1.4.2",
})Do not rely on the notebook revision history in the UI as your only record. It is useful for a quick look, but it is not something you can check out in a script.
Configuration: parameters are strings
Parameters hold the settings you passed to training. Two details matter for reproducibility.
First, log everything that changes behavior, including random seeds and the split settings. A seed that is not logged is a result you cannot recreate.
Second, MLflow stores parameter values as strings. When you read them back, you must convert them yourself. "1.0" is not the float 1.0, and "None" is not None.
import mlflow
from mlflow import MlflowClient
from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
SEED = 42
mlflow.set_experiment("/Users/<your-email>/iris-tracking")
X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=SEED)
with mlflow.start_run(run_name="seeded") as run:
mlflow.log_params({"C": 0.5, "max_iter": 200, "seed": SEED})
model = LogisticRegression(C=0.5, max_iter=200).fit(X_train, y_train)
mlflow.log_metric("test_accuracy", model.score(X_test, y_test))
# Rebuild the model from the stored configuration
params = MlflowClient().get_run(run.info.run_id).data.params
rebuilt = LogisticRegression(
C=float(params["C"]),
max_iter=int(params["max_iter"]),
).fit(X_train, y_train)
print(rebuilt.score(X_test, y_test))Autologging records the estimator's parameters, including defaults you did not set. That is valuable because a default can change between library versions. It does not know about parameters that live outside the estimator, such as your split seed, so log those yourself.
Data: log a reference, not just a name
Metrics mean little without knowing what data produced them. MLflow lets you attach dataset information to a run with mlflow.log_input. The run stores the dataset's name, a digest (a short fingerprint computed from the contents), and a source description. The data itself is not copied into the run.
import mlflow
import mlflow.data
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)
train_ds = mlflow.data.from_numpy(X_train, targets=y_train, name="iris-train")
test_ds = mlflow.data.from_numpy(X_test, targets=y_test, name="iris-test")
with mlflow.start_run(run_name="with-datasets"):
mlflow.log_input(train_ds, context="training")
mlflow.log_input(test_ds, context="evaluation")The digest is the useful part. If someone later loads a dataset and its digest differs from the one on the run, the data changed, even if the table name did not.
For tables in Unity Catalog or Delta, the stronger habit is to log the exact table version as a tag or parameter, because a table name alone points at whatever the table holds today:
import mlflow
with mlflow.start_run(run_name="delta-reference"):
mlflow.set_tags({
"data.table": "main.default.iris_features",
"data.delta_version": "17",
})You must fill in the version yourself, for example from the table history. Nothing records it unless you do.
Environment: the model artifact carries it
The environment is recorded when you log a model. mlflow.sklearn.log_model writes these files into the run's model folder:
| File | Purpose |
|---|---|
| `MLmodel` | Model flavors, signature, input example reference, MLflow version, and when it was saved |
| `requirements.txt` | Pip requirements inferred for the model |
| `python_env.yaml` | Python version and pip requirements for rebuilding an environment |
| `conda.yaml` | Conda-style environment description |
Read the requirements back without downloading the whole model:
import mlflow
run_id = "<your-run-id>"
requirements_path = mlflow.pyfunc.get_model_dependencies(f"runs:/{run_id}/model")
with open(requirements_path) as f:
print(f.read())Replace <your-run-id> with the ID of a run that logged a model, such as the one from the model-logging chapter.
A model logged without a run-scoped environment cannot be reloaded reliably in a different one. This is why logging the model, not just the metrics, is part of reproducibility.
Failure modes to watch for
- Unlogged randomness. Seeds for splits, shuffling and initialization are not captured unless you log them.
- Moving data. A table or file path that is overwritten silently changes the data under the same name. Log a digest or a table version.
- Edited notebooks. A notebook path identifies a file, not a version. Use a Git folder and keep the commit tag.
- String parameters. Converting
"True"withbool("False")returnsTrue. Parse booleans explicitly. - Partial environments. The inferred requirements may miss training-only dependencies.
- Mutable tags. Tags can be edited after a run finishes. Parameters cannot be overwritten with a different value in the same run. Put facts you want to trust in parameters, and use tags for labels and notes.
A short reproducibility checklist
- Run from a Git folder so the commit is recorded.
- Log every parameter that changes behavior, including seeds.
- Log input datasets with
mlflow.log_input, and record table versions for Delta data. - Log the model with a signature and an input example so the environment files are written.
- Read the run back with
MlflowClient().get_runand confirm the fields you rely on are present.
Exercise
A teammate reruns your logged configuration and gets a different test accuracy. The run shows C=0.5 and max_iter=200, the notebook path matches, and the table name is unchanged. Name three things you would check on the original run, and say where each one is recorded.
Show answer
First, check whether the split seed was logged as a parameter. If it is missing, the train/test split cannot be recreated. Second, check the dataset digest from mlflow.log_input, or a logged Delta table version, because a table with the same name can hold different rows today. Third, check the Git commit tag mlflow.source.git.commit and the model's requirements.txt or python_env.yaml. A notebook path does not identify the code version, and a different library version can change defaults or numerical results.
Exercise
You read params = MlflowClient().get_run(run_id).data.params and see params["fit_intercept"] == "False". Why does fit_intercept=bool(params["fit_intercept"]) give the wrong model, and what should you write instead?
Show answer
MLflow stores parameter values as strings, and any non-empty string is truthy, so bool("False") is True. Write fit_intercept=(params["fit_intercept"] == "True"), or parse the value explicitly with a small helper.