[Operator Mechanism] Fix index_select empty-axis validation#79509
Open
cangtianhuang wants to merge 2 commits into
Open
[Operator Mechanism] Fix index_select empty-axis validation#79509cangtianhuang wants to merge 2 commits into
index_select empty-axis validation#79509cangtianhuang wants to merge 2 commits into
Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
risemeup1111
approved these changes
Jul 19, 2026
risemeup1111
left a comment
Contributor
There was a problem hiding this comment.
已复查,未发现需要阻塞合入的问题;本地窄测因环境缺少 numpy 未能执行。
Powered by Nyanpasu with gpt-5.5 xhigh, please check the suggestions carefully.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #79509 +/- ##
==========================================
Coverage ? 75.00%
==========================================
Files ? 1
Lines ? 4
Branches ? 0
==========================================
Hits ? 3
Misses ? 1
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
risemeup1111
approved these changes
Jul 20, 2026
risemeup1111
left a comment
Contributor
There was a problem hiding this comment.
已复查当前提交,这次只是补充 index_select 的 int32 测试覆盖,没有看到新的回归点。
Powered by Nyanpasu with gpt-5.5 xhigh, please check the suggestions carefully.
Contributor
Author
|
/re-run all-failed |
Member
|
覆盖率未达标为cpu代码 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
PR Category
Operator Mechanism
PR Types
Bug fixes
Description
问题描述
对于
paddle.index_select(x, index, axis=0, name=None)而言,输入应满足以下约束:index为空时,不读取x中的任何元素;index非空时,则应存在可选择的元素;如果所选择的轴
x[axis] == 0,则合法索引区间为空,对于任意非空index均应报错。本次排查发现,CPU/GPU/XPU 在 0size 快速路径下,均未正确处理“选择轴为空且 Index 非空”输入,因此一并修改并补充单测。output.numel() == 0时 early return此时输出 shape 为
[1, 0],output.numel() == 0:选择轴axis=0由0替换为index.numel()==1,另一维仍为0。虽然输出 shape 形状推导正确,但axis=0的输入轴长度为 0,而index=[0]非空,语义上不存在合法可选元素。解决方案
原有实现根据
output.numel() == 0判断 0size 并直接返回:其中,负 axis 的归一化、以及选择轴的相关处理均位于该早退之后。CPU 会因
numel==0静默返回;GPU 用例则因numel非零,进入 CUDA kernel 后在空选择轴上计算非法内存访问。本 PR 将
x.dims()获取、负 axis 归一化及结构检查移到三个 kernel 的 early return 和后端数据处理前:修改后,相同输入会抛出明确报错:
修改文件与含义
本 PR 共修改 5 个文件:
Kernel 实现
paddle/phi/kernels/cpu/index_select_kernel.ccx.dims()获取和负 axis 归一化移到 empty-output fast path 前。paddle/phi/kernels/gpu/index_select_kernel.cux.dims()获取和负 axis 归一化移到 empty-output fast path 前,并增加同一结构检查,非法输入不会启动 CUDA kernel。output_dim、stride、size、delta、dtype 分派和设备指针处理继续保留在合法的非空正常路径,不新增一般 GPU Index 值域验证。paddle/phi/kernels/xpu/index_select_kernel.cc回归测试
test/legacy_test/test_index_select_op.pyTestIndexSelectInvalidIndexCPU,固定 CPU 覆盖[1, 0], axis=-1与[0, 0], axis=0两个非法案例,并验证[0, 0]配合空 Index 仍返回[0, 0]。TestIndexSelectInvalidIndex,在 GPU 可用时运行 GPU,否则运行 CPU;覆盖[1, 2048, 0], axis=-1和[0, 0], axis=0,验证非法输入均抛出新增参数异常,同时保留空 Index 对照。test/xpu/test_index_select_op_xpu.pyTestIndexSelectInvalidInput,在 XPU dygraph 环境覆盖[1, 0], axis=-1与[0, 0], axis=0的异常路径。[0, 0]配合空 Index 的合法对照,验证输出 shape 为[0, 0]。是否引起精度变化
否