Skip to content

[distributed] Add fsdp_mesh_size for "FSDP2 is applied" - #50494

Closed
3outeille wants to merge 1 commit into
cp-1-implementationsfrom
cp-2-fsdp-mesh-size
Closed

3outeille wants to merge 1 commit into
cp-1-implementationsfrom
cp-2-fsdp-mesh-size

Conversation

@3outeille

@3outeille 3outeille commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

🤗 Transformers CI

What does this PR do?

Stack: #50493 → this PR → DistributedConfig(cp_size=N) (next)

dp_size (dp_replicate_size * fsdp_size) means two things today: the number of ranks that see different batches, and "FSDP2 is applied". With context parallelism, FSDP2 also shards over the ranks of a cp group, which share one batch, so the two differ.

This adds DistributedConfig.fsdp_mesh_size and uses it wherever "FSDP2 is applied" is meant (8 places in mixin.py, and the FSDP + PP check). Same values today: no behavior change.

Tests

The existing FSDP / HSDP / EP tests pass on CPU (llama, qwen3_moe, tests/utils/test_modeling_utils.py).

`dp_size` says how many ranks see a distinct batch. FSDP2 is applied to a mesh
of `dp_replicate_size * fsdp_size` ranks, which the two only coincide with while
there is no context parallelism. Add `fsdp_mesh_size` for the second meaning and
use it at every place that asked whether FSDP2 is applied. Values are unchanged.
@3outeille

Copy link
Copy Markdown
Member Author

Folded into the next PR: dp_size will include cp_size instead of adding a new property.

@3outeille 3outeille closed this Nov 9, 2026
@3outeille
3outeille deleted the cp-2-fsdp-mesh-size branch November 9, 2026 09:44
@3outeille
3outeille removed this pull request from stack #50495 November 9, 2026 09:50
@HuggingFaceDocBuilderDev

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.

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