Skip to the workspace
Pebellslearn by building
Versioning Code, Data and Models  ›  Capstone Project

DVC Pipelines and Data Lineage

Data Lineage 15 minA DVC pipeline declares each stage's command, inputs and outputs, so DVC can rerun only what changed and record exactly which data and code produced every model.

mlops / DVC Pipelines and Data Lineage

Explore each scene at your own pace.

01 · The rule

The rule

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: false

Because train depends on prepare's output, DVC knows the order. Running dvc repro does three things:

  1. Hashes every stage's deps and reads its params.
  2. Compares them with what was saved in dvc.lock from the last run.
  3. 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.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.