DVC Pipelines and Data Lineage
Training the churn model takes two steps: turn the raw CSV into features, then fit the model. Run them by hand and you will one day forget to rerun the first after changing it — and train on stale features. A DVC pipeline writes the steps down with their inputs and outputs, so the tool decides what needs to run.
The rule
Declare the inputs; rerun only what they touched.
A pipeline lives in dvc.yaml. Each stage has a command, its deps (inputs), its params (settings read from params.yaml) and its outs (outputs):
stages:
prepare:
cmd: python prepare.py
deps:
- data/subscriptions.csv
- prepare.py
outs:
- data/features.parquet
train:
cmd: python train.py
deps:
- data/features.parquet
- train.py
params:
- max_depth
outs:
- models/model.pkl
metrics:
- metrics.json:
cache: falseBecause train depends on prepare's output, DVC knows the order. Running dvc repro does three things:
- Hashes every stage's deps and reads its params.
- Compares them with what was saved in
dvc.lockfrom the last run. - Reruns only stages whose inputs changed. A rerun that produces a new output changes the inputs of the stages downstream, so they rerun too. Then it updates
dvc.lock.
dvc.lock is committed to Git. That makes it a lineage record: for any commit, it lists the exact hashes of the data, code and model involved, plus the parameter values. Asked "what made this model?", you read the lock file of the commit that produced it.