skip to content

In DVC 3.x, how do you run an overnight grid over learning rate and n-gram range with `dvc exp run --queue` and `dvc queue`, and what can break it?

level: seniorimportance: nice to knowfreq 4%

answer

  1. queue now, run later
  2. comma lists and range() need --queue
  3. workers in .dvc/tmp/exps, one shared cache
  4. untracked files are not copied
  5. --run-all is now a dvc queue start shortcut

basics

~20 s

Queue the grid with dvc exp run --queue and sweep overrides in -S, then run it with dvc queue start. Each run executes in a copy under .dvc/tmp/exps, so untracked inputs and parallel jobs are the usual breakers.

solid answer

~50 s

`dvc exp run --queue -n lr-ngram -S 'train.lr=0.01,0.03,0.1' -S 'featurize.ngram_max=3,4,5'` adds all nine combinations to the queue as `lr-ngram-1` to `lr-ngram-9`; such sweep overrides are rejected without `--queue`. Nothing runs until `dvc queue start`, whose `-j` defaults to 1 worker; `dvc queue status` and `dvc queue logs -f <task>` show progress, and `dvc queue stop` ends it gracefully. Each experiment is a snapshot of the workspace when it was queued and runs in a copy under `.dvc/tmp/exps` that shares the project cache. What breaks it: files that are neither Git- nor DVC-tracked are not copied (track them or pass `-C`), several workers on one GPU box compete for it, and isolated runs can repeat shared stages. In DVC 3.67, `dvc exp run --run-all` is only a shortcut for `dvc queue start` plus `dvc queue logs -f`.

code

bash · 8 lines
bash
dvc exp run --queue -n lr-ngram \
  -S 'train.lr=0.01,0.03,0.1' \
  -S 'featurize.ngram_max=3,4,5' \
  -C vocab
dvc queue start -j 1
dvc queue status
dvc queue logs -f 753b005
dvc exp show --only-changed --sort-by macro_f1 --sort-order desc

go deeper

for a junior

Recall that --queue only records an experiment and dvc queue start runs the queue, by default one at a time.

for a middle

Explain sweep overrides with -S, the snapshot taken at queue time, the copies in .dvc/tmp/exps and how dvc queue status and logs follow progress.

for a senior

Anticipate overnight failures: untracked inputs missing from the copies, GPU contention from -j, repeated shared stages, killed runs that never re-queue. Know --run-all is now a shortcut.

for a principal

Decide when one box's queue is enough and when a sweep has outgrown it, weighing the simplicity of Git-based experiments against the lack of scheduling across machines.

## Queueing the grid DVC's **experiment queue** separates deciding what to run from running it. `dvc exp run --queue` records an experiment for later; nothing executes. Combined with `-S` (`--set-param`), it accepts Hydra-style **sweep overrides**: a comma-separated **choice** list (`train.lr=0.01,0.03,0.1`) or a **range** (`range(1,4,1)`, end excluded). With two swept params, every combination is queued. Without `--queue`, DVC rejects sweep overrides with an error saying they can't be used without `--queue`. ```bash dvc exp run --queue -n lr-ngram \ -S 'train.lr=0.01,0.03,0.1' \ -S 'featurize.ngram_max=3,4,5' # Queued experiments get names lr-ngram-1 ... lr-ngram-9 dvc queue start -j 1 dvc queue status ``` Each queued experiment is derived from the **workspace at the time it was queued**. Edit `src/train.py` after queueing and the queued runs still use the old code; queue again after the edit. ## Running and watching it | Command | What it does | |---|---| | `dvc queue start [-j N]` | Starts workers that each run one queued experiment at a time in the background. `-j` defaults to 1 (serial) | | `dvc queue status` | Lists tasks (Queued, Running, Success, Failed) and how many workers are active | | `dvc queue logs [-f] <task>` | Shows a task's console output; `-f` follows a running task, and interrupting it leaves the task running | | `dvc queue stop [--kill]` | Stops workers after the current runs finish; `--kill` interrupts them, and killed runs count as failed | | `dvc queue kill <task>` | Stops specific running tasks | | `dvc queue remove --queued` / `--failed` | Clears queued tasks, or failed ones and their logs | Tasks usually run first in, first out, but the order is not guaranteed. In the morning, `dvc exp show --only-changed --sort-by macro_f1 --sort-order desc` ranks the nine results. ## What isolation means DVC copies the experiment's workspace into a temporary directory under **`.dvc/tmp/exps/`** and runs it there; all of these workspaces share the single project **cache**. That isolation is what lets you keep working, and it explains most overnight failures: - **Untracked and Git-ignored files are not copied.** A local `vocab/` directory that is neither in Git nor tracked by DVC exists in your workspace but not in the copy, so the first stage that opens it fails. Track it, `git add` it before queueing, or pass `-C vocab` (`--copy-paths`) on the queued run. - **Stages can repeat.** Runs are isolated, so a stage common to several runs, such as prepare, may execute more than once depending on what the run cache holds at that moment. Serial runs benefit most from the run cache: once featurize has run with `ngram_max=3`, later runs with that value restore it instead of recomputing. - **Workers are just processes.** `--jobs` is a worker count, and the docs advise no more jobs than CPU cores; they say nothing about GPUs. On one GPU box, `-j 3` starts three training processes that share the same GPU, so `-j 1` is usually right. ## What else breaks a long sweep - A failed run stays `Failed` in `dvc queue status`; `dvc queue logs <task>` shows its traceback from inside `.dvc/tmp/exps`. - `dvc queue stop --kill` turns running experiments into failed ones that are not re-queued; plain `dvc queue stop` lets them finish. - Raising `-j` on an already-running queue takes effect only if the number exceeds the current worker count; lowering it needs `dvc queue stop` first. ## --run-all and --temp in DVC 3.x | Option | Meaning in DVC 3.67 | |---|---| | `dvc exp run --run-all [--jobs N]` | Shortcut for `dvc queue start [--jobs N]` followed by `dvc queue logs -f`; the docs say `--run-all` and `--jobs` will be deprecated in a future release | | `dvc exp run --temp` | Runs one experiment immediately, outside the workspace in `.dvc/tmp/exps`, so you can keep editing while it runs | | `dvc exp run --queue` | Records the experiment without running it | Scripts written around `--run-all` still work, but new automation should call `dvc queue start` and the other `dvc queue` subcommands directly. Choosing which grid points are worth trying is a model-selection question; this answer covers how DVC runs the ones you choose.

  • What is the difference between `dvc exp run --temp` and `--queue`?
    `--temp` runs one experiment immediately, but in a copy under `.dvc/tmp/exps` instead of your workspace, so you can keep editing. `--queue` runs nothing; it records the experiment, snapshotting the workspace, until `dvc queue start` processes it. Both run outside the workspace and both accept `-C` for untracked paths.
  • A teammate's CI script still calls `dvc exp run --run-all --jobs 2`. Does it need changing?
    It works on DVC 3.67, where `--run-all` is a shortcut for `dvc queue start --jobs 2` followed by `dvc queue logs -f`. The docs say both options will be deprecated in a future release, so switch the script to `dvc queue start` and the `dvc queue` subcommands now.

  • dvc exp run --queue starts running the experiment in the background immediately
  • Queued experiments pick up code edits made after they were queued
  • Every file in the workspace, tracked or not, is copied into the temp run
  • dvc queue start runs all queued experiments in parallel by default
  • dvc queue assigns each worker its own GPU
  • --run-all is a separate execution engine from the dvc queue commands

Assumes DVC 3.67: in 3.x dvc exp run --run-all is a shortcut for dvc queue start plus dvc queue logs -f, and the docs say --run-all and --jobs will be deprecated.