[ONNX FE] Improve error handling during op registration (#14201)
This commit is contained in:
@@ -384,6 +384,21 @@ OutputVector Graph::make_ng_nodes(const Node& onnx_node) {
|
||||
std::rethrow_exception(std::current_exception());
|
||||
}
|
||||
|
||||
const size_t outputs_size = std::accumulate(std::begin(ng_subgraph_outputs),
|
||||
std::end(ng_subgraph_outputs),
|
||||
0,
|
||||
[](const size_t lhs, const Output<ov::Node>& rhs) {
|
||||
return lhs + rhs.get_node()->get_output_size();
|
||||
});
|
||||
NGRAPH_CHECK(onnx_node.get_outputs_size() <= outputs_size,
|
||||
"Expected output number of ",
|
||||
onnx_node.op_type(),
|
||||
" node is ",
|
||||
onnx_node.get_outputs_size(),
|
||||
" while the implementation provides ",
|
||||
outputs_size,
|
||||
" outputs");
|
||||
|
||||
set_friendly_names(onnx_node, ng_subgraph_outputs);
|
||||
|
||||
for (std::size_t i{0}; i < onnx_node.get_outputs_size(); ++i) {
|
||||
|
||||
@@ -82,3 +82,23 @@ TEST(ONNXConversionExtensionTest, custom_op_with_custom_domain) {
|
||||
}
|
||||
FAIL() << "Expected operation not found in the converted model";
|
||||
}
|
||||
|
||||
TEST(ONNXConversionExtensionTest, custom_op_with_incorrect_numer_of_outputs_exception) {
|
||||
const auto ext =
|
||||
std::make_shared<onnx::ConversionExtension>("CustomAdd",
|
||||
"custom.op",
|
||||
[](const ov::frontend::NodeContext& node) -> ov::OutputVector {
|
||||
// the default constructor called, the op with 0 output created
|
||||
auto op = std::make_shared<ov::op::v1::Add>();
|
||||
return {op};
|
||||
});
|
||||
|
||||
auto fe = std::make_shared<ov::frontend::onnx::FrontEnd>();
|
||||
fe->add_extension(ext);
|
||||
|
||||
const auto input_model = fe->load(CommonTestUtils::getModelFromTestModelZoo(
|
||||
ov::util::path_join({TEST_ONNX_MODELS_DIRNAME, "missing_op_domain.onnx"})));
|
||||
|
||||
std::shared_ptr<ov::Model> model;
|
||||
ASSERT_THROW(fe->convert(input_model), ov::Exception);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user