Skip to main content

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 in dvc/repo/experiments/__init__.py.

Experiment Lifecycle

Running an Experiment

The simplest way to run an experiment:
This executes your pipeline and creates an experiment commit with:
  • Current code state
  • Parameter values from params.yaml
  • All pipeline outputs
  • Metrics and plots
From dvc/repo/experiments/run.py:14-113, the implementation:

Parameter Overrides

Run experiments with different parameters without editing files:
Shorthand:
DVC temporarily modifies 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. From dvc/repo/experiments/refs.py:
Structure:
This keeps experiments:
  • Associated with baseline: Each experiment links to its parent commit
  • Isolated from branches: Won’t appear in git log or git branch
  • Persistent: Stored in .git/refs/exps/
  • Shareable: Can be pushed to remote Git servers

The Experiments Class

The core experiments manager is defined in dvc/repo/experiments/__init__.py:43-58:

Experiment Queue

Queue multiple experiments to run sequentially or in parallel:
Then run all queued experiments:
Or run with multiple workers:
The queue implementation uses different backends from dvc/repo/experiments/queue/:
  • WorkspaceQueue: Runs in current workspace
  • TempDirQueue: Runs in temporary directories
  • LocalCeleryQueue: Distributes via Celery workers
From dvc/repo/experiments/__init__.py:79-97:

Comparing Experiments

View experiment results in a table:
Output:
Compare specific experiments:
Use dvc exp show --only-changed to see only metrics/params that differ between experiments.

Experiment Naming

Name your experiments for easier reference:
Named experiments are easier to identify:
The naming implementation validates names in 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:
This:
  1. Restores code from the experiment commit
  2. Updates params.yaml to experiment values
  3. Checks out pipeline outputs from cache
  4. Updates metrics files
Important: dvc exp apply modifies your workspace but doesn’t commit. Review changes, then commit to persist them.
To create a branch from an experiment:
This creates a regular Git branch, making the experiment part of your normal history.

Experiment Cleanup

Remove experiments you don’t need:
From 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:
Each checkpoint becomes a separate experiment you can compare and apply.

Experiment Cache

Experiments have their own cache separate from the main DVC cache. From dvc/repo/experiments/__init__.py:103-105:
This enables:
  • 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:
From dvc/repo/experiments/run.py:58-95:
This queues multiple experiments, one for each parameter combination.

Experiment Tables

Customize what’s shown in dvc exp show:

Baseline Commits

Each experiment is associated with a baseline commit. From dvc/repo/experiments/__init__.py:256-289:
This ensures experiments are only applied to compatible commits, preventing confusion.

Remote Experiments

Push experiments to remote Git servers:
Pull experiments from remote:

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 creates a temporary directory, runs the experiment there, and cleans up afterward. Your workspace remains unchanged. From dvc/repo/experiments/__init__.py:114-132:

Next Steps

Pipelines

Understand the pipeline system that experiments run on

Remote Storage

Share experiment outputs with your team