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

Remove ControlDepVar in GraphToBlock #44591

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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