Repository navigation
feat: support afmoe and bailing_hybrid expert defusion - #70
Conversation
Add registry entries for AfmoeExperts and BailingHybridExperts so their fused gate_up_proj/down_proj tensors are split into per-expert gate_proj/up_proj/ down_proj nn.Linear modules and driven by the linear_loop implementation. Without these entries Defuser left both families packed as 3-D parameters, so quantizers could not see or quantize the routed experts. Bump the package version to 0.0.29 for the release that carries the new entries.
|
Reviewed No actionable correctness findings in this diff. Both upstream expert classes have the projection layout, activation, expert-count attribute, and routing call signature expected by the existing Validation on CPU with Transformers 5.20.2 and PyTorch 2.16.0.dev20261021+cpu:
Validation limit: no CUDA execution or full BailingHybrid delta-attention decoder forward was exercised; its numerical check covers the routed experts. The broader suite is not green in this environment, although its failures also reproduce on the base commit. |
Summary
Add
EXPERTS_DEFUSEregistry entries forafmoeandbailing_hybrid, so their fused routed-expert tensors are split into per-expertgate_proj/up_proj/down_projnn.Linearmodules and driven by the existinglinear_loopimplementation.Without these entries both families stayed packed as 3-D parameters (
gate_up_proj/down_proj), so quantizers could not see or quantize any routed expert.Changes
defuser/model_registry.pyafmoe→transformers.models.afmoe.modeling_afmoe.AfmoeExperts,forward_impl="linear_loop"bailing_hybrid→transformers.models.bailing_hybrid.modeling_bailing_hybrid.BailingHybridExperts,forward_impl="linear_loop"README.md: addbailing_hybridto the "Standard routed expert tensors" tablepyproject.toml: version0.0.28→0.0.29Both expert classes store
gate_up_projas(num_experts, 2 * intermediate, hidden)anddown_projas(num_experts, hidden, intermediate), which is exactly the layoutlinear_loop/SplitFusedExpertGateUpProjexpects, so no new forward implementation was required.Tests
New tests in
tests/test_convert_model.py:test_afmoe_registry_and_defusion/test_afmoe_split_forward_matches_fused_mathtest_bailing_hybrid_registry_and_defusion/test_bailing_hybrid_split_forward_matches_fused_mathEach asserts: registry entry shape, fused parameter shapes before conversion, that conversion removes the 3-D parameters, that numbered containers
0..N-1exist with per-expertnn.Linearprojections, per-expert weight equality against the original slices, and forward equivalence against the fused math (atol=1e-5).Also adds
bailing_hybridtoMETA_MODEL_CASESintests/test_meta_model_defusion.py.The 13 failures are pre-existing on
main(transformers-version / environment issues) and are identical with and without this branch — no regressions introduced. Focused runs:The
bailing_hybridforward-equivalence test exercises the experts module only, not the full decoder: its delta-attention path callscausal_conv1d, which requires a CUDA device.Note for reviewers
This is the prerequisite for the GPTQModel PR that fixes MoE expert quantization coverage. GPTQModel's
requirements.txtneedsdefuser>=0.0.29, so this release must land first.