feat(megatron): support MTP in split training - #3881
Open
yfw wants to merge 2 commits into
Open
Conversation
Add MTP loss masking and gradient scaling to the split Megatron train-step lifecycle. Collect MTP losses, acceptance rates, and gradient norms at finish, then propagate them through TQPolicy. Signed-off-by: Yi-Fu Wu <yifu.wu@gmail.com>
yfw
commented
Aug 27, 2026
yfw
left a comment
Contributor
Author
There was a problem hiding this comment.
The MTP lifecycle port looks sound. scale_gradients does reach the MTP parameters (it iterates buffers + expert_parallel_buffers and scales each whole buffer, with no MTP or expert exclusion), so the raw-accumulate-per-chunk then normalize-once-at-finish contract holds. The loss mask is load-bearing too — without it process_mtp_loss gets loss_mask=None and trains MTP over prompt and padding tokens.
Three inline comments: a latent fp16 issue in the gradient-scale hook, a test assertion that cannot currently fail, and one intent question about auxiliary-branch normalization that is pre-existing on this path.
Generated by Claude Code
Let MCore inherit the optimizer loss scale for MTP and normalize detached MTP gradients by valid tokens when the main loss uses a sequence denominator. Reject the nonzero attached-head combination that cannot be corrected after split-step accumulation. Signed-off-by: Yi-Fu Wu <yifu.wu@gmail.com>
Contributor
Author
|
/ok to test 60c55c8 |
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.
What does this PR do ?
Ports the Megatron multi-token prediction (MTP) training lifecycle from #2801 into the SingleController split training path.
mtp_grad_scale_funcunset so MCore inherits the optimizer's loss scale, including fp16 dynamic scaling.No TQ schema or new user configuration fields are required.
Issues
Follow-up to #2801.
Usage
Existing MTP-enabled Megatron recipes now use the same MTP training behavior when driven through the SingleController split API.
Before your PR is "Ready for review"
Pre checks:
Additional Information
Validation:
The MCore-specific state-machine tests were skipped locally because Transformer Engine is unavailable on this host. Installing the full MCore extras is also blocked here by the missing
infiniband/mlx5dv.hsystem header.