Repository navigation
fix(awq,qqq,paroquant): gauge offset-gain folds and fix QQQ/ParoQuant load paths (#4074) - #4081
Merged
Merged
Conversation
…ant HF alias, QQQ damp (#4074) Item 1 (AWQ Gemma-3 bf16): renormalise offset-gain scales by their peak (max(s) <= 1) before folding (1 + w) / s - 1. A uniform factor on the per-channel scale is an exact gauge for per-group symmetric quantisation, and without it Gemma-3 MLP scales near 1e3 push 1 + w' outside bf16. scale_ln_fcs now returns the effective scale and apply_scale uses it for captured features and non-quantized consumers. gemma-3-1b AWQ4 wikitext-2 PPL: 848.5 -> 67.8 (RTN4 72.6, base 59.6). Item 2 (QQQ bf16 in-memory): select the in-memory kernel from the packed module dtype through BaseQuantLinear.supports_dtype, the same SUPPORTS_DTYPES declaration the reload path validates. BF16 now builds QQQTorchLinear instead of the FP16-only QQQLinear. Item 3 (ParoQuant): drop the transformers "paroquant" -> GPTQConfig alias. It renamed the method to gptq and optimum then rejected the checkpoint with a FORMAT/METHOD mismatch; transformers now fails cleanly with an unknown quantization type and GPTQModel.load still uses ParoLinear. Item 4 (QQQ damp): raise the default damp_percent from 0.005 to 0.05 to match GPTQ and the issue's Llama-3.2-1B measurement (59.5 -> 34.4). This is a visible default change for existing QQQ users; the PR documents it and the model/calibration dependence. Docs: extend docs/awq-scale-folding.md and add docs/qqq-kernel-selection.md and docs/qqq-default-damp.md, all linked from README.md.
This was referenced Nov 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4074
TL;DR
Four independent defects from the real-model matrix, one per item:
1 + w'to bf16 cancellation when the per-channel scale reached~1e3. The scale is now gauged tomax(s) <= 1, which is exact for per-group symmetric quantisation.gemma-3-1bAWQ4 wikitext-2 PPL: 848.5 → 67.8 (RTN4 72.6, unquantized 59.6).QQQProcessornow picks the kernel from the packed module dtype through the sameSUPPORTS_DTYPESdeclaration the reload path validates; BF16 buildsQQQTorchLinearinstead of the FP16-onlyQQQLinear.transformersparoquant -> GPTQConfigalias is removed, sofrom_pretrainedfails with an honest unknown-method error instead of a FORMAT/METHOD mismatch;GPTQModel.loadis unchanged.0.005to0.05(GPTQ parity). This is a visible default change and is called out below with the issue's measurement and our independent reproduction.origin/mainalready contains #4063's variable-length calibration aggregation (39b62765e, PR #4071); item 1's fix builds on it.Item 1 — AWQ offset-gain fold loses the gain to bf16 cancellation
Problem
scale_ln_fcs(gptqmodel/quantization/awq/quantize/scale.py:316-320onorigin/main) computed(1 + w) / s - 1in float32 but stored it back in bf16. Gemma-3pre_feedforward_layernormchannels withx_mean == 0push the MLP-group scale tos ~ 1e3(sqrt(max*min)normalisation ingptqmodel/looper/awq_processor.py:2578). Therew' ~ -0.999,1 + w'is not representable in bf16, and the "neutral" fold changes the model.Measured fold round-trip on the pre-fix code (relative L2 of the block output, bf16):
Gemma3RMSNorm,max(s) ≈ 148Gemma3RMSNorm,max(s) ≈ 1485LlamaRMSNorm,max(s) ≈ 1499Fix
A uniform factor on the per-channel scale is an exact gauge of per-group symmetric quantisation: scaling every column by
1/cscales each group's absmax by1/c, so the packed codes are unchanged and only the group scale moves. For offset-gain norms only,scale_ln_fcsdividessby its peak whenmax(s) > 1, folds in float32, and returns the effective scale.apply_scaleuses that returned scale for the captured input features and the non-quantized consumers (MoE router / shared-expert gate), so the fold, the quantization input and the consumers share one gauge. Plain-gain norms storew / s, which keeps its relative precision at anys, and are left untouched.flowchart TD A["apply_scale group<br/>prev_op, layers, s"] --> B{"is_foldable_source?"} B -- "no" --> B1["skip group<br/>log warning"] B -- "yes" --> C["scale_ln_fcs(prev_op, layers, s)"] C --> D{"_norm_gain_offset(prev_op)"} D -- "raises" --> D1["UnresolvableGainOffset<br/>skip group"] D -- "0.0 plain gain" --> E["w.div_(s)<br/>return s"] D -- "1.0 offset gain" --> F{"max(s) > 1?"} F -- "yes" --> G["s = s / max(s)<br/>max(s) = 1"] F -- "no" --> H["keep s"] G --> I["fold (1 + w) / s - 1 in float32<br/>cast once to serving dtype"] H --> I I --> J["return effective s"] E --> J J --> K["apply_scale divides captured features<br/>and consumer input columns by effective s"] style B1 fill:#f8d7da,stroke:#b02a37,stroke-width:2px style D1 fill:#f8d7da,stroke:#b02a37,stroke-width:2pxBefore,
scale_ln_fcsreturnedNoneandapply_scaledivided features by the originals; renormalising inside the fold alone would have desynchronised the quantization input. The same gauge covers Gemma, Gemma 2, Gemma 3, Qwen3.5 and Qwen3-Next because_norm_gain_offsetresolves the live semantics; Gemma-3 is the measured case and the other families are covered by the new parametrized unit test.End-to-end
gemma-3-1b-it, bf16,sym=False,FORMAT.GEMM, 128 C4 calibration documents, 80 × 512 wikitext-2 test tokens, save + reload:AWQ went from 12.5× worse than RTN to slightly better than RTN and within 14% of the unquantized model — the same relative result reported in #4074 (45.3 vs rtn 48.0, base 39.8).
Item 2 — QQQ bf16 in-memory model raises
Problem
QQQProcessor._quant_linear_kernel(gptqmodel/looper/qqq_processor.py:85-108onorigin/main) returnedQQQLinearfor every CUDA device, whatever the model dtype.QQQLinear.SUPPORTS_DTYPES == [torch.float16], and since #4001 itsforwardraises for non-FP16 input, soquantize(offload_to_disk=False)left a BF16 model that could not run. The reload path already passeddtype=self.model.dtypeintoselect_quant_linearand pickedQQQTorchLinear.Fix
BaseQuantLinear.supports_dtypenow owns theSUPPORTS_DTYPEScheck used by both_validate_sharedandQQQProcessor.submodule_finalizepasses the packed module dtype into the selector. An explicitBACKEND.QQQrequest for a non-FP16 dtype raises with theBACKEND.QQQ_TORCHremedy instead of failing in the first forward.flowchart TD A["QQQProcessor._quant_linear_kernel(dtype)"] --> B{"requested BACKEND<br/>QQQ_TORCH or darwin?"} B -- "yes" --> T["QQQTorchLinear<br/>BACKEND.QQQ_TORCH"] B -- "no" --> C{"IS_ROCM?"} C -- "yes" --> C1{"explicit BACKEND.QQQ?"} C1 -- "yes" --> C2["raise NotImplementedError<br/>QQQ_ROCM_UNSUPPORTED"] C1 -- "no" --> T C -- "no" --> D{"qcfg.device is<br/>cpu or npu?"} D -- "yes" --> T D -- "no" --> E{"QQQLinear.supports_dtype(dtype)?"} E -- "yes" --> N["QQQLinear<br/>BACKEND.QQQ"] E -- "no" --> F{"explicit BACKEND.QQQ?"} F -- "yes" --> F1["raise NotImplementedError<br/>use BACKEND.QQQ_TORCH"] F -- "no (AUTO)" --> T style C2 fill:#f8d7da,stroke:#b02a37,stroke-width:2px style F1 fill:#f8d7da,stroke:#b02a37,stroke-width:2pxBefore/after on a tiny BF16 Llama,
QQQConfig(offload_to_disk=False)on CUDA:quantize()QQQLinearQQQTorchLinearNotImplementedError: QQQLinear is an FP16 kernelQQQTorchLinearQQQTorchLinear(unchanged)Item 3 — ParoQuant checkpoint crashes
transformers.from_pretrainedgptqmodel/__init__.py:114-142registeredquant_method="paroquant"as an alias for HFGPTQConfig/GptqHfQuantizer. That path renamed the method togptq, so optimum kernel selection rejected the checkpoint withUnsupported format: FORMAT.PAROQUANT for quantization method METHOD.GPTQ.The alias is removed.
transformersnow reportsUnknown quantization type, got paroquant(the real problem), andGPTQModel.loadstill detectsMETHOD.PAROand buildsParoLinear; the loader's supported-method check does not use the HF registry.tests/test_paroquant.pynow pins the absence of the alias and the clean error.transformersfrom_pretrainedValueError: Unsupported format: FORMAT.PAROQUANT for ... METHOD.GPTQValueError: Unknown quantization type, got paroquantGPTQModel.loadParoLinearParoLinear(unchanged)Item 4 — QQQ default
damp_percent=0.005is 10× below GPTQ_default_damp_percent(gptqmodel/quantization/config.py:3816-3817) returned0.005for QQQ (GPTQ:0.05; upstreamHandH1998/QQQpercdamp=0.01). QQQ has no activation-group-aware calibration, so Llama's BOS massive activation dominates the Hessian.This is a visible default change for existing QQQ users who did not set
damp_percent. Explicitdamp_percent=values and_default_damp_auto_incrementare unchanged.Issue #4074's measurement, Llama-3.2-1B QQQ4 wikitext-2 PPL:
damp_percent0.005(old default)0.01(upstream)0.05(new default)Independent reproduction on this PR's branch (Llama-3.2-1B, 128 C4 docs, bf16, 80 × 512 wikitext-2):
damp_percentcalibration_concat_size=512calibration_concat_size=20480.0050.05On our harness the lower damp was better, i.e. the opposite direction from the issue's Llama table; that matches the issue's own note that the effect is model-dependent (Qwen2.5 is slightly better at the lower damp). The default is raised as specified because it matches GPTQ and the issue's Llama case, and the conflict is documented rather than hidden.
Change inventory
gptqmodel/quantization/awq/quantize/scale.pyapply_scale)gptqmodel/looper/qqq_processor.pygptqmodel/nn_modules/qlinear/__init__.pysupports_dtypegptqmodel/__init__.pygptqmodel/quantization/config.py0.05docs/awq-scale-folding.md,docs/qqq-kernel-selection.md,docs/qqq-default-damp.md,docs/paroquant.md,README.mdtests/test_awq_scale_folding.py,tests/test_qqq_config.py,tests/test_qqq_bf16_in_memory.py,tests/test_paroquant.py,tests/test_finalize_module_lookup.py,tests/test_silent_exception_handling.pyTests / guarantees
test_scale_ln_fcs_offset_gain_folds_in_float32(nowscale_peak1.5/100/1000)test_apply_scale_uses_the_gauge_for_captured_features_and_weightstest_offset_gain_fold_is_neutral_at_gemma3_mlp_scalemax(s) ~1e3test_qqq_processor_kernel_selection_follows_supports_dtypestest_qqq_bf16_in_memory_model_uses_the_torch_kerneltest_paroquant_is_not_registered_as_a_transformers_gptq_aliastest_qqq_default_damp_percent_matches_gptq0.05Validation
Hardware: RTX 4090 (
GPU-d458708b-c760-bbf1-08fb-8b8803a2157d, sm_89) and AMD R9700 gfx1201 (HIP_VISIBLE_DEVICES=0). The RTX 5090 was not used.origin/mainmerged before the final run (Already up to dateat39b62765e).Fail-before evidence: the pre-fix Gemma-3 fold shows 0.111 / 0.993 relative error at
max(s) ≈ 148 / 1485(0.0036 after); the QQQ BF16 test buildsQQQLinearand fails before the forward; the QQQ default test reads0.005before the change; the ParoQuant alias test fails because the old registry maps the method to GPTQ.Reviewer notes
swas already small (max(s) > 1is the common case because the search normalises bysqrt(max*min)). The block output is gauge-invariant; the unit tests pin both the exact stored gain and the output.docs/qqq-default-damp.md.GPTQMODEL_*environment switches were added; no dense inference weight caches were introduced.