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

[Custom operator] Fix custom operator backward=None bug #48656

Merged

Conversation

jiahy0825
Copy link
Contributor

@jiahy0825 jiahy0825 commented Dec 2, 2022

PR types

Bug fixes

PR changes

OPs

Describe

Bug describes: when custom backward op outputs gradient with a discrete order, the output of some gradient=None.

For example: backward op's input = {a, b, c, d, e}, output = {a@GRAD, d@GRAD, e@GRAD}, the output of d@GRAD and e@GRAD will be None.

Reason: The order of RunCustomOpNode::operator(): line220 in custom_operator_node.cc is {a@GRAD, null, null, d@GRAD, e@GRAD}. However, the order of eager_api_run_custom_op: line560 in eager_functions.cc is {a@GRAD, d@GRAD, e@GRAD, null, null}.

Change: Change the order in RunCustomOpNode::operator() to {a@GRAD, d@GRAD, e@GRAD, null, null}

本 PR 修复了自定义算子反向 op 的输出值可能为 None 的 bug,当用户的输出梯度不是连续输出时(例如输出第0、3、4个前向输入的梯度时),第3、4个梯度会被置为 None,这是由于对反向 op 的输出梯度进行处理时,RunCustomOpNode::operator(): line220eager_api_run_custom_op: line560的动作不一致。更改为按照RunCustomOpNode::operator()对齐,在反向 op 的输出梯度后面,填充不需要梯度的输出,修改后的返回值为 {第 0 个梯度,第 3 个梯度,第 4 个梯度,null, null}

@paddle-bot
Copy link

paddle-bot bot commented Dec 2, 2022

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

Copy link
Contributor

@JiabinYang JiabinYang left a comment

Choose a reason for hiding this comment

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

LGTM

@jiahy0825 jiahy0825 merged commit 0c1d68e into PaddlePaddle:develop Dec 5, 2022
lxsbupt pushed a commit to lxsbupt/Paddle that referenced this pull request Dec 17, 2022
jiahy0825 added a commit to jiahy0825/Paddle that referenced this pull request Dec 20, 2022
phlrain pushed a commit that referenced this pull request Dec 27, 2022
* [Release2.4] Revert python link prs (#48573)

* Revert "Fix mac link python (#48017)"

This reverts commit 3fa7a73.

* Revert "[Cherry-pick] Fix python link error (#47811)"

This reverts commit ff642c6.

* Update config.go

* fix custom operator backward=None (#48656)

* [Custom Extension] Fix custom double_grad backward=None (#49224)

* fix custom double_grad backward=None

* fix custom_relu.cu bug && polish testcase of double_grad

* remove old dynamic graph test

* add import fluid

* add import fluid

Co-authored-by: Chen Weihang <chenweihang@baidu.com>
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.

None yet

3 participants