Repository navigation
fix(awq): clear the prev-op tracker when a present block's last declaration resolves to no module - #6449
Merged
Conversation
…ration resolves to no module The generic AWQ planner tracks the previous op in tree order: after each quantized block it points `last_module` at the block's last declared entry, and the next block falls back to it when no norm in the pending run feeds it. `_try_update_last_module` silently kept the old tracker when that entry resolved to no module. MiMo-V2 declares `self_attn: (qkv_proj, q_proj, k_proj, v_proj, o_proj:1, attention_sink_bias:!)`, so the q/k/v block ends with `attention_sink_bias`, a parameter (or `None`), never a module. The tracker kept `input_layernorm` from before the block, and `self_attn.o_proj` was folded into the input norm together with q/k/v whenever `num_attention_heads * v_head_dim == hidden_size` (the config defaults; split and fused layouts, MHA and GQA). Fold-only (identity quant) full-model logits changed by ~1e-1. When the layer owns the block but its last declaration resolves to no module, the block's output producer is unknown, so the tracker is now cleared and the next block gets no fallback source (o_proj is quantized without a fold). Walking back to an earlier entry is not safe: Hymba's mixer block ends with unrelated `:!` norms. A block the layer does not own at all still keeps the tracker, so absent sibling branches (#4759) are unchanged. The same rule removes Raon-1 mini's generic `input_layernorm -> o_proj` fallback (its q/k/v block ends with `dt_bias:!`); the definition already strips it, so its negative-control test now pins that the generic planner gives `o_proj` no source. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… absent-producer case DiffusionGemma's full-attention layers own q_proj/k_proj but no v_proj. On origin/main the tracker keeps input_layernorm as last_module after the Q/K/V block, o_proj falls back to it, and the merge emits input_layernorm -> [q_proj, k_proj, o_proj] (layer output change ~2e-1). - test_awq_fold_safety_4175: build the vendored port from the pinned parity config (o_proj width == hidden, so only data flow separates them), check every emitted fold is neutral and o_proj is in no group. - test_awq_ling2_fold_4677: a generic tree with an optional last v_proj; without v_proj o_proj gets no source, with v_proj the v -> o fold remains. Both fail on origin/main and pass with the planner fix in #6449. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Qubitium
marked this pull request as ready for review
November 29, 2026 21:29
8 tasks done
Qubitium
added a commit
that referenced
this pull request
Nov 29, 2026
…ma/dots3_note/glm5_next fixes (#6452) #6446 pinned four wrong planner outcomes as `bug:` entries, and its inventory test requires a listed difference to still differ. #6449 and #6451 fixed them, so test_awq_fold_inventory.py fails on main (4 planner cases, then 2 canonical cases). - Regenerate the four fixture entries with `awq_fold_inventory.py --write --types dots3_note,mimo_v2,diffusion_gemma,glm5_next`: mimo_v2 and diffusion_gemma (k_eq_v layer 1) drop self_attn.o_proj from the input_layernorm group, dots3_note sliding layers plan instead of raising, glm5_next adds mlp.shared_experts.gate_proj/up_proj as consumers. - diffusion_gemma/parity and dots3_note/default now match the role-derived folds, so their entries are removed. - mimo_v2 and glm5_next still differ from the derivation for reasons that are not bugs (v_proj -> o_proj is not emitted after a `:!` leaf; glm5_next linear-attention layers need `v_proj:nosrc`), so they are reclassified. Co-authored-by: Claude Opus 5.5 <[email protected]>
This was referenced Nov 30, 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.
Summary
On MiMo-V2, AWQ folds
self_attn.o_proj's input scale intoinput_layernorm, in the same group as q/k/v. The two cannot share one scale:o_projreads the attention output, not the normed hidden state. With identity quantization (fold only), the full-model logits of a tiny random-initmimo_v2change by about 1e-1 relative. With this fix the change is 1.5e-7.Cause. The generic planner (
BaseQModel._awq_generic_get_modules_for_scaling) tracks a "previous op" in tree order:last_moduleat the block's last declaration (base.py:8255onef7af83db)._try_update_last_modulekeeps the old tracker when that declaration resolves to no module.MiMo-V2 declares
self_attn: (qkv_proj:0, q_proj:0, k_proj:0, v_proj:0, o_proj:1, attention_sink_bias:!). As a result:attention_sink_bias, which is a parameter (orNone), never a module.input_layernormfrom before the block.num_attention_heads * v_head_dim == hidden_size. That holds for the config defaults, for split and fused layouts, and for MHA and GQA.The released MiMo-V2.5/V2.6 checkpoints (
fused_qkv,v_head_dim=128, so o_proj is 8192 or 16384 wide against a 4096 or 6144 hidden size) are rejected by that width check today, so they are not affected.Fix (shared planner, no per-model code). When the layer owns a quantized block but the block's last declaration resolves to no module, the producer of that block's output is unknown. The tracker is now cleared instead of left pointing at a source from before the block. The next block then gets no fallback source, so
o_projis quantized without a fold.:!norms, and it foldedmamba.out_projintomamba.pre_avg_layernorm2, whichtest_scaling_groups_preserve_decoder_layer_output[hymba]caught (2.2e-1).What Changed
gptqmodel/models/base.py: at the tracker update at the end of each quantized block, if_try_update_last_modulefails and the block is not absent, setlast_moduleandlast_module_nametoNone(+12/-1).docs/awq-scaling-groups.md: the flow node and one paragraph now describe the rule.tests/module_tree/test_mimo_v2_local_port.py: new real-model regression test (below).tests/module_tree/test_awq_raon1_mini_neutrality.py: Raon-1 mini's q/k/v block ends withdt_bias:!, so the generic planner also handed itso_projthe input norm. The definition already strips that group, so Raon's effective plan does not change. The negative control that pinned the stale generic group is replaced bytest_raon_generic_planner_gives_o_proj_no_source.v_proj -> o_projfold for split-MHA MiMo-V2. The planner never emitted a correct one, and inferring it would need the role-based derivation from the AWQ fold sequence (test(awq): pin every definition's effective fold plan and add the role-derived folds alongside #6446), not a guess in the positional tracker.Effect on every
MODEL_MAPdefinition (fold-plan diff, main vs branch)I ran the meta-device fold-plan inventory from #6446 (
tests/module_tree/awq_fold_inventory.py) onorigin/main(ef7af83db) and on this branch.MODEL_MAPtypes and 254 buildable config variants. I added 4 MiMo-V2 variants:split_sinks,fused_mha,split_gqaand the releasedMiMo-V2.5-Base.awq_get_modules_for_scalingon every decoder layer and records source, targets, consumers, boundary and the_quantize_layeroutcome for each group.dbrxis the registry sentinel.Only three types change:
mimo_v2default,split_sinks,split_gqa,fused_mha(all layers)input_layernorm -> [q,k,v,o_proj]or[qkv_proj, o_proj](status ok, non-neutral)input_layernorm -> [q,k,v]/[qkv_proj]; o_proj not groupedo_projreads the attention output.mimo_v2v25_base(released)diffusion_gemmaparity, layer 1 (attention_k_eq_v, nov_proj)input_layernorm -> [q_proj, k_proj, o_proj]input_layernorm -> [q_proj, k_proj]v_proj. This is the separately tracked diffusion_gemma bug (attention part only, not the routed up->down note).dots3_notedefault, everysliding_attentionlayer (2-4, 6-8, ...)_AWQScaleGroupError: source self_attn.kv_a_proj_with_mqa has multiple scaling groupsinput_layernorm -> [q_a, kv_a]ok,kv_a -> [q_b, kv_b]drop:width, MLP groups okindexer.weights_proj, which sliding layers lack. The stalekv_a_proj_with_mqabecameo_proj's source and conflicted. On a tiny CPU dots3_note checkpoint,GPTQModel.load(...).quantize(...)with AWQ now plans 3 groups on the sliding layer instead of aborting. It later stops at packing a 2-wide indexer projection of the tiny fixture (out_features 2 must be divisible by 8), which is unrelated.Every other definition's plan is byte-identical.
Tests
Interpreter:
/root/venv/bin/python(Python 3.14.4, torch 2.15.0+cu132, transformers 5.23.0), CPU only,HF_HUB_OFFLINE=1.New regression test:
tests/module_tree/test_mimo_v2_local_port.py::test_awq_o_proj_is_not_folded_into_input_layernorm_when_widths_match[{4,2}-{split,fused_qkv}].v_head_dim = 8so that heads * v_head_dim == hidden_size.assert_awq_folds_neutral, on full-model logits.input_layernorm -> q/k/v(orqkv_proj).Measured Impact
Fold-only (identity quantization) relative change of full-model logits for each emitted group. The model is a tiny random-init
MiMoV2ForCausalLMbuilt from the vendored port config: hidden 32, 4 heads,head_dim = v_head_dim = 8, 2 layers (full + SWA), norm gains U(0.5, 1.5), scaleslinspace(0.5, 1.5).input_layernorm -> q,k,v,o_proj)input_layernorm -> qkv_proj,o_proj)No GPU A/B was run. The shared-path change is covered by the full fold-plan diff above, which leaves every other definition identical. That diff is structural, so the Qwen2.5 family has an identical plan by construction.
Model Support / Module Plan
Not applicable: no
MODEL_MAPentry, alias, tree or definition changes.tests/module_tree/test_registered_module_plans.pypassed (included above).Model test node IDs and results:
tests/module_tree/test_mimo_v2_local_port.py29 passed;tests/test_mimo_v2_local_port.py,tests/test_mimo_v2_support.pyandtests/test_awq_mimo_v2_rotary_selection.pypassed in the baseline run above.AWQ onboarding safety
o_projkeeps its existing ungrouped plain-quantization path.AWQ evidence and per-variant policy:
MiMoV2Attention.forward(gptqmodel/models/ports/mimo_v2/modeling_mimo_v2.py),o_projreadsattn_output(softmax(QK^T + sinks) V, reshaped). It does not readinput_layernorm's output.attention_sink_biasis a per-head logit parameter, not a module.input_layernorm -> q/k/v(orqkv_proj) is qualified neutral by the new test and the old one.o_projis plain-quantized with no fold.test_awq_scale_folds_preserve_real_dense_moe_and_swa_layers.Logic Flow Documentation
It is a local change to one tracker-update rule. The existing
docs/awq-scaling-groups.mdflow diagram (linked fromREADME.md) has its tracker node updated, and the page now has a paragraph describing the rule.base.py:8255atef7af83db)attention_sink_bias:!parameter, absentv_proj, absentindexer.weights_proj)Review Requirements
Kernel Accuracy Requirements
Not applicable: no kernel, pack or dispatch change.
Notes
attention_k_eq_vo_proj fold and the dots3_note sliding-layer abort (table above). Both disappear with this change, so this PR is the single planner fix for all three.v_projcase (second commit), both failing on origin/main and passing here:tests/module_tree/test_awq_fold_safety_4175.py::test_diffusion_gemma_full_attention_o_proj_is_not_folded_into_the_input_norm: the vendored port built from the pinned parity config (o_proj width == hidden). Every emitted fold is neutral on the layer output ando_projis in no group. On main the output changes by 1.970e-01.tests/test_awq_ling2_fold_4677.py::test_absent_last_producer_does_not_hand_o_proj_the_input_norm[k-eq-v|with-v-proj]: a generic tree with an optional lastv_proj; without ito_projgets no source, and with it thev_proj -> o_projfold remains.pytest tests/module_tree/test_awq_fold_safety_4175.py tests/test_awq_ling2_fold_4677.py tests/module_tree/test_mimo_v2_local_port.py-> 49 passed.🤖 Generated with Claude Code