未验证 提交 a2c4c86b 编写于 作者: R Ruibiao Chen 提交者: GitHub

Fix var duplication bug for graph_to_program_pass (#44278)

上级 d88e77a7
......@@ -579,6 +579,12 @@ void GraphToProgram(const Graph &graph,
VLOG(3) << "Graph to program need convert " << graph.SubGraphsSize()
<< " sub graph";
std::unordered_set<std::string> vars_in_root_block;
for (const proto::VarDesc &var : block->vars()) {
vars_in_root_block.insert(var.name());
}
for (size_t idx = 0; idx < graph.SubGraphsSize(); ++idx) {
// avoid kRootBlockIndex not 0
if (idx == kRootBlockIndex) continue;
......@@ -586,7 +592,14 @@ void GraphToProgram(const Graph &graph,
block = program_pb.add_blocks();
block->set_idx(idx);
block->set_parent_idx(kRootBlockIndex);
GraphToBlock(*graph.GetSubGraph(idx), block, sort_kind);
Graph *subgraph = graph.GetSubGraph(idx);
subgraph->SetNotOwned<std::unordered_set<std::string>>(
kGraphToProgramVarsToRemove, &vars_in_root_block);
GraphToBlock(*subgraph, block, sort_kind);
subgraph->Erase(kGraphToProgramVarsToRemove);
}
} else {
GraphToBlock(graph, block, sort_kind);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册