Skip to content

Commit 43608c7

Browse files
Merge branch 'ovep-develop' into preetha/get_capability
2 parents 339b524 + 7eafccb commit 43608c7

File tree

4 files changed

+62
-67
lines changed

4 files changed

+62
-67
lines changed

onnxruntime/core/providers/openvino/backend_manager.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ BackendManager::BackendManager(SessionContext& session_context,
9595
} else {
9696
model_stream = ep_ctx_handle_.GetModelBlobStream(session_context_.so_context_file_path, subgraph);
9797
}
98-
98+
9999
} else {
100100
model_proto = GetModelProtoFromFusedNode(fused_node, subgraph, logger);
101101
}

onnxruntime/core/providers/openvino/ov_versions/capability.cc

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -166,28 +166,28 @@ std::vector<std::unique_ptr<ComputeCapability>> GetCapability::Execute() {
166166
auto connected_clusters = GetConnectedClusters(graph_viewer_, ng_clusters);
167167

168168
int no_of_clusters = 0;
169-
size_t cluster_index = 0;
170-
size_t total_clusters = connected_clusters.size();
169+
size_t cluster_index = 0;
170+
size_t total_clusters = connected_clusters.size();
171171
for (auto this_cluster : connected_clusters) {
172172
bool omit_subgraph = false;
173173

174174
if (this_cluster.size() == 1) {
175-
//check next cluster
176-
auto index = this_cluster.at(0);
177-
size_t j = cluster_index;
178-
if (graph_viewer_.GetNode(index)->OpType() == "EPContext") {
179-
omit_subgraph=false;
180-
} else if(j < total_clusters-1) {
181-
bool append_node = false;
182-
while(j<total_clusters && !append_node) {
183-
j=j+1;
184-
append_node = AddTrivialClusterToNextClusterIfConnected(graph_viewer_, index, connected_clusters[j]);
185-
}
186-
if(append_node) {
187-
connected_clusters[j].emplace_back(index);
188-
}
189-
omit_subgraph=true;
175+
// check next cluster
176+
auto index = this_cluster.at(0);
177+
size_t j = cluster_index;
178+
if (graph_viewer_.GetNode(index)->OpType() == "EPContext") {
179+
omit_subgraph = false;
180+
} else if (j < total_clusters - 1) {
181+
bool append_node = false;
182+
while (j < total_clusters && !append_node) {
183+
j = j + 1;
184+
append_node = AddTrivialClusterToNextClusterIfConnected(graph_viewer_, index, connected_clusters[j]);
190185
}
186+
if (append_node) {
187+
connected_clusters[j].emplace_back(index);
188+
}
189+
omit_subgraph = true;
190+
}
191191
}
192192

193193
std::vector<std::string> cluster_graph_inputs, cluster_inputs, cluster_outputs;
@@ -199,7 +199,6 @@ std::vector<std::unique_ptr<ComputeCapability>> GetCapability::Execute() {
199199
cluster_inputs,
200200
cluster_outputs);
201201

202-
203202
// Omitting zero dim subgraphs
204203
for (auto index : this_cluster) {
205204
const Node* node = graph_viewer_.GetNode(index);
@@ -238,7 +237,7 @@ std::vector<std::unique_ptr<ComputeCapability>> GetCapability::Execute() {
238237
}
239238
}
240239

241-
cluster_index = cluster_index+1;
240+
cluster_index = cluster_index + 1;
242241
}
243242
LOGS_DEFAULT(INFO) << "[OpenVINO-EP] Supported subgraphs on OpenVINO: " << no_of_clusters;
244243
}

onnxruntime/core/providers/openvino/ov_versions/utils.cc

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -156,23 +156,21 @@ GetConnectedClusters(const GraphViewer& graph_viewer, const std::vector<std::vec
156156
bool AddTrivialClusterToNextClusterIfConnected(const GraphViewer& graph_viewer,
157157
const NodeIndex curr_node_index,
158158
const std::vector<NodeIndex>& search_cluster) {
159+
for (auto index : search_cluster) {
160+
auto curr_node = graph_viewer.GetNode(index);
161+
for (auto node = curr_node->InputNodesBegin(); node != curr_node->InputNodesEnd(); ++node) {
162+
if ((*node).Index() == curr_node_index)
163+
return true;
164+
}
159165

160-
for(auto index: search_cluster) {
161-
auto curr_node = graph_viewer.GetNode(index);
162-
for (auto node = curr_node->InputNodesBegin(); node != curr_node->InputNodesEnd(); ++node) {
163-
if((*node).Index() == curr_node_index)
164-
return true;
165-
}
166-
167-
for (auto node = curr_node->OutputNodesBegin(); node != curr_node->OutputNodesEnd(); ++node) {
168-
if((*node).Index() == curr_node_index)
169-
return true;
170-
}
166+
for (auto node = curr_node->OutputNodesBegin(); node != curr_node->OutputNodesEnd(); ++node) {
167+
if ((*node).Index() == curr_node_index)
168+
return true;
169+
}
171170
}
172171
return false;
173172
}
174173

175-
176174
void GetInputsOutputsOfCluster(const GraphViewer& graph_viewer,
177175
const std::vector<NodeIndex>& cluster,
178176
const std::unordered_set<std::string>& ng_required_initializers,

onnxruntime/core/providers/openvino/qdq_transformations/qdq_stripping.cc

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -680,22 +680,22 @@ static void AddInitializerAsInput(onnxruntime::Graph& dst_graph,
680680
// To check if the input parameters of a DQ or Q node are quantization parameters
681681
// Scale and Zero point parameters are quantization parameters
682682
static bool IsQuantizationParameter(const std::string& initializer_name,
683-
const onnxruntime::GraphViewer& src_graph) {
684-
// Check if this initializer is used as scale or zero_point in any DQ/Q node
685-
for (auto& node_idx : src_graph.GetNodesInTopologicalOrder()) {
686-
const auto* node = src_graph.GetNode(node_idx);
687-
if (node->OpType() == "DequantizeLinear" || node->OpType() == "QuantizeLinear") {
688-
const auto& input_defs = node->InputDefs();
689-
// Check if this initializer is used as scale (input 1) or zero_point (input 2)
690-
if (input_defs.size() >= 2 && input_defs[1]->Name() == initializer_name) {
691-
return true; // This is a scale parameter
692-
}
693-
if (input_defs.size() >= 3 && input_defs[2]->Name() == initializer_name) {
694-
return true; // This is a zero_point parameter
695-
}
696-
}
683+
const onnxruntime::GraphViewer& src_graph) {
684+
// Check if this initializer is used as scale or zero_point in any DQ/Q node
685+
for (auto& node_idx : src_graph.GetNodesInTopologicalOrder()) {
686+
const auto* node = src_graph.GetNode(node_idx);
687+
if (node->OpType() == "DequantizeLinear" || node->OpType() == "QuantizeLinear") {
688+
const auto& input_defs = node->InputDefs();
689+
// Check if this initializer is used as scale (input 1) or zero_point (input 2)
690+
if (input_defs.size() >= 2 && input_defs[1]->Name() == initializer_name) {
691+
return true; // This is a scale parameter
692+
}
693+
if (input_defs.size() >= 3 && input_defs[2]->Name() == initializer_name) {
694+
return true; // This is a zero_point parameter
695+
}
697696
}
698-
return false;
697+
}
698+
return false;
699699
}
700700

701701
// Creates a new model without the DQ/Q operators in the src graph.
@@ -866,31 +866,29 @@ Status CreateModelWithStrippedQDQNodes(const GraphViewer& src_graph,
866866
if (!init_with_data &&
867867
utils::HasExternalData(initializer_tensor) &&
868868
enable_ovep_weight_sharing) {
869+
// Only convert to input if it's not a quantization parameter
870+
bool is_quant_param = IsQuantizationParameter(name, src_graph);
869871

870-
// Only convert to input if it's not a quantization parameter
871-
bool is_quant_param = IsQuantizationParameter(name, src_graph);
872-
873-
if (!is_quant_param) {
874-
// This is actual weight data - so to convert to input for weight sharing
875-
insert_metadata(initializer_tensor);
876-
AddInitializerAsInput(dst_graph, accumulated_inputs, src_graph, name);
877-
} else {
878-
// This is a quantization parameter - keep as initializer even if external
879-
880-
if (initializers_to_keep.count(name) > 0) {
872+
if (!is_quant_param) {
873+
// This is actual weight data - so to convert to input for weight sharing
874+
insert_metadata(initializer_tensor);
875+
AddInitializerAsInput(dst_graph, accumulated_inputs, src_graph, name);
876+
} else {
877+
// This is a quantization parameter - keep as initializer even if external
881878

882-
dst_graph.AddInitializedTensor(initializer_tensor);
883-
}
879+
if (initializers_to_keep.count(name) > 0) {
880+
dst_graph.AddInitializedTensor(initializer_tensor);
884881
}
882+
}
885883
} else {
886-
// Add as an initialized tensor if it does not have external data
887-
if (initializers_to_keep.count(name) > 0) {
888-
if (init_with_data) {
889-
dst_graph.AddInitializedTensor(*init_with_data);
890-
} else {
891-
dst_graph.AddInitializedTensor(initializer_tensor);
892-
}
884+
// Add as an initialized tensor if it does not have external data
885+
if (initializers_to_keep.count(name) > 0) {
886+
if (init_with_data) {
887+
dst_graph.AddInitializedTensor(*init_with_data);
888+
} else {
889+
dst_graph.AddInitializedTensor(initializer_tensor);
893890
}
891+
}
894892
}
895893

896894
current_scope_initializer_set.insert(name);

0 commit comments

Comments
 (0)