Repository navigation
[Operator Mechanism] Fix topk returning NaN for an empty reduction axis #79799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
wanghuancoder
merged 7 commits into
PaddlePaddle:develop
from
feixi139:fix_topk_empty_axis
Oct 13, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
decab7d
[PHI] Fix topk returning NaN for an empty reduction axis
feixi139 018d129
[PHI] Add unit test for topk empty reduction axis
feixi139 77b1f47
[PHI] Cover topk empty-axis throw on CPU/GPU/XPU explicitly
feixi139 afa6656
[PHI] Cover the CUDA topk kernel in the empty-axis throw
feixi139 05f3979
Merge branch 'PaddlePaddle:develop' into fix_topk_empty_axis
feixi139 ab41c76
[PHI] Pin topk empty-axis throw to its own error message
feixi139 751fc65
Merge branch 'PaddlePaddle:develop' into fix_topk_empty_axis
feixi139 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
本 PR 将「空规约轴(
x.numel()==0且输出非空)」从静默返回全 NaN 改为抛出InvalidArgument,属于用户可见的行为变化,但未新增覆盖该异常路径的测试。现有
test/legacy_test/test_top_k_v2_op.py中[0, 20]、axis=1的用例,其规约轴长度为 20(非空),空的是 batch 维,走的是更早的out->numel()==0合法空输出分支,并不能触发本次改动的分支。建议在
test/legacy_test/test_top_k_v2_op.py(及/或test_top_k_op.py)补充异常路径断言,例如x = paddle.empty([1024, 0]); paddle.topk(x, 10, axis=-1)应抛InvalidArgument,以固化 CPU/GPU/XPU 三端一致的新行为并防止回归。There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
新提交
018d129已在test/legacy_test/test_top_k_v2_op.py::TestTopKAPI.test_errors补充异常路径断言:paddle.empty([1024, 0])取k=10, axis=-1断言抛ValueError,并新增[0, 5]合法空输出返回[0, 3]的回归断言。与相邻k=0/k=-1用例一致,覆盖了本次行为变化。该问题已解决。