skip to content

Where does DVC keep an experiment created by `dvc exp run`, and how do you keep the winning one and share it with a teammate?

level: middleimportance: should knowfreq 10%

answer

  1. hidden commits, not branches
  2. custom Git refs under refs/exps
  3. baseline is HEAD at run time
  4. apply into workspace, or branch off
  5. git push skips them; dvc exp push

basics

~20 s

Each DVC experiment is a hidden commit under a custom Git ref in .git/refs/exps, based on the HEAD it ran from. Keep the winner with dvc exp apply or dvc exp branch; share it with dvc exp push.

solid answer

~50 s

`dvc exp run` is `dvc repro` followed by `dvc exp save`: it runs the pipeline, then stores the result as one or more commits under a custom Git reference in `.git/refs/exps`, with the current `HEAD` as its baseline and an auto-generated name unless you pass `-n`. Only files tracked by Git or DVC go into it. `dvc exp show` lists experiments derived from `HEAD` with their params and metrics. To keep the winner, `dvc exp apply <name>` restores its files into the workspace so you can commit them, while `dvc exp branch <name>` creates a Git branch from the baseline without switching to it. A plain `git push` does not send experiment refs; `dvc exp push origin <name>` pushes the ref and, unless `--no-cache`, uploads its cached data to the DVC remote, and a teammate runs `dvc exp pull origin <name>`.

go deeper

for a junior

Recall that dvc exp run saves results as hidden Git commits, listed with dvc exp show, and that a plain git push does not share them.

for a middle

Explain refs under .git/refs/exps, the HEAD baseline, the default scope of dvc exp show, and the difference between dvc exp apply and dvc exp branch.

for a senior

Show how experiments travel: dvc exp push moves both the Git ref and the cached data, and a teammate needs both to reproduce. Know what is saved and what is not.

for a principal

Decide when an experiment should become a persistent branch and pull request, and how the team prunes refs so shared remotes do not fill with abandoned runs.

## What a DVC experiment is A **DVC experiment** is a variation of the project, such as a different `train.lr` and the model and metrics it produced, saved without adding commits or branches to the visible history. Under the hood each experiment is a **custom Git reference** in `.git/refs/exps` pointing to one or more commits built on top of the `HEAD` you ran from, which DVC calls the **baseline**. These commits are hidden: they do not appear in `git log` on your branch and DVC does not check them out. Each experiment has a unique name, auto-generated (two short words) or set with `-n`, and the name is exposed to stage commands as the `DVC_EXP_NAME` environment variable. ## Creating one - `dvc exp run` reproduces the pipeline like `dvc repro`, then saves the result. With no arguments it is equivalent to `dvc repro` followed by `dvc exp save`. `-S train.lr=0.01` edits `params.yaml` before running. - `dvc exp save` captures the current workspace as an experiment when you ran things yourself. - **Only files tracked by Git or DVC are saved.** An untracked report file is not in the experiment unless you add it with `dvc exp save -I <path>`. ## Finding the winner `dvc exp show` prints a table of experiments with metrics, params and dependency hashes. By default it shows only experiments whose baseline is the current `HEAD`. Useful flags: - `-A` (all commits), `-a` (all branches), `--rev <commit>` or `-n <num>` widen the scope. After you commit, yesterday's sweep disappears from the default view because its baseline is no longer `HEAD`. - `--only-changed` drops columns that are the same everywhere; `--sort-by <metric or param>` with `--sort-order desc` ranks experiments within a baseline. - `dvc exp diff <a> <b>` prints param and metric differences between two experiments by name. ## Keeping it | | `dvc exp apply <name>` | `dvc exp branch <name> [<branch>]` | |---|---|---| | What it does | Restores the experiment's files (code, params, metrics, DVC-tracked outputs) into the current workspace | Creates a new Git branch from the experiment's baseline containing the experiment | | Workspace | Changed; conflicting changes are overwritten | Untouched; DVC does not switch to the branch | | Next step | `git add` and `git commit` on your branch | `git checkout` the branch and `dvc checkout`, or `git merge` it and `dvc repro` | | Undo | `git stash` then `git stash apply refs/exps/apply/stash` | Delete the branch | Either way the result ends up as ordinary Git history: **persistent**, reviewable and reachable by everyone. ## Sharing it before it is a commit Because experiments live under custom refs, a plain `git push` or `git fetch` does not move them. DVC has its own pair: 1. `dvc exp push origin lr-0-01` pushes the experiment's ref to the Git remote (the same as `git push origin refs/exps/...`) and then uploads its cached outputs to the default DVC remote, unless you pass `--no-cache`. By default it pushes experiments derived from `HEAD`; `-A` pushes them all. The run cache is not pushed unless you ask with `--run-cache`. 2. A teammate runs `dvc exp list origin` to see what is there and `dvc exp pull origin lr-0-01` to fetch the ref and its data, then `dvc exp apply` or `dvc exp branch` it. How remotes store the bytes is the remotes material's subject; here what matters is that the experiment needs both the Git ref and the cached data to be reproducible elsewhere. ## Cleaning up `dvc exp remove <name>` deletes experiments locally; `-g origin` removes them from a Git remote, and `--queue` clears queued ones. Reclaiming cache space is garbage collection, which belongs to the cache material. ## Why interviewers ask Git-based experiments keep results reproducible: each one is a commit of exactly the code, params and lock that produced its metrics, rather than numbers logged somewhere else. The questions check whether a candidate knows where those commits live, why they do not appear in `git log` or on the Git server, and which command turns one into normal history.

  • An untracked `eval/confusion.png` written by the evaluate stage is missing after `dvc exp apply`. Why?
    Only files tracked by Git or DVC are saved into an experiment, so an untracked file is never part of it. Declare the image as a stage output or plot so DVC tracks it, or include it explicitly with `dvc exp save -I eval/confusion.png` when saving manually.
  • You committed the winner, and now `dvc exp show` no longer lists the rest of the sweep. Are they gone?
    No. `dvc exp show` defaults to experiments whose baseline is the current `HEAD`, and the new commit moved `HEAD`. `dvc exp show --rev <old-commit>`, `-n 2` or `-A` brings them back; they are deleted only by `dvc exp remove`.

  • Each dvc exp run creates a normal Git branch you can see in git log
  • git push origin uploads DVC experiments along with the branch
  • dvc exp branch switches the workspace to the new branch
  • dvc exp push sends only the Git ref and never the cached model
  • Untracked files the pipeline writes are always saved in the experiment