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

[Dy2stat] Add Support for paddle.grad #33110

Merged
merged 12 commits into from
Jun 4, 2021

Conversation

zhhsplendid
Copy link
Member

@zhhsplendid zhhsplendid commented May 25, 2021

PR types

New features

PR changes

APIs

Describe

This PR made these changes to support double grad:

  1. Translate paddle.grad to paddle.static.gradients to support double grad for dy2stat.
  2. Fix IfElseTransformer bug which may not change value if "Store before Load" variable is in "Store" statement is in IfElse conditional statement
  3. Add DOut to support double grad variables in run_program_op
  4. Add support for renaming for double grads for jit.save/load

@paddle-bot-old
Copy link

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

@paddle-bot-old
Copy link

paddle-bot-old bot commented Jun 2, 2021

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

def forward(self, inputs):
in_vars, out_vars, tmp_scope_vec = self._prepare(inputs)

double_grads = self._get_double_grads(self._origin_main_program)
Copy link
Contributor

Choose a reason for hiding this comment

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

这里的main_program是固定的,所以 double_grads 是否只需要 core.VarBase 创建一次就可以了,每个batch 直接复用就好了?

因为这个 get_double_grads放在forward里,调用频率会很高,grads_var的name解析等都是可以只做一次的。

Copy link
Member Author

Choose a reason for hiding this comment

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

好的,移动到构造函数里

for b_idx in six.moves.range(program_desc.num_blocks()):
cur_block = program_desc.block(b_idx)
for var_idx, var in enumerate(cur_block.all_vars()):
name_old = var.name()
is_double_grad_var = "GRAD" in name_old
Copy link
Contributor

Choose a reason for hiding this comment

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

这里是否应该是 @GRAD

Copy link
Member Author

Choose a reason for hiding this comment

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

你说得对,我的错,新commit已更正

value=[1],
name='Fake_var',
place=framework._current_expected_place())
]
Copy link
Contributor

Choose a reason for hiding this comment

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

ddout在 Maker 里标记的是 AsDispensable,如果为空,这里是不是不用 fake 了?

Copy link
Member Author

Choose a reason for hiding this comment

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

我尝试过,不管给DOut传None还是空list,都会报这个错:

7d5f4462b6435d1607fab9b038ba93e2

看上去动态图还不好区分这种Dispensable,所以我模仿这里代码的valid_vars的写法。

Copy link
Contributor

@Aurelius84 Aurelius84 left a comment

Choose a reason for hiding this comment

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

LGTM with my knowledge

Copy link
Contributor

@hbwx24 hbwx24 left a comment

Choose a reason for hiding this comment

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

LGTM

@zhhsplendid zhhsplendid merged commit 82630f3 into PaddlePaddle:develop Jun 4, 2021
@zhhsplendid zhhsplendid deleted the double_grad branch July 15, 2021 04:10
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.

3 participants