--- license: mit language: - en - fr tags: - benchmark - llama.cpp - gguf - quantization - evaluation - speculative-decoding --- # ๐Ÿ”ฌ quant-vs-api-parity-harness > **Is your local quant actually as good as the full-precision API?** This toolkit answered > that question for a 284B MoE compressed to 2.9 bpw โ€” verdict: **indistinguishable on the > real serving path** (90.8% token-identical, 240/240 paired-QA parity, deep-derivation > parity). ๐ŸŽฏ But the *real* product is the method: it caught **9 bugs in our own > instruments** before they could lie to us โ€” including one that had us convinced the quant > had lost factual recall when it hadn't. ๐Ÿชค Used to produce the results in [DeepSeek-V4-Flash-0731-StrixHalo-Verified-GGUF](https://huggingface.co/Kevletesteur/DeepSeek-V4-Flash-0731-StrixHalo-Verified-GGUF). Model-agnostic in spirit: bring any llama.cpp server + any OpenAI-compatible reference API. ## ๐Ÿš€ Install ```bash python3 -m venv venv && . venv/bin/activate pip install sympy jinja2 # that's all โ€” stdlib otherwise echo "sk-..." > deepseek_api_key.txt # your reference-API key (chmod 600!) # a llama.cpp server on 127.0.0.1:8080 serving the quant you want to test ``` ## ๐Ÿงญ The method, in the order that matters ### 1๏ธโƒฃ Validate your instruments FIRST (`scorers.py`) โ€” non-negotiable ```bash python3 scorers.py # 67 synthetic cases โ€” must print 67/67 before ANY model run ``` Answer extractors, SymPy equivalence oracle (with convention lists + decimal tolerance), degeneration detector, tool-call deep-equal. Each shipped with synthetic test cases: correct answers in hostile formats (LaTeX `\pm`, `\boxed{}`, thousand separators, mid-line), plausible wrongs, truncations, repetition loops. **This step caught 2 real bugs in our own scorers on day one.** If you skip it, your benchmark will eventually lie to you. ๐Ÿ› ### 2๏ธโƒฃ Run the gates (G2-G6) โ€” they decide what your data can mean | gate | question it answers | what we found | |---|---|---| | **G2** `reference/g2g3_drafter_reference.sh` | is speculative decoding bit-exact on YOUR stack? | โŒ 0/10 โ€” bench paired arms drafter-OFF | | **G3** (same script) | is your server deterministic? | โœ… 10/10 | | **G4** `g4g5g6_api.py` | what's the API's self-disagreement at temp 0? | short tasks 7/7 identical; long derivations **6/7 different** โ†’ vote 3 runs | | **G5** (same) | can you even prove template parity? | often no (no published template) โ†’ treat as documented confound, drop boundary tokens | | **G6** (same) | real API context ceiling? | โš ๏ธ disable thinking for the probe or your reply budget dies in the reasoning channel | ### 3๏ธโƒฃ Measure, cheapest-strongest first **๐Ÿงฌ P1 โ€” token-level teacher forcing** (`p1_*.py`) โ€” *the best instrument here.* Generate greedy reference texts via the API (with `top_logprobs`), then force that exact token sequence through your local model one token at a time (`cache_prompt=true`, `n_probs=20` โ†’ linear cost). Record top-1 agreement, the reference token's local rank, NLL. No judge, no regex โ€” the oracle is the distribution itself. **Bootstrap over TEXTS, never tokens** (autocorrelation). Compare token *ids*, not strings. **๐Ÿ“ T2 โ€” multi-step derivations, SymPy oracle** (`t2_*.py`) โ€” the compounding-error regime. Parametric bank (truths *computed*, never typed โ€” our own self-test caught a hand-typed constant that was wrong ๐Ÿ™ƒ), fixed `FINAL: ` line, equivalence by `simplify(candidate โˆ’ truth) == 0`. Truncated โ‰  wrong. McNemar on paired outcomes. Log reasoning-trace lengths both sides and report them first. **๐ŸŽฏ T1/T1b โ€” paired exact-answer bank + calibration** (`t1_items.py`, `t1b_passe.py`). 240 generated integer-answer items, two conditions (forced / UNSURE-allowed), answer-token logprob both sides โ†’ AUROC(confidence โ†’ correctness) and the metric that actually matters for routing: **P(answers โˆง wrong)**. **โฑ๏ธ Speed** (`reference/nmax_depth_bench_reference.sh`): warm-up excluded, medians of โ‰ฅ3, report `t/s` AND `ms/eval` (under speculation, t/s is not machine speed), nested prompts + prompt cache to pay prefill once. Our headline finding: **the speculative `n_max` optimum inverts with context depth** (3 at short ctx โ†’ 2 from ~16k). ## ๐Ÿฅ‡ The cardinal rule (it cost us our biggest false finding) **Evaluate QUALITY only through the real serving path โ€” `/v1/chat/completions`.** Raw `/completion` with an auto-injected `` can close the reasoning instantly at temp 0 (10-character traces!) and answer reflexively. We published an entire "the quant lost factual recall" conclusion, then replayed the failed items through the chat endpoint: **4/4 correct**. The deficit was our benchmark's serving path, not the quant. Full story and eight more traps in **[`NEGATIVE_RESULTS.md`](./NEGATIVE_RESULTS.md)** โ€” read it before you optimize anything. ๐Ÿชค ## ๐Ÿ“ Files | file | role | |---|---| | `scorers.py` | extractors + oracles + **67 self-tests** (run first, always) | | `g4g5g6_api.py` | API noise floor ยท template probe ยท context ceiling | | `p1_gen_api.py` / `p1_force_local.py` / `p1_depouille.py` | teacher forcing pipeline (resumable) + text-level bootstrap | | `t2_items.py` / `t2_passe.py` | derivation bank (self-tested truths) + paired passes + McNemar | | `t1_items.py` / `t1b_passe.py` | 240-item bank + two-condition calibration passes | | `reference/*.sh` | speed & drafter gates โ€” **reference implementations**, adapt to your service manager | | `NEGATIVE_RESULTS.md` | ๐Ÿงจ what did NOT work, with numbers โ€” the most useful file here | MIT. Benchmarked on AMD Strix Halo (gfx1151, ROCm 7.1, 115 GB unified) against the official DeepSeek API โ€” but the method owes nothing to that hardware. *Validate your instruments, equalize your serving paths, and let the distributions be the judge.* ๐Ÿ”