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】support higher order autodiff for dy2static+composite #53171

Merged
merged 12 commits into from
May 12, 2023

Conversation

cxxly
Copy link
Contributor

@cxxly cxxly commented Apr 21, 2023

PR types

New features

PR changes

Others

Description

Pcard-66975

动转静+组合模式适配高阶微分部分逻辑:

  1. 修复GetOptionalOutputGrad BUG,当输出为Optional,当前会默认创建一个非Optional Out@GRAD;
  2. 修复fill_any_like重复创建错误,fill_any_like用于gradients计算反向微分创建初始化梯度,当前组合模式会重复创建;
  3. 根据反向获取前向名称_strip_grad_suffix_适配,高阶微分模式下, 会产生z@GRAD_slice_0@GRAD 反向梯度命名,当前逻辑会错误解析为z ,正确命名应为z@GRAD_slice_0
  4. 剪枝逻辑适配,组合模式下,反向组合算子产生的中间变量不满足 'XX@GRAD' 规范,当前反向剪枝逻辑依赖该命名规则,会导致拆解后部分基础算子被裁减。
  5. 由于部分fluid算子未实现infershape/dtype,backward中会有将反向初始梯度的形状、数据类型强制设置为前向输出形状、数据类型补丁,组合模式下,对所有基础算子补充了infershape/dtype 【Prim】Add more infer var type #52818 ,移除该补丁

其它参考:

@paddle-bot
Copy link

paddle-bot bot commented Apr 21, 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.

@paddle-bot
Copy link

paddle-bot bot commented Apr 21, 2023

❌ 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.

@cxxly cxxly force-pushed the prim_higher_order_autodiff branch from 883bcd2 to ab25750 Compare April 21, 2023 11:09
@cxxly cxxly changed the title 【Prim】support higher order autodiff for dy2static 【Prim】support higher order autodiff for dy2static+composite Apr 24, 2023
@paddle-ci-bot
Copy link

paddle-ci-bot bot commented Apr 29, 2023

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

@cxxly cxxly force-pushed the prim_higher_order_autodiff branch 3 times, most recently from 94120d9 to aee095e Compare May 8, 2023 13:13
@cxxly cxxly force-pushed the prim_higher_order_autodiff branch from aee095e to 40fd316 Compare May 10, 2023 05:08
@cxxly cxxly force-pushed the prim_higher_order_autodiff branch from 40fd316 to aa74cfe Compare May 10, 2023 07:43
):
composite_block.create_var(name=name)
op.desc.infer_var_type(composite_block.desc)
op.desc.infer_shape(composite_block.desc)
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.

当前Block只包含前向OP列表,只需要对于没有输出的OP创建输出并推断形状,不需要将OP重复添加到block中。infershape_for_composite 会重复创建OP,比如fill_any_like

# this patch for primitive operators.
for arg in grad_op_desc.output_arg_names():
if arg in new_vars:
_infer_var_data_type_shape_(arg, block)
Copy link
Contributor

Choose a reason for hiding this comment

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

这部分修改是否可以合并至1784 else 分支中

Copy link
Contributor Author

Choose a reason for hiding this comment

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

可以的,只不过这样代码是一个非常Hack的补丁(Paddle 1.x版本已存在),单独放一段逻辑更容易引起注意

@cxxly cxxly merged commit b73594b into PaddlePaddle:develop May 12, 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.

4 participants