From d87f33986ffa2ba7c1ceb0dc6f0c4467337d18a4 Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Tue, 12 Dec 2023 15:10:09 +0200 Subject: [PATCH 1/4] Remove extra NodeProto serialization in Graph::VerifyNodeAndOpMatch --- onnxruntime/core/graph/graph.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/onnxruntime/core/graph/graph.cc b/onnxruntime/core/graph/graph.cc index d489a59c4b798..41f25f7995124 100644 --- a/onnxruntime/core/graph/graph.cc +++ b/onnxruntime/core/graph/graph.cc @@ -2539,14 +2539,14 @@ Status Graph::VerifyNodeAndOpMatch(const ResolveOptions& options) { // Node verification. auto& node = *GetNode(node_index); - NodeProto node_proto; - node.ToProto(node_proto); const auto& node_name = node.Name(); if (!node.Op()) { { auto status = Status::OK(); ORT_TRY { + NodeProto node_proto; + node.ToProto(node_proto); checker::check_node(node_proto, ctx, lsc); } ORT_CATCH(const std::exception& ex) { @@ -2619,8 +2619,8 @@ Status Graph::VerifyNodeAndOpMatch(const ResolveOptions& options) { NO_CHANGE_ON_SYNC_FLAG(ORT_RETURN_IF_ERROR(InferAndVerifyTypeMatch(node, *p_op, options))); // Accumulate output names of the iterated Node - for (auto& output_name : node_proto.output()) { - lsc.output_names.insert(output_name); + for (const auto &output : node.OutputDefs()) { + lsc.output_names.insert(output->Name()); } } From 783bc009eb462edb2835cfa71014d98ea6072202 Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Tue, 12 Dec 2023 15:11:52 +0200 Subject: [PATCH 2/4] Appease linter --- onnxruntime/core/graph/graph.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/onnxruntime/core/graph/graph.cc b/onnxruntime/core/graph/graph.cc index 41f25f7995124..c633895996dda 100644 --- a/onnxruntime/core/graph/graph.cc +++ b/onnxruntime/core/graph/graph.cc @@ -2545,8 +2545,8 @@ Status Graph::VerifyNodeAndOpMatch(const ResolveOptions& options) { { auto status = Status::OK(); ORT_TRY { - NodeProto node_proto; - node.ToProto(node_proto); + NodeProto node_proto; + node.ToProto(node_proto); checker::check_node(node_proto, ctx, lsc); } ORT_CATCH(const std::exception& ex) { @@ -2619,7 +2619,7 @@ Status Graph::VerifyNodeAndOpMatch(const ResolveOptions& options) { NO_CHANGE_ON_SYNC_FLAG(ORT_RETURN_IF_ERROR(InferAndVerifyTypeMatch(node, *p_op, options))); // Accumulate output names of the iterated Node - for (const auto &output : node.OutputDefs()) { + for (const auto& output : node.OutputDefs()) { lsc.output_names.insert(output->Name()); } } From eb2d26f937d6abaae3afa9e95bb88db103e47130 Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Thu, 14 Dec 2023 15:15:05 +0200 Subject: [PATCH 3/4] Call SetOpSchemaFromRegistryForNode while initializing model --- onnxruntime/core/graph/graph.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/onnxruntime/core/graph/graph.cc b/onnxruntime/core/graph/graph.cc index c633895996dda..fd36241c995bf 100644 --- a/onnxruntime/core/graph/graph.cc +++ b/onnxruntime/core/graph/graph.cc @@ -1310,7 +1310,8 @@ Graph::Graph(const Model& owning_model, } for (const auto& node_proto : graph_proto_->node()) { - AddNode(node_proto, name_to_type_map); + auto& new_node = AddNode(node_proto, name_to_type_map); + SetOpSchemaFromRegistryForNode(new_node); } if (is_loaded_from_model_file_) { From fec9829604627c27bbb4ebe3febde10d7bf29a90 Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Wed, 3 Jan 2024 14:41:30 +0200 Subject: [PATCH 4/4] Revert breaking change --- onnxruntime/core/graph/graph.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/onnxruntime/core/graph/graph.cc b/onnxruntime/core/graph/graph.cc index fd36241c995bf..c633895996dda 100644 --- a/onnxruntime/core/graph/graph.cc +++ b/onnxruntime/core/graph/graph.cc @@ -1310,8 +1310,7 @@ Graph::Graph(const Model& owning_model, } for (const auto& node_proto : graph_proto_->node()) { - auto& new_node = AddNode(node_proto, name_to_type_map); - SetOpSchemaFromRegistryForNode(new_node); + AddNode(node_proto, name_to_type_map); } if (is_loaded_from_model_file_) {