Skip to content

Fix/Fix memory leak in dygraph#17394

Merged
JiabinYang merged 11 commits intoPaddlePaddle:developfrom
JiabinYang:feature/sorted_gradient_dygraph
May 17, 2019
Merged

Fix/Fix memory leak in dygraph#17394
JiabinYang merged 11 commits intoPaddlePaddle:developfrom
JiabinYang:feature/sorted_gradient_dygraph

Conversation

@JiabinYang
Copy link
Contributor

@JiabinYang JiabinYang commented May 14, 2019

Fix memory leak problem in dygraph mode and using unique_ptr to hold Variable to make sure it can be freed automatically when Varbase is released by python gc

@JiabinYang JiabinYang requested a review from sneaxiy May 14, 2019 08:56
bck_map = new BackwardSumMap();
grad_ref = new GradientRef();
bck_map = BackwardSumMap();
grad_ref = GradientRef();
Copy link
Collaborator

Choose a reason for hiding this comment

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

These two lines are unnecessary. BTW, it seems that it is not necessary thatbck_map and grad_ref are data member of Autograd. Just make them temporary variable inside the function.

if (grad_ref->find(vb) == grad_ref->end()) {
grad_ref->insert(std::make_pair(vb, 1));
if (grad_ref.find(vb) == grad_ref.end()) {
grad_ref.insert(std::make_pair(vb, 1));
Copy link
Collaborator

Choose a reason for hiding this comment

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

C++ guarantees zero-initialization of primitive types. See here. You can just write ++grad_ref[vb];

BackwardSumMap* bck_map;
GradientRef* grad_ref;
BackwardSumMap bck_map;
GradientRef grad_ref;
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need to be data members.

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.

Excellent.

@JiabinYang JiabinYang changed the title Feature/sorted gradient dygraph Fix/Fix memory leak in dygraph May 17, 2019
@JiabinYang JiabinYang merged commit d7df4e5 into PaddlePaddle:develop May 17, 2019
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