Repository navigation
[distributed] Context parallelism: pad the sequences to a multiple of cp_size - #50508
Merged
Merged
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. Pages changed in this PR: |
3outeille
force-pushed
the
cp-7-auto-pad
branch
from
November 9, 2026 14:25
cd933c9 to
4249c6d
Compare
Member
Author
|
This was marked merged into |
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?
Stack: #50493 → #50496 → #50497 → this PR
With context parallelism, a sequence length that is not a multiple of
cp_sizeused to raise. Now_shard_inputspads the full sequences at the end before splitting them:input_idsgetpad_token_id(or 0),inputs_embedsget zeros. No real token attends to the padding, because it comes after them.position_idscontinue those of the last document, so packed sequences and flash attention see no new document.shift_labelsandnum_items_in_batchare built from the real tokens first, so the loss does not change.outputs.logitsis this rank's slice of the padded sequence. On the last rank, the padding positions at the end are not meaningful (documented).Tests
tests/context_parallel: length 7 with cp=2 (unpacked, packed,inputs_embeds) and length 5 with cp=4. The loss, every gradient and the logits at the real positions match an unsharded run on the unpadded sequences.