Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/self-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ jobs:
- name: Pin the exit-code contract
run: python -m pytest tests/test_selftest_gate.py tests/test_cli.py -v

# The eval sets ARE the measurement: a set that cannot distinguish a
# dropped case (too few cases for the tolerance, or answers so vague that
# any greedy decode matches) makes a green gate meaningless. These tests
# pin the shipped sets' shape, the alias/metadata schema, the Action's
# flag surface, and the dtype each precision actually produces.
- name: Pin the measurement, not just the plumbing
run: |
python -m pytest \
tests/test_eval_sets_arith.py \
tests/test_eval_sets_classify.py \
tests/test_action_contract.py \
tests/test_adapter_dtype.py -v

action-container:
name: action container builds and runs
runs-on: ubuntu-latest
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ build/
results/*
!results/int8_collapse.json
!results/quiet_model.json
!results/real_model.json
!results/real_model_arith.json
!results/real_model_classify.json

# Secrets and local credentials — never commit these
.env
Expand Down
91 changes: 69 additions & 22 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,75 @@ All notable changes to quant-regress. This project is pre-1.0 stable in API but
`v1` GitHub Action tag is what users are told to pin, so **action-visible changes are
called out here as breaking**.

## Unreleased

### Added — the README leads with a real-checkpoint measurement

- **`scripts/regen_real_model.py` + `results/real_model.json`** measure a real
instruction-tuned causal LM (`Qwen/Qwen2.5-0.5B-Instruct`) at fp32 and dynamic
int8 on 20 single-answer arithmetic word problems, through the same
`QuantHarness`/adapter path the Action uses. The committed run shows an 80.0%
fp32 baseline (above the `--min-accuracy` floor) collapsing to 0.0% at int8 —
a real, dramatic int8 collapse, verified against the raw completions (the
quantized model degrades into conversational filler instead of the answer).
- **The README now leads with this real measurement** (`claim:real-model`), with
the previous stub table (`claim:int8-collapse`) kept below it as an explicitly
labelled controlled reproduction. The stub is a demonstration of the gate's
arithmetic, not a model measurement; the README says so, and keeps the note
that the `AutoModelForCausalLM` adapter cannot load a cross-encoder at all.
- **`tests/test_claims_are_reproducible.py` now pins the real-model table** to the
committed artifact: the fast path of `regen_real_model.py` (no `--measure`)
prints the committed run, and the test fails if a README figure stops matching
it. `--measure` is the expensive reproduction a human runs to regenerate the
artifact; it is deliberately not what the test runs, so the suite stays fast
and deterministic.
## 1.2.0

### Changed — the eval scenario is no longer a single 20-case arithmetic stub

The published measurement used to be 20 one-step word problems with
`--max-drop-points 2.0`. At 20 cases one case is worth 5.00 points, so a
2-point tolerance was unreachable: the gate silently enforced "zero new
errors", and nothing told the user their threshold was finer than the set could
express. Both eval sets are now 60 cases (1.67 points per case), the harness
computes granularity, and the CLI says so.

- **`evals/sets/arith-tiered.jsonl`** — 60 arithmetic word problems, 20 each at
`easy` (one step), `medium` (three addends or a division step) and `hard`
(distractor clause), spread across add/sub/mul/div.
- **`evals/sets/classify.jsonl`** — 60 sentiment cases (30 positive / 30
negative) with **declared answer aliases** (`pos`, `positive`, `Positive.`),
so a task whose label vocabulary is closed is scored exactly instead of by
numeral extraction.
- **`Case` gained `accept`, `category` and `difficulty`.** `accept` is a
validated list of extra accepted answers; an alias equal to `expected` is
dropped, and a bad value raises `EvalSetError` naming the line. Both extra
fields are carried into every report, so a regression can be read per task
family and per difficulty tier instead of as one aggregate number.
- **`ComparisonResult` reports `points_per_case`, `tolerance_reachable`,
`granularity_warning`, `regressed`/`recovered` case ids and per-category
tallies.** `--strict-granularity` turns the warning into exit 2 *before any
model is loaded*.
- **The markdown and JUnit reports name the cases.** Markdown gains a
per-category table and a "Regressed cases" list; JUnit gains one
`<testcase classname="quant_regress.int8" name="int8/arith-e03">` per case,
so a red build points at a case rather than at a percentage.

### Fixed — `fp32` was not fp32

`transformers` loads a checkpoint in the dtype named by its config;
`Qwen/Qwen2.5-0.5B-Instruct` declares `bfloat16`. The `fp32` backend was
`return model`, so the arm labelled fp32 ran bf16 weights, and
`quantize_dynamic` then raised `expected scalar type Float but found BFloat16`
on exactly those checkpoints. `--precision fp32` now casts with `model.float()`,
int8 casts before quantizing, and every arm records the dtype it actually
measured (`torch.float32`, `torch.bfloat16`, `torch.qint8`) in the report — the
baseline included, because the mislabel was possible precisely because only
candidates carried it.

### Fixed — the measuring tool could manufacture a false green

`regen_real_model.py` scored every set with the numeral scorer. On the
sentiment set that produced 0/60 at *both* precisions: a perfectly flat
comparison, and the gate printed `PASS`. `--scorer auto` (new default) uses the
numeral scorer only when every expected answer is a numeral and the harness
default (exact match + declared aliases) otherwise, and records the choice in
the artifact. `--max-new-tokens` now defaults to 32 instead of 8, because 8
truncated every word problem that reasons before answering — the old figures
measured truncation.

### Added — the Action can reach the response cache

`--response-cache` existed in the CLI but `action.yml` and the entrypoint
whitelist did not know it, so the feature was unreachable from the Action.
`response-cache` is now an input, passed through only when non-empty.

### Added — the published measurement covers both task families

`scripts/regen_real_model.py` regenerates `results/real_model_arith.json` and
`results/real_model_classify.json`, prints per-category and per-difficulty
tables, and in its no-argument fast path prints every committed artifact, so all
numbers the README quotes come from one command. `--set`, `--precisions`,
`--out`, `--min-accuracy`, `--max-cases`, `--max-new-tokens` and `--scorer` make
a different checkpoint or a smoke run a one-liner.

## 1.1.0

Expand Down
90 changes: 69 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,66 @@ accuracy drops past a threshold you set.
## Measured on a real checkpoint

The headline is a real measurement, not a stub. `scripts/regen_real_model.py`
loads a real instruction-tuned causal LM — **Qwen/Qwen2.5-0.5B-Instruct** — and
runs 20 single-answer arithmetic word problems through the same `QuantHarness`
and adapter path the GitHub Action uses: an fp32 baseline and a dynamic-int8
candidate, scored on the numeral the model produces. The fp32 baseline clears
the `--min-accuracy` floor, so the int8 delta below is a real comparison, not a
measurement from a model that cannot do the task.
loads **Qwen/Qwen2.5-0.5B-Instruct** and runs two 60-case eval sets through the
same `QuantHarness` and adapter path the GitHub Action uses — one where the task
is arithmetic word problems (numeral-scored), one where it is sentiment
classification (exact match plus declared aliases). Both sets are 60 cases, so
one case is worth 1.67 points and a 2-point tolerance is reachable; the scorer
is chosen per set, and every arm records the dtype it actually measured.

### Arithmetic: int8 destroys the capability

<!-- claim:real-model -->
| precision | accuracy | correct | measured dtype |
|---|---|---|---|
| fp32 (baseline) | 33.3% <!-- claim:real-model --> | 20/60 <!-- claim:real-model --> | torch.float32 |
| int8 | 3.3% <!-- claim:real-model --> | 2/60 <!-- claim:real-model --> | torch.qint8 |
| bf16 | 33.3% <!-- claim:real-model --> | 20/60 <!-- claim:real-model --> | torch.bfloat16 |

worst drop: +30.0 pts -> FAIL <!-- claim:real-model -->

baseline 33.3% is above the --min-accuracy floor (0.3) <!-- claim:real-model -->

Read this table for the delta, not for the model. A 0.5B checkpoint is only
partly competent at these word problems, and the tiers show how uneven that is:
`easy` cases (one step) are mostly solved, `medium` (three addends, a division
step) mostly are not, and the non-monotonic `hard` row is the reason the set is
worth reading per tier instead of in aggregate.

| arm | difficulty | correct |
|---|---|---|
| fp32 | easy | 12/20 <!-- claim:real-model --> |
| fp32 | medium | 2/20 <!-- claim:real-model --> |
| fp32 | hard | 6/20 <!-- claim:real-model --> |

`bf16` matches `fp32` case for case, which is the useful negative result: the
half-precision backend is not what breaks the model, and the `measured dtype`
column is what makes that claim checkable rather than asserted.

### Sentiment: a competent baseline, and the same collapse

<!-- claim:real-model -->
| precision | accuracy | correct | seconds |
| precision | accuracy | correct | measured dtype |
|---|---|---|---|
| fp32 (baseline) | 80.0% <!-- claim:real-model --> | 16/20 | 81.4s |
| int8 | 0.0% <!-- claim:real-model --> | 0/20 | 154.2s |
| fp32 (baseline) | 98.3% <!-- claim:real-model --> | 59/60 <!-- claim:real-model --> | torch.float32 |
| int8 | 3.3% <!-- claim:real-model --> | 2/60 <!-- claim:real-model --> | torch.qint8 |

worst drop: +95.0 pts -> FAIL <!-- claim:real-model -->

worst drop: +80.0 pts -> FAIL <!-- claim:real-model -->
baseline 98.3% is above the --min-accuracy floor (0.5) <!-- claim:real-model -->

baseline 80.0% is above the --min-accuracy floor (0.5) <!-- claim:real-model -->
This is the table to quote. The same checkpoint classifies 59 of 60 reviews
correctly at fp32 and 2 of 60 at dynamic int8: the quantized model still runs,
still returns a label, and is wrong almost every time. A token-level proxy that
only watches the output distribution clears that; a task eval does not.

That is the failure this action exists to catch, on a real checkpoint: the
quantized model still runs and still returns text, but the text is wrong. The
int8 completions degrade into conversational filler ("To find the number that
is 7", "I'm here to answer any question you") instead of the answer, so a
token-level proxy that only looks at the distribution can clear it while the
task eval — which asks for the numeral — cannot. Regenerate with
`python scripts/regen_real_model.py --measure` (CPU, several minutes); the
committed run is at [`results/real_model.json`](results/real_model.json), and
`tests/test_claims_are_reproducible.py` fails the build if a number in this
table stops matching the script's output.
Regenerate everything with one command — `python scripts/regen_real_model.py`
with no flags prints both committed runs, and `--measure` re-runs the model on
CPU (about two minutes for both sets on 24 cores). The committed artifacts are
[`results/real_model_arith.json`](results/real_model_arith.json) and
[`results/real_model_classify.json`](results/real_model_classify.json), and
`tests/test_claims_are_reproducible.py` fails the build if a number in these
tables stops matching the script's output.

### The controlled reproduction (stub)

Expand Down Expand Up @@ -213,6 +246,21 @@ accuracy in the report before trusting a PASS.
drop, and the gate correctly reports PASS. It is also driven by a stub model
exposing `.answer()`, so it tells you nothing about real decoding. Use it to
see the output format; bring your own eval for a real check.
- **60 cases is 1.67 points per case.** That is the smallest drop the bundled
sets can express; a `--max-drop-points` finer than 1.67 is unreachable and the
CLI now warns (and exits `2` with `--strict-granularity`). Bigger sets buy
resolution, not credibility — 600 cases resolve 0.17 points and cost ten times
the CPU.
- **The `easy` / `medium` / `hard` tiers describe the problem, not a measured
pass rate.** They are assigned by construction — one step, three addends or a
division step, a distractor clause — so a weak checkpoint can score `hard`
above `medium`. Read the per-tier table as "where did it break", not as a
curriculum.
- **The published numbers are one checkpoint on one CPU box, greedy decoding.**
They say what dynamic int8 did to `Qwen/Qwen2.5-0.5B-Instruct` on 120 cases;
they do not rank quantization methods, and they are not a claim about larger
checkpoints. What generalises is the gate: point it at your model, your task
and your tolerance, and it answers for that combination.
### Change is not quality — read this before trusting a PASS

The gate's default judgement is about *change*: it fails when quantization costs
Expand Down
7 changes: 6 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ inputs:
description: "Optional HF cache directory."
required: false
default: ""

response-cache:
description: "Directory to cache raw generations per precision, so a rerun after a transient failure does not redo generation."
required: false
default: ""
runs:
using: "docker"
image: "Dockerfile"
Expand Down Expand Up @@ -109,3 +112,5 @@ runs:
- ${{ inputs.hf-token }}
- --cache-dir
- ${{ inputs.cache-dir }}
- --response-cache
- ${{ inputs.response-cache }}
8 changes: 7 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ JUNIT_PATH=""
REPORT="quant-regress-report.json"
HF_TOKEN_INPUT=""
CACHE_DIR=""
RESPONSE_CACHE=""

while [ $# -gt 0 ]; do
flag="$1"
case "$flag" in
--eval|--model|--precisions|--baseline-precision|--max-drop-points|--min-accuracy|--max-new-tokens|--scorer|--system-prompt|--labels|--output-format|--junit-path|--report|--hf-token|--cache-dir)
--eval|--model|--precisions|--baseline-precision|--max-drop-points|--min-accuracy|--max-new-tokens|--scorer|--system-prompt|--labels|--output-format|--junit-path|--report|--hf-token|--cache-dir|--response-cache)
shift
[ $# -gt 0 ] || { echo "::error::missing value for $flag"; exit 2; }
case "$flag" in
Expand All @@ -43,6 +44,7 @@ while [ $# -gt 0 ]; do
--report) REPORT="$1" ;;
--hf-token) HF_TOKEN_INPUT="$1" ;;
--cache-dir) CACHE_DIR="$1" ;;
--response-cache) RESPONSE_CACHE="$1" ;;
esac
shift
;;
Expand Down Expand Up @@ -92,6 +94,10 @@ if [ -n "$CACHE_DIR" ]; then
set -- "$@" --cache-dir "$CACHE_DIR"
fi

if [ -n "$RESPONSE_CACHE" ]; then
set -- "$@" --response-cache "$RESPONSE_CACHE"
fi

# Forwarded only when set, for the same reason as the floor: an empty value
# must not become the literal JUnit filename (the CLI falls back to a
# alongside --report only when the flag is absent).
Expand Down
Loading
Loading