Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【 Paddle Tensor 规范化二期 】解决隐式广播不能够处理0-size的问题 #70369

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

aquagull
Copy link
Contributor

PR Category

User Experience

PR Types

Bug fixes

Description

先前的隐式广播是不能够处理输入存在维度为0的情况:
A2E36F6B14F4C02FC3948DE3B8A10990
修改后:
46F287101CB620FC3B8BDE74C7B2CE55
测试代码

import paddle
import pdb
def test_paddle_add_broadcast(shape1, shape2):
    x = paddle.randn(shape1, dtype='float32') if shape1 != [0] and 0 not in shape1 else paddle.to_tensor([], dtype='float32').reshape(shape1)
    y = paddle.randn(shape2, dtype='float32') if shape2 != [0] and 0 not in shape2 else paddle.to_tensor([], dtype='float32').reshape(shape2)

    try:
        # pdb.set_trace()
        result = x + y
        print(f"Paddle Add: Shapes: {shape1} + {shape2}, Result shape: {result.shape}")

    except Exception as e:
        print(f"Paddle Add/Pow Add Error: Shapes: {shape1} + {shape2}, Error: {e}")

shapes = [
    ([0], [0]),
    ([0, 0], [0]),
    ([0], [0, 0]),
    ([0, 3], [3]),
    ([3], [0, 3]),
    ([0, 3], [0, 3]),
    ([2, 0], [0]),
    ([0], [2, 0]),
]


for shape1, shape2 in shapes:
    test_paddle_add_broadcast(shape1, shape2)

Copy link

paddle-bot bot commented Dec 20, 2024

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot bot added the contributor External developers label Dec 20, 2024
@luotao1 luotao1 added the HappyOpenSource 快乐开源活动issue与PR label Dec 20, 2024
@MrXnneHang
Copy link
Contributor

mark,感觉很有意思.

HydrogenSulfate

This comment was marked as outdated.

HydrogenSulfate

This comment was marked as abuse.

Copy link
Contributor

@HydrogenSulfate HydrogenSulfate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

添加一个关于0-size的广播单测,x、y的形状包含0-size、0-Dim、非0-size,长度可以在0~7,与np.broadcast_shapes的结果进行对比即可。

paddle/phi/kernels/funcs/common_shape.h Show resolved Hide resolved
paddle/phi/kernels/funcs/broadcast_function.h Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers HappyOpenSource 快乐开源活动issue与PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants