Skip to content

Fix MoE aux loss tracker hang with MTP enabled - #3401

Merged
Phlip79 merged 1 commit into
NVIDIA:mainfrom
Victarry:denliu/fix_aux_mtp_hang_main
Mar 2, 2026
Merged

Fix MoE aux loss tracker hang with MTP enabled#3401
Phlip79 merged 1 commit into
NVIDIA:mainfrom
Victarry:denliu/fix_aux_mtp_hang_main

Conversation

@Victarry

@Victarry Victarry commented Feb 13, 2026

Copy link
Copy Markdown

Mirror of #3400

Summary

Fix a deadlock (NCCL hang) in reduce_aux_losses_tracker_across_ranks when 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 first training_log call. All ranks are stuck in an all_reduce inside reduce_aux_losses_tracker_across_ranks.

Root cause: The MoE aux loss tracker values tensor has mismatched sizes across PP ranks, causing the NCCL all_reduce to hang:

  • During the forward pass, the router (router.py) creates the tracker values tensor with size num_layers + mtp_num_layers (e.g. 14 + 1 = 15).
  • During logging, track_moe_metrics() with force_initialize=True creates the tensor with size num_layers only (e.g. 14), but only for tracker keys that don't already exist.
  • PP ranks that have no MoE layers (e.g., the first PP stage with only dense layers) never populate the tracker during forward, so force_initialize creates a size-14 tensor.
  • PP ranks that have MoE layers already have size-15 tensors from the router.
  • The all_reduce across 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:

--num-layers 14 --moe-layer-freq "([0]*3+[1]*11)" --mtp-num-layers 1 \
--pipeline-model-parallel-size 4 \
--decoder-first-pipeline-num-layers 2 --decoder-last-pipeline-num-layers 2

Fix

In track_moe_metrics(), account for mtp_num_layers when creating the values tensor in the force_initialize path, matching the size used by the router in save_to_aux_losses_tracker().

Test plan

  • Verified fix with DSv3 proxy config (PP=4, EP=2, 8x H100) - training completes successfully
  • Verified no regression without MTP enabled

Made with Cursor

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>
@Victarry
Victarry requested review from a team as code owners February 13, 2026 07:32
@copy-pr-bot

copy-pr-bot Bot commented Feb 13, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@ko3n1g
ko3n1g requested a review from a team February 13, 2026 07:32
@Victarry

Copy link
Copy Markdown
Author

/ok to test d28506e

@ko3n1g ko3n1g added this to the Core 0.16 milestone Feb 14, 2026
@Victarry Victarry added the Expert Review [deprecated] Apply this label to indicate that your PR is ready for expert review. label Feb 25, 2026
@Victarry Victarry self-assigned this Feb 25, 2026
@Victarry Victarry added the bug Something isn't working label Feb 25, 2026
@yaox12 yaox12 added Final Review PR is in the "final review" stage complexity: low and removed Expert Review [deprecated] Apply this label to indicate that your PR is ready for expert review. labels Feb 26, 2026
@Phlip79
Phlip79 enabled auto-merge March 2, 2026 19:03
@Phlip79
Phlip79 added this pull request to the merge queue Mar 2, 2026
@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/22591284846

Merged via the queue into NVIDIA:main with commit c7be214 Mar 2, 2026
52 of 56 checks passed
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working complexity: low Final Review PR is in the "final review" stage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants