Skip to content

Commit ebed2c3

Browse files
Unified OV compile_model API in OVEP (microsoft#20700)
### Description Have a unified API in OVEP that pass the ONNX graph proto from ORT to OV for compilation ### Motivation and Context The earlier implementation used two different flows when onnx model path is present vs model laoded from memory. The former directly passed the onnx model path to OV when the graph is fully supported by EP. While the latter pass the ORT model proto to OV. This cause a difference in results when ORT optimizations are enabled. This PR address this issue.
1 parent 036fcd9 commit ebed2c3

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

onnxruntime/core/providers/openvino/backends/basic_backend.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ BasicBackend::BasicBackend(const ONNX_NAMESPACE::ModelProto& model_proto,
9090
device_config,
9191
subgraph_context_.subgraph_name);
9292
ie_cnn_network_ = exe_network_.Get().get_runtime_model();
93-
} else if (!subgraph_context_.has_dynamic_input_shape &&
94-
global_context_.onnx_model_path_name.find(".onnx") != std::string ::npos) {
93+
} else if (!subgraph_context_.has_dynamic_input_shape) {
9594
// Inputs with static dimenstions
9695
std::string prec_str = (global_context_.precision_str != "ACCURACY") ? global_context_.precision_str : global_context_.model_precision;
97-
exe_network_ = global_context_.ie_core.CompileModel(global_context_.onnx_model_path_name,
96+
const std::string model = model_proto.SerializeAsString();
97+
exe_network_ = global_context_.ie_core.CompileModel(model,
9898
hw_target,
9999
prec_str,
100100
global_context_.cache_dir,

onnxruntime/core/providers/openvino/ov_interface.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ OVExeNetwork OVCore::CompileModel(std::shared_ptr<const OVNetwork>& ie_cnn_netwo
8888
}
8989
}
9090

91-
OVExeNetwork OVCore::CompileModel(const std::string onnx_model_path,
91+
OVExeNetwork OVCore::CompileModel(const std::string& onnx_model,
9292
std::string& hw_target,
9393
std::string precision,
9494
std::string cache_dir,
@@ -97,13 +97,13 @@ OVExeNetwork OVCore::CompileModel(const std::string onnx_model_path,
9797
ov::CompiledModel obj;
9898
try {
9999
if (hw_target == "AUTO:GPU,CPU") {
100-
obj = oe.compile_model(onnx_model_path,
100+
obj = oe.compile_model(onnx_model, ov::Tensor(),
101101
"AUTO",
102102
ov::device::priorities("GPU", "CPU"),
103103
ov::device::properties("GPU", {ov::cache_dir(cache_dir),
104104
ov::hint::inference_precision(precision)}));
105105
} else {
106-
obj = oe.compile_model(onnx_model_path, hw_target, device_config);
106+
obj = oe.compile_model(onnx_model, ov::Tensor(), hw_target, device_config);
107107
}
108108
#ifndef NDEBUG
109109
printDebugInfo(obj);

onnxruntime/core/providers/openvino/ov_interface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class OVCore {
4444
std::string& hw_target,
4545
ov::AnyMap& device_config,
4646
std::string name);
47-
OVExeNetwork CompileModel(const std::string onnx_model_path,
47+
OVExeNetwork CompileModel(const std::string& onnx_model,
4848
std::string& hw_target,
4949
std::string precision,
5050
std::string cache_dir,

0 commit comments

Comments
 (0)