[Dev] Fix MoE aux loss tracker hang with MTP enabled - #3400
Merged
Conversation
Victarry
force-pushed
the
denliu/fix_aux_mtp_hang
branch
from
February 13, 2026 07:24
9421e09 to
9e5febf
Compare
Author
|
/ok to test 9e5febf |
BestJuly
approved these changes
Feb 24, 2026
Victarry
force-pushed
the
denliu/fix_aux_mtp_hang
branch
from
February 25, 2026 01:49
9e5febf to
b56a3a6
Compare
Author
|
/ok to test b56a3a6 |
Victarry
enabled auto-merge
February 25, 2026 01:51
ananthsub
approved these changes
Feb 25, 2026
Contributor
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/22380445188 |
2 tasks
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
PR to main: #3401
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
--decoder-first-pipeline-num-layers 2 --decoder-last-pipeline-num-layers 2 --mtp-num-layers 1(PP=4, EP=2, 8 GPUs) - training completes successfullyMade with Cursor