Add data-schedule utilities and GPTDatasetConfig fields for sequence packing - #5903
Merged
Conversation
This was referenced Jul 20, 2026
yaoyu-33
approved these changes
Jul 20, 2026
cuichenx
approved these changes
Jul 24, 2026
…packing Split 3/10 from NVIDIA#3386 (sequence packing / THD E2E support). Adds the data_schedule_utils module (unpack/gather/pack/reroute/broadcast pipeline) and four inert GPTDatasetConfig fields consumed by later split PRs. Per review feedback, HybridCPDataLoaderWrapper now delegates its DP-group seqlen gather to data_schedule_utils (proven equivalent); the two near-duplicates that differ semantically (reroute empty-send fallback, unpack output contract) are kept with NOTE comments explaining why. Original changes by @xiaoyao0115 in NVIDIA#3386. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: ilml <tolong@nvidia.com>
ilml
force-pushed
the
split/3386-03-packing-foundation
branch
from
July 27, 2026 20:04
bce5ecd to
a8835e8
Compare
Contributor
|
/claude review |
Contributor
There was a problem hiding this comment.
LGTM — clean extraction of shared data-schedule helpers into data_schedule_utils.py. The offsets-semantics change is behavior-preserving (get_global_seqlens slices offsets[:-1] and bucketize(gid, offsets[1:]-1) is unaffected by the extra trailing boundary since gid <= total-1), and the NOTE: comments documenting why the sequence-packing variants are intentionally not reused on the hybrid-CP path are very helpful. One minor docstring nit left inline.
Connor-XY
approved these changes
Jul 28, 2026
asolergi-nv
reviewed
Jul 30, 2026
…oadcast Review feedback on NVIDIA#5903: - get_batch_and_global_seqlens: document all five returned values; the Returns block only listed three (offsets and seqlens_gathered were missing). - _unpack_batch: return early on an empty batch instead of raising IndexError; hoist the collate-dimension normalization out of both branches and assert the leading dimension is 1 before squeezing, since squeeze(0) is a silent no-op otherwise; decide the input shape once for the whole batch and assert every sample agrees and carries exactly one of padded_seq_len (already unpacked) or cu_seqlens (pre-packed). - _unpack_batch: rename the local dev to device, and replace the stale micro_batch_size comment -- the packing path installs an identity collate_fn, so the limitation is specific to the default collate_fn. - broadcast_to_pp_group: document who needs which tensors, why the last PP rank stays in the collective but skips the unpacking, and what the pp_group.size() > 2 guard actually tests. No behavior change. - GPTDatasetConfig: clarify that sequence_packing_scheduler mirrors the ModelParallelConfig knob and name the BasePackingScheduler extension point; mark varlen_sbhd_validation as a verification-only knob with a TODO to drop it once a THD-vs-SBHD parity test exists. Also ran black on data_schedule_utils.py, which was not formatted. Original changes by @xiaoyao0115 in NVIDIA#3386. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: ilml <tolong@nvidia.com>
zhongbozhu
reviewed
Aug 1, 2026
Per review feedback: nothing reads this field. The scheduler is selected from ModelParallelConfig.sequence_packing_scheduler -- wrap_data_iterator reads it off the model config alongside max_seqlen_per_dp_cp_rank and microbatch_group_size_per_vp_stage -- and the dataloader/collate choice reads args.sequence_packing_scheduler directly. The dev branch, which carries the other three dataset-config fields added here, does not mirror this one either. Original changes by @xiaoyao0115 in NVIDIA#3386. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: ilml <tolong@nvidia.com>
asolergi-nv
approved these changes
Aug 4, 2026
6 tasks
Contributor
Author
|
/ok to test a15b5ab |
jaredcasper
approved these changes
Aug 17, 2026
ilml
enabled auto-merge
August 17, 2026 22:18
Contributor
Author
|
/ok to test a15b5ab |
This was referenced Aug 18, 2026
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 the new
megatron/core/datasets/data_schedule_utils.pymodule (the unpack/gather/pack/reroute/broadcast pipeline used by the sequence-packing schedulers) and four inertGPTDatasetConfigfields consumed by later PRs in the series.Per review feedback (@parthmannan), this PR also dedupes
HybridCPDataLoaderWrapperagainst the new utils where provably behavior-preserving: the DP-group seqlen gather now delegates to_get_global_seqlens_and_ids(verified equivalent — same collectives, dtypes, and results;get_global_seqlenskept as a compat shim). The two remaining near-duplicates are deliberately NOT folded and carry NOTE comments explaining why:reroute_samples_to_hdp_ranks: the utils variant uses atorch.empty(1)empty-send fallback that fails c10d split-size validation in a reachable hybrid-CP case where the existingtorch.empty(0)works, plus PP-modulo rank mapping andoriginal/padded_seq_lenkey special-casing.unpack_batch: the utils variant copies a fixed key list, injects synthesized length keys (changing the__next__output contract consumed byhybrid_cp_schedule.pyand adding two collectives per batch), and squeezes in place.Open question for @xiaoyao0115: the utils
reroute_samples_to_dcp_rankstorch.empty(1)empty-send fallback looks incorrect if ever reached — if it moves totorch.empty(0), the reroute duplication (~105 lines) becomes foldable in a follow-up.This PR now bases directly on
main, so the diff shows exactly its own 3 files.Part 03/10 of splitting #3386 (Add E2E support for THD format; dev-branch PR #2924). Original changes by @xiaoyao0115 in #3386 — split into functionally self-contained PRs to ease review. Hard dependencies (must merge first): none — independently mergeable.
Split series (#3386)
Branches are stacked linearly (each on the previous) so every PR shows a clean own-diff once its base is retargeted to the copy-pr-bot
pull-request/<parent>ref; until then the Files-changed view of a stacked PR includes its ancestors — its own change is the last commit.Stacked on #5902.
Review notes
data_schedule_utilsdirect unit tests (test_unpack_batch_*) arrive with the varlen test file later in the series (they needvarlen_dataset.pyto collect); the module is also exercised bytest_sequence_packing.pyin the two follow-up PRs.Issue tracking
Linked issue: Related to #3386
Contribution process
Pre-checks
🤖 Generated with Claude Code