Repository navigation
[0-Size Tensor问题修复] paddle.mean - #71961
Merged
Merged
Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
Contributor
Author
|
将 paddle/phi/kernels/funcs/reduce_function.h 处的 GE 修改为 GT ,是因为更底层的代码对 0-size tensor 的支持有奇怪的报错,不应该将处理逻辑下放,如 #71826 。经测试, eigen3 库对 0-size tensor 的支持也并不完善:
Eigen::Tensor<float, 3> tensor(2, 0, 4);
tensor.setZero();
auto mean_op = tensor.mean(Eigen::array<int, 1>{0});
Eigen::Tensor<float, 2> mean_tensor = mean_op;
|
YqGe585
pushed a commit
to YqGe585/Paddle
that referenced
this pull request
May 7, 2025
* Fix 0-size tensor support in mean when out->numel() > 0, add test. * Restore GT check in reduce_function. * Fix bug.
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
Bug fixes
Description
经检查和测试,当前
paddle.mean的 特判逻辑 不能正确拦截所有 0-size tensor 的 reduce 情况。gpu 上运行即会报错(cpu 上运行正常,详见 #71555 ):若输入形状为 [2, 0, 4],沿着 axis=1 求 mean,预期输出形状应为 [2, 4],填充为 NAN 。不符合特判中
if (out && out->numel() == 0)或if (x.numel() == 0 && out && out->dims().size() == 0)情况。经检查,FullKernel 中实现了对 0 显存长度的分配,因此我们可以直接调用
Full填充并返回,修改方式类似于 #71578 。最后添加了前向测试用例。使用 PaddleAPITest 测试通过,使用自己新增的配置:
@wanghuancoder