Repository navigation
fix(bailing_moe): group shared-expert down_proj after gate/up (#4325) - #4343
Merged
Merged
Conversation
- 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
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.
Fixes #4325
Problem
BailingMoeQModeldeclared"shared_experts": ("gate_proj", "up_proj", "down_proj")with no group ids, so all three landed in one quantization subset.down_projconsumesact(gate(x)) * up(x), not the post-attention norm:down_projon activations captured before gate/up were quantized;down_projwhen the hidden and MoE intermediate widths coincide (wrong tensor), and with unequal widthsdown_projwas silently left out of every AWQ group.Fix
gptqmodel/models/definitions/bailing_moe.py:This matches the routed-expert declaration and the other MoE definitions.
down_projis now its own subset/stage, so it is calibrated after gate/up are quantized and AWQ emits a correctshared_experts.up_proj -> shared_experts.down_projfold.Also updated the pinned plan inventory (
tests/module_tree/fixtures/registered_module_plans.json) and addedtests/module_tree/test_bailing_moe_shared_experts_4325.py, which builds a real tinyBailingHybridForCausalLMlayer, defuses the routed experts, and applies every emitted fold with no quantization using the #4175_assert_neutralmethodology.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:286c570f7post_attention_layernorm -> [shared gate, up, down, routed gate/up]post_attention_layernorm -> [shared gate, up, routed gate/up]mlp.shared_experts.up_proj -> mlp.shared_experts.down_projReal widths (
hidden_size=32,moe_intermediate_size=16), the shape shipped by Ling/Bailing configs:mlp.shared_experts.up_proj -> mlp.shared_experts.down_projpost_attention_layernorm -> [shared gate, up, routed gate/up]Emitted subsets before/after:
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 istest_moe_expert_coverage.py::...[bailing_hybrid](attention.dense/attention.query_key_valuematch no layer on the native layout), which fails identically on cleanorigin/main286c570f7and is unrelated to this change.ruff check gptqmodel docs/eora tests setup.py: All checks passed.Residual risk
bailing_moelayout shares this module tree and is covered structurally, but it is not instantiated here (no local reference code); the numeric check uses nativebailing_hybrid.