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

[AutoParallel] Support the backward rule of elementwise binary #57813

Merged
merged 1 commit into from
Oct 10, 2023

Conversation

LiYuRio
Copy link
Contributor

@LiYuRio LiYuRio commented Sep 27, 2023

PR types

New features

PR changes

Others

Description

Pcard-73145

本PR支持elementwise大类操作里,binary操作的反向inferspmd推导规则。

在非切分视角下,binary类操作里input_grad等于out_grad。如果在前向计算时存在广播情况,比如[4, 5] + [4, 4, 5],得到的output和out_grad的大小都是[4, 4, 5],被广播的input0需要基于0维做规约,得到最终正确的input_grad。

切分视角下,分为以下两种情况:

  • input里存在切分维度。
    • 比如两个形状完全相同为[4, 5]的DistTensor相加,且input0在0维上是shard状态,最终input_grad的形状和dist_attr应与out_grad一致;
    • 举例,如果前向inferspmd推出output是形状为[2, 5]的切分状态,代表实际每个rank进行的是[2, 5] + [2, 5]的物理计算。反向inferspmd推导出的input和input_grad应该是和output一致的形状为[2, 5]的切分状态,若返回的dist_attr和input本身不匹配,基础执行逻辑会对它进行reshard。
  • input里不存在切分维度。
    • 比如形状为[4, 5]和形状为[4, 4, 5]的DistTensor相加,且input1在0维上是shard状态,实际上做的是[4, 5] + [2, 4, 5],最终input0_grad应该设置成partial状态,弥补只进行了部分reduce。

@paddle-bot
Copy link

paddle-bot bot commented Sep 27, 2023

你的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.

@LiYuRio LiYuRio force-pushed the dev_elementwise branch 3 times, most recently from 2e1a004 to 6f8644d Compare September 28, 2023 08:34
@paddle-ci-bot
Copy link

paddle-ci-bot bot commented Oct 6, 2023

Sorry to inform you that 6f8644d's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually.

@LiYuRio LiYuRio force-pushed the dev_elementwise branch 4 times, most recently from 7e25df4 to 7c45e81 Compare October 9, 2023 08:36
Copy link
Contributor

@chenwhql chenwhql left a comment

Choose a reason for hiding this comment

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

LGTM

@LiYuRio LiYuRio merged commit bc6fa4f into PaddlePaddle:develop Oct 10, 2023
27 checks passed
Frida-a pushed a commit to Frida-a/Paddle that referenced this pull request Oct 14, 2023
jiahy0825 pushed a commit to jiahy0825/Paddle that referenced this pull request Oct 16, 2023
danleifeng pushed a commit to danleifeng/Paddle that referenced this pull request Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants