Skip to content

[cherry-pick] Fix put_along_axis grad kernel crash for integer div-by-zero…#78621

Open
wangbingguang2026 wants to merge 1 commit intoPaddlePaddle:release/3.3from
wangbingguang2026:cherry-pick/put_along_axis_fix_to_3.3
Open

[cherry-pick] Fix put_along_axis grad kernel crash for integer div-by-zero…#78621
wangbingguang2026 wants to merge 1 commit intoPaddlePaddle:release/3.3from
wangbingguang2026:cherry-pick/put_along_axis_fix_to_3.3

Conversation

@wangbingguang2026
Copy link
Copy Markdown
Contributor

@wangbingguang2026 wangbingguang2026 commented Apr 9, 2026

PR Category

Operator Mechanism

PR Types

Bug fixes

Description

devPR:#78482

是否引起精度变化

… and 0-size input (PaddlePaddle#78482)

* [BugFix] Fix put_along_axis grad kernel crash for integer div-by-zero and 0-size input

Fix two crash bugs in put_along_axis backward:

1. SIGFPE in reduce="mul" grad when integer divisor is zero (CPU & GPU)
2. Out-of-bounds memory access in CPU grad kernel when input has 0-size dim

Add unit tests covering both scenarios.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* [BugFix] Fix codestyle and test issues in put_along_axis fix

- clang-format: break long line in gather_scatter_functor.cu
- ruff-format: reformat test_put_along_axis_op.py
- Fix test_uint8_cpu: integer types do not support autograd (sum_grad
  kernel not registered for uint8/int32/int64), change to forward-only
  verification to avoid NotFoundError in CI

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* [BugFix] Add float32 backward test for put_along_axis div-by-zero guard

Add TestPutAlongAxisMulFloat32DivByZeroGrad to exercise the new
zero-divisor guards in gather_scatter_functor.cc/.cu:
- test_x_grad_with_zero_in_x: covers x==0 branch in input_grad kernel
- test_value_grad_with_zero_in_value: covers value==0 branch in value_grad kernel

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* [BugFix] Force CPU placement in float32 div-by-zero grad test for coverage

The TestPutAlongAxisMulFloat32DivByZeroGrad test was not covering
gather_scatter_functor.cc because tensors defaulted to GPU on CI
machines. Add explicit place=paddle.CPUPlace() to ensure the CPU
backward kernel path is exercised.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* [BugFix] Improve patch coverage for put_along_axis grad fix

1. gather_scatter_functor.cc: split multi-line expression into separate
   statements so gcov can attribute execution counts to each line.
2. test_put_along_axis_op.py: add place=CPUPlace() and loss.backward()
   to TestPutAlongAxisZeroSizeInputGrad so the CPU grad kernel's
   numel==0 early-return path is exercised in Coverage CI.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* [BugFix] Add zero-size x with non-empty indices test for grad kernel coverage

The existing zero-size tests all had indices.numel()==0, which triggers
a Python-level early return and never reaches the C++ grad kernel.
Add a test case with x_shape=[2,0,3] (x.numel()==0) but
idx_shape=[2,1,3] (indices.numel()!=0) so the C++ kernel's
numel==0 early-return guard (lines 38-45) is actually exercised.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
@paddle-bot
Copy link
Copy Markdown

paddle-bot bot commented Apr 9, 2026

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@wangbingguang2026 wangbingguang2026 changed the title [BugFix] Fix put_along_axis grad kernel crash for integer div-by-zero… [cherry-pick] Fix put_along_axis grad kernel crash for integer div-by-zero… Apr 9, 2026
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (release/3.3@52c898e). Learn more about missing BASE report.

Additional details and impacted files
@@               Coverage Diff               @@
##             release/3.3    #78621   +/-   ##
===============================================
  Coverage               ?   100.00%           
===============================================
  Files                  ?         2           
  Lines                  ?        16           
  Branches               ?         0           
===============================================
  Hits                   ?        16           
  Misses                 ?         0           
  Partials               ?         0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@wangbingguang2026
Copy link
Copy Markdown
Contributor Author

/re-run all-failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants