# Gemma 4 31B QAT Q4 vs standard Q4 — Top1 KLD benchmark results have me confused. Someone please explain or poke holes in this. — retained record

> Retained reddit record from reddit:LocalLLaMA.

Canonical: https://highsignal.app/data/records/00c6f35920d23e9d

[← sources](https://highsignal.app/data)


source: [reddit](https://highsignal.app/data/reddit) (reddit:LocalLLaMA)  published 2026-06-07 00:49 ingested 2026-06-07 08:48

[original source ↗](https://www.reddit.com/r/LocalLLaMA/comments/1tyxu55/gemma_4_31b_qat_q4_vs_standard_q4_top1_kld/)

## retained text



```
<!-- SC_OFF --><div class="md"><p>Edited -</p> <p>After digging into this some more and reviewing unsloth post for better understanding, the divergence APPEARS to stem from I did not use the BF16 QAT model as the &quot;reference&quot; model....</p> <p>The QAT vs standard Q4 comparison in our benchmark is <strong>not apples-to-apples</strong>. The QAT models were evaluated against a reference they were never optimised toward. The standard Q4_0 and Q4_K_M comparison is valid. The &quot;QAT is worse&quot; conclusion needs a big asterisk: we can't actually tell how good the QAT models are because we didn't have the right reference.</p> <p>re-running the QAT with the QAT Bf16 model</p> <p>-- original below:</p> <p>I'll be upfront: I vibe-benched and vibe-reported this with Claude Sonnet 4.6, but I reviewed and edited everything before posting (too lazy to take out all the AI EM dash —), so hopefully nobody considers this AI slop. And more importantly, I genuinely don't understand why I'm getting these counter-intuitive results, so I'm hoping the community can either explain it or tell me what I did wrong.</p> <p><strong>Background</strong></p> <p>One of the local LLMs I run is entirely on CPU the Gemma 4 31B model at Q8, as I can't afford the quality loss that comes with dropping to Q3 to fit on my 16GB GPU. My setup is dual Xeon Platinum 8358 (128 threads), 256 GB DDR4. Gemma 4 31B Q8_0 sits at around 4 t/s generation... slow, but it earns its keep on quality-sensitive workloads where I need the model to reason carefully over long, dense text for background/overnight type job where I don't need the speed but need the smart and accuracy.</p> <p>The new QAT Q4 models are appealing: 17 GB vs 32 GB, roughly double the generation speed on bandwidth-limited hardware. Google released the checkpoints without publishing any quantitative accuracy comparisons. Unsloth published their own numbers (96.67% top-1 vs BF16) which looked promising. I wanted something expressed as KLD — the same metric LocalBench uses — so I ran my own benchmark.</p> <p>What I did not expect: standard Q4_0 beats QAT Q4_0. By a lot. And Q4_K_M beats everything. I have no good explanation for this and I'm hoping someone does.</p> <p><strong>Why first 5,000 tokens and not the full wikitext-2 test set?</strong></p> <p>The full set is ~245,000 tokens. On CPU at ~4 t/s for Q8_0, a full stride-1 evaluation runs roughly 13 hours for all models. Instead: first 5,000 tokens, stride 5, ~820 sample positions per model. Reproducible — same file, same parameters, same result.</p> <p>Are the results deterministic? Yes — each model ran 3 times. Std dev was ±0.00% across all runs. Temperature=0 + CPU inference is perfectly deterministic. So 3 runs confirmed this isn't noise.</p> <p><strong>Inference engine</strong></p> <p>Mainline llama.cpp (<code>llama-xeon8358</code> image). Run flags: <code>numactl --interleave=all</code>, <code>--numa distribute</code>, <code>--threads 64</code>, <code>--no-mmap --mlock</code>. KV cache forced to f16 for all models — isolates weight quantization quality only, no KV noise mixed in. (Production uses the IK_LLama fork for its Xeon-optimised kernels, but it has an FA assertion bug at large sliding-window contexts so mainline was used here — same GGUF files, same math.)</p> <p><strong>Models tested</strong></p> <table><thead> <tr> <th align="left">Repo</th> <th align="left">File</th> <th align="left">Size</th> </tr> </thead><tbody> <tr> <td align="left">Reference</td> <td align="left"><a href="https://huggingface.co/bartowski/google_gemma-4-31B-it-GGUF">bartowski/google_gemma-4-31B-it-GGUF</a></td> <td align="left"><code>google_gemma-4-31B-it-Q8_0.gguf</code></td> </tr> <tr> <td align="left">Google QAT Q4_0</td> <td align="left"><a href="https://huggingface.co/google/gemma-4-31B-it-qat-q4_0-gguf">google/gemma-4-31B-it-qat-q4_0-gguf</a></td> <td align="left"><code>gemma-4-31B_q4_0-it.gguf</code></td> </tr> <tr> <td align="left">Unsloth QAT UD-Q4_K_XL</td> <td align="left"><a href="https://huggingface.co/unsloth/gemma-4-31B-it-qat-GGUF">unsloth/gemma-4-31B-it-qat-GGUF</a></td> <td align="left"><code>gemma-4-31B-it-qat-UD-Q4_K_XL.gguf</code></td> </tr> <tr> <td align="left">Unsloth Q4_0 (standard)</td> <td align="left"><a href="https://huggingface.co/unsloth/gemma-4-31B-it-GGUF">unsloth/gemma-4-31B-it-GGUF</a></td> <td align="left"><code>gemma-4-31B-it-Q4_0.gguf</code></td> </tr> <tr> <td align="left">Unsloth Q4_K_M</td> <td align="left"><a href="https://huggingface.co/unsloth/gemma-4-31B-it-GGUF">unsloth/gemma-4-31B-it-GGUF</a></td> <td align="left"><code>gemma-4-31B-it-Q4_K_M.gguf</code></td> </tr> </tbody></table> <p><em>Q8_0 used as reference — well-established proxy for BF16 at this model size and quant level.</em></p> <p><strong>Methodology</strong></p> <ul> <li>Top-1 accuracy — does the quantized model pick the same most-likely next token as Q8_0?</li> <li>Mean KLD — KL divergence of top-40 token distribution vs Q8_0, token by token</li> <li>Both metrics computed against the same fixed Q8_0 reference run for all models</li> <li>3 runs per model confirmed zero variance (fully deterministic)</li> </ul> <p><strong>Results — wikitext-2 (reproducible)</strong></p> <p><em>wikitext-2-raw-v1 test set, first 5,000 tokens, stride 5. Wikipedia-style prose only.</em></p> <table><thead> <tr> <th align="left">Model</th> <th align="left">Top-1 acc</th> <th align="left">Mean KLD</th> </tr> </thead><tbody> <tr> <td align="left">Google QAT Q4_0</td> <td align="left">50.43%</td> <td align="left">3.447</td> </tr> <tr> <td align="left">Unsloth QAT UD-Q4_K_XL</td> <td align="left">51.40%</td> <td align="left">3.397</td> </tr> <tr> <td align="left">Unsloth Q4_0 (standard)</td> <td align="left">61.54%</td> <td align="left">2.619</td> </tr> <tr> <td align="left">Unsloth Q4_K_M</td> <td align="left">66.06%</td> <td align="left">2.304</td> </tr> </tbody></table> <p><strong>Results — custom task categories</strong> (informational, not reproducible)</p> <p><em>Hand-written test strings. Not a standard dataset — directional only.</em></p> <p>From the benchmark output:</p> <table><thead> <tr> <th align="left">Category</th> <th align="left">G-QAT acc</th> <th align="left">G-QAT KLD</th> <th align="left">U-QAT acc</th> <th align="left">U-QAT KLD</th> <th align="left">Q4_0 acc</th> <th align="left">Q4_0 KLD</th> <th align="left">Q4_K_M acc</th> <th align="left">Q4_K_M KLD</th> </tr> </thead><tbody> <tr> <td align="left">code</td> <td align="left">92.31%</td> <td align="left">0.460</td> <td align="left">92.31%</td> <td align="left">0.458</td> <td align="left">97.44%</td> <td align="left">0.049</td> <td align="left">94.87%</td> <td align="left">0.025</td> </tr> <tr> <td align="left">science</td> <td align="left">55.56%</td> <td align="left">1.218</td> <td align="left">55.56%</td> <td align="left">1.293</td> <td align="left">80.56%</td> <td align="left">0.300</td> <td align="left">77.78%</td> <td align="left">0.396</td> </tr> <tr> <td align="left">chat</td> <td align="left">63.64%</td> <td align="left">1.604</td> <td align="left">63.64%</td> <td align="left">1.532</td> <td align="left">95.45%</td> <td align="left">0.097</td> <td align="left">90.91%</td> <td align="left">0.120</td> </tr> <tr> <td align="left">tool_call</td> <td align="left">77.78%</td> <td align="left">1.036</td> <td align="left">70.37%</td> <td align="left">1.105</td> <td align="left">92.59%</td> <td align="left">0.299</td> <td align="left">96.30%</td> <td align="left">0.250</td> </tr> <tr> <td align="left">long_doc</td> <td align="left">28.57%</td> <td align="left">2.438</td> <td align="left">28.57%</td> <td align="left">2.682</td> <td align="left">65.71%</td> <td align="left">1.302</td> <td align="left">77.14%</td> <td align="left">1.081</td> </tr> <tr> <td align="left"><strong>overall</strong></td> <td align="left"><strong>52.56%</strong></td> <td align="left"><strong>3.101</strong></td> <td align="left"><strong>53.17%</strong></td> <td align="left"><strong>3.071</strong></td> <td align="left"><strong>65.44%</strong></td> <td align="left"><strong>2.263</strong></td> <td align="left"><strong>69.43%</strong></td> <td align="left"><strong>1.993</strong></td> </tr> </tbody></table> <p><strong>The result that has me confused</strong></p> <p>Standard Q4_0 beats QAT Q4_0 by ~13% top-1 accuracy. And Q4_K_M beats both.</p> <p>QAT is supposed to close the gap between Q4_0 and the reference by training the model to tolerate quantization noise. Google put real effort into this — they ran actual fine-tuning specifically for the Q4_0 format. Unsloth's UD-Q4_K_XL applies their Dynamic 2.0 method on top of the QAT checkpoint. By every account these should be better than a naively quantized Q4_0.</p> <p>But they're not — at least not against a Q8_0 reference on wikitext-2 and these task categories.</p> <p>My best guess: QAT Q4_0 is still flat uniform 4-bit quantization. The QAT process may reduce quantization error <em>relative to naive Q4_0</em> — but Q4_K_M is a fundamentally different format that allocates more bits to sensitive layers. The K-quant format advantage might simply outweigh the QAT training benefit. But I'd expect someone who actually understands quantization internals to tell me if that reasoning is sound or completely wrong.</p> <p><strong>What I'd like to know:</strong></p> <ol> <li>Is comparing QAT Q4_0 against standard Q4_0 using Q8_0 as reference the right methodology, or does this introduce a systematic bias that favors Q4_K_M?</li> <li>Does the QAT training actually make Q4_0 better than naive Q4_0, just not better than K-quants — or is something else going on?</li> <li>Is there a flaw in the sliding-window logprob approach that would explain this?</li> </ol> <p>What I do know: for my use case — dense factual prose, technical documents, long-form reasoning — the long_doc numbers tell the story. QAT Q4_0 drops to 28.57% top-1 vs Q8_0. Q4_K_M holds at 77%. Q8_0 stays.</p> <p><em>Benchmark was ran in ~2 hours runtime for 4 models × 3 runs on this hardware.</em></p> </div><!-- SC_ON --> &#32; submitted by &#32; <a href="https://www.reddit.com/user/bitslizer"> /u/bitslizer </a> <br /> <span><a href="https://www.reddit.com/r/LocalLLaMA/comments/1tyxu55/gemma_4_31b_qat_q4_vs_standard_q4_top1_kld/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/LocalLLaMA/comments/1tyxu55/gemma_4_31b_qat_q4_vs_standard_q4_top1_kld/">[comments]</a></span>
```



document fetched 2026-06-07 08:48
