Skip to content

[distributed] Sequence parallelism with expert parallelism - #50514

Open
3outeille wants to merge 2 commits into
cp-6-tp-x-cpfrom
cp-9-ep-x-cp
Open

3outeille wants to merge 2 commits into
cp-6-tp-x-cpfrom
cp-9-ep-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 → #50511 → this PR → #50521 → #50522

Allows combining sequence parallelism with expert parallelism (DistributedConfig(sp_size=S, ep_size=E, ...)). Only pp_size remains unsupported with sp_size.

  • Token dispatch (ep_dispatch_experts) and efsdp = fsdp * sp * tp // ep already work out of the box since each SP rank dispatches only its local token slice.
  • Expert gradient scaling (set_gradient_divide_factor(dp_size)) already accounts for sp_size through dp_size; only the comment in fsdp.py is updated.
  • all_reduce EP continues to require ep_size == tp_size (each TP group holds the same SP slice).

Tests

Added forward and backward equivalence tests against an unsharded tiny Qwen3MoeForCausalLM in tests/sequence_parallel/test_sequence_parallel.py (CPU / gloo), covering:

  • ep_sp (unpacked, packed, padded), fsdp_ep_sp, efsdp_ep_sp
  • tp_ep_sp (ep > tp), tp_ep_sp_auto (ep == tp), all_reduce_ep_sp
  • hsdp_ep_sp, hsdp_efsdp_ep_sp, fsdp_tp_ep_sp, hsdp_tp_ep_sp

@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 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 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-9-ep-x-cp branch 2 times, most recently from 2162932 to 45dbfa4 Compare November 20, 2026 06:58
@3outeille 3outeille changed the title [distributed] Context parallelism with expert parallelism [] Sequence parallelism with expert parallelism Nov 20, 2026
@3outeille 3outeille changed the title [] Sequence parallelism with expert parallelism [distributed] Sequence parallelism with expert parallelism Nov 20, 2026
@3outeille
3outeille removed this pull request from stack #50797 November 20, 2026 08:49
@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 added this pull request to stack #51606 December 2, 2026 05:05
@3outeille
3outeille force-pushed the cp-9-ep-x-cp branch 2 times, most recently from f3a8161 to 8b3e78c Compare December 2, 2026 07:13
Each rank of an sp group dispatches the tokens of its own slice only, so no token reaches an expert
twice and `efsdp * ep` still covers `fsdp * sp * tp`. The expert gradient divide factor already
counts the sp ranks through `dp_size`, so only the explanatory comment and the mesh docstring
change; `sp_size` with `ep_size` is no longer refused.
The tiny Qwen3-MoE against the same weights on the full sequences, with token dispatch on
`sp2 x ep2`, `sp2 x fsdp2 x ep4`, `sp2 x fsdp2 x ep2` (efsdp), `sp2 x tp2 x ep4` and
`sp2 x hsdp2 x ep2`, plus the all-reduce plan with `ep_size=tp_size=2` where the ep group holds
one sp slice. Every case stays within four ranks.

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