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

create grad_var when run Backward pass #4796

Merged
merged 14 commits into from
Oct 14, 2017

Conversation

jacquesqiao
Copy link
Member

@jacquesqiao jacquesqiao commented Oct 13, 2017

project: #4679
fix: #4767

@jacquesqiao jacquesqiao changed the title Improve backward create grad_var when run Backward pass Oct 13, 2017
@@ -375,10 +376,18 @@ std::vector<std::unique_ptr<OpDescBind>> MakeBlockBackward(
backward_descs.insert(backward_descs.begin() + p.first + 1,
std::move(p.second));
}

// insert fill one op for target
std::unique_ptr<OpDescBind> fill_one_op(new OpDescBind(
Copy link
Collaborator

Choose a reason for hiding this comment

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

It should be in AppendBackward. That logic is wrong.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

auto backward_op_descs =
MakeBlockBackward(program_desc, root_block_idx, no_grad_var_names);
auto& forw_op_descs = program_desc.Block(root_block_idx)->ops_;
auto backward_op_descs = MakeBlockBackward(program_desc, root_block_idx,
Copy link
Collaborator

Choose a reason for hiding this comment

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

target does not need to pass to MakeBlockBackward.

Copy link
Member Author

Choose a reason for hiding this comment

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

removed

auto backward_op_descs = MakeBlockBackward(program_desc, root_block_idx,
target, no_grad_var_names);
auto root_block = program_desc.Block(root_block_idx);
auto& forward_op_descs = root_block->ops_;
Copy link
Collaborator

Choose a reason for hiding this comment

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

forward_op_descs --> ops

Copy link
Member Author

Choose a reason for hiding this comment

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

done

for (size_t index = backward_start_index; index < forward_op_descs.size();
++index) {
auto& op = forward_op_descs.at(index);
for (auto& input : op->Inputs()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Input does not need to be created

Copy link
Member Author

Choose a reason for hiding this comment

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

done

auto& forw_op_descs = program_desc.Block(root_block_idx)->ops_;
auto backward_op_descs = MakeBlockBackward(program_desc, root_block_idx,
target, no_grad_var_names);
auto root_block = program_desc.Block(root_block_idx);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not only root_block need create vars.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

root_block->NewVar(fill_one_op_out);

// create grad_var for all blocks in this program
for (size_t block_index = 0; block_index < program_desc.Size();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not all block is generated by backward.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Collaborator

@reyoung reyoung left a comment

Choose a reason for hiding this comment

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

LGTM

@reyoung reyoung merged commit d7383c6 into PaddlePaddle:develop Oct 14, 2017
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.

update BackwardPass, create grad vars when run backward pass
2 participants