Add checks for session options and fix gsubgraph fallback exceptions (#17095)

### Description
Bug fix for OVEP graph provider options and fallback


### Motivation and Context
A bug fix logic is added to handle the fallback to CPU EP. 
Corner case Assertions are added for ProviderOptions in OpenVINO.

---------

Co-authored-by: Sahar Fatima <sfatima.3001@gmail.com>
Co-authored-by: Saurabh Kale <saurabh1.kale@intel.com>
This commit is contained in:
Preetha Veeramalai 2023-08-16 10:06:25 -07:00 committed by GitHub
parent 133af1385c
commit 2ae930333b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 11 deletions

View file

@ -57,7 +57,7 @@ struct OpenVINO_Provider : Provider {
std::shared_ptr<IExecutionProviderFactory> CreateExecutionProviderFactory(const void* void_params) override {
auto& provider_options_map = *reinterpret_cast<const ProviderOptions*>(void_params);
const char* device_type = ""; // [device_type]: Overrides the accelerator hardware type and precision
std::string device_type = ""; // [device_type]: Overrides the accelerator hardware type and precision
// with these values at runtime.
bool enable_vpu_fast_compile = false; // [enable_vpu_fast_compile]: Fast-compile may be optionally enabled to
// speeds up the model's compilation to VPU device specific format.
@ -77,6 +77,19 @@ struct OpenVINO_Provider : Provider {
if (provider_options_map.find("device_type") != provider_options_map.end()) {
device_type = provider_options_map.at("device_type").c_str();
std::set<std::string> ov_supported_device_types = {"CPU_FP32", "CPU_FP16", "GPU_FP32",
"GPU.0_FP32", "GPU.1_FP32", "GPU_FP16",
"GPU.0_FP16", "GPU.1_FP16",
"VPUX_FP16", "VPUX_U8"};
if (!((ov_supported_device_types.find(device_type) != ov_supported_device_types.end()) ||
(device_type.find("HETERO:") == 0) || (device_type.find("MULTI:") == 0) || (device_type.find("AUTO:") == 0))) {
ORT_THROW(
"[ERROR] [OpenVINO] You have selcted wrong configuration value for the key 'device_type'. "
"Select from 'CPU_FP32', 'CPU_FP16', 'GPU_FP32', 'GPU.0_FP32', 'GPU.1_FP32', 'GPU_FP16', "
"'GPU.0_FP16', 'GPU.1_FP16', 'VPUX_FP16', 'VPUX_U8' or from"
" HETERO/MULTI/AUTO options available. \n");
}
}
if (provider_options_map.find("device_id") != provider_options_map.end()) {
device_id = provider_options_map.at("device_id").c_str();
@ -90,10 +103,16 @@ struct OpenVINO_Provider : Provider {
if (provider_options_map.find("num_of_threads") != provider_options_map.end()) {
num_of_threads = std::stoi(provider_options_map.at("num_of_threads"));
if (num_of_threads <= 0) {
num_of_threads = 1;
}
}
if (provider_options_map.find("num_streams") != provider_options_map.end()) {
num_streams = std::stoi(provider_options_map.at("num_streams"));
if (num_streams <= 0 && num_streams > 8) {
ORT_THROW("[ERROR] [OpenVINO] The value for the key 'num_streams' should be in the range of 1-8 \n");
}
}
std::string bool_flag = "";
if (provider_options_map.find("enable_vpu_fast_compile") != provider_options_map.end()) {
@ -121,7 +140,7 @@ struct OpenVINO_Provider : Provider {
else if (bool_flag == "false" || bool_flag == "False")
enable_dynamic_shapes = false;
}
return std::make_shared<OpenVINOProviderFactory>(device_type,
return std::make_shared<OpenVINOProviderFactory>(const_cast<char*>(device_type.c_str()),
enable_vpu_fast_compile,
device_id,
num_of_threads,

View file

@ -48,11 +48,6 @@ std::vector<std::unique_ptr<ComputeCapability>> GetCapability::Execute() {
return result;
}
// Check if it is a subgraph
if (graph_viewer_.IsSubgraph() && graph_viewer_.Name() == "tf2onnx") {
return result;
}
// This is a list of initializers that nGraph considers as constants. Example weights, reshape shape etc.
std::unordered_set<std::string> ng_required_initializers;
@ -83,11 +78,15 @@ std::vector<std::unique_ptr<ComputeCapability>> GetCapability::Execute() {
const auto& nodes = graph_viewer_.GetNodesInTopologicalOrder();
const auto& node = graph_viewer_.GetNode(nodes[0]);
// Handle cases where lone, reoccuring Ops in smaller models cannot be supported in OpenVINO
// If only a node of the same lone,unsupported type is present, then do not proceed with the subgraph
const auto& node = graph_viewer_.GetNode(nodes[0]);
if (data_ops_->IsOpSupportedOnlyInModel(node->OpType()))
return result;
if (nodes.size() <= 3) {
if (data_ops_->IsOpSupportedOnlyInModel(node->OpType())) {
return result;
}
}
// Nodes that work well in models but not as a single node
if (nodes.size() == 1) {

View file

@ -496,6 +496,8 @@ OnnxRuntimeTestSession::OnnxRuntimeTestSession(Ort::Env& env, std::random_device
}
} else if (key == "cache_dir") {
ov_options[key] = value;
} else if (key == "context") {
ov_options[key] = value;
} else if (key == "num_streams") {
if (std::stoi(value) <= 0 && std::stoi(value) > 8) {
ORT_THROW("[ERROR] [OpenVINO] The value for the key 'num_streams' should be in the range of 1-8 \n");

View file

@ -91,8 +91,8 @@ std::unique_ptr<IExecutionProvider> OpenVINOExecutionProviderWithOptions(const O
return OpenVINOProviderFactoryCreator::Create(params)->CreateProvider();
#else
ORT_UNUSED_PARAMETER(params);
#endif
return nullptr;
#endif
}
std::unique_ptr<IExecutionProvider> DefaultOpenVINOExecutionProvider() {