Repository navigation
fix: use minimum sequence divisibility factor - #3563
Open
NolenLiang wants to merge 1 commit into
Open
NolenLiang wants to merge 1 commit into
NolenLiang wants to merge 1 commit into
Conversation
Signed-off-by: NolenLiang <[email protected]>
Contributor
Author
|
/ok to test 4319b6a |
Contributor
Author
|
/ok to test 4319b6a |
This was referenced Sep 26, 2026
This branch has not been deployed
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.
Summary
Supersedes #3028 with the minimum sequence-length divisibility constraint derived from the actual Megatron sharding order.
Sto be divisible by2 * CP.(S / CP) % TP == 0, equivalentlyS % (CP * TP) == 0.This is not
lcm(2 * CP, TP), which can be too small, and it is not generally2 * CP * TP, which overpads by 2x for even TP.Root cause
Megatron first reshapes each sequence into
2 * cp_sizebalanced chunks and selects two chunks per CP rank, leaving a CP-local length ofS / CP(source). When sequence parallelism is enabled, the embedding path passes that local sequence to the TP group (source); its split explicitly requires the first dimension to be divisible by TP size (source).The previous product calculation treated the TP constraint as an independent global factor and multiplied it by the full CP factor, double-counting the factor of 2 when TP is even.
Changes
lcm(2 * CP, CP * TP)and validates positive multiples.CP=2, TP=4, SP=true: factor 4 is rejected, while factors 8 and 16 are accepted.CP=4, TP=2andCP=2, TP=4.8-GPU validation
The probe called the exact MCore CP partition, TP sequence-parallel scatter, and backward all-gather primitives on 8 H100 GPUs with
CP=2andTP=4.This directly rejects
lcm(2*CP, TP)=4and shows that the product2*CP*TP=16is not necessary; the derived minimumlcm(2*CP, CP*TP)=8passes end to end.Experiment source version: Megatron-LM
002255075c3728fded9a2e435677840b08560d55. Runtime: PyTorch2.13.0a0+8145d630e8.nv26.06. The corresponding PyTorch 2.11 source was separately audited and has the same CP divisibility behavior.