What are Experiments?
Experiments in DVC allow you to run multiple variations of your pipeline with different parameters, code changes, or data, while automatically tracking all results. Each experiment is a Git commit that DVC manages separately, keeping your main branch clean while preserving full reproducibility.Key Concept: Experiments are Git commits in a special namespace (
refs/exps/) that don’t clutter your branch history. They capture code, parameters, metrics, and outputs for each run.Why Experiments Matter
- Rapid iteration: Try many parameter combinations without manual bookkeeping
- Complete tracking: Automatically capture code, params, metrics, and outputs
- Comparison: Compare results across experiments in tables and plots
- Collaboration: Share experiment results with your team
- Clean history: Keep your main branch clean while tracking all attempts
How Experiments Work
DVC experiments are built on Git’s reference system and DVC’s pipeline capabilities. The implementation is indvc/repo/experiments/__init__.py.
Experiment Lifecycle
Running an Experiment
The simplest way to run an experiment:- Current code state
- Parameter values from
params.yaml - All pipeline outputs
- Metrics and plots
dvc/repo/experiments/run.py:14-113, the implementation:
Parameter Overrides
Run experiments with different parameters without editing files:params.yaml, runs the pipeline, and commits everything.
Parameter paths use dot notation:
section.subsection.param maps to YAML structure.Experiment Storage
Experiments are stored as Git references in a special namespace. Fromdvc/repo/experiments/refs.py:
- Associated with baseline: Each experiment links to its parent commit
- Isolated from branches: Won’t appear in
git logorgit branch - Persistent: Stored in
.git/refs/exps/ - Shareable: Can be pushed to remote Git servers
The Experiments Class
The core experiments manager is defined indvc/repo/experiments/__init__.py:43-58:
Experiment Queue
Queue multiple experiments to run sequentially or in parallel:dvc/repo/experiments/queue/:
- WorkspaceQueue: Runs in current workspace
- TempDirQueue: Runs in temporary directories
- LocalCeleryQueue: Distributes via Celery workers
Queue Implementation Details
Queue Implementation Details
From
dvc/repo/experiments/__init__.py:79-97:Comparing Experiments
View experiment results in a table:Experiment Naming
Name your experiments for easier reference:dvc/repo/experiments/utils.py:check_ref_format to ensure valid Git references.
Applying Experiments
When you find a good experiment, apply it to your workspace:- Restores code from the experiment commit
- Updates
params.yamlto experiment values - Checks out pipeline outputs from cache
- Updates metrics files
Experiment Cleanup
Remove experiments you don’t need:dvc/repo/experiments/remove.py, the implementation handles cleanup of Git refs and associated data.
Checkpoints (Experiment Snapshots)
For long-running training, save intermediate results:Experiment Cache
Experiments have their own cache separate from the main DVC cache. Fromdvc/repo/experiments/__init__.py:103-105:
- Fast experiment switching without re-downloading data
- Isolated experiment outputs
- Efficient storage of experiment variations
Grid Search and Sweeps
Run experiments across parameter ranges using Hydra:dvc/repo/experiments/run.py:58-95:
Experiment Tables
Customize what’s shown indvc exp show:
Baseline Commits
Each experiment is associated with a baseline commit. Fromdvc/repo/experiments/__init__.py:256-289:
Remote Experiments
Push experiments to remote Git servers:Share with Team
Experiments can be shared via Git remotes, enabling collaborative experimentation
CI/CD Integration
Run experiments in CI pipelines and automatically track results
Temporary Directory Experiments
Run experiments without modifying your workspace:dvc/repo/experiments/__init__.py:114-132:
Related Commands
dvc exp run- Run an experimentdvc exp show- Display experiments tabledvc exp diff- Compare experimentsdvc exp apply- Apply experiment to workspacedvc exp branch- Create branch from experimentdvc queue- Manage experiment queue
Next Steps
Pipelines
Understand the pipeline system that experiments run on
Remote Storage
Share experiment outputs with your team