diff --git a/onnxruntime/core/providers/openvino/backend_manager.cc b/onnxruntime/core/providers/openvino/backend_manager.cc index e1899405629c8..68d15bdfdcee0 100644 --- a/onnxruntime/core/providers/openvino/backend_manager.cc +++ b/onnxruntime/core/providers/openvino/backend_manager.cc @@ -95,7 +95,7 @@ BackendManager::BackendManager(SessionContext& session_context, } else { model_stream = ep_ctx_handle_.GetModelBlobStream(session_context_.so_context_file_path, subgraph); } - + } else { model_proto = GetModelProtoFromFusedNode(fused_node, subgraph, logger); } diff --git a/onnxruntime/core/providers/openvino/ov_versions/capability.cc b/onnxruntime/core/providers/openvino/ov_versions/capability.cc index 593a78491080a..1893700cab09c 100644 --- a/onnxruntime/core/providers/openvino/ov_versions/capability.cc +++ b/onnxruntime/core/providers/openvino/ov_versions/capability.cc @@ -166,28 +166,28 @@ std::vector> GetCapability::Execute() { auto connected_clusters = GetConnectedClusters(graph_viewer_, ng_clusters); int no_of_clusters = 0; - size_t cluster_index = 0; - size_t total_clusters = connected_clusters.size(); + size_t cluster_index = 0; + size_t total_clusters = connected_clusters.size(); for (auto this_cluster : connected_clusters) { bool omit_subgraph = false; if (this_cluster.size() == 1) { - //check next cluster - auto index = this_cluster.at(0); - size_t j = cluster_index; - if (graph_viewer_.GetNode(index)->OpType() == "EPContext") { - omit_subgraph=false; - } else if(j < total_clusters-1) { - bool append_node = false; - while(jOpType() == "EPContext") { + omit_subgraph = false; + } else if (j < total_clusters - 1) { + bool append_node = false; + while (j < total_clusters && !append_node) { + j = j + 1; + append_node = AddTrivialClusterToNextClusterIfConnected(graph_viewer_, index, connected_clusters[j]); } + if (append_node) { + connected_clusters[j].emplace_back(index); + } + omit_subgraph = true; + } } std::vector cluster_graph_inputs, cluster_inputs, cluster_outputs; @@ -199,7 +199,6 @@ std::vector> GetCapability::Execute() { cluster_inputs, cluster_outputs); - // Omitting zero dim subgraphs for (auto index : this_cluster) { const Node* node = graph_viewer_.GetNode(index); @@ -238,7 +237,7 @@ std::vector> GetCapability::Execute() { } } - cluster_index = cluster_index+1; + cluster_index = cluster_index + 1; } LOGS_DEFAULT(INFO) << "[OpenVINO-EP] Supported subgraphs on OpenVINO: " << no_of_clusters; } diff --git a/onnxruntime/core/providers/openvino/ov_versions/utils.cc b/onnxruntime/core/providers/openvino/ov_versions/utils.cc index 814378eab47d5..791341218913f 100644 --- a/onnxruntime/core/providers/openvino/ov_versions/utils.cc +++ b/onnxruntime/core/providers/openvino/ov_versions/utils.cc @@ -156,23 +156,21 @@ GetConnectedClusters(const GraphViewer& graph_viewer, const std::vector& search_cluster) { + for (auto index : search_cluster) { + auto curr_node = graph_viewer.GetNode(index); + for (auto node = curr_node->InputNodesBegin(); node != curr_node->InputNodesEnd(); ++node) { + if ((*node).Index() == curr_node_index) + return true; + } - for(auto index: search_cluster) { - auto curr_node = graph_viewer.GetNode(index); - for (auto node = curr_node->InputNodesBegin(); node != curr_node->InputNodesEnd(); ++node) { - if((*node).Index() == curr_node_index) - return true; - } - - for (auto node = curr_node->OutputNodesBegin(); node != curr_node->OutputNodesEnd(); ++node) { - if((*node).Index() == curr_node_index) - return true; - } + for (auto node = curr_node->OutputNodesBegin(); node != curr_node->OutputNodesEnd(); ++node) { + if ((*node).Index() == curr_node_index) + return true; + } } return false; } - void GetInputsOutputsOfCluster(const GraphViewer& graph_viewer, const std::vector& cluster, const std::unordered_set& ng_required_initializers, diff --git a/onnxruntime/core/providers/openvino/qdq_transformations/qdq_stripping.cc b/onnxruntime/core/providers/openvino/qdq_transformations/qdq_stripping.cc index 7f88879a7a456..e010851f22e50 100644 --- a/onnxruntime/core/providers/openvino/qdq_transformations/qdq_stripping.cc +++ b/onnxruntime/core/providers/openvino/qdq_transformations/qdq_stripping.cc @@ -680,22 +680,22 @@ static void AddInitializerAsInput(onnxruntime::Graph& dst_graph, // To check if the input parameters of a DQ or Q node are quantization parameters // Scale and Zero point parameters are quantization parameters static bool IsQuantizationParameter(const std::string& initializer_name, - const onnxruntime::GraphViewer& src_graph) { - // Check if this initializer is used as scale or zero_point in any DQ/Q node - for (auto& node_idx : src_graph.GetNodesInTopologicalOrder()) { - const auto* node = src_graph.GetNode(node_idx); - if (node->OpType() == "DequantizeLinear" || node->OpType() == "QuantizeLinear") { - const auto& input_defs = node->InputDefs(); - // Check if this initializer is used as scale (input 1) or zero_point (input 2) - if (input_defs.size() >= 2 && input_defs[1]->Name() == initializer_name) { - return true; // This is a scale parameter - } - if (input_defs.size() >= 3 && input_defs[2]->Name() == initializer_name) { - return true; // This is a zero_point parameter - } - } + const onnxruntime::GraphViewer& src_graph) { + // Check if this initializer is used as scale or zero_point in any DQ/Q node + for (auto& node_idx : src_graph.GetNodesInTopologicalOrder()) { + const auto* node = src_graph.GetNode(node_idx); + if (node->OpType() == "DequantizeLinear" || node->OpType() == "QuantizeLinear") { + const auto& input_defs = node->InputDefs(); + // Check if this initializer is used as scale (input 1) or zero_point (input 2) + if (input_defs.size() >= 2 && input_defs[1]->Name() == initializer_name) { + return true; // This is a scale parameter + } + if (input_defs.size() >= 3 && input_defs[2]->Name() == initializer_name) { + return true; // This is a zero_point parameter + } } - return false; + } + return false; } // Creates a new model without the DQ/Q operators in the src graph. @@ -866,31 +866,29 @@ Status CreateModelWithStrippedQDQNodes(const GraphViewer& src_graph, if (!init_with_data && utils::HasExternalData(initializer_tensor) && enable_ovep_weight_sharing) { + // Only convert to input if it's not a quantization parameter + bool is_quant_param = IsQuantizationParameter(name, src_graph); - // Only convert to input if it's not a quantization parameter - bool is_quant_param = IsQuantizationParameter(name, src_graph); - - if (!is_quant_param) { - // This is actual weight data - so to convert to input for weight sharing - insert_metadata(initializer_tensor); - AddInitializerAsInput(dst_graph, accumulated_inputs, src_graph, name); - } else { - // This is a quantization parameter - keep as initializer even if external - - if (initializers_to_keep.count(name) > 0) { + if (!is_quant_param) { + // This is actual weight data - so to convert to input for weight sharing + insert_metadata(initializer_tensor); + AddInitializerAsInput(dst_graph, accumulated_inputs, src_graph, name); + } else { + // This is a quantization parameter - keep as initializer even if external - dst_graph.AddInitializedTensor(initializer_tensor); - } + if (initializers_to_keep.count(name) > 0) { + dst_graph.AddInitializedTensor(initializer_tensor); } + } } else { - // Add as an initialized tensor if it does not have external data - if (initializers_to_keep.count(name) > 0) { - if (init_with_data) { - dst_graph.AddInitializedTensor(*init_with_data); - } else { - dst_graph.AddInitializedTensor(initializer_tensor); - } + // Add as an initialized tensor if it does not have external data + if (initializers_to_keep.count(name) > 0) { + if (init_with_data) { + dst_graph.AddInitializedTensor(*init_with_data); + } else { + dst_graph.AddInitializedTensor(initializer_tensor); } + } } current_scope_initializer_set.insert(name);