diff --git a/paddle/framework/backward.cc b/paddle/framework/backward.cc index 0a4688db9c930201c95d4a47658f43cad87fdbca..063b108500d95c94d5859cf6e1a5a88dcdb2ed31 100644 --- a/paddle/framework/backward.cc +++ b/paddle/framework/backward.cc @@ -172,30 +172,14 @@ static std::unique_ptr BackwardRecursive( std::to_string(i)); net->ops_[op_offset]->Rename(name, dup_outputs.back()); } - // collect all the offset to append `add` op for each alias - // - // one variable is shared between multiple operators. - // insert add operator one by one, then add it to output - for (size_t output_idx = 0; output_idx < dup_outputs.size() - 1; - ++output_idx) { - auto insert_add_x = dup_outputs[output_idx]; - auto insert_add_y = dup_outputs[output_idx + 1]; - auto insert_add_out = name + "@SHARED@" + std::to_string(output_idx); - // first add op inserted - if (output_idx == dup_outputs.size() - 2) { - insert_add_out = name; - } - if (output_idx != 0) { - insert_add_y = name + "@SHARED@" + std::to_string(output_idx - 1); - } - insert_position.push_back( - {dup_op.back(), - OpRegistry::CreateOp("sum", {{"X", {insert_add_x, insert_add_y}}}, - {{"Out", {insert_add_out}}}, {})}); - } + // collect all the offset for each alias, + // insert a sum operator to add all aliases to output + insert_position.push_back( + {dup_op.back(), OpRegistry::CreateOp("sum", {{"X", dup_outputs}}, + {{"Out", {name}}}, {})}); } - // make sure the inserted `add` ops follow the BFS order. + // make sure the inserted `sum` ops follow the BFS order. insert_position.sort( [](const Pos& l, const Pos& r) { return l.first > r.first; }); diff --git a/paddle/framework/executor.cc b/paddle/framework/executor.cc index 886e9ab33e56c5952fd8c9d2042ba46f6422e821..c388b2198e4fbf75d6584d710e00d3deca93eb51 100644 --- a/paddle/framework/executor.cc +++ b/paddle/framework/executor.cc @@ -24,8 +24,6 @@ limitations under the License. */ #include "paddle/framework/op_registry.h" #include "paddle/framework/scope.h" -#include - namespace paddle { namespace framework {