Repository navigation
[no-ci] [FSDP] Move the FlexShard engine into core; add experimental flex_shard API (AI-assisted) - #203763
Draft
weifengpy wants to merge 10 commits into
Draft
[no-ci] [FSDP] Move the FlexShard engine into core; add experimental flex_shard API (AI-assisted)#203763weifengpy wants to merge 10 commits into
weifengpy wants to merge 10 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/203763
Note: Links to docs will display an error until the docs builds have been completed. ❌ 8 New FailuresAs of commit 057d568 with merge base bba8f39 ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
weifengpy
added a commit
that referenced
this pull request
Nov 6, 2026
…flex_shard API (AI-assisted) - [ ] Passes lint (`spin fixlint`) - [x] Added/updated tests - [ ] Updated documentation where applicable - [ ] Included benchmark results ## Linked issue or supporting maintainer > No linked issue; the author has write access. Bottom of a two-PR stack on #199726; the PR above runs `fully_shard` on this engine. ## BC-breaking? > No. This adds a private package and an experimental module; nothing existing changes. ## Summary (human written only) > _Placeholder for the author._ ## Agent details (AI-generated) Drafted with an AI assistant at the author's request. This is a draft for CI and discussion, not ready for review or merge. CI is deferred with `[no-ci]` because the PR above runs CI on the whole stack. **What.** Moves the FlexShard engine from meta-pytorch/flex_shard (main d6bb546) into `torch.distributed.fsdp._flex_shard` and exposes its frontend as the experimental public module `torch.distributed.fsdp.experimental.flex_shard`. `flex_shard` shards parameters as plain `torch.Tensor` local shards with sharding metadata, and each bucket of parameters names its own placement (`Shard`, `BlockShard`, `BucketedBlockShard`, `BucketedOwned`, `MixedBucketPlacement`, ...). **How.** The move is mechanical. Imports are rewritten to the core package. The FP8/MXFP8 blockwise placements stay in the flex_shard repo, and `MixedBucketPlacement` gets a registry so that the repo can register its quantized member types. The repo's tests move to `test/distributed/_composable/flex_shard`, with their helpers in `torch/testing/_internal/distributed`. At about 21.7k added lines this is far over the 1,500-line PR limit; landing it would mean splitting it. **Review order.** `placement_contract.py` (the prepare/run/finish contract every placement implements), `bucket_storage.py` (one byte buffer per bucket, laid out by its placement), `placements/shard.py` (FSDP-style `Shard(dim)` with FSDP's native copy ops), `bucket_comm.py` and `bucket_runtime.py` (flex_shard's hook-driven scheduler), then `flex_shard.py` and the experimental re-export module. **Known gaps.** Ruff still warns in the moved files (TC001/TC003 type-checking imports, S101 asserts), and the full `spin fixlint`, including pyrefly, has not been run. ### Test Plan ``` python -m pytest test/distributed/_composable/flex_shard/<file>.py # each file on its own, 4x B200 ``` Every file passes except `test_flex_shard_fsdp2_parity.py::test_matches_fully_shard_with_head_called_twice`, which fails the same way in the flex_shard repo against this torch build: it expects FSDP2's older post-backward behavior for a module called twice in one forward. With the PR above applied, the suite reports 140 passed and that failure. These runs used the previous revision of #199726 (aad1e3c). The stack was then cherry-picked onto its current revision without conflicts; that revision changes only `_fully_shard.py` and `test_fully_shard_comm.py`. ghstack-source-id: 46bf155 Pull-Request: #203763
weifengpy
added a commit
that referenced
this pull request
Nov 8, 2026
…flex_shard API (AI-assisted) - [ ] Passes lint (`spin fixlint`) - [x] Added/updated tests - [ ] Updated documentation where applicable - [ ] Included benchmark results ## Linked issue or supporting maintainer > No linked issue; the author has write access. Bottom of a two-PR stack on #199726; the PR above runs `fully_shard` on this engine. ## BC-breaking? > No. This adds a private package and an experimental module; nothing existing changes. ## Summary (human written only) > _Placeholder for the author._ ## Agent details (AI-generated) Drafted with an AI assistant at the author's request. This is a draft for CI and discussion, not ready for review or merge. CI is deferred with `[no-ci]` because the PR above runs CI on the whole stack. **What.** Moves the FlexShard engine from meta-pytorch/flex_shard (main d6bb546) into `torch.distributed.fsdp._flex_shard` and exposes its frontend as the experimental public module `torch.distributed.fsdp.experimental.flex_shard`. `flex_shard` shards parameters as plain `torch.Tensor` local shards with sharding metadata, and each bucket of parameters names its own placement (`Shard`, `BlockShard`, `BucketedBlockShard`, `BucketedOwned`, `MixedBucketPlacement`, ...). **How.** The move is mechanical. Imports are rewritten to the core package. The FP8/MXFP8 blockwise placements stay in the flex_shard repo, and `MixedBucketPlacement` gets a registry so that the repo can register its quantized member types. The repo's tests move to `test/distributed/_composable/flex_shard`, with their helpers in `torch/testing/_internal/distributed`. The experimental module reports itself as the `__module__` of the names it re-exports, as `torch.distributed.fsdp` does for FSDP2's, and `test_testing.py`'s import check skips the two modules that need the optional `spmd_types` and `triton` packages. At about 21.7k added lines this is far over the 1,500-line PR limit; landing it would mean splitting it. **Review order.** `placement_contract.py` (the prepare/run/finish contract every placement implements), `bucket_storage.py` (one byte buffer per bucket, laid out by its placement), `placements/shard.py` (FSDP-style `Shard(dim)` with FSDP's native copy ops), `bucket_comm.py` and `bucket_runtime.py` (flex_shard's hook-driven scheduler), then `flex_shard.py` and the experimental re-export module. **Known gaps.** Lint passes for the files only this PR touches; the engine files the PR above also changes (`bucket_runtime.py`, `bucket_comm.py`, `placement_contract.py`, `placements/shard.py`, `placements/utils.py`) get their lint fixes there. Most pyrefly errors in the moved code are silenced with `# pyrefly: ignore` rather than fixed. ### Test Plan ``` python -m pytest test/distributed/_composable/flex_shard/<file>.py # each file on its own, 4x B200 python -m pytest test/test_public_bindings.py -k test_correct_module_names spin lint -- --take PYREFLY,RUFF,PYFMT,FLAKE8,MYPY,TEST_LINTER,TESTOWNERS,TEST_HAS_MAIN,CODESPELL <changed files> ``` Every file passes except `test_flex_shard_fsdp2_parity.py::test_matches_fully_shard_with_head_called_twice`, which fails the same way in the flex_shard repo against this torch build: it expects FSDP2's older post-backward behavior for a module called twice in one forward. With the PR above applied, the suite reports 140 passed and that failure. `test_correct_module_names` passes. `test_testing.py`'s import check, run over `torch/distributed/fsdp` with `spmd_types` hidden, passes; the full check needs packages this host lacks (e.g. `tabulate`). These runs used the previous revision of #199726 (aad1e3c). The stack was then cherry-picked onto its current revision without conflicts; that revision changes only `_fully_shard.py` and `test_fully_shard_comm.py`. ghstack-source-id: 5bc7e97 Pull-Request: #203763
weifengpy
added a commit
that referenced
this pull request
Nov 8, 2026
…flex_shard API (AI-assisted) - [ ] Passes lint (`spin fixlint`) - [x] Added/updated tests - [ ] Updated documentation where applicable - [ ] Included benchmark results ## Linked issue or supporting maintainer > No linked issue; the author has write access. Bottom of a two-PR stack on #199726; the PR above runs `fully_shard` on this engine. ## BC-breaking? > No. This adds a private package and an experimental module; nothing existing changes. ## Summary (human written only) > _Placeholder for the author._ ## Agent details (AI-generated) Drafted with an AI assistant at the author's request. This is a draft for CI and discussion, not ready for review or merge. CI is deferred with `[no-ci]` because the PR above runs CI on the whole stack. **What.** Moves the FlexShard engine from meta-pytorch/flex_shard (main d6bb546) into `torch.distributed.fsdp._flex_shard` and exposes its frontend as the experimental public module `torch.distributed.fsdp.experimental.flex_shard`. `flex_shard` shards parameters as plain `torch.Tensor` local shards with sharding metadata, and each bucket of parameters names its own placement (`Shard`, `BlockShard`, `BucketedBlockShard`, `BucketedOwned`, `MixedBucketPlacement`, ...). **How.** The move is mechanical. Imports are rewritten to the core package. The FP8/MXFP8 blockwise placements stay in the flex_shard repo, and `MixedBucketPlacement` gets a registry so that the repo can register its quantized member types. The repo's tests move to `test/distributed/_composable/flex_shard`, with their helpers in `torch/testing/_internal/distributed`. The experimental module reports itself as the `__module__` of the names it re-exports, as `torch.distributed.fsdp` does for FSDP2's, and `test_testing.py`'s import check skips the two modules that need the optional `spmd_types` and `triton` packages. At about 21.7k added lines this is far over the 1,500-line PR limit; landing it would mean splitting it. **Review order.** `placement_contract.py` (the prepare/run/finish contract every placement implements), `bucket_storage.py` (one byte buffer per bucket, laid out by its placement), `placements/shard.py` (FSDP-style `Shard(dim)` with FSDP's native copy ops), `bucket_comm.py` and `bucket_runtime.py` (flex_shard's hook-driven scheduler), then `flex_shard.py` and the experimental re-export module. **Known gaps.** Lint passes for the files only this PR touches; the engine files the PR above also changes (`bucket_runtime.py`, `bucket_comm.py`, `placement_contract.py`, `placements/shard.py`, `placements/utils.py`) get their lint fixes there. Most pyrefly errors in the moved code are silenced with `# pyrefly: ignore` rather than fixed. ### Test Plan ``` python -m pytest test/distributed/_composable/flex_shard/<file>.py # each file on its own, 4x B200 python -m pytest test/test_public_bindings.py -k test_correct_module_names spin lint -- --take PYREFLY,RUFF,PYFMT,FLAKE8,MYPY,TEST_LINTER,TESTOWNERS,TEST_HAS_MAIN,CODESPELL <changed files> ``` Every file passes except `test_flex_shard_fsdp2_parity.py::test_matches_fully_shard_with_head_called_twice`, which fails the same way in the flex_shard repo against this torch build: it expects FSDP2's older post-backward behavior for a module called twice in one forward. With the PR above applied, the suite reports 140 passed and that failure. `test_correct_module_names` passes. `test_testing.py`'s import check, run over `torch/distributed/fsdp` with `spmd_types` hidden, passes; the full check needs packages this host lacks (e.g. `tabulate`). These runs used the previous revision of #199726 (aad1e3c). The stack was then cherry-picked onto its current revision without conflicts; that revision changes only `_fully_shard.py` and `test_fully_shard_comm.py`. ghstack-source-id: 5bc7e97 Pull-Request: #203763
Draft
3 of 4 tasks
3 of 4 tasks
weifengpy
added a commit
that referenced
this pull request
Nov 11, 2026
…flex_shard API (AI-assisted) - [ ] Passes lint (`spin fixlint`) - [x] Added/updated tests - [ ] Updated documentation where applicable - [ ] Included benchmark results ## Linked issue or supporting maintainer > No linked issue; the author has write access. Stacked on #204282, a copy of #199726, and #203961 (the `FSDPModule` APIs torchtitan needs, independent of this PR); the PR above runs `fully_shard` on this engine. ## BC-breaking? > No. This adds a private package and an experimental module; nothing existing changes. ## Summary (human written only) > _Placeholder for the author._ ## Agent details (AI-generated) Drafted with an AI assistant at the author's request. This is a draft for CI and discussion, not ready for review or merge. CI is deferred with `[no-ci]` because the PR above runs CI on the whole stack. **What.** Moves the FlexShard engine from meta-pytorch/flex_shard (main d6bb546) into `torch.distributed.fsdp._flex_shard` and exposes its frontend as the experimental public module `torch.distributed.fsdp.experimental.flex_shard`. `flex_shard` shards parameters as plain `torch.Tensor` local shards with sharding metadata, and each bucket of parameters names its own placement (`Shard`, `BlockShard`, `BucketedBlockShard`, `BucketedOwned`, `MixedBucketPlacement`, ...). **How.** The move is mechanical. Imports are rewritten to the core package. The FP8/MXFP8 blockwise placements stay in the flex_shard repo, and `MixedBucketPlacement` gets a registry so that the repo can register its quantized member types. The repo's tests move to `test/distributed/_composable/flex_shard`, with their helpers in `torch/testing/_internal/distributed`. The experimental module reports itself as the `__module__` of the names it re-exports, as `torch.distributed.fsdp` does for FSDP2's, and `test_testing.py`'s import check skips the two modules that need the optional `spmd_types` and `triton` packages. At about 21.7k added lines this is far over the 1,500-line PR limit; landing it would mean splitting it. **Review order.** `placement_contract.py` (the prepare/run/finish contract every placement implements), `bucket_storage.py` (one byte buffer per bucket, laid out by its placement), `placements/shard.py` (FSDP-style `Shard(dim)` with FSDP's native copy ops), `bucket_comm.py` and `bucket_runtime.py` (flex_shard's hook-driven scheduler), then `flex_shard.py` and the experimental re-export module. **Known gaps.** Lint passes for the files only this PR touches; the engine files the PR above also changes (`bucket_runtime.py`, `bucket_comm.py`, `placement_contract.py`, `placements/shard.py`, `placements/utils.py`) get their lint fixes there. Most pyrefly errors in the moved code are silenced with `# pyrefly: ignore` rather than fixed. ### Test Plan ``` python -m pytest test/distributed/_composable/flex_shard/<file>.py # each file on its own, 4x B200 python -m pytest test/test_public_bindings.py -k test_correct_module_names spin lint -- --take PYREFLY,RUFF,PYFMT,FLAKE8,MYPY,TEST_LINTER,TESTOWNERS,TEST_HAS_MAIN,CODESPELL <changed files> ``` Every file passes except `test_flex_shard_fsdp2_parity.py::test_matches_fully_shard_with_head_called_twice`, which fails the same way in the flex_shard repo against this torch build: it expects FSDP2's older post-backward behavior for a module called twice in one forward. With the PR above applied, the suite reports 140 passed and that failure. `test_correct_module_names` passes. `test_testing.py`'s import check, run over `torch/distributed/fsdp` with `spmd_types` hidden, passes; the full check needs packages this host lacks (e.g. `tabulate`). These runs used an earlier revision of #199726 (aad1e3c). The stack was then cherry-picked onto the revision that #204282 copies, without conflicts; that revision changes only `_fully_shard.py` and `test_fully_shard_comm.py`. ghstack-source-id: e15e938 Pull-Request: #203763
This was referenced Nov 14, 2026
This branch has not been deployed
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.
Stack from ghstack (oldest at bottom):
spin fixlint)Linked issue or supporting maintainer
BC-breaking?
Summary (human written only)
Agent details (AI-generated)
Drafted with an AI assistant at the author's request. This is a draft for CI and discussion, not ready for review or merge. CI is deferred with
[no-ci]because the PR above runs CI on the whole stack.What. Moves the FlexShard engine from meta-pytorch/flex_shard (main d6bb546) into
torch.distributed.fsdp._flex_shardand exposes its frontend as the experimental public moduletorch.distributed.fsdp.experimental.flex_shard.flex_shardshards parameters as plaintorch.Tensorlocal shards with sharding metadata, and each bucket of parameters names its own placement (Shard,BlockShard,BucketedBlockShard,BucketedOwned,MixedBucketPlacement, ...).How. The move is mechanical. Imports are rewritten to the core package. The FP8/MXFP8 blockwise placements stay in the flex_shard repo, and
MixedBucketPlacementgets a registry so that the repo can register its quantized member types. The repo's tests move totest/distributed/_composable/flex_shard, with their helpers intorch/testing/_internal/distributed. The experimental module reports itself as the__module__of the names it re-exports, astorch.distributed.fsdpdoes for FSDP2's, andtest_testing.py's import check skips the two modules that need the optionalspmd_typesandtritonpackages. At about 21.7k added lines this is far over the 1,500-line PR limit; landing it would mean splitting it.Review order.
placement_contract.py(the prepare/run/finish contract every placement implements),bucket_storage.py(one byte buffer per bucket, laid out by its placement),placements/shard.py(FSDP-styleShard(dim)with FSDP's native copy ops),bucket_comm.pyandbucket_runtime.py(flex_shard's hook-driven scheduler), thenflex_shard.pyand the experimental re-export module.Known gaps. Lint passes for the files only this PR touches; the engine files the PR above also changes (
bucket_runtime.py,bucket_comm.py,placement_contract.py,placements/shard.py,placements/utils.py) get their lint fixes there. Most pyrefly errors in the moved code are silenced with# pyrefly: ignorerather than fixed.Test Plan
On main bba8f39 (4x GB300), every file passes except
test_flex_shard_fsdp2_parity.py::test_matches_fully_shard_with_head_called_twice(140 passed, 1 failed). It fails the same way in the flex_shard repo against this torch build: it expects FSDP2's older post-backward behavior for a module called twice in one forward. With the PR above applied, all 144 pass.test_correct_module_namespasses.test_testing.py's import check, run overtorch/distributed/fsdpwithspmd_typeshidden, passes; the full check needs packages this host lacks (e.g.tabulate).#204282 copies #199726's latest revision (d9d8b3c), in which a layout carries its own comm; this PR needed no change for it.