Data and Model Versioning with DVC
Version large datasets and model files alongside code, and define reproducible pipelines that rerun only what changed.
Intermediate · about 5 hours · difficulty 2/5
Learn first: Experiment Tracking with MLflow and Weights and Biases
Git is built for text files, not 20 GB of images. Yet a model is a function of code and data, so both need versions. DVC (Data Version Control) extends Git to handle this.
How DVC works
dvc add data/rawreplaces the data in Git with a small.dvcpointer file holding a content hash.- The actual files live in a remote (S3, GCS, Azure, SSH or a local folder) and are fetched with
dvc pull. - Checking out an old commit plus
dvc checkoutrestores the exact data used then.
Pipelines
A dvc.yaml file describes stages (prepare, featurize, train, evaluate) with their dependencies and outputs. dvc repro reruns only stages whose inputs changed, like make for ML. dvc metrics diff and dvc plots compare results across branches.
Alternatives and complements
- Lake formats such as Delta Lake or Apache Iceberg offer time travel on tables.
- LakeFS gives Git-like branches over object storage.
- Hugging Face Hub datasets have versioned repos.
- Model files usually live in the model registry from experiment tracking, linked to the data version that produced them.
Lineage
The goal is lineage: for any prediction in production you can answer which model, trained on which data, by which code. That matters for debugging, audits and regulated industries.
Good enough to move on when you can clone a repo, run dvc pull and dvc repro, and get the same model and metrics as the original author.
Key concepts
- Why data needs versions
- dvc add and remotes
- dvc.yaml pipelines and repro
- Metrics and plots diff
- Lineage and audit trails
- Delta Lake, Iceberg and LakeFS
Mini project
Put your project's raw data under DVC with a cloud or local remote, define a three-stage dvc.yaml pipeline, change one feature, and use dvc metrics diff to show the effect between two branches.
Check yourself
What is actually committed to Git when you run dvc add on a folder, and how does dvc repro decide which stages to rerun?
Free resources
- DVC documentation (Iterative)
- Made With ML (Made With ML)