KEMBAR78
[PGNCCL] Use non-blocking mode by default in eager init by kwen2501 · Pull Request #138527 · pytorch/pytorch · GitHub
Skip to content

Conversation

@kwen2501
Copy link
Contributor

@kwen2501 kwen2501 commented Oct 21, 2024

Stack from ghstack (oldest at bottom):

Why use non-blocking mode in eager init?

For overlapping comm init and model init, etc.
image

Why can we set non-blocking as default?

If the setting is dangling -- i.e. not passed in by user nor set via env -- ProcessGroupNCCL can have some preferred logic. And torch-level API semantics does not change whether the NCCL comm is blocking or non-blocking (handled within ProcessGroupNCCL).

Why not make non-blocking default for lazy mode as well?

PR #137544 tried it.
Two reasons why that's not preferred today:

  1. It is hard -- too big a blast.
  2. There is no gain by doing lazy init in non-blocking mode, because the right next CPU call is a collective, and we will block there waiting for comm to be ready, so same effect as blocked init, no "opening" compared to eager mode.

cc @H-Huang @awgu @wanchaol @fegin @fduwjj @wz337 @wconstab @d4l3k @c-p-i-o

@pytorch-bot pytorch-bot bot added oncall: distributed Add this issue/PR to distributed oncall triage queue release notes: distributed (c10d) release notes category labels Oct 21, 2024
@pytorch-bot
Copy link

pytorch-bot bot commented Oct 21, 2024

🔗 Helpful Links

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

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 821fc92 with merge base 4c91481 (image):

FLAKY - The following job failed but was likely due to flakiness present on trunk:

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

kwen2501 added a commit that referenced this pull request Oct 21, 2024
}
// 2nd priority: Respect the environment variable
if (nbEnv.has_value()) {
useNonblocking_ = nbEnv.value();
Copy link
Contributor

Choose a reason for hiding this comment

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

hm, do we need to check if bound device id exists here too? i thought we could not enable nonblocking without a bound id? maybe i just got confused by the bundling.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The env of non-blocking existed before we introduce bounded device.

useNonblocking_ = true;
goto print_and_return;
}
// 4th priority: otherwise, nonblocking = false to preserve old behavior
Copy link
Contributor

Choose a reason for hiding this comment

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

lgtm, but i wonder if longer term, is this a path we'd want to add a 'deprecation warning' to start encouraging users to add device_id?

useNonblocking_ = false;

print_and_return:
LOG(INFO) << logPrefix()
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this is ok, but i think its also useful to log which of the config pathways took precedent, in case users want to debug why their nonblocking setting wasn't as expected

Copy link
Contributor

@wconstab wconstab left a comment

Choose a reason for hiding this comment

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

overall lgtm.

@shuqiangzhang
Copy link
Contributor

Nit: Better to add a test case with eager init but without setting the ENV?

@kwen2501
Copy link
Contributor Author

kwen2501 commented Oct 23, 2024

@shuqiangzhang Yeah, that's a good idea. I added a PR on top to parameterize tests in test_c10d_nccl.py to do both lazy and eager inits. See #138644.

@kwen2501
Copy link
Contributor Author

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Oct 23, 2024
@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

@jeanschmidt
Copy link
Contributor

@pytorchbot revert -m "Seems to have introduce regressions on main, pull / linux-focal-cuda11.8-py3.10-gcc9 / test (distributed, 2, 3, linux.g4dn.12xlarge.nvidia.gpu) checking if revert will do" -c nosignal

@pytorchmergebot
Copy link
Collaborator

@pytorchbot successfully started a revert job. Check the current status here.
Questions? Feedback? Please reach out to the PyTorch DevX Team

pytorchmergebot added a commit that referenced this pull request Oct 23, 2024
)"

This reverts commit 8fbf866.

Reverted #138527 on behalf of https://github.com/jeanschmidt due to Seems to have introduce regressions on main, pull / linux-focal-cuda11.8-py3.10-gcc9 / test (distributed, 2, 3, linux.g4dn.12xlarge.nvidia.gpu) checking if revert will do ([comment](#138527 (comment)))
@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged while ignoring the following 1 checks: trunk / linux-focal-rocm6.2-py3.10 / test (distributed, 1, 1, linux.rocm.gpu)

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

@huydhn
Copy link
Contributor

huydhn commented Oct 27, 2024

@pytorchbot revert -m 'Sorry for reverting your change, but it is failing on ROCm' -c weird

distributed/test_c10d_nccl.py::ProcessGroupNCCLGroupTest::test_extra_cuda_context GH job link HUD commit link

@pytorchmergebot
Copy link
Collaborator

@pytorchbot successfully started a revert job. Check the current status here.
Questions? Feedback? Please reach out to the PyTorch DevX Team

pytorchmergebot added a commit that referenced this pull request Oct 27, 2024
)"

This reverts commit 07e30ea.

Reverted #138527 on behalf of https://github.com/huydhn due to Sorry for reverting your change, but it is failing on ROCm ([comment](#138527 (comment)))
@pytorchmergebot
Copy link
Collaborator

@kwen2501 your PR has been successfully reverted.

@kwen2501
Copy link
Contributor Author

@huydhn Thanks for the notification. It seems test_extra_cuda_context was flaky for rocm since 10/23, before my PR's landed. So I disabled that test. And relanding this PR.

@kwen2501
Copy link
Contributor Author

@pytorchbot merge -f "test_extra_cuda_context was flaky for rocm since 10/23, before my PR's landed. So I disabled that test"

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use -f as last resort and instead consider -i/--ignore-current to continue the merge ignoring current failures. This will allow currently pending tests to finish and report signal before the merge.

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

SamGinzburg pushed a commit that referenced this pull request Oct 28, 2024
### Why use non-blocking mode in eager init?
For overlapping comm init and model init, etc.
![image](https://github.com/user-attachments/assets/9b0bf7a9-be26-4d16-827b-dbe861f083cd)

### Why can we set non-blocking as default?
If the setting is dangling -- i.e. not passed in by user nor set via env -- `ProcessGroupNCCL` can have some preferred logic. And torch-level API semantics does not change whether the NCCL comm is blocking or non-blocking (handled within `ProcessGroupNCCL`).

### Why not make non-blocking default for lazy mode as well?
PR #137544 tried it.
Two reasons why that's not preferred today:
1. It is hard -- too big a blast.
2. There is no gain by doing lazy init in non-blocking mode, because the right next CPU call is a collective, and we will block there waiting for comm to be ready, so same effect as blocked init, no "opening" compared to eager mode.

Pull Request resolved: #138527
Approved by: https://github.com/wconstab
ghstack dependencies: #137855, #138488, #138374, #138384
SamGinzburg pushed a commit that referenced this pull request Oct 28, 2024
)"

This reverts commit 8fbf866.

Reverted #138527 on behalf of https://github.com/jeanschmidt due to Seems to have introduce regressions on main, pull / linux-focal-cuda11.8-py3.10-gcc9 / test (distributed, 2, 3, linux.g4dn.12xlarge.nvidia.gpu) checking if revert will do ([comment](#138527 (comment)))
pytorchmergebot pushed a commit that referenced this pull request Oct 28, 2024
Resolve comment #138527 (comment)

There was a split-vs-P2P bug:
When P2P comm creation invokes `getNCCLComm`, it may see a `split_from` options which is meant for the previous PG creation. Then the P2P comm creation may use `ncclCommSplit` and hang, because not all ranks join this call. The bug slips previously/today because there is no CI test with the following recipe: eager init + new group + P2P in that new group.

Pull Request resolved: #139013
Approved by: https://github.com/shuqiangzhang
pytorchmergebot pushed a commit that referenced this pull request Nov 2, 2024
Resolve comment #138527 (comment)

There was a split-vs-P2P bug:
When P2P comm creation invokes `getNCCLComm`, it may see a `split_from` options which is meant for the previous PG creation. Then the P2P comm creation may use `ncclCommSplit` and hang, because not all ranks join this call. The bug slips previously/today because there is no CI test with the following recipe: eager init + new group + P2P in that new group.

Pull Request resolved: #139013
Approved by: https://github.com/shuqiangzhang
kwen2501 added a commit that referenced this pull request Nov 2, 2024
Resolve comment #138527 (comment)

There was a split-vs-P2P bug:
When P2P comm creation invokes `getNCCLComm`, it may see a `split_from` options which is meant for the previous PG creation. Then the P2P comm creation may use `ncclCommSplit` and hang, because not all ranks join this call. The bug slips previously/today because there is no CI test with the following recipe: eager init + new group + P2P in that new group.

cc H-Huang awgu wanchaol fegin fduwjj wz337 wconstab d4l3k c-p-i-o

[ghstack-poisoned]
rahulsingh-intel pushed a commit to rahulsingh-intel/pytorch that referenced this pull request Nov 5, 2024
…#139013)

Resolve comment pytorch#138527 (comment)

There was a split-vs-P2P bug:
When P2P comm creation invokes `getNCCLComm`, it may see a `split_from` options which is meant for the previous PG creation. Then the P2P comm creation may use `ncclCommSplit` and hang, because not all ranks join this call. The bug slips previously/today because there is no CI test with the following recipe: eager init + new group + P2P in that new group.

Pull Request resolved: pytorch#139013
Approved by: https://github.com/shuqiangzhang
@github-actions github-actions bot deleted the gh/kwen2501/81/head branch November 28, 2024 02:13
pytorchmergebot pushed a commit that referenced this pull request Dec 9, 2024
Resolve comment #138527 (comment)

There was a split-vs-P2P bug:
When P2P comm creation invokes `getNCCLComm`, it may see a `split_from` options which is meant for the previous PG creation. Then the P2P comm creation may use `ncclCommSplit` and hang, because not all ranks join this call. The bug slips previously/today because there is no CI test with the following recipe: eager init + new group + P2P in that new group.

Pull Request resolved: #139013
Approved by: https://github.com/shuqiangzhang
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 oncall: distributed Add this issue/PR to distributed oncall triage queue release notes: distributed (c10d) release notes category Reverted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants