Skip to content
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
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 @@ -578,14 +578,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