Skip to content

[Dev] Fix MoE aux loss tracker hang with MTP enabled - #3400

Merged
Victarry merged 1 commit into
NVIDIA:devfrom
Victarry:denliu/fix_aux_mtp_hang
Feb 25, 2026
Merged

[Dev] Fix MoE aux loss tracker hang with MTP enabled#3400
Victarry merged 1 commit into
NVIDIA:devfrom
Victarry:denliu/fix_aux_mtp_hang

Conversation

@Victarry

@Victarry Victarry commented Feb 13, 2026

Copy link
Copy Markdown

Summary

PR to main: #3401
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 --decoder-first-pipeline-num-layers 2 --decoder-last-pipeline-num-layers 2 --mtp-num-layers 1 (PP=4, EP=2, 8 GPUs) - training completes successfully
  • Verified no regression without MTP enabled

Made with Cursor

@Victarry
Victarry requested review from a team as code owners February 13, 2026 07:22
@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:23
@Victarry
Victarry changed the base branch from main to dev February 13, 2026 07:23
@Victarry
Victarry requested a review from a team as a code owner February 13, 2026 07:23
@Victarry
Victarry force-pushed the denliu/fix_aux_mtp_hang branch from 9421e09 to 9e5febf Compare February 13, 2026 07:24
@Victarry
Victarry removed request for a team February 13, 2026 07:25
@Victarry

Copy link
Copy Markdown
Author

/ok to test 9e5febf

@ko3n1g ko3n1g added this to the Core 0.16 milestone Feb 13, 2026
@Victarry
Victarry requested a review from BestJuly February 14, 2026 07:17
@yanring yanring added the Expert Review [deprecated] Apply this label to indicate that your PR is ready for expert review. label Feb 24, 2026
@Victarry
Victarry force-pushed the denliu/fix_aux_mtp_hang branch from 9e5febf to b56a3a6 Compare February 25, 2026 01:49
@Victarry

Copy link
Copy Markdown
Author

/ok to test b56a3a6

@Victarry Victarry changed the title Fix MoE aux loss tracker hang with MTP enabled [Dev] Fix MoE aux loss tracker hang with MTP enabled Feb 25, 2026
@Victarry Victarry added the dev branch Dev branch related issues and development label Feb 25, 2026
@Victarry
Victarry added this pull request to the merge queue Feb 25, 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/22380445188

Merged via the queue into NVIDIA:dev with commit aa86018 Feb 25, 2026
52 of 61 checks passed
@Victarry
Victarry deleted the denliu/fix_aux_mtp_hang branch February 25, 2026 03:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dev branch Dev branch related issues and development Expert Review [deprecated] Apply this label to indicate that your PR is ready for expert review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants