Skip to content

[QUALITY] Regression from #4790 (fix of #4760): AWQ silently drops the dense-layer post_attention_layernorm -> gate/up group in ERNIE-4.5-MoE (empty seeded MoE-root feature preferred) #4903

Closed

Description

@Qubitium

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:

  1. AWQProcessor.preprocess (looper/awq_processor.py:4884-4889) seeds self.tasks["mlp"] = {"inputs": []} for every module under the declared MoE root, including the dense mlp.gate_proj of layer 0, because the root policy has capture_root=True.
  2. ERNIE-4.5-MoE has no moe_lifecycle_hooks. The fix(awq): capture declared MoE roots without lifecycle hooks (#4697) #4723 root-capture hook in stage_subset.py is only registered when the subset contains an expert, so on a dense layer nothing ever fills that task. _layer_input_features then returns features["mlp"] = torch.empty(0) (:2160-2168).
  3. 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):
    moe_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]
    The dense mlp.gate_proj/up_proj block is under mlp:moe, so it now replaces its own (populated) feature with the empty root feature. The inp.numel() == 0 branch (:5801-5816) only warns for is_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

  1. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim: agent-root-4697 is working on this issue now.

  2. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Agent release: agent-root-4697 finished this issue. Fix: #5000, squash-merged as c918fb9fd.

    awq_get_modules_for_scaling now 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's post_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 unmodified main ((0, 'mlp.gate_proj') and (0, 'mlp.up_proj') reported loss=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/flint invariants, jamba x_proj, bailing end-to-end), no delta.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions