!40286 Set Abstract for Return Node when MindIR and ONNX Import

Merge pull request !40286 from jiaorui/set-return-abstract
This commit is contained in:
i-robot 2022-08-16 01:25:06 +00:00 committed by Gitee
commit 120ea7d9ca
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 19 additions and 0 deletions

View File

@ -1375,6 +1375,7 @@ bool MSANFModelParser::BuildReturnForFuncGraph(const FuncGraphPtr &outputFuncGra
inputs.push_back(maketuple_ptr);
auto return_node = outputFuncGraph->NewCNode(inputs);
MS_EXCEPTION_IF_NULL(return_node);
return_node->set_abstract(maketuple_ptr->abstract());
return_node->set_load_flag(true);
outputFuncGraph->set_return(return_node);
MS_LOG(DEBUG) << "Construct funcgraph finined, all success.";
@ -1389,6 +1390,7 @@ bool MSANFModelParser::BuildReturnForFuncGraph(const FuncGraphPtr &outputFuncGra
inputs.push_back(anfNode);
auto return_node = outputFuncGraph->NewCNode(inputs);
MS_EXCEPTION_IF_NULL(return_node);
return_node->set_abstract(anfNode->abstract());
return_node->set_load_flag(true);
outputFuncGraph->set_return(return_node);
MS_LOG(DEBUG) << "Construct funcgraph finined, all success!";

View File

@ -185,6 +185,18 @@ STATUS BuildReturnNode(const FuncGraphPtr &anf_graph, const std::vector<AnfNodeP
MS_LOG(ERROR) << "new Return failed";
return RET_NULL_PTR;
}
if (return_inputs.empty()) {
MS_LOG(ERROR) << "return input is empty";
return RET_ERROR;
}
auto input = return_inputs[0];
MS_EXCEPTION_IF_NULL(input);
auto abstract = input->abstract();
if (abstract == nullptr) {
MS_LOG(ERROR) << "Input node abstract is null, node: " << input->fullname_with_scope();
return RET_ERROR;
}
auto return_prim_c = return_prim->GetPrim();
MS_ASSERT(return_prim_c != nullptr);
auto return_cnode = anf_graph->NewCNode(return_prim_c, return_inputs);
@ -193,6 +205,7 @@ STATUS BuildReturnNode(const FuncGraphPtr &anf_graph, const std::vector<AnfNodeP
return RET_ERROR;
}
return_cnode->set_fullname_with_scope("Return");
return_cnode->set_abstract(abstract);
anf_graph->set_return(return_cnode);
return RET_OK;
}
@ -359,6 +372,7 @@ STATUS ConvertGraphOutputs(const onnx::GraphProto &onnx_graph, const FuncGraphPt
if (onnx_graph.output_size() > 1) {
std::vector<AnfNodePtr> make_tuple_inputs;
auto make_tuple_prim_ptr = std::make_shared<ops::MakeTuple>();
AbstractBasePtrList elem;
if (make_tuple_prim_ptr == nullptr) {
MS_LOG(ERROR) << "new MakeTuple failed";
return RET_NULL_PTR;
@ -373,6 +387,7 @@ STATUS ConvertGraphOutputs(const onnx::GraphProto &onnx_graph, const FuncGraphPt
MS_LOG(ERROR) << "Can't find input node.";
return RET_NOT_FIND_OP;
}
elem.emplace_back(cnode->abstract());
make_tuple_inputs.emplace_back(cnode);
}
auto make_tuple_prim_c = make_tuple_prim_ptr->GetPrim();
@ -382,7 +397,9 @@ STATUS ConvertGraphOutputs(const onnx::GraphProto &onnx_graph, const FuncGraphPt
MS_LOG(ERROR) << "new cnode error";
return RET_ERROR;
}
make_tuple_cnode->set_fullname_with_scope("return tuple");
make_tuple_cnode->set_abstract(std::make_shared<abstract::AbstractTuple>(elem));
return_inputs.emplace_back(make_tuple_cnode);
} else {
const auto &graph_out = onnx_graph.output(0);