Fix TP-only parallelism config: always include dp_shard in device mesh#3986
Open
songhappy wants to merge 1 commit intohuggingface:mainfrom
Open
Fix TP-only parallelism config: always include dp_shard in device mesh#3986songhappy wants to merge 1 commit intohuggingface:mainfrom
songhappy wants to merge 1 commit intohuggingface:mainfrom
Conversation
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?
Fixes a crash when using TP-only parallelism (e.g., [tp_size=8, dp_shard_size=1] with error of:
KeyError: "Invalid mesh_dim_names ('dp_shard_cp',) specified. Valid mesh_dim_names are ['tp']."Root cause: _get_mesh() only includes dimensions with size > 1 in the mesh, so dp_shard is excluded when dp_shard_size=1. However, build_device_mesh() unconditionally tries to create a dp_shard_cp submesh from dp_shard + cp, which fails because neither dimension exists in the mesh.
Fix (two changes):
_get_mesh(): Always include dp_shard in the mesh dimensions (even when size == 1) so that FSDP2 has a valid submesh. A size-1 shard dimension is a no-op but keeps the composable API consistent.
build_device_mesh(): Build the dp_shard_cp submesh from dimensions actually present in the mesh instead of relying on dp_shard_cp_dim_names which assumes both dimensions exist.
Impact:
No effect on existing FSDP-only or FSDP+TP configs (dp_shard was already present). Only fixes the TP-only case where dp_shard was missing.