Skip to content

Commit

Permalink
Fix fallback failure by catching the correct exception type (#353)
Browse files Browse the repository at this point in the history
* Fix fallback failure due to handling wrong exception

* Apply lintrunner patches
  • Loading branch information
sspintel authored Mar 18, 2024
1 parent 8340059 commit 4888eb1
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions onnxruntime/core/providers/openvino/backend_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <fstream>
#include <utility>
#include <exception>

#include "core/providers/shared_library/provider_api.h"
#include "contexts.h"
Expand Down Expand Up @@ -85,9 +86,9 @@ BackendManager::BackendManager(const GlobalContext& global_context,
concrete_backend_ = BackendFactory::MakeBackend(*model_proto_,
GetGlobalContext(),
subgraph_context_);
} catch (std::string const& msg) {
} catch (const OnnxRuntimeException& ex) {
if (device_type.find("NPU") != std::string::npos) {
LOGS_DEFAULT(WARNING) << msg;
LOGS_DEFAULT(WARNING) << ex.what();
LOGS_DEFAULT(WARNING) << "Model compilation failed at OV NPU."
<< "Falling back to OV CPU for execution";
GetGlobalContext().device_type = "CPU";
Expand All @@ -100,7 +101,7 @@ BackendManager::BackendManager(const GlobalContext& global_context,
ORT_THROW(msg);
}
} else {
ORT_THROW(msg);
ORT_THROW(ex.what());
}
}
}
Expand Down Expand Up @@ -289,9 +290,9 @@ void BackendManager::Compute(OrtKernelContext* context) {
dynamic_backend = BackendFactory::MakeBackend(*modelproto_with_concrete_shapes,
GetGlobalContext(),
subgraph_context_);
} catch (std::string const& msg) {
} catch (const OnnxRuntimeException& ex) {
if (GetGlobalContext().device_type.find("NPU") != std::string::npos) {
LOGS_DEFAULT(WARNING) << msg;
LOGS_DEFAULT(WARNING) << ex.what();
LOGS_DEFAULT(WARNING) << "Model compilation failed at OV NPU."
<< "Falling back to OV CPU for execution";
GetGlobalContext().device_type = "CPU";
Expand Down

0 comments on commit 4888eb1

Please sign in to comment.