Repository navigation
Conversation
This was referenced Nov 9, 2026
|
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. |
This was referenced Nov 9, 2026
distributed] Add context parallelism: DistributedConfig(cp_size=N)distributed] DistributedConfig(cp_size=N)
This was referenced Nov 9, 2026
3outeille
force-pushed
the
cp-3-cp-size
branch
from
November 10, 2026 02:50
4ff461b to
0a373ad
Compare
3outeille
force-pushed
the
cp-3-cp-size
branch
2 times, most recently
from
November 10, 2026 05:18
e4604a6 to
81494d9
Compare
3outeille
force-pushed
the
cp-3-cp-size
branch
2 times, most recently
from
November 10, 2026 06:03
b8825e4 to
945fa19
Compare
3outeille
force-pushed
the
cp-3-cp-size
branch
from
November 12, 2026 06:19
945fa19 to
438df28
Compare
3outeille
force-pushed
the
cp-3-cp-size
branch
2 times, most recently
from
November 30, 2026 07:07
d2ec7b3 to
16f076e
Compare
distributed] DistributedConfig(sp_size=N)distributed] DistributedConfig(sp_size=N) + FSDP
distributed] DistributedConfig(sp_size=N) + FSDPdistributed] DistributedConfig(fsdp_size=N, sp_size=M)
3outeille
marked this pull request as ready for review
November 30, 2026 08:30
3outeille
force-pushed
the
cp-3-cp-size
branch
2 times, most recently
from
December 2, 2026 07:20
5c16611 to
c6a5795
Compare
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: longcat_flash |
3outeille
force-pushed
the
cp-3-cp-size
branch
from
December 3, 2026 06:59
c6a5795 to
231842b
Compare
3outeille
force-pushed
the
cp-3-cp-size
branch
from
December 3, 2026 07:38
231842b to
336c6ea
Compare
`sp_size` splits every sequence across the ranks of an `sp` mesh, which get the same batch and keep a contiguous slice each. The plan follows the other parallelisms: a `base_model_sp_plan` default in `PreTrainedConfig`, an `sp_plan` override merged and expanded like `tp_plan`, and `apply_sequence_parallelism` installing the plan's styles after TP/EP and before FSDP2. The model keeps taking whole sequences: the first decoder layer cuts `hidden_states`, every layer cuts the rotary embeddings, the model-built mask and positions stay whole, and the loss is the one of the whole sequences. FSDP2 shards over `sp`, and `dp_size` counts the sp ranks. `fsdp_size`, `tp_size`, `pp_size` and `ep_size` are refused with it for now, and so is the `Trainer`, whose dataloader would split the batch across an sp group.
A model sharded with `DistributedConfig(sp_size=N)` reproduces, step by step, the run of the same weights on the full sequences: same loss, same logits on this rank's slice, same gradients. The tests cover the plan, the refusals, packing, padding, `inputs_embeds`, sliding windows, a registered attention style, saving, and HSDP composed with `sp_size`.
`DistributedConfig(fsdp_size=N, sp_size=M)` is no longer refused. FSDP2 shards over `fsdp` and
`sp` together: the ranks of an sp group hold the same batch, so their gradients are reduced
together and their parameters can be sharded together. That axis, `fsdp_sp`, is a dim of the
dense root mesh `(pp, dp_replicate, fsdp_sp, tp)`, and the five dense axes are an `_unflatten`
view of it, so that HSDP can slice `("dp_replicate", "fsdp_sp")` without slicing a flattened dim
from the root mesh, which torch deprecates. Requires `torch>=2.10`, refused in `DistributedConfig`;
`sp_size` alone keeps the plain mesh and shards over `sp`.
`fsdp_size=2 x sp_size=2` on four ranks against the same weights on the full sequences: same loss, same logits on this rank's slice, same gradients.
…require torch>=2.10 for SP
…ply_sequence_parallelism
3outeille
force-pushed
the
cp-3-cp-size
branch
from
December 3, 2026 07:57
336c6ea to
73fcb99
Compare
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.
What does this PR do?
Stack: #50493 → this PR → #50796 → #50511 → #50514 → #50521 → #50522
distributed] Sequence parallel module, with Ulysses #50493 intoDistributedConfig,DistributedMixin,TransformersDeviceMesh, and FSDP2 so users can enable SP (and FSDP2/HSDP + SP) directly fromfrom_pretrained:distributed] Add Sequence Parallel mixin #50796.Quick GPU check (4× B200, bf16, FA2)
Qwen3-8B(bs_per_dp=1, fwd + bwd + AdamW):fsdp=1, sp=1(1 GPU)fsdp=4, sp=1(4 GPUs)fsdp=2, sp=2(4 GPUs)fsdp=1, sp=4(4 GPUs)