fix errors for node with empty name for vitis ai (#16949)

### Description
Fixed the issue of finding nodes with empty name for vitis ai.



### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
It is required because we encountered this error when testing newly
created models.
This commit is contained in:
BoarQing 2023-08-03 10:08:49 +08:00 committed by GitHub
parent 246cb3a197
commit b8bbc898c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -27,19 +27,13 @@ std::vector<const Node*> node_arg_names_to_nodes(const GraphViewer& graph,
static std::vector<NodeIndex> node_names_to_nodes(const GraphViewer& graph,
const std::vector<std::string>& node_names) {
auto find_node = [&](const std::string& node_name) -> NodeIndex {
for (auto& n : graph.Nodes()) {
if (n.Name() == node_name) {
return n.Index();
}
}
vai_assert(false, std::string("cannot find node: " + node_name));
return onnxruntime::NodeIndex(-1);
};
auto ret = std::vector<NodeIndex>();
ret.reserve(node_names.size());
for (auto& onnx_node_name : node_names) {
ret.push_back(find_node(onnx_node_name));
// onnnx_node_name is actually node arg name.
auto node = graph.GetProducerNode(onnx_node_name);
vai_assert(node != nullptr, std::string("cannot find producer. onnx_node_arg_name=" + onnx_node_name));
ret.push_back(node->Index());
}
return ret;
}