【BIT】isclose Tensor.isclose support 0-size#72263
Merged
Merged
Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
Contributor
Author
cangtianhuang
suggested changes
Apr 16, 2025
cangtianhuang
left a comment
Contributor
There was a problem hiding this comment.
同学请修改一下😊,此外测试用例可以添加报错中的配置,确保问题被解决
| if (out && out->numel() == 0) { | ||
| dev_ctx.template Alloc<bool>(out); | ||
| return; | ||
| } |
Contributor
There was a problem hiding this comment.
我认为这个判断有问题,参考 isclose api 文档:https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/isclose_cn.html#isclose
0-size 是指输入的 x、y 是 0-size tensor,isclose 的输出是 布尔类型的 tensor,out 始终不为空,判断 out->numel() == 0 应该不对
Contributor
There was a problem hiding this comment.
我感觉这里用x、y、out哪个的numel应该都对吧?他们三个的dims是一样的~
| self.atol = np.array([1e-08]).astype("float64") | ||
| self.equal_nan = False | ||
|
|
||
|
|
Co-authored-by: 苍天荒 <1903374751@qq.com>
cangtianhuang
approved these changes
Apr 16, 2025
Contributor
|
@mzj104 改一下pr标题,前面加一个【BIT】 |
wanghuancoder
approved these changes
Apr 17, 2025
| if (out && out->numel() == 0) { | ||
| dev_ctx.template Alloc<bool>(out); | ||
| return; | ||
| } |
Contributor
There was a problem hiding this comment.
我感觉这里用x、y、out哪个的numel应该都对吧?他们三个的dims是一样的~
YqGe585
pushed a commit
to YqGe585/Paddle
that referenced
this pull request
May 7, 2025
* fix isclose * fix * fix * fix * Update test/legacy_test/test_isclose_op.py Co-authored-by: 苍天荒 <1903374751@qq.com> --------- Co-authored-by: 苍天荒 <1903374751@qq.com>
This was referenced Jun 9, 2025
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
New features
Description
isclose Tensor.isclose支持0-Size。
修改历程介绍如下:
在PaddleAPITest report/0size_tensor中检索paddle.isclose的错误日志,发现CUDA error(9)报错。分析可能是前向过程出错。
前向修复:
a. 在Paddle代码中检索def isclose,发现isclose的核心实现调用的是_C_ops的isclose
b. 以_C_ops的isclose在paddle/phi/ops/yaml中检索,发现isclose的InferMeta函数使用到一个:
ValueCompareInferMeta
c. 在代码中检索ValueCompareInferMeta,并检查其dims(shape)的推导是否正确(在isclose中推导是正确因此不用修改)
d. 在paddle/phi/kernels中检索isclose,找全所有isclose的实现Kernel。发现共有四个涉及isclose的文件,分别为:
其中cc和cu文件均将前两个.h文件设为头文件,因此只用修改.h文件即可。而isclose_kernel.h和isclose_kernel_impl.h中不需要(不能)重复定义,故只修改了isclose_kernel_impl.h
在paddle/phi/kernels/impl/isclose_kernel_impl.h中加入以下代码,完成修复
添加单测:
在test/legacy_test/test_isclose_op.py中添加0 size tensor输入的单测:
备注:尽管所有的isclose的配置,accuracy均已通过,但是存在out没有alloc的问题