In a DVC project, how do `dvc params diff`, `dvc metrics diff` and `dvc plots diff` compare a pull request's branch with `main`?
answer
- same revision model for all three
- no args: workspace against HEAD
- only changed rows unless --all
- --md for a review comment
- plots overlay, no numeric deltas
basics
~20 sAll three take Git revisions: none means workspace against HEAD, one means that revision against the workspace, two compare each other. params diff lists old and new values, metrics diff adds numeric changes, plots diff overlays the versions.
solid answer
~50 sThe three commands share one revision model: with no argument they compare the workspace (including uncommitted changes) with `HEAD`, with one revision they compare it with the workspace, and with two they compare those revisions. On a pull-request branch, `dvc params diff origin/main` lists every param whose value differs, and `dvc metrics diff origin/main` lists changed metrics with old value, new value and the numeric change, rounded to 5 digits by default. Both show only changed entries unless you pass `--all`; `--md` prints a Markdown table for the review. `dvc plots diff origin/main` overlays both versions of each plot in one HTML file, written to `dvc_plots` by default, without computing deltas. They read the files declared in `dvc.yaml` (params diff also reads all of `params.yaml`) unless you name others with `--targets`, and they read each revision's copy, which is why small metrics files are often declared with `cache: false` so that copy sits in Git itself.
code
bash · 4 linesgit fetch origin main
dvc params diff origin/main --md
dvc metrics diff origin/main --md --precision 4
dvc plots diff origin/main -o pr_plotsgo deeper
Recall that params diff, metrics diff and plots diff compare files across Git revisions, and that with no argument they compare the workspace with HEAD.
Explain the zero, one and two revision forms, the changed-only default and --all, --md for reviews, and why metrics files are usually kept in Git.
Build a review check that names the base revision, catches a branch whose params changed without a rerun, and fails on a metric drop using JSON output.
Decide which metrics a pull request must report and how strict the check is, so that review rests on reproduced numbers rather than claims in the description.
## Three commands, one revision model DVC records **parameters** (inputs such as `train.lr` in `params.yaml`), **metrics** (key/value results such as `macro_f1` in `eval/metrics.json`) and **plots** (data series such as a loss curve in `eval/train_loss.csv`) in ordinary files that Git versions. Three commands compare them across revisions, and all three require Git: | Command | Shows | Notes | |---|---|---| | `dvc params diff` | Each changed param with its old and new value | `--deps` limits it to params that are stage dependencies | | `dvc metrics diff` | Each changed metric with old value, new value and numeric change | `--precision` (5 by default); non-numeric metrics have no change value | | `dvc plots diff` | All versions of each plot overlaid in one rendered page | No numeric difference; accepts any number of revisions | Revisions are Git commit hashes, tags or branch names: 1. **No revision**: the workspace, including uncommitted changes, against `HEAD`. 2. **One revision**: that revision against the workspace. 3. **Two revisions** (`a_rev b_rev`): those two against each other. ## In a pull request On the branch that raised `featurize.ngram_max` and retrained, the reviewer wants three answers: what changed, did it help, and how do the curves compare. ```bash git fetch origin main dvc params diff origin/main --md dvc metrics diff origin/main --md dvc plots diff origin/main -o pr_plots ``` - `params diff` prints the changed keys with old and new values. Only changed params appear unless you add `--all`. - `metrics diff` prints a table with the path, metric, old value, new value and `Change`. Again only changed rows by default; `--all` adds the rest, and `--json` suits a script that fails a check when `macro_f1` drops. - `plots diff` renders both revisions' `eval/train_loss.csv` on one chart in `pr_plots/` (by default `dvc_plots/`, or the `plots.out_dir` setting); `--open` opens it in a browser. - `--md` on the first two produces GitHub-flavoured Markdown tables ready to paste into a review. ## What each one reads - **Declared files by default.** Metrics and plots diffs use the files declared in `dvc.yaml`, at stage level or at the top level; params diff covers everything in `params.yaml` plus the params `dvc.yaml` references. A metrics file nobody declared does not appear unless you pass it with `--targets` (then put `--` before revisions). - **Each revision's copy is read.** The comparison opens the file as it was at each revision. Small metrics and plot files are often declared with `cache: false` so they are committed to Git and readable at any commit without the DVC cache. - **The values must come from a run.** If someone edited `params.yaml` but never ran `dvc repro`, `params diff` shows the new value while `metrics diff` still shows the old numbers. `dvc status` or `dvc repro --dry` in the check catches a branch whose results are stale. ## Commits against experiments These commands are documented for Git revisions. To compare **experiments** by name, the hidden commits created by `dvc exp run`, use `dvc exp diff <exp-a> <exp-b>`, which combines the params and metrics reports, or `dvc exp show` for a table across many. `dvc plots diff` also accepts experiment names as revisions, which makes it handy for overlaying the curves of a sweep. ## A review check that holds up 1. Fetch the base branch so `origin/main` is current; a stale base makes every diff misleading. 2. Run `dvc status` (or `dvc repro --dry`) and fail if any stage is stale, so the metrics on the branch were produced by the params on the branch. 3. Post `dvc params diff origin/main --md` and `dvc metrics diff origin/main --md` as the review comment, so reviewers see inputs and results side by side. 4. Parse `dvc metrics diff origin/main --json` and fail when `macro_f1` falls by more than an agreed margin. 5. Attach the `plots diff` page as a build artifact for anyone who wants the curves. ## What interviewers listen for - Knowing that the default comparison is workspace against `HEAD`, not against `main`, so a reviewer must name the base revision. - Knowing that only changed rows appear, so "no output" from `metrics diff` means nothing changed, not that metrics are missing. - Knowing that `plots diff` overlays series and computes no numbers, so a decision rests on `metrics diff`.
- `dvc metrics diff` prints nothing on a branch where you expected a new F1. What do you check?No output means no declared metric changed between the two sides. Check that you named the base revision, since the default compares the workspace with `HEAD`; that `eval/metrics.json` is declared in `dvc.yaml` or passed with `--targets`; and that the pipeline was actually re-run, with `dvc status`, so the metrics file was rewritten.
- How do you compare two experiments from last night's sweep rather than two commits?Use `dvc exp diff <exp-a> <exp-b>`, which takes experiment names or hashes and prints param and metric differences together, or `dvc exp show` for all of them in one table. For curves, `dvc plots diff` accepts experiment names as revisions.
- dvc metrics diff with no arguments compares the branch with main
- dvc plots diff reports numeric differences between plot values
- dvc metrics diff lists every metric by default, changed or not
- dvc params diff works without Git as long as dvc.yaml exists
- Editing params.yaml alone updates the metrics that metrics diff reports