Skip to content

[FSDP2] Copy byte payloads bytewise in the single-rank all-gather path - #199733

Closed
weifengpy wants to merge 1 commit into
gh/weifengpy/215/basefrom
gh/weifengpy/215/head
Closed

weifengpy wants to merge 1 commit into
gh/weifengpy/215/basefrom
gh/weifengpy/215/head

Conversation

@weifengpy

@weifengpy weifengpy commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

AI-assisted change prepared with Claude Code. It was split out of #199430 and rewritten for main so it can land independently.

With a size-1 shard mesh, FSDP skips the all-gather and copies the all-gather input directly into the cached all-gather output (since #160135). When an extension's fsdp_pre_all_gather returns a byte view (uint8) of its payload while the cached output keeps the payload's original dtype, copy_ converts values instead of copying bytes. For wider dtypes that fails on the size mismatch (The size of tensor a (128) must match the size of tensor b (512) in the new test), and for one-byte dtypes such as float8 it converts the byte values silently. The world size > 1 path already views the outputs as bytes when the buffer is bytes, and the direct copy now views the cached output as bytes for byte payloads too. Main's single-rank path copies only the first payload; copying every payload is part of #197204.

Test Plan: test_all_gather_extension_single_rank_byte_payload gathers a typed payload and then a byte view of it over a size-1 shard mesh; it fails without the fix with the size mismatch above and passes with it. The local build predates main, so the test ran on an older main (ff18741) whose single-rank path and test file match main's.

python test/distributed/_composable/fsdp/test_fully_shard_extensions.py -k test_all_gather_extension_single_rank_byte_payload

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/199733

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit db63d62 with merge base b8ef869 (image):
💚 Looks good so far! There are no failures yet. 💚

🟢 GREEN LIGHT - PR approved to be merged without human review:

  • Triviality
    • Single-cause bugfix: wait_for_unshard single-rank path now views the cached output as torch.uint8 before copy_ when the payload is bytes
    • Mirrors the world_size > 1 path in _copy_all_gather_outputs, which views outs as uint8 when the buffer is uint8
  • Tests
    • test_all_gather_extension_single_rank_byte_payload gathers typed then byte payloads, so init_all_gather_outputs keeps a float32 cache
    • Pre-change copy_ of 512 uint8 elements into the 128-element float32 cache fails on size, so the old code would not pass
  • Scope
    • Two production lines; a uint8 cache or a non-byte payload copies exactly as before
    • No signature, default, or error-message change; extension hooks follow the existing test_all_gather_extension_hsdp_mesh pattern

reason: clean
Reviewed commit: db63d62

Inference job

🐛 Report a wrong verdict

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot Bot added ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests release notes: distributed (fsdp) release notes category labels Oct 5, 2026
@weifengpy
weifengpy marked this pull request as ready for review October 5, 2026 06:11
@weifengpy
weifengpy requested a review from anshul-si October 5, 2026 06:11
@weifengpy

Copy link
Copy Markdown
Contributor Author

@pytorchmergebot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Oct 5, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

cyyever pushed a commit to BakeLab/pytorch that referenced this pull request Oct 11, 2026
pytorch#199733)

> AI-assisted change prepared with Claude Code. It was split out of pytorch#199430 and rewritten for main so it can land independently.
>
> With a size-1 shard mesh, FSDP skips the all-gather and copies the all-gather input directly into the cached all-gather output (since pytorch#160135). When an extension's `fsdp_pre_all_gather` returns a byte view (`uint8`) of its payload while the cached output keeps the payload's original dtype, `copy_` converts values instead of copying bytes. For wider dtypes that fails on the size mismatch (`The size of tensor a (128) must match the size of tensor b (512)` in the new test), and for one-byte dtypes such as float8 it converts the byte values silently. The world size > 1 path already views the outputs as bytes when the buffer is bytes, and the direct copy now views the cached output as bytes for byte payloads too. Main's single-rank path copies only the first payload; copying every payload is part of pytorch#197204.
>
> Test Plan: `test_all_gather_extension_single_rank_byte_payload` gathers a typed payload and then a byte view of it over a size-1 shard mesh; it fails without the fix with the size mismatch above and passes with it. The local build predates main, so the test ran on an older main (ff18741) whose single-rank path and test file match main's.
> ```bash
> python test/distributed/_composable/fsdp/test_fully_shard_extensions.py -k test_all_gather_extension_single_rank_byte_payload
> ```
Pull Request resolved: pytorch#199733
Approved by: https://github.com/pytorchgreenlight
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests ciflow/trunk Trigger trunk jobs on your pull request Merged release notes: distributed (fsdp) release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants