Sub topic 12
Versioning Data, Code, and Models for Reproducibility
Assume you know the basic train–validate–test workflow, Python and NumPy, batch or online serving, and version control. This chapter focuses on lineage: recording which data, code, configuration, and environment produced each model.
Why lineage matters
A model is reproducible when another person can recreate the same result from the same inputs. A Git commit alone is not enough. Training may also depend on a changing dataset, feature definitions, random seeds, library versions, and hyperparameters.
Store each training run as an immutable record. The record should identify:
- The data snapshot and feature-generation code.
- The training and evaluation code commit.
- The train, validation, and test split rules.
- Hyperparameters and random seeds.
- Python and dependency versions.
- The resulting model artifact and evaluation metrics.
- The person, job, or pipeline that started the run.
A data version is an immutable snapshot, such as a partition in object storage or a dataset identifier in a data-versioning system. A model version is the exact serialized artifact produced by one run. A lineage record connects these versions.
A useful lineage record
| Artifact | Example identifier | Why it matters |
|---|---|---|
| Data snapshot | `orders-2026-11-30` | Recreates the training inputs |
| Code | Git commit `a81f2c9` | Recreates transformations and training |
| Environment | `requirements.lock` hash | Recreates library behavior |
| Model | Registry version `fraud:42` | Identifies the deployable result |
Use content hashes when possible. A hash is a short fingerprint computed from file contents. If the contents change, the hash usually changes too. Record both a human-readable name and the hash because names help people while hashes support verification.
from dataclasses import asdict, dataclass
from hashlib import sha256
import json
@dataclass(frozen=True)
class RunManifest:
data_version: str
code_commit: str
environment_lock_hash: str
seed: int
model_sha256: str
def digest(content: bytes) -> str:
return sha256(content).hexdigest()
model_bytes = b"serialized-model-example"
manifest = RunManifest(
data_version="orders-2026-11-30",
code_commit="a81f2c9",
environment_lock_hash=digest(b"numpy==2.1.0\nscikit-learn==1.5.2\n"),
seed=7,
model_sha256=digest(model_bytes),
)
print(json.dumps(asdict(manifest), indent=2, sort_keys=True))The manifest should be stored beside the model and linked from the model registry. Do not overwrite an existing version. If a training run fails, preserve its validation results and failure reason instead of silently replacing them.
Exercise
Exercise
A deployed model has good metrics, but the team cannot identify which feature-code commit produced it. Which lineage field is missing, and what should the team do?
Show answer
The code commit identifier is missing. Record the exact commit, connect it to the data and environment versions, and create a new immutable manifest for the next run.