Repository navigation
fix(awq): compensate dense expert gate/up under the MoE root - #6451
Merged
Merged
Conversation
The generic AWQ planner folds the norm before a `:moe` root into every
routed expert's gate/up projection. `_moe_block_consumers` compensated
only direct children of the root that own a 2-D weight (routers,
`shared_expert_gate`). An expert family the tree keeps dense, such as
GLM-5.3's `shared_experts: ("gate_proj:!", "up_proj:!", "down_proj:!")`,
also reads the MoE input. Its leaves are grandchildren of the root, so
they were neither fold targets nor scale consumers. Their input columns
were never multiplied by the scale that was divided out of
`post_attention_layernorm`, so the dense shared expert's output changed.
With identity quantization, the fold alone changes the tiny GLM-5.3
logits by 2.3e-2.
`_moe_block_consumers` now also collects the declared non-quantized
leaves with a gate/up role anywhere under the MoE root, subject to the
existing width check and `noconsumer` opt-out. `apply_scale` already
multiplies `_scale_consumers` by the scale, and the search already leaves
consumers unchanged, so no processor change is needed. The fold change
drops to 5.9e-8.
Across every MODEL_MAP definition, the resolved fold plans differ from
main only in the glm5_next MoE layers.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Qubitium
marked this pull request as ready for review
November 29, 2026 21:30
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
The generic AWQ planner folds the norm in front of a
:moeroot (post_attention_layernorm) into every routed expert'sgate_proj/up_proj._moe_block_consumerscompensated only the direct children of that root that own a 2-D weight, i.e. routers andshared_expert_gate.GLM-5.3 (
glm5_next) keeps its shared experts dense:They read the same normed MoE input. Their leaves are grandchildren of the root, though, so they were neither fold targets nor
_scale_consumers. The scale divided out of the norm was never multiplied back into their input columns, and the dense shared expert's output changed.Measured on a tiny random-init GLM-5.3 built from the vendored port config, with the fold only (no quantization): logits relative change 2.3e-2 on main, 5.9e-8 on this branch.
The fix is general, with no glm5_next special case. Any declared non-quantized (
:!/:?) leaf with a gate/up role anywhere under the MoE root is now a scale consumer of the MoE-input group. The existing width check and thenoconsumeropt-out still apply.No linked issue. This was found while building the AWQ fold-plan inventory (AWQ lifecycle debloat).
What Changed
gptqmodel/models/base.py,_moe_block_consumers::moeroot whose plan roles includegateorup.apply_scalealready multiplies_scale_consumers, and the scale search already leaves consumers unchanged.tests/module_tree/test_awq_glm5_next_neutrality.py(new):awq_neutralityhelper) and asserts the full-model logits are unchanged.["mlp.gate", "mlp.shared_experts.gate_proj", "mlp.shared_experts.up_proj"].docs/awq-scaling-groups.md: one sentence under "One group per norm", plus a before/after row.Behavior change: limited to definitions that declare a dense gate/up expert family under a
:moeroot and run the generic AWQ planner. On every currentMODEL_MAPdefinition that is onlyglm5_next(see the fold-plan diff below).Out of scope:
dynamicnegative-match) modules. These are config-level, not declared:!; this PR does not change them.Tests
Regression: red on
origin/main(ef7af83), green on this branch. The test file was copied into a detachedorigin/mainworktree for the red run.Affected families. These are every test file that calls
awq_get_modules_for_scaling, reads_scale_consumersor usesassert_awq_folds_neutral, plus alltests/test_awq*.py, all non-real-model glm5_next tests andtests/module_tree/test_registered_module_plans.py: 219 files.tests/test_awq_variable_length_ppl.py::test_awq_beats_rtn_with_variable_length_calibration(dense Qwen2.5-0.5B,RuntimeError: Inference tensors do not track version counter). It fails identically onorigin/main. It is pre-existing, unrelated, and its model has no MoE root.tests/test_awq_moe.py::TestGroupSize::test_quant_and_inference_0(a real Qwen3-30B-A3B quantize). I stopped it after more than 30 min on one GPU. Its fold plan is unchanged by this PR (qwen3_moe has no dense experts; see the diff below).RUN_AWQ_FP16_HEURISTIC_BENCHbenchmark gate.gptqmodel[minicpm-o]extra, network-only release asset, Mistral-7B-AWQ not in the local cache,cuda:1unavailable.End-to-end processor path:
tests/test_awq_shared_indexer_replay.py::test_glm5_next_shared_indexer_replay_is_per_batchpassed on the branch. It is the existing AWQ quantize of a tiny GLM-5.3 checkpoint.bash format/check.sh: All checks passed (ruff 0.14.2).Measured Impact
The fold alone with identity quantization:
apply_scalewithlinspace(0.5, 1.5)scales and the group's_scale_consumers. It runs on the tiny random-init GLM-5.3 fromtests/fixtures/ports/native_parity/glm5_next.json: 2 layers (KDA+dense, DSA+MoE, 8 routed + 1 shared expert), with norm gains drawn from U(0.5, 1.5).post_attention_layernorm-> routed gate/up, logits rel. changemlp.gatemlp.gate,mlp.shared_experts.gate_proj,mlp.shared_experts.up_projinput_layernorm,up->down)Fold-plan diff across every
MODEL_MAPdefinition. This uses the fold-plan inventory harness from the AWQ canonical-folds work. It builds each of the 210 types and its config variants on meta and callsawq_get_modules_for_scalingon every decoder layer. It records source, targets, consumers, boundary, feature and the structural outcome. I ran it on main and on this branch.glm5_next.glm5_nextdifference is one field. It appears in both sparse-layer variants (3,7,...,43, MTP layer 45 and the KDA+MoE layers):ok; there is no conflict or width drop.:moeroot arekimi_k3andkimi_linear(block_sparse_moe.shared_experts). Both reject AWQ (awq_get_modules_for_scalingraisesNotImplementedError), so nothing changes for them.deepseek_v4's dense MTP shared experts live in its MTP-only tree, which the AWQ planner does not use.Model Support / Module Plan
Not applicable. There is no new model, alias or tree change. The registered module-plan tests pass (
tests/module_tree/test_registered_module_plans.py).Model test node IDs and results:
tests/module_tree/test_awq_glm5_next_neutrality.py::test_glm5_next_awq_folds_compensate_dense_shared_expertsPASSED.AWQ onboarding safety
Glm5NextTextMoE.forwardfeeds the same normedhidden_statestogate,expertsandshared_experts.Logic Flow Documentation
Not applicable. The selection order and mechanism are unchanged; the existing consumer collector gains one structural source of consumers. Documented in
docs/awq-scaling-groups.md.Review Requirements
Kernel Accuracy Requirements
Not applicable. No kernel change.
Notes
tests/test_awq_variable_length_ppl.py::test_awq_beats_rtn_with_variable_length_calibrationfails onorigin/mainwithInference tensors do not track version counter.🤖 Generated with Claude Code