Skip to content

Commit

Permalink
[FSDP2] Added missing event wait (for future) (pytorch#132568)
Browse files Browse the repository at this point in the history
Nothing is actually wrong currently, but we should add this in case we land pytorch#127032 in the future.

Pull Request resolved: pytorch#132568
Approved by: https://github.com/weifengpy, https://github.com/Skylion007
  • Loading branch information
awgu authored and pytorchmergebot committed Aug 5, 2024
1 parent fb87796 commit b30d091
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion torch/distributed/_composable/fsdp/_fsdp_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,11 @@ def _root_post_backward_final_callback(self) -> None:
state._finalize_backward()
if self._state_ctx.is_last_backward:
self._comm_ctx.post_forward_order.clear()
self._comm_ctx.reduce_scatter_state = None
if self._comm_ctx.reduce_scatter_state is not None:
torch.cuda.current_stream().wait_event(
self._comm_ctx.reduce_scatter_state.event
)
self._comm_ctx.reduce_scatter_state = None
self._state_ctx.post_backward_final_callback_queued = False

def _finalize_backward(self) -> None:
Expand Down

0 comments on commit b30d091

Please sign in to comment.