Repository navigation
Conversation
Collaborator
|
需要解决下冲突 |
Collaborator
|
请签署CLA,commit使用的lubingxin,和提交PR的账号luyl975不一样 |
luyl975
force-pushed
the
feature/argmax-change
branch
from
July 1, 2025 07:49
99d9ea5 to
81aa5ba
Compare
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
Execute Infrastructure
PR Types
Improvements
Description
在PaddleAPITest report/0size_tensor中检索paddle.argmax的错误日志。分析paddle.argmax用于沿指定轴查找张量中最大值的索引,返回的是离散索引,认为不存在反向过程,因而认为是前向过程出错。
前向修复:
a. 在Paddle代码中检索def argmax,发现该函数中并没有对输入张量维数的检查,而argmax的核心实现调用的是_C_ops的argmax
b. 以_C_ops的argmax在paddle/phi/ops/yaml中检索,发现argmax的InferMeta函数使用为:ArgMinMaxInferMeta
c. 在代码中检索ArgMinMaxInferMeta,其函数体位于paddle\phi\infermeta\unary.cc,检查其对于0-size张量的操作,发现它对于张量为0维时的处理为要求axis必须为-1或0
d. 在paddle/phi/kernels中检索argmax(考虑到报错的文件名为arg_min_max_kernel.cc,因而还对max_、arg_等进行检索),找全所有argmax有关Kernel的相关实现。发现存在函数ArgMaxKernel,共有四个涉及该函数的文件,分别为:
paddle\phi\kernels\arg_min_max_kernel.h
paddle\phi\kernels\cpu\arg_min_max_kernel.cc
paddle\phi\kernels\gpu\arg_min_max_kernel.cu
paddle\phi\kernels\xpu\arg_min_max_kernel.cc
其中第一个文件是后三个文件的头文件,因而考虑对后三个文件中的函数进行检查,其中0-size张量的报错由以下代码引发(改代码在后三个文件中均存在):
因而考虑在该函数执行前对输入的张量形状进行判断,
在paddle\phi\kernels\cpu\arg_min_max_kernel.cc的ArgMinMaxKernel函数
在paddle\phi\kernels\gpu\arg_min_max_kernel.cu的ArgMinMaxOpCUDAKernel函数
在paddle\phi\kernels\xpu\arg_min_max_kernel.cc的ArgMaxKernel函数分别添加以下代码
反向修复:
由于认为paddle.argmax函数不存在反向过程,因而不进行相关反向修复
单元测试:
在test\legacy_test\test_arg_min_max_op.py中添加0-size张量输入的单测:
其中self.dims若设为(0, 4, 5)时numpy产生报错,因而暂时无法进行self.dims=(0, 4, 5)的单元测试
测试结果:
PaddleAPITest测试结果:
下载PaddleAPITest:
进行测试:
Pcard-67164