Skip to content

Commit

Permalink
Merge pull request #3725 from QiJune/refine_backward
Browse files Browse the repository at this point in the history
refine backward
  • Loading branch information
QiJune authored Aug 29, 2017
2 parents 794c2f2 + 4f0c071 commit 75e16bd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 4 additions & 1 deletion paddle/framework/backward.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ static std::unique_ptr<OperatorBase> BackwardRecursive(
std::list<Pos> insert_position;
for (auto& dup_output_op : dup_output_ops) {
const std::string& name = dup_output_op.first;
// duplicate @Empty@ don't need to be added
if (name == kEmptyVarName) continue;

auto& dup_op = dup_output_op.second;
// no duplicate output
if (dup_op.size() == 1) continue;
Expand Down Expand Up @@ -209,7 +212,7 @@ std::unique_ptr<OperatorBase> Backward(
const OperatorBase& forwardOp,
const std::unordered_set<std::string>& no_grad_vars) {
std::unordered_set<std::string> no_grad_names;
no_grad_names.reserve(no_grad_vars.size());
no_grad_names.reserve(no_grad_vars.size() + 1);

no_grad_names.insert(std::string(kEmptyVarName) + kGradVarSuffix);

Expand Down
9 changes: 6 additions & 3 deletions paddle/operators/net_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ void NetOp::CompleteAddOp(bool calc) {
for (auto& op : ops_) {
for (auto& ipt : op->Inputs()) {
for (auto& var_name : ipt.second) {
if (!Contains(output_set, var_name)) { // Not other op's output
input_set.insert(var_name);
} else {
// If input variable has been in output set, then it will be
// added into intermediate_outputs_. Otherwise, it will be
// added into input set.
if (Contains(output_set, var_name)) {
intermediate_outputs_.insert(var_name);
} else {
input_set.insert(var_name);
}
}
}
Expand Down

0 comments on commit 75e16bd

Please sign in to comment.