Repository navigation
【快乐开源】Paddle Tensor 规范化二期 API 支持 0-size Tensor No.13:paddle.mean - #71578
Closed
cangtianhuang wants to merge 4 commits into
Closed
cangtianhuang wants to merge 4 commits into
cangtianhuang wants to merge 4 commits into
Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
Contributor
Author
看上去确实是重复了,@cszdrg 的修改方法应该更佳。 |
Contributor
Author
|
如果 #71555 的pr通过,我将关闭这个pr。或者我可以为其添加0-size tensor的测试用例。 |
Collaborator
@HydrogenSulfate 请森森老师看下。测试用例应该是要添加的。 |
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
该 PR 主要修改了
paddle.mean的内核代码,使其支持处理 0-size Tensor 。C++ 侧修改了多个前向 kernel,但未修改反向 kernel 。增加了测试用例,包括多个形状的 0-size Tensor ,如 [], [0,], [0, 3], [2, 0, 4]。期望的值:("mean", float("nan"))。具体修改如下:
paddle.mean修改了 phi 库的 C++ 前向 kernel,包括 cpu、kps、onednn、xpu 等多设备。为了增强算子 kernel 的复用,修改集中在了底层的
MeanRawKernel处。在 paddle\phi\kernels\cpu\reduce_mean_kernel.cc 、paddle\phi\kernels\kps\reduce_kernel.cu 、paddle\phi\kernels\onednn\reduce_mean_kernel.cc 、paddle\phi\kernels\xpu\reduce_mean_kernel.cc 中,增加了对 0-size Tensor 的处理逻辑。由于输出形状已经由 SumRawInferMeta 正确推断并保存在
DenseTensor* out中,因此无需增加额外推断逻辑,直接调用FullKernel,填充 NaN 值并返回。此外 ,onednn 的
FullKernel(位于 paddle\phi\kernels\onednn\full_kernel.cc)原先不支持phi::dtype::bfloat16类型,为其增添了注册类型。经测试,
paddle.mean通过了 “0-size tensorAPI 支持 0-size Tensor No.13” 的测试。且在 [], [0,], [0, 3], [2, 0, 4] 等多个 0-size Tensor 形状中表现与预期一致。测试结果如下: