Model Registry, data versioning & lineage
Register model versions in MLflow, promote them with aliases like `@champion` (stages are deprecated), version datasets with DVC, and connect code, data, run and model into one lineage.
Experiment tracking answers “what did I try?”. A [[model-registry]] answers “which model is in production right now, which one was before, and where did it come from?”. [[data-versioning]] answers “exactly which data was it trained on?”. Together they give lineage: from a prediction in production you can walk back to the model version, the training run, the code commit and the data snapshot.
What must be versioned
| Thing | Tool | Identifier |
|---|---|---|
| Code & configs | Git | commit SHA |
| Data | DVC (or lakeFS, Delta Lake time travel…) | content hash (md5) in a .dvc / dvc.lock file |
| Experiment | MLflow Tracking | run_id |
| Model | MLflow Model Registry | name + version number (+ aliases) |
| Environment | lock file, Docker image | image digest |
1. MLflow Model Registry
A registered model is a named entry (e.g. churn-clf). Each time you register a logged model under that name it gets an auto-incrementing version (1, 2, 3…). A version can carry tags (validation_status=approved) and aliases — mutable, named pointers such as champion or challenger that point to exactly one version. Serving code loads models:/churn-clf@champion; promoting a new model is just moving the alias, and rollback is moving it back[1][4].
import mlflow
from mlflow import MlflowClient
mlflow.set_tracking_uri("http://127.0.0.1:5000")
# (a) register while logging
with mlflow.start_run() as run:
model.fit(X_train, y_train)
info = mlflow.sklearn.log_model(
model, name="model", # MLflow 2.x: artifact_path="model"
input_example=X_train[:5],
registered_model_name="churn-clf", # creates version N+1
)
# (b) or register an already-logged model afterwards
mv = mlflow.register_model(info.model_uri, "churn-clf")
print(mv.name, mv.version)
client = MlflowClient()
client.set_registered_model_alias("churn-clf", "champion", mv.version)
client.set_model_version_tag("churn-clf", mv.version, "validation_status", "approved")
# Serving / batch code never hard-codes a version number:
champion = mlflow.pyfunc.load_model("models:/churn-clf@champion")
preds = champion.predict(X_new)
# Look up which version the alias points to
print(client.get_model_version_by_alias("churn-clf", "champion").version)None → Staging → Production → Archived) and client.transition_model_version_stage(...), loading models:/churn-clf/Production. Since MLflow 2.9 model stages are deprecated (scheduled for removal in a future major release). The recommended replacements are aliases for deployment pointers (@champion, @challenger) and tags for status; environments such as dev/staging/prod are better separated with different registered models or workspaces/catalogs, not stages[1]. Aliases are more flexible: you can define as many as you need, and one version can hold several.| Old (stages) | New (aliases & tags) |
|---|---|
transition_model_version_stage(name, v, "Production") | set_registered_model_alias(name, "champion", v) |
models:/churn-clf/Production | models:/churn-clf@champion |
Stage Staging as a status | Tag validation_status=pending or alias @challenger |
| Only 4 fixed stages | Any number of custom aliases |
2. Versioning data with DVC
Git is bad at large binary files. [[dvc]] (Data Version Control) keeps the real files in a cache and a remote (S3, GCS, Azure, SSH, a shared drive…), and commits only a tiny .dvc pointer file containing the file's hash to Git. Checking out an old commit and running dvc checkout/dvc pull restores exactly the data that went with it[2][3].
git init && dvc init # creates .dvc/ ; commit it
dvc add data/raw/churn.csv # -> data/raw/churn.csv.dvc (hash) + adds file to .gitignore
git add data/raw/churn.csv.dvc data/raw/.gitignore
git commit -m "Track raw churn data v1"
dvc remote add -d storage s3://my-bucket/dvc-store # -d = default remote
git commit -am "Configure DVC remote"
dvc push # upload data to the remote
# a teammate / CI machine:
git clone <repo> && cd <repo>
dvc pull # download the exact data for this commit
# new data version
cp new_export.csv data/raw/churn.csv
dvc add data/raw/churn.csv && git commit -am "Data v2" && dvc pushDVC can also describe the pipeline in dvc.yaml as stages with dependencies (deps), outputs (outs), params and metrics. dvc repro re-runs only the stages whose inputs changed, and dvc.lock records the hashes of everything — a lightweight, Git-friendly lineage record.
stages:
prepare:
cmd: python src/data.py data/raw/churn.csv data/processed
deps:
- src/data.py
- data/raw/churn.csv
outs:
- data/processed
train:
cmd: python src/train.py
deps:
- src/train.py
- data/processed
params:
- train.lr
- train.n_estimators
outs:
- models/model.pkl
metrics:
- metrics.json:
cache: false3. Lineage: tie it all together
- Log the git commit and the DVC data hash as MLflow tags on every training run.
- Register the model from that run — the model version keeps a link to its
run_id. - Log the model version (or alias resolution) with every prediction in production logs.
- Result: prediction → model version → run → commit + data hash → reproducible training.
import subprocess, yaml, mlflow
commit = subprocess.check_output(["git", "rev-parse", "HEAD"], text=True).strip()
data_md5 = yaml.safe_load(open("data/raw/churn.csv.dvc"))["outs"][0]["md5"]
with mlflow.start_run():
mlflow.set_tags({"git_commit": commit, "data_md5": data_md5})
... # train, log metrics, log_model(registered_model_name="churn-clf")- What it is
- The rule that decides when the
@championalias moves to a new version (manual approval, automatic after passing tests, after an A/B test…). - ↑ If you increase it
- More automation = faster, more frequent updates, but a weak quality gate can promote a bad model.
- ↓ If you decrease it
- More manual review = safer, but models go stale and people become the bottleneck.
- Typical values
- Automatic
@challenger, human or A/B-gated move to@champion.
- What it is
- Seconds
mlflow.register_modelwaits for the new version to become READY before returning. - ↑ If you increase it
- Safer in scripts that immediately set an alias or load the version; the call may block longer.
- ↓ If you decrease it
- 0 returns immediately — the version may still be PENDING_REGISTRATION on some backends.
- Typical values
- Default 300 s.
- What it is
- How DVC places files from its cache into your workspace.
- ↑ If you increase it
- Links (reflink/hardlink/symlink) avoid duplicating huge datasets on disk and make checkouts instant; hard/symlinks must not be edited in place (DVC protects them).
- ↓ If you decrease it
copyis the most compatible and safe to edit, but doubles disk usage and is slow for big data.- Typical values
- Default
reflink,copy; switch to links for multi-GB datasets.
models:/churn-clf/3 — a hard-coded version means every release needs a code change; use an alias. • Using stages in new projects — they are deprecated. • dvc add without dvc push → teammates' dvc pull fails. • Editing a dataset in place without re-running dvc add → Git and data silently disagree. • Registering models without the training run link, signature or data hash → no lineage when something goes wrong.▸Go deeper: model cards and governance
Beyond versions, mature teams attach documentation to each registered model: intended use, training data summary, evaluation results per slice, known limitations and ethical considerations — the “model card” idea (Mitchell et al., 2019). Registries in managed platforms (e.g. Databricks Unity Catalog, SageMaker, Vertex AI) add access control and audit logs. The core pattern is always the same: immutable versions + movable pointers + metadata linking back to code and data.
Quiz
dvc add data/raw/churn.csv commit to Git?dvc pull. Most likely cause?dvc.yaml pipeline, you only edit src/train.py. What does dvc repro do?References
- [1]
- [2]DVC — Get Started: Data VersioningDocsIterative / DVCdoc.dvc.org
- [3]DVC documentationDocsIterative / DVCdoc.dvc.org
- [4]mlflow.client — MlflowClient APIDocsMLflowmlflow.org