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

add backward inplace for dygraph #35412

Merged
merged 3 commits into from
Sep 8, 2021

Conversation

zhiqiu
Copy link
Contributor

@zhiqiu zhiqiu commented Sep 2, 2021

PR types

New features

PR changes

Others

Describe

add backward inplace for dygraph

how

In dygraph mode, the forward part is not determined, while the backward computation graph is determined after forward. So the graph optimization can be performed. And, the reference count used to guide inplace optimization can be easily get shared_ptr of input tensor.

Two benefits: (1) reduce d2d copy and speed up training, (2) reduce memory usage

performance

GPT model, speed up +2.8%.
f5f2b2cb62e7531cf3d5f698e4de5734

@paddle-bot-old
Copy link

paddle-bot-old bot commented Sep 2, 2021

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

paddle::framework::OpInfoMap::Instance().Get(op_type).infer_inplace_;

if (infer_inplace) {
auto in_to_outs = infer_inplace(true);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why always be true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed offline, the parameter being true and false has no difference now.

Copy link
Collaborator

@sneaxiy sneaxiy left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@chenwhql chenwhql left a comment

Choose a reason for hiding this comment

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

LGTM

@zhiqiu zhiqiu merged commit 0cb413d into PaddlePaddle:develop Sep 8, 2021
AnnaTrainingG pushed a commit to AnnaTrainingG/Paddle that referenced this pull request Sep 29, 2021
* add backward inplace for dygraph

* fix bug

* support gradient accumulation
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