feat: add MTP (multi-token prediction) training support for nemotron - #2801
Merged
Conversation
Contributor
Author
|
/ok to test 05c85eb |
yfw
marked this pull request as draft
June 12, 2026 19:58
yfw
marked this pull request as ready for review
June 13, 2026 06:06
Contributor
Author
|
/ok to test 2fc8700 |
Cherry-pick of 8106050 (MTP changes) onto ci/bump-mbridge-79c8957. Resolved conflicts against the newer base; build-custom-vllm.sh change dropped per request. Where the commit's context lines were stale (master_config access style, model_forward cfg= arg, vllm hf_overrides.update, the inline IPC weight loader), kept the new base's versions and grafted only the genuine MTP additions (mtp_loss_mask plumbing, mtp_metrics logging, num_speculative_tokens==0 handling, megatron parallel-state imports). Signed-off-by: Yi-Fu Wu <yifu.wu@gmail.com> Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Yi-Fu Wu <yifu.wu@gmail.com>
- test_mtp_metrics.py: get_mtp_metrics per-layer loss/acceptance (1-indexed), empty-tracker and defaults-when-only-loss cases. Stubs the cross-rank reduce so it runs single-process on CPU. - test_megatron_data.py: process_microbatch propagates mtp_loss_mask in the no-packing path and packs it alongside input_ids in the packing path; absent -> None. Tightened the existing with_packing fixture's __contains__ mock (was return_value=True for all keys, which now spuriously triggers the mtp_loss_mask branch). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Yi-Fu Wu <yifu.wu@gmail.com>
setup._apply_mtp_config currently only wires mtp_num_layers; extend it to also apply mtp_loss_scaling_factor, mtp_use_repeated_layer and mtp_detach_heads onto the mcore model config (gated on presence), so these MTP knobs are user-controllable instead of silently using megatron defaults. Ported from 499108c. Config conventions: - Declare the MTP keys (incl. mtp_positive_only) on the MegatronConfig TypedDict and add documented defaults to the exemplar examples/configs/grpo_math_1B.yaml (+ matching tests/unit/reference_configs/grpo_math_1B.yaml so the v1->v2 check stays green). - Drop the forbidden call-site default in megatron_policy_worker: cfg["megatron_cfg"].get("mtp_positive_only", False) -> .get("mtp_positive_only"). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Yi-Fu Wu <yifu.wu@gmail.com>
mtp_positive_only (restrict the MTP loss mask to positive-advantage tokens) was experimental and is unused. Remove it from the MTP loss-mask computation, the MegatronConfig schema, and the grpo_math_1B exemplar/reference configs. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Yi-Fu Wu <yifu.wu@gmail.com>
Collecting MTP metrics inline in MegatronPolicyWorker.train() made cloudpickle pull an unpicklable torch ConfigModuleInstance into the actor serialization (`cannot pickle 'ConfigModuleInstance' object`), so Ray could not create the megatron policy worker. Move the collection into a small _collect_mtp_metrics method that lazily imports get_mtp_metrics, and drop the module-level get_mtp_metrics import, so train()'s (large) globals footprint no longer references it. Verified the worker class cloudpickles again. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Yi-Fu Wu <yifu.wu@gmail.com>
yfw
force-pushed
the
yifu/super_mtp_merge_main
branch
from
June 15, 2026 18:23
2fc8700 to
f22fece
Compare
ashors1
reviewed
Jun 15, 2026
ashors1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the MTP training support — clean implementation with good test coverage!
A few findings below (5 inline comments). The VLM guard and test assertion are the most actionable.
Copyright note (spans multiple files): common.py, data.py, megatron_policy_worker.py, __init__.py, lm_policy.py, and grpo.py still carry # Copyright (c) 2025. Current year is 2026 — train.py and setup.py were already correctly updated in this PR.
Generated by Claude Code
macandro96
reviewed
Jun 15, 2026
Co-authored-by: Anna Shors <ashors@nvidia.com> Signed-off-by: Yi-Fu Wu <yifu.wu@gmail.com>
Signed-off-by: Yi-Fu Wu <yifu.wu@gmail.com>
Contributor
Author
|
/ok to test 0981ab0 |
Signed-off-by: Yi-Fu Wu <yifu.wu@gmail.com>
Contributor
Author
|
/ok to test b86c1a1 |
macandro96
approved these changes
Jun 16, 2026
ashors1
approved these changes
Jun 16, 2026
ashors1
added a commit
that referenced
this pull request
Jun 27, 2026
Signed-off-by: Yi-Fu Wu <yifu.wu@gmail.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> Co-authored-by: Anna Shors <ashors@nvidia.com> Signed-off-by: Anna Shors <ashors@nvidia.com>
4 tasks
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 ?
Adds training-side Megatron Multi-Token Prediction support, rebased onto the Megatron-Bridge 79c8957 bump which includes needed Megatron-LM changes. Part of Nemotron 3 Super upstreaming.
Scope: training only. The MTP inference path (vLLM drafter weight load / speculative-config handling) will be handled separately as part of the ultra upstreaming.
Issues
List issues that this PR closes (syntax):
Usage
# Add a code snippet demonstrating how to use thisBefore your PR is "Ready for review"
Pre checks:
Additional Information