Skip to content

fix(training): avoid double-counting MTP MoE metric layers - #5795

Merged
gautham-kollu merged 3 commits into
NVIDIA-NeMo:mainfrom
odedovadia:fix/moe-mtp-metric-layer-count
Sep 2, 2026
Merged

gautham-kollu merged 3 commits into
NVIDIA-NeMo:mainfrom
odedovadia:fix/moe-mtp-metric-layer-count

Conversation

@odedovadia

Copy link
Copy Markdown
Contributor

What does this PR do ?

Fix aggregate MoE metric normalization for unified hybrid patterns containing MTP layers.

The change separates the main decoder from the MTP suffix, counts their MoE layers independently, and passes those counts to MCore. For Nemotron 3.5 Lightning, the denominator changes from the incorrect 25 + 2 = 27 to 23 + 2 = 25.

Changelog

  • Count main-decoder MoE layers before the MTP separator.
  • Derive the MTP MoE count from the unified pattern when present.
  • Add regression coverage for the Nemotron 3.5 Lightning pattern.

GitHub Actions CI

See the CI section in the Contributing doc for how to trigger the CI. A Nvidia developer will need to approve and trigger the CI for external contributors.

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you add or update any necessary documentation?
  • Does the PR affect components that are optional to install? (Ex: Numba, Pynini, Apex etc)
    • Reviewer: Does the PR have correct import guards for all optional libraries?

If you haven't finished some of the above items you can still open "Draft" PR.

Additional Information

@copy-pr-bot

copy-pr-bot Bot commented Aug 25, 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.

yaoyu-33
yaoyu-33 previously approved these changes Aug 25, 2026
@yaoyu-33 yaoyu-33 added the ready-to-merge PR is approved, current, and only waiting for CI to pass before merge label Aug 25, 2026
Comment thread src/megatron/bridge/training/utils/train_utils.py Outdated
@Phlip79

Phlip79 commented Aug 25, 2026

Copy link
Copy Markdown
Member

This logic has been changed on the Megatron-Core side in NVIDIA/Megatron-LM#6748.

@yaoyu-33 yaoyu-33 added area:training Training loop, callbacks, and runtime integration bug Something isn't working needs-review PR is ready for code review and waiting on a reviewer and removed ready-to-merge PR is approved, current, and only waiting for CI to pass before merge labels Aug 25, 2026
@yaoyu-33

Copy link
Copy Markdown
Contributor

/ok to test a3f1f25

Signed-off-by: Oded Ovadia <oded7272@gmail.com>
@odedovadia
odedovadia force-pushed the fix/moe-mtp-metric-layer-count branch from f24809d to 7590c51 Compare August 30, 2026 17:39
Signed-off-by: Oded Ovadia <oded7272@gmail.com>
@odedovadia

odedovadia commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor Author

This logic has been changed on the Megatron-Core side in NVIDIA/Megatron-LM#6748.

I see. I re-wrote this PR accordingly, as as far as I can tell a fix is still needed (jsut a slightly different one). I created a new function to properly count the real number of MoE/MTP layers according to the new MCore logic for both hybrid and non-hybrid models.

For example, Nemotron 3.5 Lightning counts num_moe_layers = num_layers + mtp_num_layers = 25 + 2 = 27 in main, which is wrong. After this new fix, we get num_moe_layers=24 (23 main MoE layers + 1 MTP, as MCore correctly scales the repeated MTPs).

I added some tests for different architectures too. While the issue was with hybrid models, I added a few tests for other architectures.

@yaoyu-33 yaoyu-33 added waiting-on-maintainers Waiting on maintainers to respond and removed needs-review PR is ready for code review and waiting on a reviewer labels Sep 1, 2026
@Phlip79

Phlip79 commented Sep 1, 2026

Copy link
Copy Markdown
Member

This logic has been changed on the Megatron-Core side in NVIDIA/Megatron-LM#6748.

I see. I re-wrote this PR accordingly, as as far as I can tell a fix is still needed (jsut a slightly different one). I created a new function to properly count the real number of MoE/MTP layers according to the new MCore logic for both hybrid and non-hybrid models.

For example, Nemotron 3.5 Lightning counts num_moe_layers = num_layers + mtp_num_layers = 25 + 2 = 27 in main, which is wrong. After this new fix, we get num_moe_layers=24 (23 main MoE layers + 1 MTP, as MCore correctly scales the repeated MTPs).

I added some tests for different architectures too. While the issue was with hybrid models, I added a few tests for other architectures.

Thanks for making the changes. LGTM.

@yaoyu-33 yaoyu-33 added ready-to-merge PR is approved, current, and only waiting for CI to pass before merge and removed waiting-on-maintainers Waiting on maintainers to respond labels Sep 1, 2026
@gautham-kollu

Copy link
Copy Markdown
Contributor

/ok to test 7e1cd6e

@gautham-kollu

Copy link
Copy Markdown
Contributor

Requesting review from @balasaajay/ @ko3n1g @malay-nagda

@gautham-kollu
gautham-kollu merged commit 8eea7a9 into NVIDIA-NeMo:main Sep 2, 2026
62 checks passed

This branch was previously deployed

2 inactive (1 outdated) deployments
test — 7e1cd6ec Deployed Sep 1, 2026 by copy-pr-bot[bot] via cicd-wait-in-queue #21357
public — a3f1f25e Deployed Aug 29, 2026 by copy-pr-bot[bot] via release / finalize / publish-docs #5222
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:training Training loop, callbacks, and runtime integration bug Something isn't working community-request ready-to-merge PR is approved, current, and only waiting for CI to pass before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants