Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/199439
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 1ec31a0 with merge base 8bf2072 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@claude review this PR. Note that you already did a review here: #191827 (comment) |
|
Claude finished @galv's task in 2m 34s —— View job The fix only reaches the Full reviewPR Review: #199439SummaryThe PR adds Code Quality
Thread Safety
Testing
RecommendationNeeds Discussion The PR fixes only |
Any code that doesn't set NCCL_GRAPH_MIXING_SUPPORT=0 will fail with an error at cudaGraphInstantiate() time, so this isn't a concern. An explicit warning about event record and wait nodes not being supported inside of conditional nodes will be part of the error message. This work also allows us to use child graph nodes in pytorch with NCCL as well, which I may be interested in for other reasons. Non-conditional child graphs are allowed to use event record nodes internally. I don't think this is a concern. |
|
I was unaware of the legacy nccl vs nccl2 distinction, which apparently showed up at the end of August, after the original PR. I will need to take some time to understand that. |
|
Default backend is nccl2 now, so it's ok for fixes to only go into nccl2 backend |
daa69e8 to
95ee8e9
Compare
Build on PR #191827 to prevent cudaErrorStreamCaptureMerge when NCCL runs in both an enclosing CUDA graph capture and a conditional-node body. There were a few issues with that PR. First of all, as identified in #191827 (comment), the tests did not actually verify that the constructed graphs were functionally correct by running them. The underlying problem can be worked around by running nccl with the environment variable setting NCCL_GRAPH_MIXING_SUPPORT=0. The original PR #191827 also failed to test that more than 32 nested torch.cond()'s would work properly, which was the original motivation for having a separate pool of streams from the normal stream pool. test_nccl_cudagraph_nested_conditionals now tests this. There was another problem with the separate pool of streams. This pool was originally an instance variable of the ProcessGroup object. Destroying it would destroy the underlying cudaStream_t's, but recordStream() is run on some tensors as part of ProcessGroupNCCL's internal implementation. Once these tensors are destroyed, a cudaEventRecord() will be called on these now deleted cudaStream_t's, causing undefined behavior if the user has already destroyed the process group. The obvious solution is to make sure that cudaStream_t's in this pool are alive for the entirety of the process. I don't think this will cause any serious mutex contention problems, since usage of multiple process groups concurrently from multiple CPU threads is not common these days. test_cudagraph_stream_outlives_process_group tests that the behavior is correct. Test Plan --------- Built an editable Release configuration with CUDA 13.3 and NCCL 2.30.7 for two A100 GPUs. The full operation suite passed 33 tests with two existing FP8 skips; both lifetime variants passed. Setting graph mixing to 1 in the parent deliberately verifies that the fresh-worker fixtures override it to 0. The toolkit library path lets NVRTC locate its builtins for the pre-existing complex-tensor comparison test. ```bash timeout -k 5s 240s env CUDA_VISIBLE_DEVICES=0,1 OMP_NUM_THREADS=1 \ NCCL_GRAPH_MIXING_SUPPORT=1 \ TORCH_DIST_USE_NCCL2=0 TORCH_NCCL_WAIT_TIMEOUT_DUMP_MILSEC=0 \ LD_LIBRARY_PATH="/home/scratch.dgalvez_ent/cuda-installs/cuda-13.3.1/lib64${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" \ .venv/bin/python test/distributed/test_c10d_ops_nccl.py -v \ > agent_space/test_nccl_ops_process_wide_pool_with_nvrtc.log 2>&1 timeout -k 5s 180s env CUDA_VISIBLE_DEVICES=0,1 OMP_NUM_THREADS=1 \ NCCL_GRAPH_MIXING_SUPPORT=1 \ TORCH_NCCL_WAIT_TIMEOUT_DUMP_MILSEC=0 \ .venv/bin/python test/distributed/test_c10d_nccl.py \ ProcessGroupNCCLCaptureStreamTest -v \ > agent_space/test_stream_lifetime_after_build.log 2>&1 env PYTHONPATH=$PWD/agent_space/lint_deps PATH=$PWD/.venv/bin:$PATH \ MAX_JOBS=4 spin lint -a -- --skip CLANGTIDY \ test/distributed/test_c10d_ops_nccl.py \ test/distributed/test_c10d_nccl.py \ torch/csrc/distributed/c10d/ProcessGroupNCCL.cpp \ torch/csrc/distributed/c10d/ProcessGroupNCCL.hpp \ > agent_space/lint_before_commit.log 2>&1 ``` Clang-tidy is excluded because of previously identified findings in unchanged code. The remaining targeted linters pass. Prepared with assistance from Codex. Co-authored-by: Rohit Singh Rathaur <[email protected]>
Remove race condition by joining stream before returning it from getNCCLStreamForCapture(). Copy priority of defaultStream rather than reconstructing it. Remove redundant test code. Parameterize over nccl-legacy and nccl2, though I may just remove the nccl-legacy support if it isn't in use any more.
95ee8e9 to
f6485b4
Compare
Previous changes were just too hard to read.
f6485b4 to
2e43a0b
Compare
|
@RohitRathore1 @d4l3k and @ngimel this is good for review now. |
|
@claude review this PR |
|
Claude finished @galv's task in 1m 57s —— View job The pool logic looks correct and both earlier maintainer requests are in (flat map, Full reviewPR Review: #199439SummaryOn Testing
Code Quality
RecommendationRequest Changes The lifetime regression test and its comment claim coverage the code doesn't provide; fix the test or rename it. The redundant capture check is a one-line cleanup on the path this PR is specifically meant to keep fast. |
|
claude comments were right. Pushed some small fixes. |
|
Pretty sure submodule updates are unintended |
ngimel
left a comment
There was a problem hiding this comment.
Don't land with submodule updates
Restore the PR base revisions after stale local submodule checkouts were staged into the review-fix commit. Align the local checkouts as well to avoid reintroducing these unrelated dependency changes. Test Plan: ```bash spin quicklint -- -a third_party/flash-attention third_party/ideep git diff --cached --check --ignore-submodules=none ``` Verified both pins against the base side of PR #199439's diff. Prepared with assistance from an AI coding assistant.
|
@pytorchbot merge |
Merge startedYour 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 |
This is built on PR #191827.
There were a few issues with that PR.
First of all, as identified in
#191827 (comment), the tests did not actually verify that the constructed graphs were functionally correct by running them. The underlying problem can be worked around by running nccl with the environment variable setting NCCL_GRAPH_MIXING_SUPPORT=0.
The original PR #191827 also failed to test that more than 32 nested torch.cond()'s would work properly, which was the original motivation for having a separate pool of streams from the normal stream pool. test_nccl_cudagraph_nested_conditionals now tests this.
There was another problem with the separate pool of streams. This pool was originally an instance variable of the ProcessGroup object. Destroying it would destroy the underlying cudaStream_t's, but recordStream() is run on some tensors as part of ProcessGroupNCCL's internal implementation. Once these tensors are destroyed, a cudaEventRecord() will be called on these now deleted cudaStream_t's, causing undefined behavior if the user has already destroyed the process group. The obvious solution is to make sure that cudaStream_t's in this pool are alive for the entirety of the process. I don't think this will cause any serious mutex contention problems, since usage of multiple process groups concurrently from multiple CPU threads is not common these
days. test_cudagraph_stream_outlives_process_group tests that the behavior is correct.
Test Plan
Built an editable Release configuration with CUDA 13.3 and NCCL 2.30.7 for two A100 GPUs. The full operation suite passed 33 tests with two existing FP8 skips; both lifetime variants passed. Setting graph mixing to 1 in the parent deliberately verifies that the fresh-worker fixtures override it to 0. The toolkit library path lets NVRTC locate its builtins for the pre-existing complex-tensor comparison test.
timeout -k 5s 240s env CUDA_VISIBLE_DEVICES=0,1 OMP_NUM_THREADS=1 \ NCCL_GRAPH_MIXING_SUPPORT=1 \ TORCH_DIST_USE_NCCL2=0 TORCH_NCCL_WAIT_TIMEOUT_DUMP_MILSEC=0 \ LD_LIBRARY_PATH="/home/scratch.dgalvez_ent/cuda-installs/cuda-13.3.1/lib64${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" \ .venv/bin/python test/distributed/test_c10d_ops_nccl.py -v \ > agent_space/test_nccl_ops_process_wide_pool_with_nvrtc.log 2>&1 timeout -k 5s 180s env CUDA_VISIBLE_DEVICES=0,1 OMP_NUM_THREADS=1 \ NCCL_GRAPH_MIXING_SUPPORT=1 \ TORCH_NCCL_WAIT_TIMEOUT_DUMP_MILSEC=0 \ .venv/bin/python test/distributed/test_c10d_nccl.py \ ProcessGroupNCCLCaptureStreamTest -v \ > agent_space/test_stream_lifetime_after_build.log 2>&1 env PYTHONPATH=$PWD/agent_space/lint_deps PATH=$PWD/.venv/bin:$PATH \ MAX_JOBS=4 spin lint -a -- --skip CLANGTIDY \ test/distributed/test_c10d_ops_nccl.py \ test/distributed/test_c10d_nccl.py \ torch/csrc/distributed/c10d/ProcessGroupNCCL.cpp \ torch/csrc/distributed/c10d/ProcessGroupNCCL.hpp \ > agent_space/lint_before_commit.log 2>&1Clang-tidy is excluded because of previously identified findings in unchanged code. The remaining targeted linters pass.
Prepared with assistance from Codex.
Fixes #191681
cc @gujinghui @PenghuiCheng @XiaobingSuper @jianyuh @jgong5 @mingfeima @sanchitintel @ashokei @jingxu10 @min-jean-cho @yanbing-j @Guobing-Chen @Xia-Weiwen @snadampal @mcarilli @ezyang @eellison @penguinwu @BoyuanFeng