fix(optimizer): route ETP-only experts through expert groups - #84
Merged
Merged
Conversation
Tag native, Transformer Engine, grouped, and ModelOpt expert parameters for expert data-parallel reduction whenever EP > 1 or ETP differs from TP. Preserve TE tensor-parallel metadata, including SwiGLU partition stride, and add direct plus real MoE-to-DDP-to-LayerWise Muon regression coverage.
yueming-yuan
approved these changes
Aug 17, 2026
Author
|
@codex review |
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.
Summary
Route ETP-only expert parameters through expert reduction and LayerWise ownership.
Symptom & Reproduction
3d107754c, TP2/ETP1/EP1 expert parameters carryallreduce=True, so DDP puts them in dense buffers and LayerWise uses the dense ownership plane.NVIDIA_PYTORCH_VERSION=25.06 torchrun --standalone --nproc-per-node=2 -m pytest -q tests/unit_tests/test_muon_optimizer.py::test_real_moe_ddp_layerwise_muon_expert_ownership_tp2_etp1_ep1; the parent behavior violates the expert-tag and expert-buffer assertions, while this commit passes them.Root Cause
ColumnParallelLinearderivedparam.allreducefromEP > 1only.DistributedDataParallelselected dense buffers for those mislabeled parameters._get_param_groupspropagated dense ownership intoLayerWiseDistributedOptimizer.Fix
Port the producer predicate
is_expert and (EP > 1 or ETP != TP)from NVIDIA/Megatron-LM#5916 at head6ccd20e2005b0698e908d42db771e2f22b0281e8across native, Transformer Engine, grouped, legacy, and ModelOpt linear layers. The TE helper also restores numbered-parameter TP metadata and preserves SwiGLU partition stride; DDP remains unchanged because it already honorsparam.allreduce.Verification
pytest -q tests/unit_tests/transformer/moe/test_grouped_mlp.py -k 'expert_parameter_attributes' tests/unit_tests/post_training/test_modelopt_module_spec.py -k 'expert_parameter_attributes or modelopt_expert_linear': 9 passed.GroupedMLPruntime case skipped becausegrouped_gemmis unavailable.stride=2plus real MoE end-to-end set: 2 passed on each rank.git diff --check,isort --check-only, andpython -m compileall -q: passed for the changed files.Review Focus
_set_expert_parameter_attributes: numbered weight/bias matching, row-bias replication, andpartition_stridepreservation.use_expert_pgs: identical topology semantics across every expert parameter producer.test_real_moe_ddp_layerwise_muon_expert_ownership_tp2_etp1_ep1: deterministic gradients still exercise real MoE construction, DDP collectives, optimizer grouping, ownership, clipping, and updates.