Repository navigation
[BUG] Quant accuracy: AWQ dense layers scale-search on only the last calibration sample (+ down_proj silently RTN) so AWQ == RTN; EXL3 still crashes under default auto_nf12 (#4006 bypass); in-memory model after quantize uses v1 qzeros as v2 (garbage generate) #4063
Description
Audit of main @ 2c032e0 (includes #4055–#4061), CUDA (RTX 4090 / 5090). Found by an end-to-end method matrix: quantize → save → reload → wikitext-2 PPL (80 × 512) on Qwen2.5-0.5B-Instruct, Llama-3.2-1B-Instruct and gemma-3-1b-it, calibrated on 128 C4 docs.
1. AWQ scale search on dense layers uses only the last calibration sample, so AWQ is no better than RTN (high, accuracy)
#3036 (for #3035) fixed variable-length aggregation only for MoE modules: BaseQModel.awq_input_feature_aggregation (models/base.py:4780-4802) returns a token_rows policy only for MoE roots. Every dense module goes to the else branch of looper/awq_processor.py:1355-1370. With the usual batch_size=1 and variable-length text, captures can't be concatenated, so that branch keeps tensors[-1] (mode: "latest_batch"). Since calibration is sorted by length (descending), that is the shortest sample: 307 of 62,767 tokens (0.49%) on Qwen2.5-0.5B.
There is a second effect. _should_fallback_group (awq_processor.py:1535-1561) sums retained_tokens over the sibling layers of a group. So q/k/v (3×) and gate/up (2×) pass the coverage check, while down_proj (a single layer) falls below 0.5% and silently gets RTN. Each layer is therefore scaled from about 300 tokens, and its down_proj isn't scaled at all.
Wikitext-2 PPL, 4-bit g128 (fp16 baseline: Llama 18.97, Qwen 18.55):
| RTN | AWQ (HEAD) | AWQ + token_rows for mlp.* |
|
|---|---|---|---|
| Llama-3.2-1B asym | 23.58 | 23.53 (down_proj → RTN fallback in every layer) | 21.09 |
| Qwen2.5-0.5B asym | 22.73 | 24.01 | 22.97 |
| Qwen2.5-0.5B sym | 24.8 | 27.85 (worse than RTN) | – |
For reference, an AWQ checkpoint of the same Llama made with GPTQModel 6.1 measures 20.84 when loaded with HEAD. That matches the token_rows result, so the gap is a recent regression, not a ceiling of the method. The "+ token_rows" column only patches awq_input_feature_aggregation to also return {"mode": "token_rows"} for names starting mlp.. Attention modules still use the latest batch, so the real fix should do better.
Fix: use token_rows (bounded, all samples) as the default policy for every module, not only MoE. At minimum, pad/mask and concatenate, or average activation statistics over all captures; never keep one capture. Make the fallback coverage check per layer rather than summed over siblings. Add a test asserting that AWQ PPL < RTN PPL on a tiny real model with variable-length calibration.
2. EXL3 quantization still crashes under the default auto_dtype_cast=auto_nf12 (bf16 models): #4006 fix is bypassed (high)
looper/stage_subset.py:937-942 replaces the inventory entry with the raw module (full[named_module.name] = named_module.module) when auto_dtype_cast_source_spec is set. Right after that, prepare_layer_runtime_weights_for_forward (looper/loop_processor.py:105-109), added for #4006, skips every entry that is not a NamedModule. q/k/v packed by the previous subset therefore keep EXL3's META placeholder for the next layer forward:
tiny bf16 Llama (2 layers), EXL3Config(bits=4.0) -> NotImplementedError: Cannot copy out of meta tensor; no data!
diag: prepared 0, raw-module entries still META: ['self_attn.q_proj', 'self_attn.k_proj', 'self_attn.v_proj']
same, auto_dtype_cast="off" -> OK
Qwen2.5-0.5B-Instruct EXL3 4.0 default -> crash at layer 0 q_proj ("not on the expected device meta")
Qwen2.5-0.5B-Instruct EXL3 4.0 auto_dtype_cast="off" -> PPL 19.08 (+2.9%)
Every bf16 checkpoint takes the auto_nf12 path, so the default EXL3 flow fails on most modern models. Fix: keep the NamedModule in full (have the forward use the swapped .module), or have prepare_layer_runtime_weights_for_forward also ask processors about raw modules (by name). Add the exl3 recovery test with a bf16 source.
3. With offload_to_disk=False, the in-memory model after quantize() generates garbage: v1 qzeros read as v2 (high)
pack_module (utils/model.py:1379-1392) converts packed qzeros to v1 when the target format is gptq and the kernel REQUIRES_FORMAT_V2 (TorchLinear), so the module ends up with qzero_format() == 1. The module isn't converted back, and TorchLinear.forward uses the zeros as v2, so every zero point is off by one:
Llama-3.2-1B-Instruct, RTNConfig(bits=4, group_size=128, offload_to_disk=False)
KERNEL TorchLinear qzero_format() 1 REQUIRES_FORMAT_V2 True
m.generate (right after quantize): 'The capital of France is!!!!!!!!!!!!!!!!'
after save + reload : 'The capital of France is Paris. Paris is a city located in the country of France. ...'
GPTQ behaves the same way. Any in-process eval right after quantize (lm-eval, PPL, generation) silently measures a broken model. The saved checkpoint is correct. Fix: convert a copy of qzeros for serialization (in the writer), or convert the in-memory module back to v2 after pack. Add an "in-memory == reloaded logits" test.
Repro scripts: exl3_nf12_repro.py, inmem_generate.py, awq_groups2.py (fallback trace), and a matrix harness with an AWQ_TOKROWS=1 toggle. I can attach them if useful.
🤖 Generated with Claude Code
Activity
fix(looper,gptq): restore EXL3 AUTO_NF12 and the in-memory v2 qzero l…
fix(awq): aggregate variable-length calibration for every module (#4063…
Qubitium commentedon Nov 14, 2026
Resolved by #4071 (item 1: variable-length calibration aggregation now applies to every module, not just MoE roots, so the scale search no longer trains on the last/shortest capture; per-layer coverage check instead of summed over siblings) and #4069 (items 2-3: EXL3 AUTO_NF12 keeps NamedModules so runtime weights are re-materialised, and the in-memory module is restored to v2 qzeros after pack so generate() right after quantize matches a reload).
fix(awq): keep AWQ for covered MoE experts when one is starved (#4675) (
test: fix stale doubles/oracles in the suite-triage red list (#4769) (#…