From 26c8b5519b421ae7e381b6a9bdc7d59d91858880 Mon Sep 17 00:00:00 2001 From: jackzhang235 Date: Wed, 1 Apr 2020 09:39:10 +0000 Subject: [PATCH] fix a bug in subgraph division: put all intermediate outputs to local outputs wrongly --- lite/core/mir/subgraph/subgraph_detector.cc | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lite/core/mir/subgraph/subgraph_detector.cc b/lite/core/mir/subgraph/subgraph_detector.cc index 454682043b..9799cc7243 100644 --- a/lite/core/mir/subgraph/subgraph_detector.cc +++ b/lite/core/mir/subgraph/subgraph_detector.cc @@ -450,9 +450,6 @@ void SubgraphFuser::InsertNewNode(SSAGraph *graph, for (auto &var_node : output_var_nodes) { output_var_names.push_back(var_node->AsArg().name); } - for (auto &var_node : local_var_nodes) { - output_var_names.push_back(var_node->AsArg().name); - } subgraph_op_desc.SetAttr>("input_data_names", input_var_names); subgraph_op_desc.SetAttr>("output_data_names", @@ -494,6 +491,9 @@ void SubgraphFuser::InsertNewNode(SSAGraph *graph, for (auto &var_node : weight_var_nodes) { input_var_names.push_back(var_node->AsArg().name); } + for (auto &var_node : local_var_nodes) { + output_var_names.push_back(var_node->AsArg().name); + } for (auto &var_node : unused_var_nodes) { output_var_names.push_back(var_node->AsArg().name); } @@ -579,13 +579,14 @@ void ExtractInputsOutputs(const std::vector &op_nodes, unused_var_nodes->insert(var_node); continue; } - // Var can have more than one next op node, So, if any one in the - // op_nodes then continue - bool next_op_in_nodes = false; + // Var can have more than one next op node, So, if all next nodes are in + // op_nodes then it should be put into local_var_nodes + bool next_op_in_nodes = true; for (auto &next_op_node : var_node->outlinks) { - if (std::find(op_nodes.begin(), op_nodes.end(), next_op_node) != + if (std::find(op_nodes.begin(), op_nodes.end(), next_op_node) == op_nodes.end()) { - next_op_in_nodes = true; + next_op_in_nodes = false; + break; } } if (next_op_in_nodes) { -- GitLab