Repository navigation
[MoE] Make structured fused grouped-expert projection the default - #4871
Merged
Merged
Conversation
Summary: Carry forward the reviewed implementation from #4552 while storing routed-expert W13 as `[E, 2, F, D]`. The explicit gate/up axis matches DistMoE's native parameter layout and keeps the feature axis independently shardable. Standard grouped GEMM consumes a zero-copy `[E, 2F, D]` view and returns `[R, 2, F]` before the existing activation. Logical initialization and external HF keys remain `w1_EFD`, `w2_EDF`, and `w3_EFD`. Native model, DCP, optimizer, and EMA state use the physical `w13_E2FD` key, keeping `named_parameters()` and state-dict FQNs identical. Adapters split or merge W13 only at the HF boundary; the model installs no state-dict hooks, so save and load share the same native contract. Routing and activation semantics are unchanged. The physical fusion intentionally resets deterministic from-seed numerics. The old parameter order consumed random values as W1, W2, W3; the fused parameter initializes its slices as W1, W3 before W2. It also replaces two BF16 grouped GEMMs with one wider W13 grouped GEMM, whose rounding need not match two independent launches. Fixed-weight forward/backward tests validate the mapping, and the affected DeepSeek V3 and Qwen3 A10G goldens are regenerated from full-precision TensorBoard metrics for fake-PG and real-PG configurations. Fused W13 also adds a second native matrix-batch dimension. DistMuon now accepts native `[..., rows, columns]` parameters, matching the existing Newton-Schulz implementation, and its expert redistribution test exercises the production `[E, 2, F, D]` layout without adding another test case. Kimi K3's DistMuon configuration now assigns the physical `w13_E2FD` and `w2_EDF` expert parameters directly, so the fused W13 weight cannot fall through to the fallback AdamW group. This is the Sanket-owned replacement for #4552; Animesh's PR and stack remain untouched. Test Plan: - `python -m pytest tests/unit_tests/cpu -q --deselect tests/unit_tests/cpu/test_lora.py::test_lora_forward` (1244 passed, 23 skipped, 1 deselected) - `python -m pytest -q tests/unit_tests/cpu/test_convert_ema_to_hf.py tests/unit_tests/cpu/test_state_dict_adapter.py tests/unit_tests/cpu/test_moe.py` (41 passed) - Transformer-backend native-W13 round-trip and focused MoE/quantization tests (60 passed, 23 skipped) - `python -m pytest -q tests/unit_tests/gpu/flex_shard/test_dist_muon.py` (7 passed) - `python -m pytest -q tests/unit_tests/gpu/test_fsdp_moe_sharding.py tests/unit_tests/gpu/test_fused_swiglu_override.py` (20 passed) - Native state-key, EMA-export, and HF adapter round-trip tests pass without model state-dict hooks. - The Kimi K3 optimizer-pattern test verifies that native W13/W2 expert parameters are owned by DistMuon and stale logical W1/W3 names are absent. - A10G fake-PG and real-PG numerics were exported from the exact CI configurations; repeated DeepSeek V3 and Qwen3 runs produced identical full-precision trajectories. - Scoped formatting, flake8, pydoclint, codespell, link, and targeted Pyrefly checks passed. Project-wide Pyrefly retains one unrelated nullable-video-duration baseline error. Review history: This replaces #4643, which retains the original review discussion and approvals. ghstack-source-id: 9c5d570c958d3b8c336765cfb58f213c6d2eb86e [ghstack-poisoned]
sanketpurandare
requested review from
fegin,
felipemello1,
pzhan9,
tianyu-l,
wconstab and
wwwjn
as code owners
September 24, 2026 19:19
…default" Summary: Carry forward the reviewed implementation from #4552 while storing routed-expert W13 as `[E, 2, F, D]`. The explicit gate/up axis matches DistMoE's native parameter layout and keeps the feature axis independently shardable. Standard grouped GEMM consumes a zero-copy `[E, 2F, D]` view and returns `[R, 2, F]` before the existing activation. Logical initialization and external HF keys remain `w1_EFD`, `w2_EDF`, and `w3_EFD`. Native model, DCP, optimizer, and EMA state use the physical `w13_E2FD` key, keeping `named_parameters()` and state-dict FQNs identical. Adapters split or merge W13 only at the HF boundary; the model installs no state-dict hooks, so save and load share the same native contract. Routing and activation semantics are unchanged. The physical fusion intentionally resets deterministic from-seed numerics. The old parameter order consumed random values as W1, W2, W3; the fused parameter initializes its slices as W1, W3 before W2. It also replaces two BF16 grouped GEMMs with one wider W13 grouped GEMM, whose rounding need not match two independent launches. Fixed-weight forward/backward tests validate the mapping, and the affected DeepSeek V3 and Qwen3 A10G goldens are regenerated from full-precision TensorBoard metrics for fake-PG and real-PG configurations. Fused W13 also adds a second native matrix-batch dimension. DistMuon now accepts native `[..., rows, columns]` parameters, matching the existing Newton-Schulz implementation, and its expert redistribution test exercises the production `[E, 2, F, D]` layout without adding another test case. Kimi K3's DistMuon configuration now assigns the physical `w13_E2FD` and `w2_EDF` expert parameters directly, so the fused W13 weight cannot fall through to the fallback AdamW group. This is the Sanket-owned replacement for #4552; Animesh's PR and stack remain untouched. Test Plan: - `python -m pytest tests/unit_tests/cpu -q --deselect tests/unit_tests/cpu/test_lora.py::test_lora_forward` (1244 passed, 23 skipped, 1 deselected) - `python -m pytest -q tests/unit_tests/cpu/test_convert_ema_to_hf.py tests/unit_tests/cpu/test_state_dict_adapter.py tests/unit_tests/cpu/test_moe.py` (41 passed) - Transformer-backend native-W13 round-trip and focused MoE/quantization tests (60 passed, 23 skipped) - `python -m pytest -q tests/unit_tests/gpu/flex_shard/test_dist_muon.py` (7 passed) - `python -m pytest -q tests/unit_tests/gpu/test_fsdp_moe_sharding.py tests/unit_tests/gpu/test_fused_swiglu_override.py` (20 passed) - Native state-key, EMA-export, and HF adapter round-trip tests pass without model state-dict hooks. - The Kimi K3 optimizer-pattern test verifies that native W13/W2 expert parameters are owned by DistMuon and stale logical W1/W3 names are absent. - A10G fake-PG and real-PG numerics were exported from the exact CI configurations; repeated DeepSeek V3 and Qwen3 runs produced identical full-precision trajectories. - Scoped formatting, flake8, pydoclint, codespell, link, and targeted Pyrefly checks passed. Project-wide Pyrefly retains one unrelated nullable-video-duration baseline error. Review history: This replaces #4643, which retains the original review discussion and approvals. [ghstack-poisoned]
anijain2305
approved these changes
Sep 24, 2026
tianyu-l
approved these changes
Sep 24, 2026
sanketpurandare
changed the base branch from
gh/sanketpurandare/45/base
to
main
September 24, 2026 19:53
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.
Stack from ghstack (oldest at bottom):
Summary:
Carry forward the reviewed implementation from #4552 while
storing routed-expert W13 as
[E, 2, F, D]. The explicit gate/up axis matchesDistMoE's native parameter layout and keeps the feature axis independently
shardable. Standard grouped GEMM consumes a zero-copy
[E, 2F, D]view andreturns
[R, 2, F]before the existing activation.Logical initialization and external HF keys remain
w1_EFD,w2_EDF, andw3_EFD. Native model, DCP, optimizer, and EMA state use the physicalw13_E2FDkey, keepingnamed_parameters()and state-dict FQNs identical.Adapters split or merge W13 only at the HF boundary; the model installs no
state-dict hooks, so save and load share the same native contract. Routing and
activation semantics are unchanged.
The physical fusion intentionally resets deterministic from-seed numerics. The
old parameter order consumed random values as W1, W2, W3; the fused parameter
initializes its slices as W1, W3 before W2. It also replaces two BF16 grouped
GEMMs with one wider W13 grouped GEMM, whose rounding need not match two
independent launches. Fixed-weight forward/backward tests validate the mapping,
and the affected DeepSeek V3 and Qwen3 A10G goldens are regenerated from
full-precision TensorBoard metrics for fake-PG and real-PG configurations.
Fused W13 also adds a second native matrix-batch dimension. DistMuon now accepts
native
[..., rows, columns]parameters, matching the existing Newton-Schulzimplementation, and its expert redistribution test exercises the production
[E, 2, F, D]layout without adding another test case.Kimi K3's DistMuon configuration now assigns the physical
w13_E2FDandw2_EDFexpert parameters directly, so the fused W13 weight cannot fallthrough to the fallback AdamW group.
This is the Sanket-owned replacement for #4552; Animesh's PR and stack remain
untouched.
Test Plan:
python -m pytest tests/unit_tests/cpu -q --deselect tests/unit_tests/cpu/test_lora.py::test_lora_forward(1244 passed, 23 skipped, 1 deselected)python -m pytest -q tests/unit_tests/cpu/test_convert_ema_to_hf.py tests/unit_tests/cpu/test_state_dict_adapter.py tests/unit_tests/cpu/test_moe.py(41 passed)python -m pytest -q tests/unit_tests/gpu/flex_shard/test_dist_muon.py(7 passed)python -m pytest -q tests/unit_tests/gpu/test_fsdp_moe_sharding.py tests/unit_tests/gpu/test_fused_swiglu_override.py(20 passed)Review history:
This replaces #4643, which retains the original review discussion and approvals.