Fix MoE aux loss tracker hang with MTP enabled - #3401
Merged
Conversation
When MTP is enabled with MoE and pipeline parallelism, the aux loss tracker values tensor has mismatched sizes across PP ranks, causing NCCL all_reduce to hang. The router creates values with size (num_layers + mtp_num_layers), but force_initialize in track_moe_metrics only uses num_layers. PP ranks without MoE layers get the smaller tensor from force_initialize, while ranks with MoE layers have the larger one. Fix by accounting for mtp_num_layers in the force_initialize path. Co-authored-by: Cursor <cursoragent@cursor.com>
2 tasks
kvareddy
approved these changes
Feb 13, 2026
Author
|
/ok to test d28506e |
yaox12
approved these changes
Feb 26, 2026
ericharper
approved these changes
Mar 2, 2026
Contributor
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/22591284846 |
BoxiangW
pushed a commit
to BoxiangW/Megatron-LM
that referenced
this pull request
Mar 4, 2026
Co-authored-by: Cursor <cursoragent@cursor.com>
LiJunscs
added a commit
to LiJunscs/Megatron-LM-FL
that referenced
this pull request
Mar 16, 2026
1. fix some corne case of engram related communicaton groups. 2. simplify the codes of engram overlap_moe_expert_parallel_comm. 3. fix a bug of moe aux loss, see NVIDIA#3401
yangbofun
pushed a commit
to xlm-research/Megatron-LM
that referenced
this pull request
May 22, 2026
Co-authored-by: Cursor <cursoragent@cursor.com>
terminator123
pushed a commit
to 021ai/Megatron-LM
that referenced
this pull request
Aug 3, 2026
Co-authored-by: Cursor <cursoragent@cursor.com>
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.
Mirror of #3400
Summary
Fix a deadlock (NCCL hang) in
reduce_aux_losses_tracker_across_rankswhen MTP (Multi-Token Prediction) is enabled with MoE and pipeline parallelism.Bug Description
When MTP is enabled together with MoE and pipeline parallelism (
--mtp-num-layers 1), the training hangs at the firsttraining_logcall. All ranks are stuck in anall_reduceinsidereduce_aux_losses_tracker_across_ranks.Root cause: The MoE aux loss tracker
valuestensor has mismatched sizes across PP ranks, causing the NCCLall_reduceto hang:router.py) creates the trackervaluestensor with sizenum_layers + mtp_num_layers(e.g. 14 + 1 = 15).track_moe_metrics()withforce_initialize=Truecreates the tensor with sizenum_layersonly (e.g. 14), but only for tracker keys that don't already exist.force_initializecreates a size-14 tensor.all_reduceacross the PP group then receives mismatched tensor sizes (14 vs 15), causing NCCL to hang indefinitely.Repro: Any config with MoE + MTP + PP where at least one PP rank has no MoE layers. For example:
Fix
In
track_moe_metrics(), account formtp_num_layerswhen creating thevaluestensor in theforce_initializepath, matching the size used by the router insave_to_aux_losses_tracker().Test plan
Made with Cursor