r/oMLX • u/arfung39 • 11h ago
Qwen4-35B-A3B: KL divergence for various oQ quants
I wanted to know how much accuracy each Qwen4-35B-A3B quant gives up compared with full-precision BF16, so I measured KL divergence against the BF16 model. Everything ran on an M5 Max with 64 GB under oMLX 0.8.5. The models are the mlx-community oQ builds plus Qwen's official FP8 release. Surprisingly, the oQ6e quant beats the official FP8 release.
If you have 64+ gigs of unified memory, I recommend the oQ6e quant. You lose a lot with the oQ4e quant. This confirms my anecdotal experience with various simple coding tests.
(details of how I generated this was written by Claude; I include that for people who want to know about the method)
| Model | Size (GB) | Mean KLD | ± s.e. | p99 KLD | Same top token as BF16 | PPL |
|---|---|---|---|---|---|---|
| oQ3e-mtp | 29.5 | 0.1218 | 0.0017 | 1.317 | 86.2% | 6.747 |
| oQ4e-mtp | 33.8 | 0.0517 | 0.0007 | 0.578 | 90.9% | 6.688 |
| oQ5e-mtp | 40.4 | 0.0300 | 0.0004 | 0.307 | 93.0% | 6.670 |
| oQ6e-mtp | 47.1 | 0.0236 | 0.0004 | 0.242 | 94.0% | 6.659 |
| FP8 official, exact weights | 58.4 | 0.0251 | 0.0004 | 0.257 | 93.6% | 6.654 |
| FP8 official, as oMLX loads it | 58.4 | 0.0294 | 0.0005 | 0.314 | 93.2% | 6.650 |
| oQ8e-mtp | 60.2 | 0.0211 | 0.0003 | 0.230 | 94.3% | 6.655 |
| BF16 (reference) | - | - | - | - | - | 6.652 |
- Text model on disk, including the n-gram table (12.8 GB in oQ3e/oQ4e, 15.4 GB in oQ5e, 17.9 GB in oQ6e, about 20.5 GB in FP8) but not the vision encoder or MTP head.
Takeaways
- oQ6e is the closest to BF16 of anything I tested, closer even than Qwen's own FP8 release, and it's 11 GB smaller. FP8 uses one scale for each 128×128 block of weights. oQ uses a scale for every 64 weights, gives more bits to the sensitive layers, and calibrates with an importance matrix.
- oQ5e is about as close as FP8 in oMLX, at 18 GB less.
- Each step down from oQ5e roughly doubles the drift. oQ5e → oQ4e is 1.7× and oQ4e → oQ3e is 2.4×. At oQ3e, about 1 token in 7 differs from BF16's first choice, and the worst 1% of tokens change a lot (p99 KLD > 1).
- oQ3e saves less memory than "3-bit" suggests. The backbone averages 3.8 bits per weight, but the 12.8 GB n-gram table stays at 4 bits or more, so the whole checkpoint averages 4.3. If memory is the problem, the SSD N-gram Offload setting takes that table out of RAM, which may help more than dropping a quant level.
- When oMLX loads the FP8 checkpoint, it converts the weights to MXFP8. That adds a bit of drift (KLD 0.025 → 0.029) and wastes a little of FP8's advantage. The FP8 checkpoint does load and run fine in oMLX, though.
- Perplexity barely tells them apart. Every quant is within about 1.4% of BF16, and FP8-oMLX actually scores a hair below BF16, which is noise. KLD is the better measure for comparing quants.
Method
- Text: WikiText-2 (raw) test set, 32 chunks of 2048 tokens. Only the second half of each chunk is scored, as in llama.cpp's KLD, for 32,736 scored tokens. KLD is computed over the full 248k vocabulary.
- BF16 reference: the BF16 backbone (~70 GB) doesn't fit in 64 GB, so I ran it one decoder layer at a time. Each layer was loaded from disk, every chunk was pushed through it, and then the next layer was loaded. This used oQ's own streamed-layer loader, the one it uses to calibrate models bigger than RAM. Peak memory was about 7 GB and the whole pass took about 40 s.
- Checking the method: on oQ6e, the layer-by-layer path matched a normal full forward exactly (KLD 0). Skipping a single layer gave KLD 0.22, so the check does catch mistakes.
- "FP8 exact" decodes the FP8 weights with the same layer-by-layer loader. "FP8 as oMLX loads it" is the normal mlx-vlm load path, i.e. what you get when you serve the checkpoint.
- Quants were loaded the way oMLX's VLM engine loads them, with SSD n-gram offload on, and run as plain forward passes. MTP isn't involved, since it only affects speed.
Caveats
- This is one dataset of English prose. Code, other languages, chat formatting, and long-context behavior could rank differently. With 2048-token chunks, the sparse attention's 2048-token selection budget never kicks in, so long context isn't tested at all.
- The ± values are standard errors over tokens. They show the differences are stable on this text, not that they hold everywhere.
- These numbers aren't directly comparable to Unsloth's GGUF KLD charts, which use different evaluation sets, a different reference run, and llama.cpp.
(I updated the graph to include oQ8e, but I can't figure out how to delete the first version of the figure...)
