Repository navigation
Conversation
PR Status: Approved 🚀Please fix all CI failures and trigger merge by commenting "@pytorchbot merge". ✅ AUTOMATED REVIEW - OUTDATED (earlier commit) - Ready for human review:
Findings (3): Reviewed commit: 🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/197194
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 27ee711 with merge base a4b3692 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
| // shutdown). ncclEpGroupDestroy synchronizes and deregisters windows. | ||
| try { | ||
| ncclEpGroupDestroy(reinterpret_cast<ncclEpGroup_t>(group)); | ||
| } catch (const std::exception&) {} |
There was a problem hiding this comment.
Should at least log to info, no?
| if (handle) { | ||
| try { | ||
| ncclEpHandleDestroy(reinterpret_cast<ncclEpHandle_t>(handle)); | ||
| } catch (const std::exception&){} |
a2ada21 to
803c3f9
Compare
|
@claude review this PR |
|
Claude finished @Skylion007's task in 1m 59s —— View job The window-offset fix is correct, but I'm asking for changes: the fix doesn't validate the counter tensor the caller passes in, the regression coverage depends on test order, and it only covers the PR review detailsPR Review: #197194SummaryThe PR does three things:
The offset math is correct. Code Quality
Testing
Needs discussion (low confidence)
RecommendationRequest Changes The main blockers are the missing validation of the caller's counter (line 212) and a regression test that doesn't depend on test order. The window-offset change can go in as is. |
|
@claude could you review this again? |
|
Claude encountered an error after 21s —— View job I'll analyze this and get back to you. |
|
@pytorchbot rebase |
|
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
|
Successfully rebased |
6955373 to
4cd88f6
Compare
|
@claude review this PR |
|
Claude finished @Skylion007's task in 1m 22s —— View job The follow-up commits fix every blocker from my last review, and only minor items are left, so I recommend approving. PR review detailsWhat changed since the last review
Correctness
Minor / nits (none blocking)
RecommendationApprove. I read the code but didn't run the tests here (they need multiple H100s). Dr. CI shows no failures on |
4cd88f6 to
1e3fd98
Compare
There was a problem hiding this comment.
Automated review of 1e3fd98: nothing blocking; ready for human review.
The PR binds a live int32 expert counter to every HT FLAT NCCL EP handle and keeps it alive on the handle, fixes the zero-copy win_offset so it no longer lands in the signal pad, and adds a _cleanup_worker hook so tests release cached TokenSwitchNCCL objects before destroy_process_group. Recommendation: Approve. Both earlier blocking findings and the maintainer's comments are fixed at HEAD, and every remaining point is non-blocking.
⚪ 3 non-blocking findings
Non-blocking: the combined recv_expert_counter check tests dim() == 1, but its message reports only dtype, device and numel. In the torch.zeros((1, 1), dtype=torch.int32) case the test exercises, it prints "...1D int32 tensor on cuda:N with 1 elements; got Int on cuda:N with 1 elements". Every field it shows matches, so nothing tells the user the shape is wrong. It also raises RuntimeError, while the topk_idx dtype check just above (:181) uses TORCH_CHECK_TYPE and the EpTensor checks use TORCH_CHECK_VALUE. Fix: split it into TORCH_CHECK_TYPE for dtype and TORCH_CHECK_VALUE for dim/numel/device, print expert_counter.sizes(), and update test_create_routing_invalid_counts, which expects RuntimeError for all five cases.
Non-blocking: the new expert_counter block (lines 195-219) uses 2-space indentation. The rest of the function and file uses 4 spaces, and the CLANGFORMAT lint does not cover .cu files.
Non-blocking: ~NcclEpGroup and ~NcclEpHandle (lines 120-136) still call ncclEpGroupDestroy / ncclEpHandleDestroy without a shutdown guard. The other symm_mem allocation destructors check should_skip_cuda_cleanup(device_idx) (CUDASymmetricMemoryUtils.cpp:23) before touching CUDA/NCCL during interpreter finalization, e.g. NCCLSymmetricMemory.cu:66 and :366, CUDASymmetricMemory.cu:98. So a TokenSwitchNCCL held in a module-level global, or one that outlives a failed test (_cleanup_worker runs only on a clean exit), still calls into the library at shutdown. This PR did not introduce the problem, but the guard is worth adding now that these destructors are being hardened.
This review is AI-generated and advisory. Each new automated review replaces the previous one. Report a bad review
Withdrawn: the automated review of 1e3fd98 found nothing blocking.
kwen2501
left a comment
There was a problem hiding this comment.
Looks good. The expert-counter validation and handle ownership of the counter, zero-copy window offset calculation, and clean-exit teardown ordering look correct. Reviewed at 1e3fd98; multi-GPU tests were not run as part of this review.
|
@pytorchbot merge |
Merge failedReason: Approvers from one of the following sets are needed:
|
Reusing a `TokenSwitchNCCL` group across tests mixed HT FLAT handles
that supplied `RECV_EXPERT_COUNTER` with ones that did not. That
switched NCCL EP from the pec scan kernel to nopec, which then hit a
CUDA illegal address on the next `create_routing`. Always bind a live
`int32` expert-counter buffer (caller-owned or internally allocated) and
keep it on the handle for the metadata kernel's lifetime. Store
`num_local_experts` on the group so a missing caller counter can
allocate that buffer.
Zero-copy dispatch/combine also computed `win_offset` as data_ptr minus
the data-buffer base, which skips the signal pad at the start of the
NCCL window. Use `get_window_offset()` plus storage_offset. Tests call
`symm_mem.set_backend("NCCL")` so that path is actually exercised.
Test Plan:
```
python test/distributed/test_token_switch.py -v
```
28 tests OK on nccl and nccl2.
Authored with Grok 4.6 Extra High.
Signed-off-by: Masaki Kozuki <[email protected]>
Authored with Grok 4.6 Extra High. Signed-off-by: Masaki Kozuki <[email protected]>
NCCL EP writes per-expert counts into the caller's tensor, but the wrapper accepted tensors with an invalid shape, dtype, size, or device. Validate the counter before binding it so a short buffer cannot cause an out-of-bounds device write. Check expert divisibility before creating the collective group and simplify deconstructor error handling. Authored with GPT-6 Sol Medium Signed-off-by: Masaki Kozuki <[email protected]>
…h in tests The review bot flagged two things on this PR. First, TokenSwitch.create_routing documented per_expert_token_counts as "length >= local experts", but nccl_ep_create_handle now requires exactly num_experts // world_size elements, so a caller following the docstring would hit a RuntimeError. The docstring now states the exact length, matching the check and test_create_routing_invalid_counts. Second, the warn-in-destructor path in nccl_ep.cu was justified by cached TokenSwitch objects outliving destroy_process_group, which is a test lifetime bug rather than something the C++ should paper over. The cached switches live in class attributes that MultiProcContinuousTest never clears before destroying the process group. Add a no-op _cleanup_worker() hook that runs in each worker just before destroy_process_group, and override it in TokenSwitchNCCLTest and TokenSwitchRoutingDtypeTest to drop the cached switches. The destructors keep warning instead of throwing as a defensive fallback, and the comment no longer claims to handle a torn-down comm. An alternative was to clear the caches in a final test method, but that depends on test ordering, so a worker-level hook is more robust. The hook is in the shared common_distributed.py, a small addition that other MultiProcContinuousTest users can ignore. Test Plan: ``` ninja -C build _nccl_ep python test/distributed/test_token_switch.py -v ``` Ran on a 4x GB200 node: 93 tests, OK, none skipped, including the new counter-validation, handle-reuse and storage-offset tests. ruff check and ruff format --check pass on the changed Python files. This change was authored with an AI assistant (Claude Code). Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1e3fd98 to
27ee711
Compare
|
@claude is this ready to land? |
|
Claude finished @eqy's task in 39s —— View job Yes, it looks ready to land: it has three approvals (kwen2501, fduwjj, kapilsh), CI at HEAD DetailsStatus
Why the 11-06 merge attempt failedThe bot rejected the merge on 11-06, saying it needed approvers from the Metamates, Core Reviewers or Core Maintainers sets, and listed Core Maintainers as the failing rule. I can't see from here why kwen2501 and fduwjj didn't satisfy it. The PR now has a third approval and a fresh green run, so retry Non-blocking leftovers (fine as follow-ups)
I only read the code; I didn't run the multi-GPU tests. The author's test plan reports 93 tests passing on 4x GB200. |
|
@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 |
Reusing a
TokenSwitchNCCLgroup across tests mixed HT FLAT handles that suppliedRECV_EXPERT_COUNTERwith ones that did not. That switched NCCL EP from the pec scan kernel to nopec, which then hit a CUDA illegal address on the nextcreate_routing. Always bind a liveint32expert-counter buffer (caller-owned or internally allocated) and keep it on the handle for the metadata kernel's lifetime.Zero-copy dispatch/combine also computed
win_offsetas data_ptr minus the data-buffer base, which skips the signal pad at the start of the NCCL window. Useget_window_offset()plus storage_offset.Authored with Grok 4.6 Extra High.