Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/176334
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New Failure, 3 Pending, 1 Unrelated FailureAs of commit 82db5c8 with merge base 4f4276b ( NEW FAILURE - The following job has failed:
BROKEN TRUNK - The following job failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
…mesh Enable fully_shard to operate on models whose parameters are already DTensors distributed across a full SPMD mesh, including the data-parallel dimensions. Previously, fully_shard only handled the case where DP dimensions were not part of an existing DTensor mesh (TP). This PR introduces DataParallelMeshDimNames, which lets users specify which mesh dimensions correspond to data parallelism (sharding and/or replication). The DP dimensions must carry Replicate placements in the original DTensor spec before fully_shard replaces them with Shard Note that, the input/activation will also be DTensors distributed across the full SPMD mesh. ghstack-source-id: 7a69142 Pull-Request: #176334
…mesh Enable fully_shard to operate on models whose parameters are already DTensors distributed across a full SPMD mesh, including the data-parallel dimensions. Previously, fully_shard only handled the case where DP dimensions were not part of an existing DTensor mesh (TP). This PR introduces DataParallelMeshDimNames, which lets users specify which mesh dimensions correspond to data parallelism (sharding and/or replication). The DP dimensions must carry Replicate placements in the original DTensor spec before fully_shard replaces them with Shard Note that, the input/activation will also be DTensors distributed across the full SPMD mesh. ghstack-source-id: 1e2f340 Pull-Request: #176334
…mesh Enable fully_shard to operate on models whose parameters are already DTensors distributed across a full SPMD mesh, including the data-parallel dimensions. Previously, fully_shard only handled the case where DP dimensions were not part of an existing DTensor mesh (TP). This PR introduces DataParallelMeshDimNames, which lets users specify which mesh dimensions correspond to data parallelism (sharding and/or replication). The DP dimensions must carry Replicate placements in the original DTensor spec before fully_shard replaces them with Shard Note that, the input/activation will also be DTensors distributed across the full SPMD mesh. ghstack-source-id: 575a8f5 Pull-Request: #176334
…mesh Enable fully_shard to operate on models whose parameters are already DTensors distributed across a full SPMD mesh, including the data-parallel dimensions. Previously, fully_shard only handled the case where DP dimensions were separate from the DTensor mesh (e.g., DP + TP on separate submeshes). This PR introduces DataParallelMeshDims, which lets users specify which mesh dimension names correspond to data parallelism (FSDP sharding and/or HSDP replication). The DP dimensions must carry Replicate() placements in the original DTensor spec before fully_shard replaces them with Shard(). Note that, the input/activation will also be DTensors distributed across the full SPMD mesh. ghstack-source-id: 3d915a6 Pull-Request: #176334
| optim.zero_grad(set_to_none=(i % 2 == 0)) | ||
| if mesh is not None: | ||
| inp = DTensor.from_local( | ||
| inp, mesh, [Replicate()] * mesh.ndim, run_check=False |
There was a problem hiding this comment.
noob: why it's Replicate() instead of Shard(0) on the DP (batch) dim?
There was a problem hiding this comment.
Think about it is DDP, if no fully_shard is applied. fully_shard is just an optimization that perform the allgather and reduce_scatter. Without fully_shard, it will still work correctly due to DTensor.
weifengpy
left a comment
There was a problem hiding this comment.
done with the review - totally understand it's in draft yet. just want to have a complete review first
…mesh Enable fully_shard to operate on models whose parameters are already DTensors distributed across a full SPMD mesh, including the data-parallel dimensions. Previously, fully_shard only handled the case where DP dimensions were separate from the DTensor mesh (e.g., DP + TP on separate submeshes). This PR introduces DataParallelMeshDims, which lets users specify which mesh dimension names correspond to data parallelism (FSDP sharding and/or HSDP replication). The DP dimensions must carry Replicate() placements in the original DTensor spec before fully_shard replaces them with Shard(). Note that, the input/activation will also be DTensors distributed across the full SPMD mesh. ghstack-source-id: 3d915a6 Pull-Request: #176334
…mesh Enable fully_shard to operate on models whose parameters are already DTensors distributed across a full SPMD mesh, including the data-parallel dimensions. Previously, fully_shard only handled the case where DP dimensions were separate from the DTensor mesh (e.g., DP + TP on separate submeshes). This PR introduces DataParallelMeshDims, which lets users specify which mesh dimension names correspond to data parallelism (FSDP sharding and/or HSDP replication). The DP dimensions must carry Replicate() placements in the original DTensor spec before fully_shard replaces them with Shard(). Note that, the input/activation will also be DTensors distributed across the full SPMD mesh. ghstack-source-id: ea1790b Pull-Request: #176334
…mesh Enable fully_shard to operate on models whose parameters are already DTensors distributed across a full SPMD mesh, including the data-parallel dimensions. Previously, fully_shard only handled the case where DP dimensions were separate from the DTensor mesh (e.g., DP + TP on separate submeshes). This PR introduces DataParallelMeshDims, which lets users specify which mesh dimension names correspond to data parallelism (FSDP sharding and/or HSDP replication). The DP dimensions must carry Replicate() placements in the original DTensor spec before fully_shard replaces them with Shard(). Note that, the input/activation will also be DTensors distributed across the full SPMD mesh. ghstack-source-id: 5fe7824 Pull-Request: #176334
…mesh Enable fully_shard to operate on models whose parameters are already DTensors distributed across a full SPMD mesh, including the data-parallel dimensions. Previously, fully_shard only handled the case where DP dimensions were separate from the DTensor mesh (e.g., DP + TP on separate submeshes). This PR introduces DataParallelMeshDims, which lets users specify which mesh dimension names correspond to data parallelism (FSDP sharding and/or HSDP replication). The DP dimensions must carry Replicate() placements in the original DTensor spec before fully_shard replaces them with Shard(). Note that, the input/activation will also be DTensors distributed across the full SPMD mesh. ghstack-source-id: a2c76ec Pull-Request: #176334
…mesh Enable fully_shard to operate on models whose parameters are already DTensors distributed across a full SPMD mesh, including the data-parallel dimensions. Previously, fully_shard only handled the case where DP dimensions were separate from the DTensor mesh (e.g., DP + TP on separate submeshes). This PR introduces DataParallelMeshDims, which lets users specify which mesh dimension names correspond to data parallelism (FSDP sharding and/or HSDP replication). The DP dimensions must carry Replicate() placements in the original DTensor spec before fully_shard replaces them with Shard(). Note that, the input/activation will also be DTensors distributed across the full SPMD mesh. ghstack-source-id: 20a2568 Pull-Request: #176334
…mesh Enable fully_shard to operate on models whose parameters are already DTensors distributed across a full SPMD mesh, including the data-parallel dimensions. Previously, fully_shard only handled the case where DP dimensions were separate from the DTensor mesh (e.g., DP + TP on separate submeshes). This PR introduces DataParallelMeshDims, which lets users specify which mesh dimension names correspond to data parallelism (FSDP sharding and/or HSDP replication). The DP dimensions must carry Replicate() placements in the original DTensor spec before fully_shard replaces them with Shard(). Note that, the input/activation will also be DTensors distributed across the full SPMD mesh. ghstack-source-id: ea4dff5 Pull-Request: #176334
**NOT READY YET** This PR is still a WIP, so code quality and design are not finalized. We publish this PR to get early signals of CIs and also verify pytorch/pytorch#176334. ghstack-source-id: fc1597e Pull-Request: #2616
**NOT READY YET** This PR is still a WIP, so code quality and design are not finalized. We publish this PR to get early signals of CIs and also verify pytorch/pytorch#176334. ghstack-source-id: 184da4a Pull-Request: #2616
wconstab
left a comment
There was a problem hiding this comment.
mostly lgtm. @weifengpy do you want to do the final review?
| shard (Optional[Union[str, tuple[str, ...]]]): Mesh dimension name(s) | ||
| that FSDP shards parameters on. If a tuple of names, those dims | ||
| are flattened into a single shard dimension. At least one of | ||
| ``shard`` and ``replicate`` must be set. |
There was a problem hiding this comment.
add a post__init to validate this?
| def _get_submesh(names: tuple[str, ...]) -> "DeviceMesh": | ||
| if len(names) == 1: | ||
| return mesh[names[0]] | ||
| return mesh[names]._flatten("_".join(names)) |
There was a problem hiding this comment.
does fsdp already have the convention of creating new flattened meshes (with PGs, which is what i assume this line does), or is this new behavior?
There was a problem hiding this comment.
This is a new behavior. The existing behavior is that users need to "flatten" CP and FSDP by themselves.
| replicate_mesh_dim: int | None = None | ||
| dp_mesh_dims: DataParallelMeshDims | None = None | ||
| spmd_mesh: DeviceMesh | None = field(default=None, repr=False) | ||
| is_spmd_mesh: bool = field(default=False, init=False, repr=False) |
There was a problem hiding this comment.
i wonder if we could validate that the mesh is actually an spmd mesh. i guess not. we can not compare it to the world since we don't know if PP is involved and we can't assume the whole world is part of SPMD. it is important that users don't accidentally pass a submesh that excludes any other spmd dims here though right?
There was a problem hiding this comment.
We could do some validations, but it is not possible to the accurate validation as you mentioned, if PP exists.
weifengpy
left a comment
There was a problem hiding this comment.
thanks for resolving my long list of comments!
…mesh Enable fully_shard to operate on models whose parameters are already DTensors distributed across a full SPMD mesh, including the data-parallel dimensions. Previously, fully_shard only handled the case where DP dimensions were separate from the DTensor mesh (e.g., DP + TP on separate submeshes). This PR introduces DataParallelMeshDims, which lets users specify which mesh dimension names correspond to data parallelism (FSDP sharding and/or HSDP replication). The DP dimensions must carry Replicate() placements in the original DTensor spec before fully_shard replaces them with Shard(). Note that, the input/activation will also be DTensors distributed across the full SPMD mesh. ghstack-source-id: 26553d4 Pull-Request: #176334
…mesh Enable fully_shard to operate on models whose parameters are already DTensors distributed across a full SPMD mesh, including the data-parallel dimensions. Previously, fully_shard only handled the case where DP dimensions were separate from the DTensor mesh (e.g., DP + TP on separate submeshes). This PR introduces DataParallelMeshDims, which lets users specify which mesh dimension names correspond to data parallelism (FSDP sharding and/or HSDP replication). The DP dimensions must carry Replicate() placements in the original DTensor spec before fully_shard replaces them with Shard(). Note that, the input/activation will also be DTensors distributed across the full SPMD mesh. ghstack-source-id: 7d19071 Pull-Request: #176334
|
@pytorchbot merge -f "The failing tests are not related" |
Merge startedYour change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
**NOT READY YET** This PR is still a WIP, so code quality and design are not finalized. We publish this PR to get early signals of CIs and also verify pytorch/pytorch#176334. ghstack-source-id: 97bf135 Pull-Request: #2616
**NOT READY YET** This PR is still a WIP, so code quality and design are not finalized. We publish this PR to get early signals of CIs and also verify pytorch/pytorch#176334. ghstack-source-id: b888637 Pull-Request: #2616
…mesh (pytorch#176334) **Summary** Enable `fully_shard` to operate on models whose parameters are already DTensors distributed across a full SPMD mesh, including the data-parallel dimensions. Previously, `fully_shard` only handled the case where DP dimensions were not part of an existing DTensor mesh (which is TP or EP). This PR introduces `DataParallelMeshDims`, which lets users specify which mesh dimensions correspond to data parallelism (sharding and/or replication). The DP dimensions must carry `Replicate` placements in the original DTensor spec before `fully_shard` replaces them with `Shard`. Note that, the input/activation will also be DTensors distributed across the full SPMD mesh. **Verification** We verify this PR through unittests and TorchTitan integration: pytorch/torchtitan#2616. Pull Request resolved: pytorch#176334 Approved by: https://github.com/weifengpy
…mesh (pytorch#176334) **Summary** Enable `fully_shard` to operate on models whose parameters are already DTensors distributed across a full SPMD mesh, including the data-parallel dimensions. Previously, `fully_shard` only handled the case where DP dimensions were not part of an existing DTensor mesh (which is TP or EP). This PR introduces `DataParallelMeshDims`, which lets users specify which mesh dimensions correspond to data parallelism (sharding and/or replication). The DP dimensions must carry `Replicate` placements in the original DTensor spec before `fully_shard` replaces them with `Shard`. Note that, the input/activation will also be DTensors distributed across the full SPMD mesh. **Verification** We verify this PR through unittests and TorchTitan integration: pytorch/torchtitan#2616. Pull Request resolved: pytorch#176334 Approved by: https://github.com/weifengpy
Upstream 52a292d introduced torchtitan/distributed/full_dtensor.py with an unconditional `from torch.distributed.fsdp import DataParallelMeshDims`. That symbol was only added to PyTorch on 2026-03-19 (pytorch/pytorch#176334); sqsh containers baked against an older torch nightly (i.e. anything before the recipe was bumped to torch 2.13.0.dev20260505) crash at module-load: ImportError: cannot import name 'DataParallelMeshDims' from 'torch.distributed.fsdp' The crash is unconditional because trainer.py and components/validate.py both do `from torchtitan.distributed import full_dtensor` at module scope, which executes the offending import. DeepSeek-V3 already raises NotImplementedError on `parallelism.full_dtensor=True`, so the runtime callsites are dead code for the LLMB DeepSeek-V3 recipe -- the module just needs to *import*. Wrap the DataParallelMeshDims import in a try/except in both torchtitan/distributed/full_dtensor.py and torchtitan/models/llama3/parallelize.py. Fallback is `None`; the resulting function annotations (`-> None`, `tuple[DeviceMesh, None]`) are valid in Python 3.9+ and never executed under DeepSeek-V3. This lets users running containers built against an older torch nightly pick up the latest LLMB recipe without rebuilding the sqsh.
…mesh (pytorch#176334) **Summary** Enable `fully_shard` to operate on models whose parameters are already DTensors distributed across a full SPMD mesh, including the data-parallel dimensions. Previously, `fully_shard` only handled the case where DP dimensions were not part of an existing DTensor mesh (which is TP or EP). This PR introduces `DataParallelMeshDims`, which lets users specify which mesh dimensions correspond to data parallelism (sharding and/or replication). The DP dimensions must carry `Replicate` placements in the original DTensor spec before `fully_shard` replaces them with `Shard`. Note that, the input/activation will also be DTensors distributed across the full SPMD mesh. **Verification** We verify this PR through unittests and TorchTitan integration: pytorch/torchtitan#2616. Pull Request resolved: pytorch#176334 Approved by: https://github.com/weifengpy
Stack from ghstack (oldest at bottom):
Summary
Enable
fully_shardto operate on models whose parameters are already DTensors distributed across a full SPMD mesh, including the data-parallel dimensions.Previously,
fully_shardonly handled the case where DP dimensions were not part of an existing DTensor mesh (which is TP or EP). This PR introducesDataParallelMeshDims, which lets users specify which mesh dimensions correspond to data parallelism (sharding and/or replication). The DP dimensions must carryReplicateplacements in the original DTensor spec beforefully_shardreplaces them withShard.Note that, the input/activation will also be DTensors distributed across the full SPMD mesh.
Verification
We verify this PR through unittests and TorchTitan integration: pytorch/torchtitan#2616.