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

[AMP] Support amp for Intermediate_dygraph #40623

Merged
merged 22 commits into from
Mar 24, 2022

Conversation

zhangbo9674
Copy link
Contributor

@zhangbo9674 zhangbo9674 commented Mar 16, 2022

PR types

New features

PR changes

Others

Describe

AMP适配动态图中间态

** 1 实现要点:**
(1)动态图 api 中添加 amp 逻辑分支:

  • 依据 inputs + amp_level + amp_dtype 确定待 cast 数据类型
  • 遍历 inputs,调用cast_dygraph_function 得到 casted_inputs
  • 输入 casted_inputs 递归调用原api。

(2)实现 amp 公共组件:

  • GetAmpDestDtype:依据amp参数,获取需要cast的数据类型
  • AmpAutoCast/ AmpAutoCasts:将输入数据cast为指定数据类型

2 实现效果:
eager_generator.cc中加入amp代码生成逻辑:
图片

** 3 注:**

  • inplace api 不添加amp逻辑。

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

# def func():
# with fluid.dygraph.guard():
# model = fluid.dygraph.Conv2D(3, 2, 3, bias_attr=False, act=None)
# opt = paddle.optimizer.SGD(parameters=model.parameters())
Copy link
Contributor

Choose a reason for hiding this comment

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

why commment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已开启全部amp单测

" auto amp_dst_dtype = "
"egr::GetAmpDestDtype(egr::Controller::Instance().GetCurrentTracer()-"
">GetAmpDtype(), "
"egr::Controller::Instance().GetAMPLevel(), \"%s\", "
Copy link
Contributor

Choose a reason for hiding this comment

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

u can reuse egr::Controller::Instance()

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.

jim19930609
jim19930609 previously approved these changes Mar 22, 2022
JiabinYang
JiabinYang previously approved these changes Mar 22, 2022
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.

little problem, fix it in next PR

inputs_casted.push_back(
std::move(cast_dygraph_function(input, cast_attrs)));
} else {
inputs_casted.push_back(input);
Copy link
Contributor

Choose a reason for hiding this comment

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

emplace_back is better

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, tks!

@zhangbo9674 zhangbo9674 dismissed stale reviews from JiabinYang and jim19930609 via fd69d72 March 22, 2022 06:18
Copy link
Contributor

@zhwesky2010 zhwesky2010 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 changing parallel_UT_rule.py

@JiabinYang JiabinYang merged commit c12f7d4 into PaddlePaddle:develop Mar 24, 2022
@zhangbo9674 zhangbo9674 deleted the dev/amp_intermediate branch March 2, 2023 02:59
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.

5 participants