Repository navigation
Conversation
The channels_last (NHWC) CUDA backward kernel recovered the input pixel coordinates without the padding offset, while its window formulas require padded coordinates (the NCHW kernel adds the offset). For padding > 0 this returned silently wrong input gradients. Add the missing pad offsets and repair test_avg_pool2d_nhwc, which never forwarded its padding argument. Fixes pytorch#188344 Signed-off-by: Ting Sun <[email protected]>
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/188345
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New FailureAs of commit 5013831 with merge base 7649a5b ( NEW FAILURE - The following job has failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
|
|
Looks like the CPU kernel is broken too |
|
RuntimeError: pad should be at most half of effective kernel size, but got pad=2, kernel_size=3 and dilation=1 |
|
Yeah these test cases do not work with CPU style checks. |
|
@Sunt-ing sorry I didn't see this, do you want to try landing yours since my change was reverted? You just need to remove some xfails |
|
Thanks @eqy. I removed the stale I also rebuilt the PR branch on an RTX 4090 and ran: CUDA_VISIBLE_DEVICES= python test/nn/test_pooling.py TestPoolingNNDeviceTypeCPU.test_avg_pool2d_nhwc_cpu_float32
python test/nn/test_pooling.py TestPoolingNNDeviceTypeCUDA.test_avg_pool2d_nhwc_cuda_float32
python test/test_modules.py TestModuleCUDA.test_memory_format_nn_AvgPool2d_cuda_float32All three passed. |
|
@pytorchbot label "release notes: nn" |
|
@pytorchmergebot merge |
|
This PR needs to be approved by an authorized maintainer before merge. |
|
@pytorchmergebot 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 |
Merge failedReason: 1 mandatory check(s) failed. The first few are: Dig deeper by viewing the failures on hud |
|
@pytorchmergebot merge -i |
Merge startedYour change will be merged while ignoring the following 1 checks: pull / linux-jammy-aarch64-py3.10 / build-osdc Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
…ytorch#188345) ## Issue Fixes pytorch#188344 ## Summary The channels_last (NHWC) CUDA backward kernel `avg_pool2d_backward_out_cuda_frame_nhwc` recovered the input pixel coordinates from the flat index without the padding offset (`const int w = (index / channels) % width;`), while the `phstart/phend/pwstart/pwend` window formulas it then uses require padded coordinates. The contiguous (NCHW) kernel `avg_pool2d_backward_out_cuda_frame` adds the offset (`+ pad_w` / `+ pad_h`); the NHWC kernel did not, so for `padding > 0` it mapped each input pixel to the wrong set of output windows and returned silently wrong input gradients. `padding = 0` was unaffected because the two coordinate systems coincide. This adds the missing `+ pad_w` / `+ pad_h`, matching the NCHW kernel. `test_avg_pool2d_nhwc` did not catch this because its `helper` accepted a `padding` argument but never forwarded it to `AvgPool2d` (nor into the grad-output shape), so its `padding=1` / `padding=2` cases actually ran with `padding=0`. This PR forwards `padding` so those cases exercise the path, fixes the one call whose `padding=2, kernel_size=3` combination is invalid once padding is applied (`pad` must be `<= kernel_size / 2`), and adds a `count_include_pad=True` padded case. The repaired test fails on the current kernel and passes with the fix. ## Checklist - [x] Passes lint (`spin fixlint`) - [x] Added/updated tests - [ ] Updated documentation (if applicable) - [ ] Included benchmark results (for PRs impacting perf) ## BC-breaking? No. This corrects silently-wrong gradients; only incorrect outputs change. Pull Request resolved: pytorch#188345 Approved by: https://github.com/eqy
…ytorch#188345) ## Issue Fixes pytorch#188344 ## Summary The channels_last (NHWC) CUDA backward kernel `avg_pool2d_backward_out_cuda_frame_nhwc` recovered the input pixel coordinates from the flat index without the padding offset (`const int w = (index / channels) % width;`), while the `phstart/phend/pwstart/pwend` window formulas it then uses require padded coordinates. The contiguous (NCHW) kernel `avg_pool2d_backward_out_cuda_frame` adds the offset (`+ pad_w` / `+ pad_h`); the NHWC kernel did not, so for `padding > 0` it mapped each input pixel to the wrong set of output windows and returned silently wrong input gradients. `padding = 0` was unaffected because the two coordinate systems coincide. This adds the missing `+ pad_w` / `+ pad_h`, matching the NCHW kernel. `test_avg_pool2d_nhwc` did not catch this because its `helper` accepted a `padding` argument but never forwarded it to `AvgPool2d` (nor into the grad-output shape), so its `padding=1` / `padding=2` cases actually ran with `padding=0`. This PR forwards `padding` so those cases exercise the path, fixes the one call whose `padding=2, kernel_size=3` combination is invalid once padding is applied (`pad` must be `<= kernel_size / 2`), and adds a `count_include_pad=True` padded case. The repaired test fails on the current kernel and passes with the fix. ## Checklist - [x] Passes lint (`spin fixlint`) - [x] Added/updated tests - [ ] Updated documentation (if applicable) - [ ] Included benchmark results (for PRs impacting perf) ## BC-breaking? No. This corrects silently-wrong gradients; only incorrect outputs change. Pull Request resolved: pytorch#188345 Approved by: https://github.com/eqy
…ytorch#188345) ## Issue Fixes pytorch#188344 ## Summary The channels_last (NHWC) CUDA backward kernel `avg_pool2d_backward_out_cuda_frame_nhwc` recovered the input pixel coordinates from the flat index without the padding offset (`const int w = (index / channels) % width;`), while the `phstart/phend/pwstart/pwend` window formulas it then uses require padded coordinates. The contiguous (NCHW) kernel `avg_pool2d_backward_out_cuda_frame` adds the offset (`+ pad_w` / `+ pad_h`); the NHWC kernel did not, so for `padding > 0` it mapped each input pixel to the wrong set of output windows and returned silently wrong input gradients. `padding = 0` was unaffected because the two coordinate systems coincide. This adds the missing `+ pad_w` / `+ pad_h`, matching the NCHW kernel. `test_avg_pool2d_nhwc` did not catch this because its `helper` accepted a `padding` argument but never forwarded it to `AvgPool2d` (nor into the grad-output shape), so its `padding=1` / `padding=2` cases actually ran with `padding=0`. This PR forwards `padding` so those cases exercise the path, fixes the one call whose `padding=2, kernel_size=3` combination is invalid once padding is applied (`pad` must be `<= kernel_size / 2`), and adds a `count_include_pad=True` padded case. The repaired test fails on the current kernel and passes with the fix. ## Checklist - [x] Passes lint (`spin fixlint`) - [x] Added/updated tests - [ ] Updated documentation (if applicable) - [ ] Included benchmark results (for PRs impacting perf) ## BC-breaking? No. This corrects silently-wrong gradients; only incorrect outputs change. Pull Request resolved: pytorch#188345 Approved by: https://github.com/eqy
Issue
Fixes #188344
Summary
The channels_last (NHWC) CUDA backward kernel
avg_pool2d_backward_out_cuda_frame_nhwcrecovered the input pixel coordinates from the flat index without the padding offset (const int w = (index / channels) % width;), while thephstart/phend/pwstart/pwendwindow formulas it then uses require padded coordinates. The contiguous (NCHW) kernelavg_pool2d_backward_out_cuda_frameadds the offset (+ pad_w/+ pad_h); the NHWC kernel did not, so forpadding > 0it mapped each input pixel to the wrong set of output windows and returned silently wrong input gradients.padding = 0was unaffected because the two coordinate systems coincide. This adds the missing+ pad_w/+ pad_h, matching the NCHW kernel.test_avg_pool2d_nhwcdid not catch this because itshelperaccepted apaddingargument but never forwarded it toAvgPool2d(nor into the grad-output shape), so itspadding=1/padding=2cases actually ran withpadding=0. This PR forwardspaddingso those cases exercise the path, fixes the one call whosepadding=2, kernel_size=3combination is invalid once padding is applied (padmust be<= kernel_size / 2), and adds acount_include_pad=Truepadded case. The repaired test fails on the current kernel and passes with the fix.Checklist
spin fixlint)BC-breaking?
No. This corrects silently-wrong gradients; only incorrect outputs change.