Skip to content

Commit

Permalink
Fix var duplication bug for graph_to_program_pass (PaddlePaddle#44278)
Browse files Browse the repository at this point in the history
  • Loading branch information
From00 authored Jul 14, 2022
1 parent d88e77a commit a2c4c86
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion paddle/fluid/framework/ir/graph_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -579,14 +579,27 @@ 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;

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);
Expand Down

0 comments on commit a2c4c86

Please sign in to comment.