Skip to content

Add sequence_packing_scheduler config field, CLI arg, and validation - #5902

Open
ilml wants to merge 2 commits into
NVIDIA:mainfrom
ilml:split/3386-02-packing-config
Open

Add sequence_packing_scheduler config field, CLI arg, and validation#5902
ilml wants to merge 2 commits into
NVIDIA:mainfrom
ilml:split/3386-02-packing-config

Conversation

@ilml

@ilml ilml commented Jul 20, 2026

Copy link
Copy Markdown
Contributor
  • I, the PR author, have personally reviewed every line of this PR.

What does this PR do?

Adds the sequence_packing_scheduler knob to ModelParallelConfig, its TransformerConfig.__post_init__ validation (TE>=2.9 pin, variable_seq_lengths, alltoall MoE dispatcher), the explicit --sequence-packing-scheduler / --max-seqlen-per-dp-cp-rank / --hybrid-context-parallel args with factory exclude-list entries, and the packed-sequence buffer-size check in validate_args. Fully feature-flagged: setting the flag validates but is a no-op until the scheduler lands.

Part 02/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)

Part PR Hard deps (merge first)
01 #5901
02 #5902
03 #5903
04 #6625 #5903
05 #6626 #6625
06 #6627 #5902, #5903
07 #6628 #5902, #6625, #6626
08 #5908
09 #6629 #6627, #5908
10 #6630 #6628, #6629

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.

Issue tracking

Linked issue: Related to #3386

Contribution process

Pre-checks

  • I have added relevant unit tests
  • I have added relevant functional tests
  • I have added proper typing to my code Typing guidelines
  • I have added relevant documentation
  • I have run the autoformatter.sh on my PR

🤖 Generated with Claude Code

Series status (updated)

Remaining PRs of the #3386 split, tracked in the Dynamic Context Parallelism project. Reviews run in parallel; merge order:

Order PR Content
1 #5902 config field, CLI arg, validation (independent)
1 #6684 core packing scheduler (independent)
2 #6685 mock SFT + varlen datasets (stacked on #6684)
3 #6686 training-loop + varlen wiring (stacked on #6685)

Merged so far: #5901, #5903, #5908, #6625.

Split 2/10 from NVIDIA#3386 (sequence packing / THD E2E support). Adds the
sequence_packing_scheduler knob to ModelParallelConfig, its
TransformerConfig validation (TE>=2.9 pin, variable_seq_lengths,
alltoall dispatcher), the explicit CLI args, and validate_args checks.
Feature-flagged no-op until the scheduler lands.

Original changes by @xiaoyao0115 in NVIDIA#3386.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: ilml <tolong@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented Jul 20, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@ilml
ilml marked this pull request as ready for review July 22, 2026 01:02
@ilml
ilml requested review from a team as code owners July 22, 2026 01:02
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the Final Review PR is in the "final review" stage label Jul 22, 2026
@ilml

ilml commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 30a81d8

…-config

Signed-off-by: Tom Long <tolong@nvidia.com>

# Conflicts:
#	megatron/training/arguments.py
#	tests/unit_tests/models/test_hybrid_moe_model.py
@ilml

ilml commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test d76a634


# Packed-sequence buffer-size check. Placed after varlen scheduler
# auto-select so it validates the final resolved scheduler.
if args.sequence_packing_scheduler is not None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from my understanding, --calculate-per-token-loss should be required when sequence_packing_scheduler is set. for example, if two packed microbatches contain 1 and 9 valid tokens, the default path in schedules.py gives the two microbatches equal weight (i.e., weight 1/2 for the first token, and 1/18 for each of the other tokens) instead of token weights of 1:9, so gradients depend on how samples happen to be packed. the --hybrid-context-parallel already does this validation near line 1385.

self.variable_seq_lengths = True

# TODO(tailaim): add support for other dispatcher types
assert self.moe_token_dispatcher_type == "alltoall", (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this check also runs for dense models, where num_moe_experts is None and moe_token_dispatcher_type is unused; its default is allgather. for example, TransformerConfig(..., sequence_packing_scheduler="dp_balanced", max_seqlen_per_dp_cp_rank=4096) fails even though it has no MoE dispatcher; please require alltoall only when num_moe_experts is set and add dense and MoE coverage.

@ilml

ilml commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test d76a634

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

complexity: low Final Review PR is in the "final review" stage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants