From d9219685ade750211a887f9cb217580eefddef24 Mon Sep 17 00:00:00 2001 From: Yulong Wang <7679871+fs-eire@users.noreply.github.com> Date: Fri, 27 Jan 2023 16:56:14 -0800 Subject: [PATCH] always set OpSchema in CreateNodeHelper() (#14356) ### Description as a more generic solution to #13660, always set OpSchema in CreateNodeHelper() so that added nodes by transformers will have OpSchema set ### Motivation and Context --- .../transpose_optimizer/optimizer_api_impl.cc | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/onnxruntime/core/optimizer/transpose_optimizer/optimizer_api_impl.cc b/onnxruntime/core/optimizer/transpose_optimizer/optimizer_api_impl.cc index 517fcf63de..37409086a0 100644 --- a/onnxruntime/core/optimizer/transpose_optimizer/optimizer_api_impl.cc +++ b/onnxruntime/core/optimizer/transpose_optimizer/optimizer_api_impl.cc @@ -646,6 +646,12 @@ static Node& CreateNodeHelper(onnxruntime::Graph& graph, std::string_view op_typ graph.UpdateProducerNode(arg->Name(), node.Index()); } +#if !defined(ORT_MINIMAL_BUILD) + // add schema to make it equivalent with the other nodes in the graph created by Graph::Resolve() + // EPs may do kernel lookup during GetCapability which requires the schema + graph.SetOpSchemaFromRegistryForNode(node); +#endif + return node; } @@ -909,18 +915,7 @@ Status TransformLayoutForEP(Graph& graph, bool& modified, const IExecutionProvid onnx_layout_transformation::WrapTransposesAroundNode(*api_graph, *node, {&input_perm}, {&output_perm}); } - [[maybe_unused]] auto new_node_ref = - onnx_layout_transformation::SwapNodeOpTypeAndDomain(*api_graph, *node, node->OpType(), kMSInternalNHWCDomain); - -#if !defined(ORT_MINIMAL_BUILD) - // Set the schema if one is available. This keeps the node equivalent with the state of the original ONNX - // node (if possible - some replacement nodes do not have a schema). - // - Node& new_node = NodeFromApiNode(*new_node_ref); - // add schema if available. - // not guaranteed to be (compiling EP doesn't need schemas, not available in minimal build - graph.SetOpSchemaFromRegistryForNode(new_node); -#endif + onnx_layout_transformation::SwapNodeOpTypeAndDomain(*api_graph, *node, node->OpType(), kMSInternalNHWCDomain); modified = true; } }