feat(moe): Support placing MTP layers into standalone stages - #2136
Merged
Conversation
move output layer outside mtp block support mtp layer for --pipeline-model-parallel-layout run test with mtp on the second last vpp stage, with the following error message. can run, but need to check lm loss and mtp loss with baseline. fix some issue by refering to MR2996 Signed-off-by: Li Tao <lit@nvidia.com>
Signed-off-by: Li Tao <lit@nvidia.com>
Signed-off-by: Li Tao <lit@nvidia.com>
…apes later Signed-off-by: Li Tao <lit@nvidia.com>
Signed-off-by: Li Tao <lit@nvidia.com>
Signed-off-by: Li Tao <lit@nvidia.com>
Signed-off-by: Li Tao <lit@nvidia.com>
Signed-off-by: Li Tao <lit@nvidia.com>
Signed-off-by: Li Tao <lit@nvidia.com>
Signed-off-by: Li Tao <lit@nvidia.com>
Signed-off-by: Li Tao <lit@nvidia.com>
Signed-off-by: Li Tao <lit@nvidia.com>
Signed-off-by: Li Tao <lit@nvidia.com>
6 tasks
Member
|
@BestJuly can you please fix conflicts? |
asolergi-nv
reviewed
Dec 31, 2025
| ), "All of the MTP layers must be in the same one virtual pipeline stage" | ||
| for vpp_rank in range(self.virtual_pipeline_model_parallel_size - 1): | ||
| assert LayerType.mtp not in self.layout[0][vpp_rank], ( | ||
| f"Corrently we restrict that the MTP should not be in the first pp rank." |
Contributor
Author
There was a problem hiding this comment.
Good catch! Thanks for your review and I have modified the code according to your review comments. The UT should pass and I have checked the failed one which also passed with the CI container. I believe that would be a environment issue.
============================================================================= short test summary info =============================================================================
PASSED tests/unit_tests/data/test_builder.py::test_builder
May I have your further review then? Thank you.
Comment on lines
+87
to
+90
|
|
||
| # print("========================") | ||
| # print("[DEBUG] mtp_block_spec is ", mtp_block_spec) | ||
| # exit() |
Contributor
There was a problem hiding this comment.
Suggested change
| # print("========================") | |
| # print("[DEBUG] mtp_block_spec is ", mtp_block_spec) | |
| # exit() |
Comment on lines
+397
to
+399
| # TODO(shifangx): Currently, we only support put all of MTP layers | ||
| # on the last pipeline stage, so the offset is always 0. | ||
| # We will support more flexible MTP placement in the future. |
| """Build pretraining datasets.""" | ||
| if train_valid_test_num_samples is None: | ||
| train_valid_test_num_samples = get_train_valid_test_num_samples() | ||
| print_rank_0(' > datasets target sizes (minimum size):') |
Contributor
There was a problem hiding this comment.
Why would we drop this message?
Comment on lines
+2831
to
+2834
| if vp_stage is not None: | ||
| return build_train_valid_test_datasets_provider(train_valid_test_num_samples, vp_stage=vp_stage) | ||
| else: | ||
| return build_train_valid_test_datasets_provider(train_valid_test_num_samples) |
Contributor
There was a problem hiding this comment.
Do we really need this?
Signed-off-by: lit <lit@nvidia.com>
Member
|
/ok to test 50d34a3 |
Contributor
|
/ok to test d03c64c |
jkamalu
approved these changes
Jan 12, 2026
jaredcasper
approved these changes
Jan 14, 2026
ericharper
approved these changes
Jan 14, 2026
6 tasks
5 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 ?
Support placing MTP to a standalone stage, e.g., MTP in the 2nd last VPP stage for better VPP balance.
This is the PR for main branch, and the corresponding PR1916 for dev branch.
Highlights
This document outlines the design of a new MTP (Multi-Token Prediction) standalone feature. This feature allows MTP layers to be placed into a standalone VPP (Virtual Pipeline Parallelism) stage, rather than being confined to the last VPP stage.
Key Benefits:
Considerations:
Design idea
We split MTP computation into two parts
The advantage is that we put the MTP loss computation as main, so for the untie embedding part, the MTP loss can use exactly the same code path of the lm loss as they are in the same vpp stage, which is simpler than putting MTP loss calculation in the same vpp stage as MR#2996 so that we can avoid bugs related to this. With the new design, the DSv3 TFLOPs will also be compatible with the #2996 one which included in the 0.13 EA branch.We divide MTP computation into two parts: output head computation and others. This approach offers the advantage of treating MTP loss computation as primary. Consequently, for the untied embedding, the MTP loss can utilize the exact same code path as the LM loss, as they are within the same VPP stage. This simplifies the process compared to placing MTP loss calculation in the same VPP stage as MR#2996, thereby mitigating potential bugs. Furthermore, this new design ensures DSv3 TFLOPs compatibility with the #2996 version included in the 0.13 EA branch.
Perf and results
Perf
Convergence
On full DSv3
(Real training mode) Almost overlapped with the main branch settings for the metrics which is related to convergence.
Deterministic correctness check
We validate the correctness in mainly two parts (when using different pp layout, can be bitwise aligned when manually disabling grad clipping)
Pre-checks
Core 0.8)Code review
The following process is enforced via the CODEOWNERS file for changes into
megatron/core. For changes outside ofmegatron/core, it is up to the PR author whether or not to tag the Final Reviewer team.For MRs into `main` branch
(Step 1): Add PR label
Expert Review(Step 2): Collect the expert reviewers reviews
Expert Reviewlabel when your PR is ready for review.Final Review might get declined if these requirements are not fulfilled.
(Step 3): Final Review
Final Reviewlabel(Optional Step 4): Cherry-pick into release branch
If this PR also needs to be merged into
core_r*release branches, after this PR has been merged, selectCherry-pickto open a new PR into the release branch.For MRs into `dev` branch
The proposed review process for `dev` branch is under active discussion.MRs are mergable after one approval by either
eharper@nvidia.comorzijiey@nvidia.com.Merging your PR
Any member of core-adlr and
core-nemowill be able to merge your PR.