Repository navigation
Fix the FC1 size of the fused shared expert with tensor parallel - #8145
Merged
gautham-kollu merged 1 commit intoOct 28, 2026
Merged
Conversation
FusedSharedExpertMLP makes the TE GroupedLinear op for FC1 with out_features=fc1_weight.size(0) * tp_world_size. But fc1_weight is the local tensor-parallel shard, and GroupedLinear has no tensor-parallel mode. So out_features must be the local size. With TP > 1, TE does not fuse GroupedLinear + ScaledSwiGLU + GroupedLinear, because the fusion needs FC1 out_features == 2 * FC2 in_features. The unfused ScaledSwiGLU then gets the single unit scale of the shared expert and stops with "scales_tensor.numel() == rows". This problem does not occur with TP=1. Use the local size, and remove the get_pg_size import that has no use now. Add a unit test for TP=2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Michal Futrega <mfutrega@nvidia.com>
yaox12
approved these changes
Oct 15, 2026
kvareddy
approved these changes
Oct 27, 2026
Contributor
|
/ok to test bc56a09 |
zhongbozhu
approved these changes
Oct 27, 2026
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/40678856079 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/40683345995 |
3 of 7 tasks
This branch was previously deployed
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.
What does this PR do?
Fix the FC1
out_featuresofFusedSharedExpertMLPfor tensor parallel (TP) > 1. Then TE can fuse the shared expert MLP.The problem
_make_fused_grouped_swiglu_opsmakes the TEGroupedLinearop for FC1 without_features=fc1_weight.size(0) * tp_world_size. Butfc1_weightis the local TP shard(
op.weight0 = fc1_weight), andte.pytorch.ops.GroupedLinearhas no TP mode. So the op must use the local size.With TP > 1, TE does not fuse GroupedLinear + ScaledSwiGLU + GroupedLinear, because
validate_grouped_mlp_dimsneedsfc1.out_features == 2 * fc2.in_features.TE then runs the unfused ops. The unfused
ScaledSwiGLUneeds one scale for each row,but the shared expert gives one unit scale. The forward pass stops with:
This problem does not occur with TP=1, because then the two sizes are equal.
We found it with DeepSeek-V3 on GB200: TP=2 with sequence parallel, MXFP8,
use_grouped_gemm_for_shared_expert=True, andmoe_shared_expert_glu_interleave_size=32.Changes
out_features=fc1_weight.size(0)for the FC1 op.get_pg_sizeimport, because it has no use now.test_make_fused_grouped_swiglu_ops_uses_local_shard_sizes_with_tp.The existing tests set the TP size to 1, so they did not find the problem.
Tests
tests/unit_tests/transformer/moe/test_shared_experts.pyon one GB200 node (4 GPUs): 23 tests pass.test_shared_expert_forward_backward[2-4-alltoall]needs 8 GPUs (TP2 x EP4), so it cannot run there.mainwithout this fix fails withassert 16 == 8.black,isort,ruff, andpylint(versions frompyproject.toml) pass on the two changed files.26.09-alpha.rc2:Issue tracking
Linked issue: none. Related: #8024 makes the fused path use the TP group of the module for its collectives.
The two changes do not overlap. A TP > 1 run needs both if
tp_groupis not the global TP group.Contribution process
Pre-checks
🤖 Generated with Claude Code