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

[Prim] add reduce_as op for paddle #63064

Merged
merged 42 commits into from
Apr 19, 2024
Merged

Conversation

zeroRains
Copy link
Contributor

@zeroRains zeroRains commented Mar 27, 2024

PR Category

Others

PR Types

New features

Description

由于broadcast类算子的反向拆解无法适配动态shape,

在静态shape中的例子如下,

x.shape = [2,3]
y.shape = [1,3]
z = x+y 
# z.shape = [2,3]
# dz -> dy
reduce_dim = get_reduce_dim(y.shape, z.shape)
# reduce_dim = [0]
dy = sum(dz, reduce_dim, True)

但在动态shape的编译期拿不到reduce_dim,于是要添加reduce_as算子,其伪代码如下:

def reduce_as(x: Tensor, y: Tensor):
      reduce_dim = get_reduce_dim(x.shape, y.shape)
      res = sum(x, reduce_dim)
      return res

有了这个算子之后,动态shape的场景写法如下:

x.shape = [-1,3]
y.shape = [1,3]
z = x+y 
# z.shape = [-1,3]
# dz -> dy
# dz.shape = [-1,3]
dy = reduce_as(dz, y)

这个pr就是实现对reduce_as op的添加

Copy link

paddle-bot bot commented Mar 27, 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 Mar 27, 2024
Copy link

paddle-bot bot commented Mar 27, 2024

❌ The PR is not created using PR's template. You can refer to this Demo.
Please use PR's template, it helps save our maintainers' time so that more developers get helped.

test/legacy_test/test_sum_as_op.py Outdated Show resolved Hide resolved
test/legacy_test/test_sum_as_op.py Outdated Show resolved Hide resolved
self.python_api = paddle.sum_as
self.public_python_api = paddle.sum_as
self.op_type = "sum_as"
self.prim_op_type = "prim"
Copy link
Contributor

Choose a reason for hiding this comment

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

这个算子目前没有反向拆解,这里是不能设置的

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@cyber-pioneer
Copy link
Contributor

补充动态shape的单侧

@zeroRains zeroRains closed this Apr 4, 2024
@zeroRains zeroRains reopened this Apr 4, 2024
@zeroRains zeroRains changed the title [Prim] add sum_as op for paddle [Prim] add reduce_as op for paddle Apr 9, 2024
@zeroRains
Copy link
Contributor Author

由于在本地cuda 11.2环境, 本地cuda12.0环境 以及CI环境都无法复现test_assign_pos_op 单测出错的场景,现将该PR的实现部分进行拆解,分成多个子PR,确认是哪个部分的改动引起了这个单测出错。这些PR并不需要Review和Merge具体PR如下:

reduce_as 前向计算: #63652

Copy link
Contributor

@Xreki Xreki left a comment

Choose a reason for hiding this comment

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

LGTM for op-benchmark ci

Copy link
Contributor

@sunzhongkai588 sunzhongkai588 left a comment

Choose a reason for hiding this comment

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

LGTM,中文也同步增加文档吧

Copy link
Contributor

@XieYunshen XieYunshen left a comment

Choose a reason for hiding this comment

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

LGTM

'float64',
'int16',
'int32',
'int64',
Copy link
Contributor

Choose a reason for hiding this comment

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

can we support other data type of complex64/128uint8 andint8?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

后续的PR再进行补充吧

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants