Commit d95745b9 authored by Tomasz Dołbniak's avatar Tomasz Dołbniak Committed by Scott Cyphers

[ONNX] Handling of unknown domains in ONNX models [r0.26] (#3632)

* Do not throw for unknown domains in ONNX models

* UT that makes sure onnx_importer does not throw for unknown domains

* Check if nGraph throws for unknown ONNX domain and op
parent a8d206b3
......@@ -178,7 +178,8 @@ namespace ngraph
auto dm = m_map.find(domain);
if (dm == std::end(m_map))
{
throw error::UnknownDomain{domain};
NGRAPH_WARN << "Domain '" << domain << "' not recognized by nGraph";
return OperatorSet{};
}
if (domain == "" && version > OperatorsBridge::LATEST_SUPPORTED_ONNX_OPSET_VERSION)
{
......
ir_version: 4
producer_name: "nGraph ONNX Importer"
graph {
node {
input: "A"
input: "B"
output: "C"
op_type: "Add"
}
name: "compute_graph"
input {
name: "A"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 2
}
dim {
dim_value: 2
}
}
}
}
}
input {
name: "B"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 2
}
dim {
dim_value: 2
}
}
}
}
}
output {
name: "C"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 2
}
dim {
dim_value: 2
}
}
}
}
}
}
opset_import {
domain: "unknown.domain"
version: 1
}
opset_import {
domain: ""
version: 7
}
ir_version: 4
producer_name: "nGraph ONNX Importer"
graph {
node {
input: "A"
input: "B"
output: "C"
op_type: "Add"
domain: "unknown.domain"
}
name: "compute_graph"
input {
name: "A"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 2
}
dim {
dim_value: 2
}
}
}
}
}
input {
name: "B"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 2
}
dim {
dim_value: 2
}
}
}
}
}
output {
name: "C"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 2
}
dim {
dim_value: 2
}
}
}
}
}
}
opset_import {
domain: "unknown.domain"
version: 1
}
......@@ -268,6 +268,31 @@ NGRAPH_TEST(onnx_${BACKEND_NAME}, model_missing_op_domain)
EXPECT_TRUE(test::all_close_f(expected_output.front(), outputs.front()));
}
NGRAPH_TEST(onnx_${BACKEND_NAME}, model_unknown_domain)
{
// the importer should not throw when it encounters an unknown domain in the model
EXPECT_NO_THROW(onnx_import::import_onnx_model(
file_util::path_join(SERIALIZED_ZOO, "onnx/unknown_domain.prototxt")));
}
NGRAPH_TEST(onnx_${BACKEND_NAME}, model_op_in_unknown_domain)
{
try
{
onnx_import::import_onnx_model(
file_util::path_join(SERIALIZED_ZOO, "onnx/unknown_domain_add.prototxt"));
FAIL() << "The onnx_importer did not throw for unknown domain and op";
}
catch (const ngraph::ngraph_error& e)
{
const std::string msg = e.what();
EXPECT_NE(msg.find("unknown.domain.Add"), std::string::npos)
<< "The error message should contain domain and op name: unknown.domain.Add";
}
}
NGRAPH_TEST(onnx_${BACKEND_NAME}, model_missing_input)
{
onnx_import::register_operator(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment