diff --git a/paddle/fluid/framework/ir/subgraph_detector.cc b/paddle/fluid/framework/ir/subgraph_detector.cc index 987194752ad3bf80f81ed2d8a5e51227e8ab735f..cce72ae161b51ebcc2b43d59be41e3b79d36c36f 100644 --- a/paddle/fluid/framework/ir/subgraph_detector.cc +++ b/paddle/fluid/framework/ir/subgraph_detector.cc @@ -45,7 +45,9 @@ ExtractInputAndOutputOfSubGraph(std::vector &graph) { // NOLINT } } for (auto *out : node->outputs) { - if (!nodes.count(out) && out->IsVar()) { + // we forbid out is a persistable var, for case when weight is shared + // between within and outside this tensorrt_engine op. + if (!nodes.count(out) && out->IsVar() && !out->Var()->Persistable()) { outputs.insert(out); } } @@ -416,7 +418,7 @@ void DetachDeletedNodes(framework::ir::Graph *graph) { void SubGraphFuser::ReplaceNodesWithSubGraphs() { auto subgraphs = SubgraphDetector(graph_, node_inside_subgraph_teller_)(); for (auto &subgraph : subgraphs) { - if (subgraph.size() <= (size_t)min_subgraph_size_) continue; + if (subgraph.size() <= static_cast(min_subgraph_size_)) continue; std::unordered_set subgraph_uniq(subgraph.begin(), subgraph.end()); // replace this sub-graph with the first node. Two steps: 1. Create a Block // Node that contains this subgraph 2. Mark the nodes inside the sub-graph