Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/199732
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 3ef5f2e with merge base b8ef869 ( 🟢 GREEN LIGHT - PR approved to be merged without human review:
reason: This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@claude review this PR |
|
Claude finished @Skylion007's task in 43s —— View job The fix is correct and I'd approve it. My only note is a small wording issue in the new code comment. Review detailsPR Review: #199732SummaryThe CUDA fast path for Code Quality
RecommendationApprove The fix is minimal and correct, and the regression test hits both divide-by-zero paths on CUDA. |
|
@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 |
> AI-assisted change prepared with Claude Code. It was split out of pytorch#199430 so it can land on main independently. > > On CUDA, `split_with_sizes_copy` crashed the process when its input had no elements (since pytorch#117203). The fast path's launch size math computed zero chunks per block and then divided by it, so any call with an empty input that took the fast path crashed. The CUDA fast path now returns early for empty inputs, since there is nothing to copy. > > Test Plan: the new empty cases in `test_split_with_sizes_copy_out`, including all-empty splits, crash the process without the fix (found when the fix was written for pytorch#199430) and pass with it. The test runs on CUDA when a GPU is available. The local build predates main, so the test ran on an older main (ff18741) whose build includes this kernel change; `TensorShape.cu` is unchanged on main since then. > ```bash > python test/test_torch.py -k test_split_with_sizes_copy_out > ``` Pull Request resolved: pytorch#199732 Approved by: https://github.com/pytorchgreenlight, https://github.com/Skylion007
Fixes #5661 ### Root cause `split_with_sizes_copy_out_xpu_contiguous_no_cast` divides by values derived from self.numel(). For an empty self, get_num_chunks computes 0 / 0 when the split dim has size 0. When num_chunks is 0, chunks_per_group is also 0, so ceil_div(iter_factor, chunks_per_group) divides by zero. Both cases raise SIGFPE and kill the interpreter. ### Fix CUDA has the same launch-size math and fixed the crash in pytorch/pytorch#199732 with an early return when self.numel() == 0. Every output is empty in that case, so there is nothing to copy. This PR adds the same guard in the same place, after the caller has validated and resized the outputs, so the XPU behavior matches CUDA. ### Testing It also updates `test_split_with_sizes_copy_out` in test/xpu/test_torch_xpu.py to the current upstream version. That version is device-generic (TestTorchDeviceType) and includes the empty-input cases. The old device-less copy in TestTorch is removed. The CUDA-graph part lives in upstream TestTorchCUDA and was not ported. ``` python test/test_torch.py TestTorchDeviceTypeXPU.test_split_with_sizes_copy_out_xpu # on upstream python test/xpu/test_torch_xpu.py -k split_with_sizes_copy_out ``` ### Steps after merge Create PR to PyTorch upstream to unskip test_split_with_sizes_copy_out in test_torch.py --------- Co-authored-by: Damian Janusz <[email protected]> Co-authored-by: Benedykt Bela <[email protected]>
test_split_with_sizes_copy_out was skipped on XPU because split_with_sizes_copy.out crashed with SIGFPE on empty inputs (intel/torch-xpu-ops#5661). The XPU kernel computed launch sizes by dividing by values derived from self.numel(); for an empty input the chunk count was 0, so both get_num_chunks and ceil_div(iter_factor, chunks_per_group) divided by zero. The kernel now returns early when self.numel() == 0 (every output is empty, so there is nothing to copy), matching the CUDA fix in pytorch#199732. That fix is in intel/torch-xpu-ops#5912. This change only removes the now-unneeded @skipIfXpu so the test runs on XPU. Only the skip decorator is removed. Fixing the kernel in the same PR is not possible because the XPU ops live in the torch-xpu-ops repo. Test Plan: (fill in after running; requires a build with torch-xpu-ops#5912) python test/test_torch.py -k test_split_with_sizes_copy_out
Stack from ghstack (oldest at bottom):