Skip to content

[BUG] AWQ scale folding corrupts Gemma2/Gemma3/Qwen3.5/Qwen3-Next: wrong (1+w) RMSNorm detection and wrong prev_op norm #3973

Closed

Description

@Qubitium

Audit of main @ a16977e. Both bugs silently change model outputs during AWQ scale folding. The scale search doesn't catch them because it scores the inspected submodule, not the folded norm.

1. scale_ln_fcs only handles (1 + weight) norms for GemmaRMSNorm/Gemma2RMSNorm

gptqmodel/quantization/awq/quantize/scale.py:144-150 checks the offset path with isinstance(ln, GemmaRMSNorm) or isinstance(ln, Gemma2RMSNorm). These norms also compute x * (1 + weight) but don't subclass either one, so they fall through to a plain weight /= s:

  • Gemma3RMSNorm
  • Qwen3_5RMSNorm
  • Qwen3_5MoeRMSNorm
  • Qwen3NextRMSNorm

The effective gain becomes 1 + w/s instead of (1 + w)/s.

Repro: apply a random AWQ scale via apply_scale(norm, [linear]) and compare norm→linear output before and after.

norm rel. L2 error
LlamaRMSNorm / Gemma2RMSNorm ~1e-7
Gemma3RMSNorm 0.48
Qwen3_5RMSNorm 0.47
Qwen3_5MoeRMSNorm 0.44
Qwen3NextRMSNorm 0.44

Fix: detect the offset semantics, not a class list. Options: a registry covering Gemma3, Qwen3.5(-MoE), Qwen3-Next, VaultGemma, T5Gemma and others; or a check for 1.0 + self.weight / 1 + self.weight in the forward. Then do w.add_(1).div_(s).sub_(1), ideally in fp32.

2. Gemma2/Gemma3: MLP scale is folded into post_attention_layernorm instead of pre_feedforward_layernorm

awq_get_modules_for_scaling in gptqmodel/models/base.py (~4400-4410) keeps only the first of consecutive non-quantized blocks as prev_op. The Gemma2/3 layer is post_attention_layernorm:! → pre_feedforward_layernorm:! → mlp.gate/up, so prev_op for gate/up ends up as post_attention_layernorm.

That norm's output is added to the residual and then re-normalized by pre_feedforward_layernorm. Dividing it by s is therefore not equivalent to scaling the MLP input, and it also perturbs the residual stream.

Repro: real Gemma2QModel.awq_get_modules_for_scaling on a tiny Gemma2DecoderLayer:

prev_op: ['post_attention_layernorm'] -> layers: ['mlp.gate_proj', 'mlp.up_proj']
relative layer-output change after folding mlp scales: 0.38

Every Gemma2/Gemma3 AWQ quant is affected. For Gemma3, bug 1 makes it worse.

Fix: use the norm that immediately feeds the consumer block (pre_feedforward_layernorm). Alternatively, mark sandwich post-norms as non-scaling sources in the gemma2/gemma3 module trees.

🤖 Generated with Claude Code

Activity

  1. added
    bug
    on Nov 14, 2026
  2. Qubitium commented on Nov 14, 2026

    @Qubitium
    CollaboratorAuthor

    Follow-up review of the merged fix found remaining problems; see #4002.

  3. Qubitium commented on Nov 14, 2026

    @Qubitium
    CollaboratorAuthor

    Follow-up: the offset-gain fold is still not neutral in bf16 when AWQ scales are large. Gemma-3 MLP scales reach ~1e3, so 1+w' cancels in bf16 and gemma-3-1b AWQ PPL goes from 39.8 to 486 (RTN is 48). Details in the new matrix issue, item 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions