Skip to content

Commit c923132

Browse files
saurabhkale17ankitm3k
authored andcommitted
Enable adaptive stripping and eliminate dependency of weight sharing feature on OVEP qdq stripping (#629)
* eliminate dependency of weight sharing on ovep qdq stripping pass * fix qdqnodeunit issue * enable compiler stripping * enable adaptive stripping: cleanup code * fix backward compatibility issue * add logs to identify which stripping is enabled * address PR review comments * fix unused variable error * resolve unused var issue * fix CI issues
1 parent 97dbd19 commit c923132

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

onnxruntime/core/providers/openvino/backend_manager.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "core/providers/openvino/ov_interface.h"
2121
#include "core/providers/openvino/ov_versions/capability.h"
2222
#include "core/providers/openvino/qdq_transformations/qdq_stripping.h"
23+
#include "core/providers/openvino/ov_interface.h"
2324

2425
namespace onnxruntime {
2526
namespace openvino_ep {
@@ -384,7 +385,7 @@ BackendManager::GetModelProtoFromFusedNode(const onnxruntime::Node& fused_node,
384385
if (session_context_.device_type.find("NPU") != std::string::npos &&
385386
(enable_ovep_qdq_optimizer || session_context_.so_share_ep_contexts)) {
386387
std::unique_ptr<onnxruntime::Model> model;
387-
Status status = CreateModelWithStrippedQDQNodes(subgraph, logger, session_context_.so_share_ep_contexts, enable_ovep_qdq_optimizer, model, shared_context_.shared_weights);
388+
Status status = CreateModelWithStrippedQDQNodes(subgraph, logger, session_context_.so_share_ep_contexts, model, shared_context_.shared_weights, enable_ovep_qdq_optimizer);
388389
auto model_proto = model->ToProto();
389390
model_proto->set_ir_version(ONNX_NAMESPACE::Version::IR_VERSION);
390391
print_model_proto_duration();

onnxruntime/core/providers/openvino/ov_interface.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ void printDebugInfo(const ov::CompiledModel& obj) {
4646
}
4747
#endif
4848

49+
// Function to check if a given OV property is enabled
50+
std::optional<bool> queryOVProperty(const std::string& property, const std::string& device_type) {
51+
try {
52+
// Get the property value
53+
auto supported_properties = OVCore::Get()->core.get_property(device_type, ov::supported_properties);
54+
return std::find(supported_properties.begin(), supported_properties.end(), property) != supported_properties.end();
55+
} catch (const std::exception&) {
56+
return std::nullopt; // Property not found or invalid
57+
}
58+
}
59+
4960
std::shared_ptr<OVNetwork> OVCore::ReadModel(std::string&& model, const std::string& model_path) {
5061
try {
5162
std::istringstream modelStringStream(std::move(model));

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,8 @@ static bool HandleDoubleQDQ(onnxruntime::Graph& dst_graph, const onnxruntime::Gr
449449
static void AddStandaloneNodeUnit(onnxruntime::Graph& dst_graph, const onnxruntime::GraphViewer& src_graph,
450450
const NodeUnit& node_unit,
451451
std::set<std::string>& initializers_to_keep,
452-
bool IsWeightSharingWithoutOVEPQDQStripping,
453-
const logging::Logger& /* logger */) {
452+
const logging::Logger& /* logger */,
453+
bool IsWeightSharingWithoutOVEPQDQStripping) {
454454
assert(node_unit.UnitType() == NodeUnit::Type::SingleNode);
455455

456456
// this is the scenario where WAI is enabled and ovep stripping is disabled
@@ -521,8 +521,8 @@ static void AddQDQNodeUnit(onnxruntime::Graph& dst_graph,
521521
const onnxruntime::GraphViewer& src_graph,
522522
const NodeUnit& node_unit,
523523
std::set<std::string>& initializers_to_keep,
524-
bool IsWeightSharingWithoutOVEPQDQStripping,
525-
const logging::Logger& /* logger */) {
524+
const logging::Logger& /* logger */,
525+
bool IsWeightSharingWithoutOVEPQDQStripping) {
526526
assert(node_unit.UnitType() == NodeUnit::Type::QDQGroup);
527527

528528
// Collect inputs coming into the node unit.
@@ -683,7 +683,8 @@ Status CreateModelWithStrippedQDQNodes(const GraphViewer& src_graph,
683683
bool enable_ovep_weight_sharing,
684684
bool enable_ovep_qdq_optimizer,
685685
/*out*/ std::unique_ptr<onnxruntime::Model>& model,
686-
/*out*/ sw& shared_weights) {
686+
/*out*/ sw& shared_weights,
687+
bool enable_ovep_qdq_optimizer) {
687688
// NOTE: This function is a re-implementation of GraphViewerToProto() in core/graph/graph_proto_serializer.cc
688689
// with the following differences:
689690
// - Uses onnxruntime::Graph APIs instead of onnx::GraphProto APIs.
@@ -777,9 +778,9 @@ Status CreateModelWithStrippedQDQNodes(const GraphViewer& src_graph,
777778
bool IsWeightSharingWithoutOVEPQDQStripping = enable_ovep_weight_sharing && !enable_ovep_qdq_optimizer;
778779

779780
if (node_unit->UnitType() == NodeUnit::Type::SingleNode) {
780-
AddStandaloneNodeUnit(dst_graph, src_graph, *node_unit, initializers_to_keep, IsWeightSharingWithoutOVEPQDQStripping, logger);
781+
AddStandaloneNodeUnit(dst_graph, src_graph, *node_unit, initializers_to_keep, logger, IsWeightSharingWithoutOVEPQDQStripping);
781782
} else {
782-
AddQDQNodeUnit(dst_graph, src_graph, *node_unit, initializers_to_keep, IsWeightSharingWithoutOVEPQDQStripping, logger);
783+
AddQDQNodeUnit(dst_graph, src_graph, *node_unit, initializers_to_keep, logger, IsWeightSharingWithoutOVEPQDQStripping);
783784
}
784785

785786
seen_node_units.insert(node_unit);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ Status CreateModelWithStrippedQDQNodes(const GraphViewer& src_graph,
1818
bool enable_ovep_weight_sharing,
1919
bool enable_ovep_qdq_optimizer,
2020
/*out*/ std::unique_ptr<onnxruntime::Model>& model,
21-
/*out*/ sw& shared_weights);
21+
/*out*/ sw& shared_weights,
22+
bool enable_ovep_qdq_optimizer);
2223

2324
bool dumpMetaDataMapToBinary(const sw::Metadata::Map& shared_weights, const std::string& filename);
2425
} // namespace openvino_ep

0 commit comments

Comments
 (0)