Skip to content

Sahar/psu lora fix 2 #788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: ovep-develop
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,23 @@ common::Status OpenVINOExecutionProvider::Compile(
auto& logger = *GetLogger();
Status status = Status::OK();

bool is_epctx_model = false;
if (!fused_nodes.empty()) {
// Assume these properties are constant for all the model subgraphs, otherwise move to SubGraphContext
const auto& graph_body_viewer_0 = fused_nodes[0].filtered_graph.get();
session_context_.onnx_model_path_name = graph_body_viewer_0.ModelPath().string();
session_context_.onnx_opset_version =
graph_body_viewer_0.DomainToVersionMap().at(kOnnxDomain);

// OVIR wrapped in epctx should be trated as source but this code does not
// This corner case is not in use and will be addressed in a future commit
is_epctx_model = ep_ctx_handle_.CheckForOVEPCtxNodeInGraph(graph_body_viewer_0);
}

// The block below is executed during EP context model inference
auto& metadata = shared_context_->shared_weights.metadata; // Metadata object in memory
if (session_context_.so_share_ep_contexts &&
!session_context_.so_context_enable &&
is_epctx_model &&
metadata.empty()) {
fs::path context_model_file_path = session_context_.so_context_file_path;
if (context_model_file_path.empty()) {
Expand Down
50 changes: 21 additions & 29 deletions onnxruntime/core/providers/openvino/ov_versions/capability.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,33 +166,23 @@ std::vector<std::unique_ptr<ComputeCapability>> GetCapability::Execute() {
auto connected_clusters = GetConnectedClusters(graph_viewer_, ng_clusters);

int no_of_clusters = 0;
std::vector<NodeIndex> prev_cluster;
bool try_next_cluster = false;

int cluster_index = 0;
for (auto this_cluster : connected_clusters) {
bool omit_subgraph = false;
if (try_next_cluster) {
// no need to check previous cluster
for (auto idx : prev_cluster) {
if ((std::find(this_cluster.begin(), this_cluster.end(), idx)) == this_cluster.end()) {
this_cluster.emplace_back(idx);
}
}
try_next_cluster = false;
}

// If subgraph has less then three, graph is considered trivial unless its an epctx cluster
if (!try_next_cluster && this_cluster.size() < 3) {
bool is_epctx_node = false;
for (auto node_idx : this_cluster) {
if (graph_viewer_.GetNode(node_idx)->OpType() == "EPContext")
is_epctx_node = true;
}
if (!is_epctx_node) {
omit_subgraph = true;
prev_cluster = this_cluster;
try_next_cluster = true;
}
//auto id = this_cluster.at(0);
if (this_cluster.size() == 1) {
//check next cluster
auto index = this_cluster.at(0);
if (graph_viewer_.GetNode(index)->OpType() == "EPContext") {
omit_subgraph=false;
} else if(cluster_index < connected_clusters.size()-1) {
bool append_node = AddTrivialClusterToNextClusterIfConnected(graph_viewer_, index, connected_clusters[cluster_index+1]);
if(append_node) {
connected_clusters[cluster_index+1].emplace_back(index);
}
omit_subgraph=true;
}
}

std::vector<std::string> cluster_graph_inputs, cluster_inputs, cluster_outputs;
Expand Down Expand Up @@ -233,15 +223,17 @@ std::vector<std::unique_ptr<ComputeCapability>> GetCapability::Execute() {
}
}
}
if (omit_subgraph)
continue;

/* In scenarios, when there are no inputs or all inputs being initializers,
ConstantFolding optimization in onnxruntime pre-computes the value.*/
if (!cluster_inputs.empty()) {
AppendClusterToSubGraph(this_cluster, cluster_inputs, cluster_outputs, result);
no_of_clusters++;
if (!omit_subgraph) {
if (!cluster_inputs.empty()) {
AppendClusterToSubGraph(this_cluster, cluster_inputs, cluster_outputs, result);
no_of_clusters++;
}
}

cluster_index = cluster_index+1;
}
LOGS_DEFAULT(INFO) << "[OpenVINO-EP] Supported subgraphs on OpenVINO: " << no_of_clusters;
}
Expand Down
20 changes: 20 additions & 0 deletions onnxruntime/core/providers/openvino/ov_versions/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,26 @@ GetConnectedClusters(const GraphViewer& graph_viewer, const std::vector<std::vec
return connected_clusters;
}

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 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
4 changes: 4 additions & 0 deletions onnxruntime/core/providers/openvino/ov_versions/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ void IdentifyConnectedNodes(
std::vector<std::vector<NodeIndex>>
GetConnectedClusters(const GraphViewer& graph_viewer, const std::vector<std::vector<NodeIndex>>& clusters);

bool AddTrivialClusterToNextClusterIfConnected(const GraphViewer& graph_viewer,
const NodeIndex index,
const std::vector<NodeIndex>& search_cluster);

void GetInputsOutputsOfCluster(const GraphViewer& graph_viewer,
const std::vector<NodeIndex>& cluster,
const std::unordered_set<std::string>& ng_required_initializers,
Expand Down