Skip to content

[distributed] Sequence parallelism with tensor parallelism - #50511

Open
3outeille wants to merge 3 commits into
cp-4-tester-mixinfrom
cp-6-tp-x-cp
Open

3outeille wants to merge 3 commits into
cp-4-tester-mixinfrom
cp-6-tp-x-cp

Conversation

@3outeille

@3outeille 3outeille commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

🤗 Transformers CI

What does this PR do?

Stack: #50493 → #50496 → #50796 → this PR → #50514 → #50521 → #50522

Enables combining sequence parallelism with tensor parallelism via DistributedConfig(tp_size=T, sp_size=S) (also works with fsdp_size and dp_replicate_size):

  • Allow tp_size > 1 with sp_size > 1 in DistributedConfig (pp_size and ep_size remain disallowed for now). Ranks in a tp group receive the same batch and the same sequence slice.
  • Head divisibility check in UlyssesAttention: under TP each rank holds num_heads / tp_size heads, which Ulysses splits across sp ranks, so sp_size * tp_size must divide both num_attention_heads and num_key_value_heads.

Tests

Added TP + SP coverage in tests/sequence_parallel/test_sequence_parallel.py (reusing the forward/backward helpers from tests/test_sequence_parallel_mixin.py):

  • Head divisibility validation under tp_size > 1.
  • Forward (logits) and backward (loss + gradients) parity against an unsharded model on CPU (gloo):
    • tp=2 × sp=2 (4 ranks): unpacked, packed, padded
    • fsdp=2 × tp=2 × sp=2 (8 ranks): packed
    • dp_replicate=2 × tp=2 × sp=2 (8 ranks, HSDP): packed

@HuggingFaceDocBuilderDev

HuggingFaceDocBuilderDev commented Nov 9, 2026 •

Copy link
Copy Markdown

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.

@3outeille
3outeille changed the base branch from cp-5-docs to cp-4-tester-mixin November 9, 2026 14:24
@3outeille
3outeille added this pull request to stack #50517 November 9, 2026 14:29
@3outeille
3outeille removed this pull request from stack #50517 November 9, 2026 14:30
@3outeille
3outeille added this pull request to stack #50518 November 9, 2026 14:30
@3outeille
3outeille removed this pull request from stack #50518 November 9, 2026 14:36
@3outeille
3outeille changed the base branch from cp-4-tester-mixin to cp-3-cp-size November 9, 2026 14:36
@3outeille
3outeille added this pull request to stack #50520 November 9, 2026 14:37
@3outeille
3outeille removed this pull request from stack #50520 November 10, 2026 02:50
@3outeille
3outeille added this pull request to stack #50546 November 10, 2026 02:51
@3outeille
3outeille force-pushed the cp-6-tp-x-cp branch 2 times, most recently from 2512a3a to 5e27442 Compare November 16, 2026 08:03
@3outeille 3outeille changed the title [distributed] Context parallelism with tensor parallelism [] Sequence parallelism with tensor parallelism Nov 20, 2026
@3outeille 3outeille changed the title [] Sequence parallelism with tensor parallelism [distributed] Sequence parallelism with tensor parallelism Nov 20, 2026
@3outeille
3outeille removed this pull request from stack #50797 November 20, 2026 08:49
@3outeille
3outeille changed the base branch from cp-4-tester-mixin to cp-4b-fsdp-x-cp November 20, 2026 08:50
@3outeille
3outeille added this pull request to stack #51004 November 20, 2026 08:50
@3outeille
3outeille removed this pull request from stack #51004 November 30, 2026 05:31
@3outeille
3outeille changed the base branch from cp-4b-fsdp-x-cp to cp-4-tester-mixin November 30, 2026 06:27
@3outeille
3outeille added this pull request to stack #51606 December 2, 2026 05:05
@3outeille
3outeille force-pushed the cp-6-tp-x-cp branch 2 times, most recently from c42e315 to a57e86c Compare December 2, 2026 06:21
FSDP2 composes the mesh it shards over (`sp`, or `fsdp_sp` with `fsdp_size > 1`) with the `tp`
mesh the parameters are already sharded on, and torch only composes meshes built from the same
root: both are dims of the dense mesh, or of the `fsdp_sp` root mesh it is unflattened from.

Under TP this rank holds `num_heads / tp_size` heads and Ulysses splits those across the sp
group, so `sp_size * tp_size` must divide the attention and key/value heads.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants