refactor(data): consolidate get_batch and enable PP for SFT THD#4103
Merged
Conversation
…ank, and mtp_on_this_rank Move batch processing functions from megatron/training/utils.py to megatron/core/utils.py, introducing a unified batch handling framework that supports pretraining, SFT (THD packed sequences), and hybrid context parallelism modes. Refactor mtp_on_this_rank to accept explicit layout and mtp_num_layers parameters instead of the full TransformerConfig. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
Author
|
/ok to test dbdd34c |
Contributor
Author
|
/ok to test 8c4c82b |
Contributor
Author
|
/ok to test 0d5d42b |
Contributor
Author
|
/ok to test bead714 |
Contributor
Author
|
/ok to test a7da44a |
Contributor
Author
|
/ok to test 9f6af12 |
Contributor
Author
|
/ok to test b309cbc |
Contributor
Author
|
/ok to test 1bdd865 |
ericharper
approved these changes
May 21, 2026
santhnm2
approved these changes
May 21, 2026
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/26239906766 |
5 tasks
Contributor
|
It seems that this PR breaks the MBridge: When running with CP without sequence packing, it fails with: |
2 tasks
6 tasks
janEbert
pushed a commit
to janEbert/Megatron-LM
that referenced
this pull request
Jun 2, 2026
…IA#4103) Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
6 tasks
mathemakitten
pushed a commit
to mathemakitten/Megatron-LM
that referenced
this pull request
Jun 12, 2026
…IA#4103) Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
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 ?
Unifies batch-processing utilities (get_batch, get_batch_on_this_tp_rank, get_batch_on_this_cp_rank) behind a single framework that handles pretraining, SFT (THD packed sequences), and Hybrid Context Parallel, and enables pipeline parallelism for SFT with THD layout.
Changes
Core refactor (megatron/core/utils.py, megatron/training/utils.py)
PP for SFT (THD)
MTP API cleanup (megatron/core/transformer/multi_token_prediction.py)
Entry scripts (pretrain_gpt.py, pretrain_mamba.py)
Tests (tests/unit_tests/data/test_get_batch.py)
Contribution process
Pre-checks
Code review
Feel free to message or comment the @mcore-oncall to help accelerate your merge into main. The less complex your PR is, the faster it will be approved and merged!
All PRs start as draft. If you open a non-draft PR, it will be automatically converted to draft.
Step 1: Mark PR as "Ready for Review"
.github/CODEOWNERS.Final Review might get declined if these requirements are not fulfilled.
Step 2: Final Review
For PRs that change
megatron/core, once all expert reviewers have approved, theFinal Reviewlabel is applied automatically and final reviewers are assigned.For PRs outside
megatron/core, this step is skipped.Step 3: Approved
Once all required reviewers have approved, the
Approvedlabel is applied automatically.Merge
Any member of mcore-engineers will be able to merge your PR.
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.