feat(megatron): support MTP in split training - #3881
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
left a comment
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>
|
/ok to test 60c55c8 |
Signed-off-by: Yi-Fu Wu <yifu.wu@gmail.com>
|
/ok to test 3ea9fd7 |
mehraakash
left a comment
There was a problem hiding this comment.
The core MTP lifecycle and scaling logic looks consistent with the synchronous path: mask construction, fp16 loss-scale inheritance, detached-head token normalization, metric reduction, and TQ propagation all look sound.
I left one compatibility question about forwarding the model-owned packing and context-parallel flags through the split microbatch path.
Could we also run CI:L1 against the exact current head and include a real MCore split-MTP functional test? The current head has only metadata, security, and submodule checks. The previous Lfast PPO failure used a non-MTP configuration and appears unrelated, but there is not yet a clean functional signal for this training-path change.
Signed-off-by: Yi-Fu Wu <yifu.wu@gmail.com>
Keep the SingleController microbatch iterator aligned with synchronous training for models that own sequence packing, MTP-mask packing, or context-parallel slicing. Add regression coverage for both supported capability combinations. Signed-off-by: Yi-Fu Wu <yifu.wu@gmail.com>
|
/ok to test b93b84c |
|
I triggered CI:L1 for the exact updated head, b93b84c. I did not add a nominal MTP L1 script because the current SingleController L1 recipe uses Qwen3-0.6B with mtp_num_layers=0 and no MTP weights, so it would not exercise the behavior under review. The repository’s actual Megatron MTP functional recipe requires the private Super Omni checkpoint/training data and 16 nodes, and is currently disabled. The added MCore regression instead covers propagation for both supported model-owned packing/CP-slicing combinations; a true end-to-end CI lane will require a small CI-accessible MTP checkpoint. |
|
/ok to test b93b84c |
|
/ok to test b93b84c |
|
CI:L1 is explicitly dispatched against b93b84c: https://github.com/NVIDIA-NeMo/RL/actions/runs/33715206186 |
…t tests Two unit tests drifted from code this branch added and went red in CI (run 33939587768 on 30d300c): - test_train_pump_e2e::_prepopulate_buffer inserts a ready slot into TQReplayBuffer by appending to its parallel lists by hand. The branch added _rollout_ids_list and _staging_keys_list to the buffer, so the first remove() indexed past the end of the empty staging list (IndexError in _remove_unlocked). Append None to both, matching what begin_group/commit and checkpoint restore do for finalized groups. - test_rollout_pump_writes_expected_tq_data pins the TQ tag schema. The branch added num_routed_experts_backfilled to VIOLATION_TAG_KEYS so every row's tags now carry it; add it to the expected set. The remaining red shard, L0_Unit_Tests_Megatron_Policy_1, is a main-side conflict between #3881 (test expects train_microbatch to forward model_slices_context_parallel_inputs) and #2957 (guard raises on it) and is inherited unchanged. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Signed-off-by: Pranav Thombre <pthombre@nvidia.com>
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.Sample run with single controller and mtp training enabled:

wandb: https://wandb.ai/nvidia/nano35-rlvr-convergence/runs/nk99s0qe