Skip to content

Commit cf851bf

Browse files
Merge pull request #752 from intel/rdmetca/disallowed_ep_options
disallowed provider option guidance & new GTests
2 parents 9e1d62c + 43e2415 commit cf851bf

File tree

2 files changed

+66
-7
lines changed

2 files changed

+66
-7
lines changed

onnxruntime/core/providers/openvino/openvino_provider_factory.cc

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -445,17 +445,35 @@ struct OpenVINO_Provider : Provider {
445445
return Status(common::ONNXRUNTIME, ORT_EP_FAIL, "No devices provided to CreateEp");
446446
}
447447

448-
// Block setting certain provider options via AppendExecutionProvider_V2
449-
// TODO: Expand this out and give better guidance for keys that should now flow through load_config.
450-
const std::unordered_set<std::string> blocked_provider_keys = {
451-
"device_type", "device_id", "device_luid", "cache_dir", "precision",
452-
"context", "num_of_threads", "model_priority", "num_streams",
453-
"enable_opencl_throttling", "enable_qdq_optimizer", "disable_dynamic_shapes"};
448+
// For provider options that we don't support anymore, give some guidance & examples
449+
// about how to make use of the option through load_config.
450+
const std::vector<std::pair<std::string, std::string>> block_and_advise_entries = {
451+
{"cache_dir", "\"CACHE_DIR\": \"<filesystem_path>\""},
452+
{"precision", "\"INFERENCE_PRECISION_HINT\": \"F32\""},
453+
{"num_streams", "\"NUM_STREAMS\": \"1\""},
454+
{"model_priority", "\"MODEL_PRIORITY\": \"LOW\""},
455+
{"enable_opencl_throttling", "\"GPU\": {\"PLUGIN_THROTTLE\": \"1\"}"},
456+
{"enable_qdq_optimizer", "\"NPU\": {\"NPU_QDQ_OPTIMIZATION\": \"YES\"}"}
457+
};
458+
459+
for (auto& block_and_advise_entry : block_and_advise_entries) {
460+
if (provider_options.find(block_and_advise_entry.first) != provider_options.end()) {
461+
std::string message = "OpenVINO EP: Option '" + block_and_advise_entry.first +
462+
"' cannot be set when using AppendExecutionProvider_V2. " +
463+
"It can instead be enabled by a load_config key / value pair. For example: " +
464+
block_and_advise_entry.second;
465+
return Status(common::ONNXRUNTIME, ORT_INVALID_ARGUMENT, message);
466+
}
467+
}
468+
469+
// For the rest of the disallowed provider options, give a generic error message.
470+
const std::vector<std::string> blocked_provider_keys = {
471+
"device_type", "device_id", "device_luid", "context", "num_of_threads", "disable_dynamic_shapes"};
454472

455473
for (const auto& key : blocked_provider_keys) {
456474
if (provider_options.find(key) != provider_options.end()) {
457475
return Status(common::ONNXRUNTIME, ORT_INVALID_ARGUMENT,
458-
"OpenVINO EP: Option '" + key + "' cannot be set explicitly when using AppendExecutionProvider_V2.");
476+
"OpenVINO EP: Option '" + key + "' cannot be set when using AppendExecutionProvider_V2.");
459477
}
460478
}
461479

onnxruntime/test/providers/openvino/openvino_plugin.cc

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,22 @@ TEST_F(OrtEpLibraryOv, MetaDevicesAvailable) {
137137
}
138138
}
139139

140+
TEST_F(OrtEpLibraryOv, RunSessionWithAllAUTODevices) {
141+
auto ep_devices = ort_env->GetEpDevices();
142+
std::vector<Ort::ConstEpDevice> matching_devices;
143+
144+
for (const auto& device : ep_devices) {
145+
std::string ep_name = device.EpName();
146+
if (ep_name.find(registration_name) != std::string::npos &&
147+
(ep_name == registration_name + ".AUTO")) {
148+
matching_devices.push_back(device);
149+
}
150+
}
151+
Ort::SessionOptions session_options;
152+
session_options.AppendExecutionProvider_V2(*ort_env, matching_devices, std::unordered_map<std::string, std::string>{});
153+
Ort::Session session(*ort_env, ORT_TSTR("testdata/mul_1.onnx"), session_options);
154+
}
155+
140156
TEST_F(OrtEpLibraryOv, PluginEp_AppendV2_MulInference) {
141157
auto plugin_ep_device = GetOvCpuEpDevice();
142158
ASSERT_NE(plugin_ep_device, nullptr);
@@ -178,6 +194,31 @@ TEST_F(OrtEpLibraryOv, PluginEp_AppendV2_cpu_epctx_variants) {
178194
}
179195
}
180196

197+
TEST_F(OrtEpLibraryOv, PluginEp_CheckV2DisallowedProviderOptions) {
198+
auto plugin_ep_device = GetOvCpuEpDevice();
199+
ASSERT_NE(plugin_ep_device, nullptr);
200+
std::vector<std::unordered_map<std::string, std::string>> disallowed_provider_option_examples = {
201+
{{"device_type", "CPU"}},
202+
{{"device_id", "CPU"}},
203+
{{"device_luid", "1234"}},
204+
{{"cache_dir", "cache"}},
205+
{{"precision", "F32"}},
206+
{{"context", "4"}},
207+
{{"num_of_threads", "1"}},
208+
{{"model_priority", "DEFAULT"}},
209+
{{"num_streams", "1"}},
210+
{{"enable_opencl_throttling", "true"}},
211+
{{"enable_qdq_optimizer", "true"}},
212+
{{"disable_dynamic_shapes", "true"}},
213+
};
214+
for (auto& example : disallowed_provider_option_examples) {
215+
EXPECT_THROW({
216+
Ort::SessionOptions session_options;
217+
session_options.AppendExecutionProvider_V2(*ort_env, std::vector<Ort::ConstEpDevice>{plugin_ep_device}, example);
218+
Ort::Session session(*ort_env, ORT_TSTR("testdata/mul_1.onnx"), session_options); }, Ort::Exception);
219+
}
220+
}
221+
181222
TEST_F(OrtEpLibraryOv, GenerateEpContextEmbedded) {
182223
GenerateEpContextOnPluginPath(ORT_TSTR("mul_1_ctx_cpu_embed1.onnx"), true);
183224
}

0 commit comments

Comments
 (0)