Repository navigation
fix(awq): keep the dense-prefix norm group when the MoE root is empty (#4903) - #5000
Merged
Merged
Conversation
…#4903) A hybrid MoE such as ERNIE-4.5-MoE declares dense decoder layers before `moe_layer_start_index`. The AWQ root policy seeds a capture task for the declared MoE root (`mlp`) on every layer, but the root hook only runs on a layer that executes an expert, so on a dense layer the seeded `mlp` feature exists with zero elements. `awq_get_modules_for_scaling` preferred the root whenever its key was present, including that empty tensor. A zero-width source makes every consumer look width-foreign, so the dense layer's `post_attention_layernorm -> [mlp.gate_proj, mlp.up_proj]` group was dropped without a log line and those projections were quantized with plain RTN inside an "AWQ" checkpoint. The root is now preferred only when it captured activations. A routed-expert block keeps the existing fail-closed path (an empty root still warns and skips the group, #4697); a dense block falls through to its own captured feature. The empty-feature skip now warns for every gate/up block, not only routed-expert ones. Verified with `tests/test_awq_hybrid_moe_root_4903.py` on a tiny `ernie4_5_moe` (2 layers, `moe_layer_start_index=1`): red on unmodified main (layer 0 `mlp.gate_proj`/`mlp.up_proj` report `loss=not applicable`), green here (layer 0 keeps an AWQ scale; layer 1 keeps its routed-expert group). The same file guards #4697: with the module-plan root capture disabled, the MoE layer's shared expert falls back to plain quantization and the test fails.
This was referenced Nov 17, 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
AWQ silently dropped the
post_attention_layernorm -> [mlp.gate_proj, mlp.up_proj]scaling group of every dense decoder layer in a hybrid MoE such as
ERNIE-4.5-MoE (the layers before
moe_layer_start_index), so those projectionswere quantized with plain RTN inside an "AWQ" checkpoint and nothing was logged.
Root cause: the AWQ root policy seeds a capture task for the declared MoE root
(
mlp) on every layer, but the root capture hook only runs on a layer thatexecutes an expert. On a dense layer the seeded
mlpfeature exists with zeroelements, and
awq_get_modules_for_scalingpreferred it over the dense block'sown captured feature (
#4790added that preference). A zero-width source makesevery consumer look width-foreign, so the group was skipped silently.
Fixes #4903. Verifies #4697 stays fixed (the routed-expert group is still kept
for a definition without
moe_lifecycle_hooks).What Changed
gptqmodel/models/base.py: prefer the declared MoE root only when it capturedactivations (
numel() > 0). A dense block then falls through to its owncaptured feature; a routed-expert block keeps the existing fail-closed path.
routed-expert ones (the dense prefix used to lose its group without a trace).
tests/test_awq_hybrid_moe_root_4903.py: two end-to-end CPU tests on a tinyernie4_5_moe(dense prefix + MoE layer), asserting per-layer AWQ scales fromquant_logand no fallback/empty-capture warnings..github/workflows/awq_cpu.yml: run the new file in the AWQ CPUunitsuite.No API change. A routed-expert block with an empty root still warns and skips the
group, exactly as before.
Tests
Red on unmodified
origin/main(7f0ca1f44), test file copied into a separateworktree at that commit:
Green with the fix:
# 2 passedRed proof for the #4697 guard (module-plan root capture disabled, simulating
pre-#4723):
2 failed— the MoE layer's shared expert falls back to plainquantization. Green with the fix:
2 passed.Regression suites (fix vs unmodified main — identical failure sets):
test_awq_hybrid_moe_root_4903.py,test_awq_moe_root_capture_4697.pytest_awq_scaling_groups.py,test_awq_moe_shared_expert_group_4760.py,test_awq_falcon_h1_parallel_branch_4741.py,test_awq_empty_groups.py,test_awq_clip_empty_feature_4679.py,test_awq_moe_starved_expert_group_4675.py,test_awq_moe_router_scaling.py,test_awq_ling2_fold_4677.py,test_awq_scale_folding.py,test_awq_mpt_replay_4872.py,test_awq_moe_prune_uncovered_4456.pyThe 7 failures are pre-existing on unmodified main (
afmoe/flintgroupinvariants,
jambax_projsource, and the end-to-end bailing MoE test).ruff checkclean on both changed Python files.Model Support / Module Plan
Not applicable: no
MODEL_MAPentry, alias, or definition change.