Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion onnxruntime/core/providers/openvino/backend_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
37 changes: 18 additions & 19 deletions onnxruntime/core/providers/openvino/ov_versions/capability.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,28 +166,28 @@ std::vector<std::unique_ptr<ComputeCapability>> 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(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;
// 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 (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<std::string> cluster_graph_inputs, cluster_inputs, cluster_outputs;
Expand All @@ -199,7 +199,6 @@ std::vector<std::unique_ptr<ComputeCapability>> GetCapability::Execute() {
cluster_inputs,
cluster_outputs);


// Omitting zero dim subgraphs
for (auto index : this_cluster) {
const Node* node = graph_viewer_.GetNode(index);
Expand Down Expand Up @@ -238,7 +237,7 @@ std::vector<std::unique_ptr<ComputeCapability>> GetCapability::Execute() {
}
}

cluster_index = cluster_index+1;
cluster_index = cluster_index + 1;
}
LOGS_DEFAULT(INFO) << "[OpenVINO-EP] Supported subgraphs on OpenVINO: " << no_of_clusters;
}
Expand Down
22 changes: 10 additions & 12 deletions onnxruntime/core/providers/openvino/ov_versions/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,23 +156,21 @@ GetConnectedClusters(const GraphViewer& graph_viewer, const std::vector<std::vec
bool AddTrivialClusterToNextClusterIfConnected(const GraphViewer& graph_viewer,
const NodeIndex curr_node_index,
const std::vector<NodeIndex>& 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<NodeIndex>& cluster,
const std::unordered_set<std::string>& ng_required_initializers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
Loading