Skip to content

fix(awq): keep the dense-prefix norm group when the MoE root is empty (#4903) - #5000

Merged
Qubitium merged 1 commit into
mainfrom
root/awq-dense-prefix-4903
Nov 17, 2026
Merged

Qubitium merged 1 commit into
mainfrom
root/awq-dense-prefix-4903

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

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 projections
were 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 that
executes an expert. On a dense layer the seeded mlp feature exists with zero
elements, and awq_get_modules_for_scaling preferred it over the dense block's
own captured feature (#4790 added that preference). A zero-width source makes
every 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 captured
    activations (numel() > 0). A dense block then falls through to its own
    captured feature; a routed-expert block keeps the existing fail-closed path.
  • The empty-feature skip now warns for every gate/up block, not only
    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 tiny
    ernie4_5_moe (dense prefix + MoE layer), asserting per-layer AWQ scales from
    quant_log and no fallback/empty-capture warnings.
  • .github/workflows/awq_cpu.yml: run the new file in the AWQ CPU unit suite.

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 separate
worktree at that commit:

CUDA_VISIBLE_DEVICES="" PYTHONPATH=<worktree> python /tmp/root-rt.py \
  tests/test_awq_hybrid_moe_root_4903.py -q -o addopts= -o log_cli=false
# 1 failed, 1 passed   (test_dense_prefix_layer_keeps_its_norm_gate_up_group:
#   (0, 'mlp.gate_proj') loss == 'not applicable')

Green with the fix:

# 2 passed

Red proof for the #4697 guard (module-plan root capture disabled, simulating
pre-#4723): 2 failed — the MoE layer's shared expert falls back to plain
quantization. Green with the fix: 2 passed.

Regression suites (fix vs unmodified main — identical failure sets):

suite main fix
test_awq_hybrid_moe_root_4903.py, test_awq_moe_root_capture_4697.py 3 passed, 1 failed (new test) 5 passed
test_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.py 7 failed, 221 passed, 3 skipped 7 failed, 222 passed, 3 skipped

The 7 failures are pre-existing on unmodified main (afmoe/flint group
invariants, jamba x_proj source, and the end-to-end bailing MoE test).

ruff check clean on both changed Python files.

Model Support / Module Plan

Not applicable: no MODEL_MAP entry, alias, or definition change.

…#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant