Repository navigation
Description
Found on main @ 12c1273, CPU (fold check) + AMD R9700 / ROCm 10.1 (AWQ run).
What is wrong
On Ling 2.0 checkpoints (model_type=bailing_moe, remote-code BailingMoeV2ForCausalLM, e.g. inclusionAI/Ling-mini-2.0), AWQ folds the attention output projection attention.dense into the input_layernorm scaling group together with attention.query_key_value. dense reads the attention output, not the normed hidden state. So the fold multiplies dense's input columns by s without dividing its real input by s, and the full-precision output changes before any quantization happens.
This is a regression from #4429 (d01e8fd, "honor Ling remote-code layout and declare MLA projections"). That PR changed the attention block in models/definitions/bailing_moe.py from query_key_value:0, dense:1 to
"query_key_value:0", "q_a_proj:0", "kv_a_proj_with_mqa:0", "g_proj:0",
"q_b_proj:1", "kv_b_proj:1",
"dense:2",Ling 2.0 layers have no q_b_proj/kv_b_proj, so the subset-1 block resolves to nothing. In BaseQModel.awq_get_modules_for_scaling (models/base.py, normal-subset branch), an empty block only clears pending_nonquant. When the dense block comes next, _select_prev_op finds no pending source and falls back to last_module. That is input_layernorm, and its width matches because dense is hidden -> hidden. The two norm-sourced groups are then merged into one: input_layernorm -> [query_key_value, dense].
Evidence
Fold invariant (the same check as tests/test_awq_scaling_groups.py: fold a random scale in [0.5, 1.5] with the library's apply_scale, then compare full-model logits). Ling-mini-2.0 real weights, truncated to 2 layers, fp32:
| commit | layer | group | relative logit change |
|---|---|---|---|
main 12c1273 |
0 | input_layernorm -> [attention.query_key_value, attention.dense] |
1.43e-01 |
main 12c1273 |
1 | same | 1.29e-01 |
| d01e8fd^ (before #4429) | 0/1 | input_layernorm -> [attention.query_key_value] |
6.2e-07 / 4.8e-07 |
All other groups are below 1e-6 on both commits.
The real AWQ pipeline applies that group. With a hook on apply_scale during GPTQModel.load(Ling-mini-2.0 [2 layers], AWQConfig(bits=4, group_size=128)).quantize(c4):
APPLY input_layernorm ['attention.query_key_value', 'attention.dense'] scale min/max 0.711/1.414 # layer 0
APPLY input_layernorm ['attention.query_key_value', 'attention.dense'] scale min/max 0.695/1.422 # layer 1
The dense input columns are rescaled by up to 1.4x/0.7x with no compensation.
On the same 2-layer model (reload, prompt logits vs bf16 native), the AWQ result is rel err 0.414 / top-1 agreement 0.316. Removing dense from that group (monkeypatched) gives 0.396 / 0.368. GPTQ gives 0.296 / 0.684.
Suggested fix
Two parts:
- In
awq_get_modules_for_scaling, a block that follows an empty (absent-on-this-layer) block must not fall back tolast_module. It should be treated like any block whose producer is not a foldable source, and get no scale. A non-gain-norm input fordensealready yields no group before fix(models): honor Ling-2.6-flash remote-code layout and declare MLA projections (#4373) #4429. - In
bailing_moe.py, keep the Ling 2.0 numbering contiguous, or give the remote MLA branch its own block, sodensedirectly followsquery_key_valuewhenq_b/kv_bare absent.
Test that should have caught it
tests/test_awq_scaling_groups.py (the output-preservation invariant) covers neither bailing_moe nor the remote Ling 2.0 layout. #4429 added module-plan fixtures but no fold check. Add a tiny Ling 2.0 case, and a generic case where a layer_modules_strict=False layer is missing a middle subset.
Severity
High for AWQ on Ling 2.0 (Ling-mini-2.0, Ling-flash-2.0, Ring-2.0): every layer's attention output projection is silently miscalibrated, with a 13-14% logit change from the fold alone. GPTQ is unaffected.
🤖 Generated with Claude Code
Activity
Qubitium commentedon Nov 17, 2026
Claimed by an AI agent. Will reproduce on CPU, fix, add a focused regression test, and open a PR.
fix(awq): do not fold a block that follows an absent declaration (#4677)
fix(awq): do not fold a block that follows an absent declaration (#4677…
fix(awq): keep the norm fold for an absent sibling branch (#4759) (#4800