Repository navigation
Description
Found on main @ 4f287eb, CPU. Real ERNIE-4.5-21B-A3B-PT truncated to 2 layers (layer 0 dense, layer 1 MoE), trust_remote_code=True, 16 C4 rows.
What is wrong
Since #4790 (9a00eaa, the fix of #4760), AWQ silently drops the post_attention_layernorm -> [mlp.gate_proj, mlp.up_proj] scaling group of every dense decoder layer in ERNIE-4.5-MoE. These are the layers before moe_layer_start_index: 1 layer in the 21B, 3 in the 300B. Those gate_proj/up_proj are quantized with no AWQ scale, and nothing is logged.
Mechanism:
AWQProcessor.preprocess(looper/awq_processor.py:4884-4889) seedsself.tasks["mlp"] = {"inputs": []}for every module under the declared MoE root, including the densemlp.gate_projof layer 0, because the root policy hascapture_root=True.- ERNIE-4.5-MoE has no
moe_lifecycle_hooks. The fix(awq): capture declared MoE roots without lifecycle hooks (#4697) #4723 root-capture hook instage_subset.pyis only registered when the subset contains an expert, so on a dense layer nothing ever fills that task._layer_input_featuresthen returnsfeatures["mlp"] = torch.empty(0)(:2160-2168). - fix(awq): search the MoE root feature for shared-expert gate/up groups (#4760) #4790 added this to
awq_get_modules_for_scaling(models/base.py:5869-5874):The densemoe_gate_up_root = _block_moe_root(block) if has_gate_up_roles and is_moe_family else None if moe_gate_up_root is not None and moe_gate_up_root in input_feat: # key exists, tensor is empty feature_name = moe_gate_up_root inp = input_feat[moe_gate_up_root]
mlp.gate_proj/up_projblock is undermlp:moe, so it now replaces its own (populated) feature with the empty root feature. Theinp.numel() == 0branch (:5801-5816) only warns foris_moe_gate_up_block, so the dense block is skipped silently.
Evidence (same model, same data, awq_get_modules_for_scaling output and the groups passed to apply_scale)
| commit | layer 0 (dense) scaled groups | layer 1 (MoE) scaled groups |
|---|---|---|
| 12c1273 | input_layernorm(3), post_attention_layernorm(2), mlp.up_proj(1) |
input_layernorm(3), per-expert up->down (MoE gate/up group fell back, #4697) |
| 9a00eaa^ | input_layernorm(3), post_attention_layernorm(2), mlp.up_proj(1) |
input_layernorm(3), per-expert up->down |
| 9a00eaa (#4790) | input_layernorm(3), mlp.up_proj(1) |
input_layernorm(3), post_attention_layernorm(130), ... |
| main 4f287eb | input_layernorm(3), mlp.up_proj(1) |
same as 9a00eaa |
In layer 0 the captured features include 'mlp' with numel()==0 and no warning is emitted. The dropped group is valid: folding a random scale into post_attention_layernorm -> [mlp.gate_proj, mlp.up_proj] on the real weights changes the logits by <1e-6.
Repro
import torch
from gptqmodel import GPTQModel
from gptqmodel.models.base import BaseQModel
from gptqmodel.quantization import AWQConfig
from gptqmodel.quantization.config import CalibrationConfig
from gptqmodel.quantization.awq.utils.module import get_op_name
orig = BaseQModel.awq_get_modules_for_scaling
def spy(self, module, feats, kw):
nodes = orig(self, module, feats, kw)
print("empty feats:", [k for k, v in feats.items() if v.numel() == 0],
"groups:", [(get_op_name(module, n["prev_op"]), len(n["layers"])) for n in nodes][:4])
return nodes
BaseQModel.awq_get_modules_for_scaling = spy
q = GPTQModel.load("baidu/ERNIE-4.5-21B-A3B-PT", # num_hidden_layers=2 copy used here
AWQConfig(bits=4, group_size=128), trust_remote_code=True, dtype=torch.bfloat16)
q.quantize(CalibrationConfig(dataset=c4_texts[:16]))
# layer 0: empty feats: ['mlp'] groups: [('input_layernorm', 3), ('self_attn.v_proj', 1), ('mlp.up_proj', 1)]
# (at 9a00eaadd^ the list also has ('post_attention_layernorm', 2))Suggested fix
In awq_get_modules_for_scaling, prefer the root capture only when it is non-empty (input_feat[root].numel() > 0). Otherwise keep the block's own feature. Alternatively, stop seeding the root task for modules of a dense layer: only seed when the layer owns an expert, matching the #4723 hook condition. Also make the empty-feature skip at :5801 warn for every gate/up block, not only routed-expert ones.
Test that should have caught it
tests/test_awq_moe_shared_expert_group_4760.py only covers MoE layers. A dense-prefix layer (ERNIE moe_layer_start_index>0, or any mlp:moe tree with a "" dense fallback and no lifecycle hooks) should assert that its norm -> gate/up group survives a real quantize().
Severity
Medium (quality regression): silent loss of the AWQ scale on the dense-prefix MLPs of ERNIE-4.5-MoE (and any other no-hook mlp:moe definition with dense layers).
🤖 Generated with Claude Code
Activity
Qubitium commentedon Nov 17, 2026
Agent claim:
agent-root-4697is working on this issue now.Qubitium commentedon Nov 17, 2026
Agent release:
agent-root-4697finished this issue. Fix: #5000, squash-merged asc918fb9fd.awq_get_modules_for_scalingnow prefers the declared MoE root only when it actually captured activations. On ERNIE-4.5-MoE's dense prefix the root task is seeded but never runs (no expert executes), so the dense layer'spost_attention_layernorm -> [mlp.gate_proj, mlp.up_proj]group was being replaced by an empty(0,)feature and dropped without a log line. It now falls through to the block's own captured feature, and the empty-feature skip warns for every gate/up block (routed-expert blocks keep the fail-closed path from #4697).Verified on a tiny
ernie4_5_moe(2 layers,moe_layer_start_index=1,AWQConfig(bits=4, group_size=32)),tests/test_awq_hybrid_moe_root_4903.py: red on unmodifiedmain((0, 'mlp.gate_proj')and(0, 'mlp.up_proj')reportedloss=not applicable), green with the fix — layer 0 keeps an AWQ scale, layer 1 keeps its routed-expert group. Neighbouring AWQ group suites: 7 pre-existing failures on both trees (afmoe/flintinvariants,jambax_proj, bailing end-to-end), no delta.fix(awq): keep the dense-prefix norm group when the MoE root is empty (…
refactor(awq): build scaling groups from fold declarations; the tree …