Skip to content

Commit

Permalink
Remove ControlDepVar in GraphToBlock (#44591)
Browse files Browse the repository at this point in the history
  • Loading branch information
From00 authored Jul 26, 2022
1 parent 1892a44 commit 8d3672f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions paddle/fluid/framework/ir/graph_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,27 @@ std::vector<ir::Node *> TopologySortGraphByDescOrder(const Graph &graph) {
return ret;
}

void RemoveControlDepInputAndOuput(OpDesc *op_desc) {
auto remove_control_dep_var = [](VariableNameMap *var_name_map) {
for (auto &pair : *var_name_map) {
std::vector<std::string> &var_names = pair.second;
auto it = var_names.begin();
while (it != var_names.end()) {
if (it->find(ir::Node::kControlDepVarName) != std::string::npos) {
it = var_names.erase(it);
VLOG(6) << "Remove var " << *it;
} else {
++it;
}
}
}
};

remove_control_dep_var(op_desc->MutableInputs());
remove_control_dep_var(op_desc->MutableOutputs());
op_desc->Flush();
}

static OpDesc *ReplaceScaleLossGradOp(const Node &node, OpDesc *desc) {
desc->SetType("fill_constant");
desc->SetAttr(
Expand Down Expand Up @@ -552,7 +573,9 @@ static void GraphToBlock(const Graph &graph,

std::vector<OpDesc> ops;
GetGraphOpDesc(nodes, &ops);

for (auto &op : ops) {
RemoveControlDepInputAndOuput(&op);
block->add_ops()->MergeFrom(*op.Proto());
}
}
Expand Down

0 comments on commit 8d3672f

Please sign in to comment.