Skip to content

fix(awq,qqq,paroquant): gauge offset-gain folds and fix QQQ/ParoQuant load paths (#4074) - #4081

Merged
Qubitium merged 1 commit into
mainfrom
fix/issue-4074-awqgemma
Nov 15, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/issue-4074-awqgemma

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #4074

TL;DR

Four independent defects from the real-model matrix, one per item:

  1. AWQ on Gemma-3 bf16 (headline). The offset-gain fold lost 1 + w' to bf16 cancellation when the per-channel scale reached ~1e3. The scale is now gauged to max(s) <= 1, which is exact for per-group symmetric quantisation. gemma-3-1b AWQ4 wikitext-2 PPL: 848.5 → 67.8 (RTN4 72.6, unquantized 59.6).
  2. QQQ bf16 in-memory. QQQProcessor now picks the kernel from the packed module dtype through the same SUPPORTS_DTYPES declaration the reload path validates; BF16 builds QQQTorchLinear instead of the FP16-only QQQLinear.
  3. ParoQuant HF alias. The transformers paroquant -> GPTQConfig alias is removed, so from_pretrained fails with an honest unknown-method error instead of a FORMAT/METHOD mismatch; GPTQModel.load is unchanged.
  4. QQQ default damp. Raised from 0.005 to 0.05 (GPTQ parity). This is a visible default change and is called out below with the issue's measurement and our independent reproduction.

origin/main already 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-320 on origin/main) computed (1 + w) / s - 1 in float32 but stored it back in bf16. Gemma-3 pre_feedforward_layernorm channels with x_mean == 0 push the MLP-group scale to s ~ 1e3 (sqrt(max*min) normalisation in gptqmodel/looper/awq_processor.py:2578). There w' ~ -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):

Case Before After
Gemma3RMSNorm, max(s) ≈ 148 0.111 0.0036
Gemma3RMSNorm, max(s) ≈ 1485 0.993 0.0036
LlamaRMSNorm, max(s) ≈ 1499 0.0041 0.0041

Fix

A uniform factor on the per-channel scale is an exact gauge of per-group symmetric quantisation: scaling every column by 1/c scales each group's absmax by 1/c, so the packed codes are unchanged and only the group scale moves. For offset-gain norms only, scale_ln_fcs divides s by its peak when max(s) > 1, folds in float32, and returns the effective scale. apply_scale uses 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 store w / s, which keeps its relative precision at any s, 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:2px
Loading

Before, scale_ln_fcs returned None and apply_scale divided features by the original s; 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_offset resolves 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:

Method PPL
AWQ4 before this PR 848.5
AWQ4 after this PR 67.8
RTN4 (same harness) 72.6
unquantized base 59.6

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-108 on origin/main) returned QQQLinear for every CUDA device, whatever the model dtype. QQQLinear.SUPPORTS_DTYPES == [torch.float16], and since #4001 its forward raises for non-FP16 input, so quantize(offload_to_disk=False) left a BF16 model that could not run. The reload path already passed dtype=self.model.dtype into select_quant_linear and picked QQQTorchLinear.

Fix

BaseQuantLinear.supports_dtype now owns the SUPPORTS_DTYPES check used by both _validate_shared and QQQProcessor. submodule_finalize passes the packed module dtype into the selector. An explicit BACKEND.QQQ request for a non-FP16 dtype raises with the BACKEND.QQQ_TORCH remedy 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:2px
Loading

Before/after on a tiny BF16 Llama, QQQConfig(offload_to_disk=False) on CUDA:

Before After
kernel after quantize() QQQLinear QQQTorchLinear
in-memory forward NotImplementedError: QQQLinear is an FP16 kernel finite logits
reload kernel QQQTorchLinear QQQTorchLinear (unchanged)

Item 3 — ParoQuant checkpoint crashes transformers.from_pretrained

gptqmodel/__init__.py:114-142 registered quant_method="paroquant" as an alias for HF GPTQConfig / GptqHfQuantizer. That path renamed the method to gptq, so optimum kernel selection rejected the checkpoint with Unsupported format: FORMAT.PAROQUANT for quantization method METHOD.GPTQ.

The alias is removed. transformers now reports Unknown quantization type, got paroquant (the real problem), and GPTQModel.load still detects METHOD.PARO and builds ParoLinear; the loader's supported-method check does not use the HF registry. tests/test_paroquant.py now pins the absence of the alias and the clean error.

Before After
transformers from_pretrained ValueError: Unsupported format: FORMAT.PAROQUANT for ... METHOD.GPTQ ValueError: Unknown quantization type, got paroquant
GPTQModel.load ParoLinear ParoLinear (unchanged)

Item 4 — QQQ default damp_percent=0.005 is 10× below GPTQ

_default_damp_percent (gptqmodel/quantization/config.py:3816-3817) returned 0.005 for QQQ (GPTQ: 0.05; upstream HandH1998/QQQ percdamp=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. Explicit damp_percent= values and _default_damp_auto_increment are unchanged.

Issue #4074's measurement, Llama-3.2-1B QQQ4 wikitext-2 PPL:

damp_percent BOS kept BOS removed
0.005 (old default) 59.5 28.1
0.01 (upstream) 55.5 –
0.05 (new default) 34.4 (= reference GPTQ without AGA) 25.1

Independent reproduction on this PR's branch (Llama-3.2-1B, 128 C4 docs, bf16, 80 × 512 wikitext-2):

damp_percent calibration_concat_size=512 calibration_concat_size=2048
0.005 18.8 27.4
0.05 27.0 56.1

On 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

Area File Purpose
AWQ fold gptqmodel/quantization/awq/quantize/scale.py offset-gain scale gauge; return effective scale
AWQ fold caller same file (apply_scale) reuse effective scale for features and consumers
QQQ kernel gptqmodel/looper/qqq_processor.py dtype-aware in-memory kernel
Kernel contract gptqmodel/nn_modules/qlinear/__init__.py shared supports_dtype
ParoQuant gptqmodel/__init__.py remove HF GPTQ alias
QQQ damp gptqmodel/quantization/config.py default 0.05
Docs docs/awq-scale-folding.md, docs/qqq-kernel-selection.md, docs/qqq-default-damp.md, docs/paroquant.md, README.md flow diagrams, before/after, measured numbers
Tests tests/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.py fail-before / pass-after

Tests / guarantees

Test Invariant
test_scale_ln_fcs_offset_gain_folds_in_float32 (now scale_peak 1.5/100/1000) fp32 fold + gauge, bf16 and fp16, exact stored gain
test_apply_scale_uses_the_gauge_for_captured_features_and_weights fold, features and consumers share the effective scale
test_offset_gain_fold_is_neutral_at_gemma3_mlp_scale every offset-gain family survives max(s) ~1e3
test_qqq_processor_kernel_selection_follows_supports_dtypes BF16 → torch kernel, FP16 → native, explicit QQQ + BF16 raises
test_qqq_bf16_in_memory_model_uses_the_torch_kernel no FP16-only kernel; in-memory and reloaded forwards run
test_paroquant_is_not_registered_as_a_transformers_gptq_alias alias absent; unknown-type error
test_qqq_default_damp_percent_matches_gptq QQQ default is 0.05

Validation

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/main merged before the final run (Already up to date at 39b62765e).

CUDA  /opt/venvs/cu130t/bin/python -m pytest \
  tests/test_awq_scale_folding.py tests/test_qqq_config.py \
  tests/test_finalize_module_lookup.py tests/test_silent_exception_handling.py \
  tests/test_paroquant.py::test_paroquant_is_not_registered_as_a_transformers_gptq_alias \
  tests/test_qqq_bf16_in_memory.py -q
-> 75 passed

ROCm  HIP_VISIBLE_DEVICES=0 /opt/venvs/rocm101t/bin/python -m pytest <same set> -q
-> 75 passed

CUDA  pytest tests/test_rocm_backend_gating.py -k qqq tests/test_npu_support.py -k qqq \
  tests/test_qqq_cpu.py tests/test_qqq_inference.py -q
-> 58 passed, 5 skipped

CUDA  pytest tests/kernels/test_selection.py -q
-> 135 passed, 39 skipped

ruff check gptqmodel docs/eora tests setup.py
-> All checks passed!

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 builds QQQLinear and fails before the forward; the QQQ default test reads 0.005 before the change; the ParoQuant alias test fails because the old registry maps the method to GPTQ.

Reviewer notes

  • Item 1 changes the stored norm gain for offset-gain norms even when s was already small (max(s) > 1 is the common case because the search normalises by sqrt(max*min)). The block output is gauge-invariant; the unit tests pin both the exact stored gain and the output.
  • Item 3 deliberately drops the alias instead of teaching optimum the ParoQuant format. That is the simpler fix the issue allows; HF now fails with an actionable error.
  • Item 4 is a real default change; the issue's table and our independent, partially conflicting reproduction are both in the PR and docs/qqq-default-damp.md.
  • No GPTQMODEL_* environment switches were added; no dense inference weight caches were introduced.

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant