Support isolated MTP loss - #5098
Closed
Victarry wants to merge 1 commit into
Closed
Conversation
svcnvidia-nemo-ci
marked this pull request as draft
June 2, 2026 01:53
Contributor
|
This PR has been automatically converted to draft because all PRs must start as drafts. When you are ready for review, click Ready for Review to begin the review process. This will:
See the contribution guide for more details. |
Author
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
mtp_isolated_lossto isolate MTP auxiliary loss gradients from the main decoder, shared embeddings, and output layer weights.mtp_isolated_loss=True.mainbranch code path.This is the
mainbranch counterpart of #5080. The explicitreturn_logitsAPI path is not included; online RL/MTP training should use the #3457 scheme (labels=Nonereturns main logits, while MTP auxiliary labels are derived frominput_idsin the MTP loss path).RL / Online MTP Background
Online RL training frameworks such as veRL usually run the policy model on sampled responses, read the logits, and compute the policy loss outside the model. The labels for those sampled tokens are still useful for auxiliary objectives such as MTP, but they should not automatically turn the main model output into a supervised LM loss.
Before this change, MCore uses one
labelsargument for both purposes:labelsare consumed by MTP auxiliary loss.labelsalso make the main GPT/Hybrid forward return LM loss instead of logits.That coupling is inconvenient for RL. In online RL + MTP, the desired contract is:
labelsso MTP can compute its auxiliary CE loss;This PR keeps the regular pretraining/SFT behavior unchanged by default. For RL-style callers,
return_logits=Truechanges only the main LM output contract: labels are still consumed by MTP auxiliary loss, but the forward returns logits instead of main LM loss.mtp_isolated_loss=Trueseparately controls the gradient boundary for the auxiliary objective.Example RL-style use:
Test plan
git diff --checkuv run --project /Users/denliu/Projects/repos/agentic-mcore-dev --extra mcore-lint ruff check megatron/core/transformer/multi_token_prediction.py megatron/core/transformer/transformer_config.py tests/unit_tests/models/test_hybrid_moe_model.py tests/unit_tests/transformer/test_multi_token_prediction.pyuv run --project /Users/denliu/Projects/repos/agentic-mcore-dev python -m pytest tests/unit_tests/transformer/test_multi_token_prediction.py::TestProcessMTPLoss -q(local env missingtorch:ModuleNotFoundError: No module named 'torch')