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

【pir】modify test_Conditional_block.py #61091

Merged
merged 9 commits into from
Jan 29, 2024

Conversation

xiaoguoguo626807
Copy link
Contributor

@xiaoguoguo626807 xiaoguoguo626807 commented Jan 24, 2024

PR types

others

PR changes

others

Description

pcard-67164

1.修复assign_out_(0%, 1%) 的vjp , 将1 %的梯度作为vjp output_grads 传入, 直接转发作为输入0%的梯度, 1%的梯度修改为zero_like(1%) 因为inplace的输入,其被覆盖的输入值没有被其他op使用,梯度应该为0.
2.image
上述网络中,由于3%的梯度在父block 中是11%, 3% 是if的输出,因此子block 构建assign_out_ 的反向时需要用11%, 因此sub_state 中需要维护3% -> 11%的关系; 又由于3%是if的输入,因此子block 中也产生梯度20%, sub_state 将维护3% -> 11% ,20%, 在做反向yield 的输出时 add_n为26% 转发给父block 的15%, 而此时父block 如果不对state 中3%的map置空,则最终3% = 11% + 15% = 11% + 11% + 20%, 计算会错误。因此对于if内的inplace 输入,输出state需要在if 更新前置空。
3由于if 支持了combine 的结果作为cond, vjp 需要的input 是vectype 以构造if_grad的cond输入, 与其他op 的make_input_input_stop_gradient 有冲突,因此考虑将if的cond 置为无梯度语意,在对应分支跳过combine的拆解处理. 相应的对其vjp 处理,默认cond 不传stop_gradient 信息,因此内部与input 对应的索引需要错位。

Copy link

paddle-bot bot commented Jan 24, 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.

)
# update_no_grad_set_after_prune(
# total_ops, effective_forward_ops, no_grad_set, inputs, complete_outputs
# )
Copy link
Contributor

Choose a reason for hiding this comment

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

这里是暂时保留的注释还是忘记删掉的?

@xiaoguoguo626807 xiaoguoguo626807 merged commit 5b6fbeb into PaddlePaddle:develop Jan 29, 2024
30 checks passed
@xiaoguoguo626807 xiaoguoguo626807 deleted the condition branch January 29, 2024 03:05
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