Skip to content

fix(bailing_moe): group shared-expert down_proj after gate/up (#4325) - #4343

Merged
Qubitium merged 2 commits into
mainfrom
fix/issue-4325-bailing-shared-experts
Nov 16, 2026
Merged

Qubitium merged 2 commits into
mainfrom
fix/issue-4325-bailing-shared-experts

Conversation

@Qubitium

@Qubitium Qubitium commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #4325

Problem

BailingMoeQModel declared "shared_experts": ("gate_proj", "up_proj", "down_proj") with no group ids, so all three landed in one quantization subset. down_proj consumes act(gate(x)) * up(x), not the post-attention norm:

  • GPTQ calibrated down_proj on activations captured before gate/up were quantized;
  • with AWQ, the post-attention norm fold could be applied to down_proj when the hidden and MoE intermediate widths coincide (wrong tensor), and with unequal widths down_proj was silently left out of every AWQ group.

Fix

gptqmodel/models/definitions/bailing_moe.py:

-                "shared_experts": ("gate_proj", "up_proj", "down_proj"),
+                "shared_experts": ("gate_proj:0", "up_proj:0", "down_proj:1"),

This matches the routed-expert declaration and the other MoE definitions. down_proj is now its own subset/stage, so it is calibrated after gate/up are quantized and AWQ emits a correct shared_experts.up_proj -> shared_experts.down_proj fold.

Also updated the pinned plan inventory (tests/module_tree/fixtures/registered_module_plans.json) and added tests/module_tree/test_bailing_moe_shared_experts_4325.py, which builds a real tiny BailingHybridForCausalLM layer, defuses the routed experts, and applies every emitted fold with no quantization using the #4175 _assert_neutral methodology.

Neutral-fold before/after (real tiny layer, no quantization)

Equal widths (hidden_size = moe_intermediate_size = 32), the case where the old declaration emitted the unsafe norm fold:

fold origin/main 286c570f7 this branch
post_attention_layernorm -> [shared gate, up, down, routed gate/up] 1.743e-04 — (down_proj removed)
post_attention_layernorm -> [shared gate, up, routed gate/up] — 1.743e-10
mlp.shared_experts.up_proj -> mlp.shared_experts.down_proj not emitted 4.644e-10

Real widths (hidden_size=32, moe_intermediate_size=16), the shape shipped by Ling/Bailing configs:

fold origin/main this branch
mlp.shared_experts.up_proj -> mlp.shared_experts.down_proj not emitted (down_proj left unscaled) 0.000e+00
post_attention_layernorm -> [shared gate, up, routed gate/up] 1.930e-09 1.930e-09

Emitted subsets before/after:

before: ["mlp.shared_experts.gate_proj", "mlp.shared_experts.up_proj", "mlp.shared_experts.down_proj"]
after:  ["mlp.shared_experts.gate_proj", "mlp.shared_experts.up_proj"]
        ["mlp.shared_experts.down_proj"]

Dense and attention declarations are unchanged and asserted in the new test (self_attn q/k/v/g/kv_a/forget_gate/b_proj, o_proj/kv_b, attention.qkv/dense, dense MLP gate/up and down, routed expert gate/up and down).

Tests / lint

  • tests/module_tree/test_bailing_moe_shared_experts_4325.py: 3 passed (fails on origin/main: structural subset + 1.743e-04 unsafe fold).
  • test_bailing_moe_shared_experts_4325, test_registered_module_plans, test_bailing_hybrid_support, test_issue_4174_model_trees, test_moe_expert_coverage: 467 passed, 135 skipped, 1 failed — the failure is test_moe_expert_coverage.py::...[bailing_hybrid] (attention.dense/attention.query_key_value match no layer on the native layout), which fails identically on clean origin/main 286c570f7 and is unrelated to this change.
  • ruff check gptqmodel docs/eora tests setup.py: All checks passed.

Residual risk

  • The remote-code bailing_moe layout shares this module tree and is covered structurally, but it is not instantiated here (no local reference code); the numeric check uses native bailing_hybrid.
  • The GPTQ benefit is verified at the plan/subset level plus the real-layer fold neutrality; no end-to-end quantization run is included.
  • The equal-width configuration is synthetic (real Ling configs have unequal widths); it is included specifically to exercise the previously unsafe fold.

stagedev and others added 2 commits November 16, 2026 09:10
- declare shared_experts gate/up in :0 and down_proj in :1 so GPTQ
  calibrates down_proj after gate/up are quantized and AWQ folds the
  gate/up product into down_proj instead of the post-attention norm
- update the pinned module-plan inventory
- add a real tiny BailingHybrid neutral-fold regression test
- clear two pre-existing ruff failures on main so the lint gate passes
@Qubitium
Qubitium merged commit f02099a into main Nov 16, 2026
7 of 9 checks passed
@Qubitium
Qubitium deleted the fix/issue-4325-bailing-shared-experts branch November 16, 2026 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] BailingMoe shared experts are still ungrouped: down_proj is in the same subset as gate/up (incomplete fix of #4175)

1 participant