Skip to content

Make barrier sync against current stream instead of whole device - #96785

Closed
kwen2501 wants to merge 2 commits into
mainfrom
remove_dev_sync_from_barrier
Closed

kwen2501 wants to merge 2 commits into
mainfrom
remove_dev_sync_from_barrier

Conversation

@kwen2501

@kwen2501 kwen2501 commented Mar 14, 2023 •

Copy link
Copy Markdown
Collaborator

The document says:

torch.distributed.barrier(group=None, async_op=False, device_ids=None)

Synchronizes all processes.
This collective blocks processes until the whole group enters this function...

Both cudaStreamSynchronize and cudaDeviceSynchronize would sync the host-side process to the completion of the barrier kernel in the GPU, hence achieving the above functionality.

This PR chooses a smaller set cudaStreamSynchronize instead of cudaDeviceSynchronize, for three reasons:

  1. lower chance of hang;
  2. CurrentCUDAStream is usually the context for next operation in Python script;
  3. better barrier performance.

@pytorch-bot

pytorch-bot Bot commented Mar 14, 2023 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ You can merge normally! (1 Unrelated Failure)

As of commit 8393604 with merge base 3a823e4 (image):

UNSTABLE - The following job failed but was likely due to flakiness present on trunk and has been marked as unstable:

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

@pytorch-bot pytorch-bot Bot added the release notes: distributed (c10d) release notes category label Mar 14, 2023
@kwen2501

Copy link
Copy Markdown
Collaborator Author

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot successfully started a rebase job. Check the current status here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Successfully rebased remove_dev_sync_from_barrier onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via git checkout remove_dev_sync_from_barrier && git pull --rebase)

@pytorchmergebot
pytorchmergebot force-pushed the remove_dev_sync_from_barrier branch from fa5cbcb to 791b958 Compare March 28, 2023 05:42
@github-actions

Copy link
Copy Markdown
Contributor

Looks like this PR hasn't been updated in a while so we're going to go ahead and mark this as Stale.
Feel free to remove the Stale label if you feel this was a mistake.
If you are unable to remove the Stale label please contact a maintainer in order to do so.
If you want the bot to never mark this PR stale again, add the no-stale label.
Stale pull requests will automatically be closed after 30 days of inactivity.

@github-actions github-actions Bot added the Stale label Jun 16, 2023
@kwen2501 kwen2501 removed the Stale label Jun 23, 2023
@kwen2501
kwen2501 force-pushed the remove_dev_sync_from_barrier branch from 791b958 to 8393604 Compare June 23, 2023 23:41
@kwen2501
kwen2501 marked this pull request as ready for review June 23, 2023 23:42
@wconstab

Copy link
Copy Markdown
Contributor

is there a way to get more confidence about this change? or could we offer perhaps an env to restore the old behavior if someone hits a bug? idk..

@kumpera kumpera left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It would be great if we update the documentation as well to properly explain this behavior.

Additionally, we should note this potentially breaking change in the release notes.

for (auto& device : devices_) {
gpuGuard.set_index(device.index());
AT_CUDA_CHECK(cudaDeviceSynchronize());
// `dist.barrier()` only requires all CPU processes to enter this

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should take this chance to update the documentation of dist::barrier to cover NCCL and explain the expected behavior around CPU and accelerators.

@kumpera kumpera added topic: bc breaking topic category topic: bug fixes topic category labels Jun 25, 2023

@kumpera kumpera left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM.

We should make sure this makes into the release notes for the next PT.

@github-actions

Copy link
Copy Markdown
Contributor

Looks like this PR hasn't been updated in a while so we're going to go ahead and mark this as Stale.
Feel free to remove the Stale label if you feel this was a mistake.
If you are unable to remove the Stale label please contact a maintainer in order to do so.
If you want the bot to never mark this PR stale again, add the no-stale label.
Stale pull requests will automatically be closed after 30 days of inactivity.

@github-actions github-actions Bot added the Stale label Sep 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release notes: distributed (c10d) release notes category topic: bc breaking topic category topic: bug fixes topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants