Repository navigation
Description
Audit of main @ ad0525c, RTX 5090. The real-model method matrix (quantize → save → reload → wikitext-2 PPL 80×512) was extended to Qwen3-0.6B (bf16, base 27.59) and gemma-3-1b-it (bf16, base 39.78). Calibration: 128 C4 docs.
1. AWQ on Gemma-3 (bf16): folding scales into (1+w) norms loses the gain to bf16 cancellation; PPL 39.8 → 486, 10× worse than RTN (high, silent; #3973 fix incomplete)
The offset-gain fold (quantization/awq/quantize/scale.py:316-320) computes (1+w)/s − 1 in fp32 but stores the result back in bf16. Some Gemma-3 pre_feedforward_layernorm channels have x_mean == 0, so the sqrt(max·min) normalisation (looper/awq_processor.py:2578) pushes MLP-group scales to s ≈ 1e3; the measured MLP max was 1430, while attention stays at ≤3.8. At that scale w' ≈ −0.999, 1+w' is not representable in bf16, and the supposedly neutral fold changes the model:
bf16 fold round-trip rel err: Gemma3RMSNorm s~1: 0.004 | s~100: 0.028 | s~1000: 0.265 LlamaRMSNorm: 0.004 at every s
real gemma-3-1b, NO quantization, uniform x1000 scale folded via awq_get_modules_for_scaling + apply_scale:
bf16 PPL 45.9 -> 8.9e6 ; x100 -> 49.3 ; fp32 x1000 exact ; Llama fp16 x1000 exact
gemma-3-1b awq4 end to end: HEAD 485.9 | #4063 token_rows patch only 451.1 | s/s.max() gauge patch only 52.5 | both 45.3 (rtn4 48.0, gptq4 41.9)
This root cause is independent of #4063. Fix: for offset-gain norms, renormalise s so that max(s) ≤ 1 (a uniform factor is a free gauge for per-group quantisation), or keep the gain in fp32, or reject a fold whose round-trip error exceeds a tolerance. The likely same issue affects the other offset-gain norms (Gemma2, Qwen3.5, Qwen3-Next), inferred and not run. tests/test_awq_scale_folding.py::test_scale_ln_fcs_offset_gain_folds_in_float32 only uses scales in [0.5, 1.5]; it should cover s ≫ 1 in bf16.
2. QQQ on a bf16 model (CUDA): the in-memory model after quantize() raises (medium; #4001 / #3977 incomplete)
looper/qqq_processor.py:84-108 (_quant_linear_kernel) always selects QQQLinear on CUDA, whatever the model dtype. Since #4001, QQQLinear.forward (nn_modules/qlinear/qqq.py:539-543) raises for non-fp16 input. The reload path correctly picks QQQTorchLinear:
tiny bf16 Llama, QQQ, offload_to_disk=False
KERNEL after quantize: QQQLinear (model dtype torch.bfloat16)
in-memory forward: NotImplementedError: QQQLinear is an FP16 kernel; use BACKEND.QQQ_TORCH for torch.bfloat16 activations.
reload: QQQTorchLinear forward OK
The same happens on real Qwen3-0.6B and gemma-3-1b. Fix: select QQQTorchLinear for non-fp16 models, using the same rule as the AUTO load logic (models/base.py:1929-1938).
3. ParoQuant checkpoints crash transformers from_pretrained, although GPTQModel registers them with HF (medium-low)
gptqmodel/__init__.py:114-142 maps quant_method="paroquant" to HF GPTQConfig / GptqHfQuantizer. That path renames the method to gptq, so kernel selection (utils/importer.py:1255 → 1313, through optimum convert_model) rejects the checkpoint:
GPTQModel.load: OK (ParoLinear)
AutoModelForCausalLM.from_pretrained: ValueError: Unsupported format: `FORMAT.PAROQUANT` for quantization method `METHOD.GPTQ`
This also happens with real Qwen3 and gemma paro checkpoints. tests/test_paroquant.py:2300 only checks that the config is registered. Fix: keep the method as PAROQUANT through the HF path, or drop the alias.
4. QQQ's default damp_percent=0.005 is 2× too low (amplifies the BOS-Hessian problem); Llama-3.2-1B QQQ PPL 59.5 (low, default)
quantization/config.py:3816-3817 _default_damp_percent returns 0.005 for QQQ (GPTQ uses 0.05; upstream HandH1998/QQQ fasterquant uses percdamp=0.01). QQQ has no act_group_aware, so Llama's BOS massive activation dominates the Hessian. Packing/export is not the cause: the captured float Q evaluates to the same PPL, and int8 double rounding adds only 3e-4 relative error.
Llama-3.2-1B QQQ4 damp_percent |
BOS kept | BOS removed |
|---|---|---|
| 0.005 (default) | 59.5 | 28.1 |
| 0.01 (upstream) | 55.5 | – |
| 0.05 | 34.4 (= reference GPTQ without AGA) | 25.1 |
On Qwen2.5 the lower damp is slightly better (20.99 vs 21.30), so the effect depends on the model. Consider a default of 0.05, or adding AGA support to QQQ.
Matrix (all on ad0525c; reload, HF-load and in-memory agree unless noted)
| method | Qwen3-0.6B | gemma-3-1b |
|---|---|---|
| rtn4 | 36.8 | 48.0 |
| gptq4 / desc_act | 31.0 / 31.0 | 41.9 / 44.5 |
| awq4 | 36.1 (≈RTN, #4063) | 485.9 (item 1) |
| gptaq4 / foem4 | 30.2 / 31.3 | 42.7 / 42.3 |
| qqq4 | 31.3 | 44.5 |
| fp8 / nf12 | 27.8 / 27.6 | 40.2 / 39.8 |
| gguf q4_k_m | 33.7 | 49.6 |
| paro4 | 30.2 | 42.4 |
exl3 4.0 (auto_dtype_cast off) |
29.4 | 41.0 |
| vptq (~2 bpw) | 90.0 | – |
- Calibration equivalence:
- strings vs pre-tokenized calibration gives identical results;
- bs=1 vs bs=4 is within noise on Qwen3;
- on Llama, bs=4 is consistently about 1 PPL worse, but this isn't padding (fixed-length calibration shows the same gap, and the layer-0 Hessians are bit-identical) and stays within the calibration-subset spread.
- Already filed: the GGUF HF-load issue (random weights) is [BUG] Follow-up on #4061 + HF interop: load_state_dict(state_dict()) corrupts GPTQ v1 models (PPL 9.8 -> 1.9e6, regression), partial/PEFT load flips qzeros format -> garbage re-save, RTN gemm writes quant_method gptq, GGUF ckpt loads in HF as random weights, torch.save(model) PicklingError #4070 item 4; this run saw Qwen3 HF PPL 2.2e8 vs 33.7.
Plausible, not verified
- A ThreadX worker OOM in
torch.cuda.set_device(utils/threadx.py:145) leftquantize()hung for more than 10 minutes with no error. Seen once under GPU contention.
🤖 Generated with Claude Code
Activity
fix(awq,qqq,paroquant): fix offset-gain fold, QQQ bf16 kernel, ParoQu…