Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FSDP][Easy] Rename streams; add back stream sharing test #104966

Closed
wants to merge 1 commit into from

Conversation

awgu
Copy link
Contributor

@awgu awgu commented Jul 11, 2023

Stack from ghstack (oldest at bottom):

Purely out of preference, this PR renames the streams to _unshard_stream instead of _streams_unshard etc. since the former reads more naturally. The PR also removes some duplicated comments and adds back a unit test that streams are shared.

@pytorch-bot
Copy link

pytorch-bot bot commented Jul 11, 2023

🔗 Helpful Links

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

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

✅ No Failures

As of commit b57126f:
💚 Looks good so far! There are no failures yet. 💚

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

@@ -283,17 +283,10 @@ def _share_state_and_init_handle_attrs(
"set yet or should have been set to `False`",
)
fsdp_state._is_root = False
# Stream for unshard logic, including allocating the all-gather destination
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not need to duplicate these comments with the initial construction in _init_streams(), as the comments may become stale and here we are only sharing the state.

def _init_streams(
state: _FSDPState,
) -> _FSDPState:
"""
Initializes CUDA streams for overlapping communication, computation, and
data transfers. The streams should be shared across FSDP instances.
"""
assert state._is_root
assert state._device_handle.is_available()
# Stream for unshard logic, including allocating the all-gather destination
# tensors and the all-gathers themselves.
state._unshard_stream = state._device_handle.Stream()
# Stream for overlapping gradient reduction with the backward pass gradient
# computation.
state._post_backward_stream = state._device_handle.Stream()
# Stream for pre-unshard logic, namely allocations and writes for CPU
# offloading (H2D copy) and mixed precision (low precision cast).
state._pre_unshard_stream = state._device_handle.Stream()
# Default stream for computation
state._default_stream = state._device_handle.current_stream()

@@ -276,7 +276,14 @@ def _test_nested_fully_shard_shared_state(self, use_policy: bool):
# NOTE: This check only requires that the data structure state is
# shared. Namely, sharing the FSDP state object itself is sufficient
# but not necessary.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We used to test that state._streams was shared. This adds back testing that each stream is shared.

@awgu awgu added the topic: not user facing topic category label Jul 11, 2023
@awgu awgu marked this pull request as ready for review July 11, 2023 13:39
@awgu awgu added the ciflow/trunk Trigger trunk jobs on your pull request label Jul 11, 2023
awgu added a commit to awgu/pytorch that referenced this pull request Jul 11, 2023
ghstack-source-id: 623474b088ab2d5ade75a1f952ae666d7e8e1f04
Pull Request resolved: pytorch#104966
Copy link
Member

@rohan-varma rohan-varma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@awgu
Copy link
Contributor Author

awgu commented Jul 13, 2023

@pytorchbot merge

@pytorchmergebot
Copy link
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/trunk Trigger trunk jobs on your pull request Merged release notes: distributed (fsdp) release notes category topic: not user facing topic category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants