Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[ONNX FE] Fix handling of tensor values with UINT32 type (#32806)

Szymon Gutaj2addbf7d58bf
diff --git a/src/frontends/onnx/frontend/src/core/tensor.hpp b/src/frontends/onnx/frontend/src/core/tensor.hpp
index 28a6cbe3773..8c3001156cb 100644
--- a/src/frontends/onnx/frontend/src/core/tensor.hpp
+++ b/src/frontends/onnx/frontend/src/core/tensor.hpp
@@ -340,12 +340,14 @@ private:
return m_tensor_proto->int32_data().data();
case TensorProto_DataType::TensorProto_DataType_INT64:
return m_tensor_proto->int64_data().data();
+ case TensorProto_DataType::TensorProto_DataType_UINT32:
+ [[fallthrough]];
case TensorProto_DataType::TensorProto_DataType_UINT64:
return m_tensor_proto->uint64_data().data();
case TensorProto_DataType::TensorProto_DataType_DOUBLE:
return m_tensor_proto->double_data().data();
}
- ONNX_INVALID_DATA_TYPE(m_tensor_proto->data_type(), "FLOAT, INT32, INT64, UINT64, DOUBLE");
+ ONNX_INVALID_DATA_TYPE(m_tensor_proto->data_type(), "FLOAT, INT32, INT64, UINT32, UINT64, DOUBLE");
}
size_t get_data_size() const {
@@ -367,10 +369,10 @@ private:
switch (m_tensor_proto->data_type()) {
case TensorProto_DataType::TensorProto_DataType_FLOAT:
return m_tensor_proto->float_data_size();
- case TensorProto_DataType::TensorProto_DataType_INT32:
- return m_tensor_proto->int32_data_size();
case TensorProto_DataType::TensorProto_DataType_INT64:
return m_tensor_proto->int64_data_size();
+ case TensorProto_DataType::TensorProto_DataType_UINT32:
+ [[fallthrough]];
case TensorProto_DataType::TensorProto_DataType_UINT64:
return m_tensor_proto->uint64_data_size();
case TensorProto_DataType::TensorProto_DataType_DOUBLE:
@@ -378,22 +380,36 @@ private:
case TensorProto_DataType::TensorProto_DataType_STRING:
return m_tensor_proto->string_data_size();
case TensorProto_DataType::TensorProto_DataType_INT4:
+ [[fallthrough]];
case TensorProto_DataType::TensorProto_DataType_INT8:
+ [[fallthrough]];
case TensorProto_DataType::TensorProto_DataType_INT16:
+ [[fallthrough]];
+ case TensorProto_DataType::TensorProto_DataType_INT32:
+ [[fallthrough]];
case TensorProto_DataType::TensorProto_DataType_UINT4:
+ [[fallthrough]];
case TensorProto_DataType::TensorProto_DataType_UINT8:
+ [[fallthrough]];
case TensorProto_DataType::TensorProto_DataType_UINT16:
+ [[fallthrough]];
case TensorProto_DataType::TensorProto_DataType_BOOL:
+ [[fallthrough]];
case TensorProto_DataType::TensorProto_DataType_BFLOAT16:
+ [[fallthrough]];
case TensorProto_DataType::TensorProto_DataType_FLOAT16:
+ [[fallthrough]];
case TensorProto_DataType::TensorProto_DataType_FLOAT8E4M3FN:
+ [[fallthrough]];
case TensorProto_DataType::TensorProto_DataType_FLOAT8E5M2:
return m_tensor_proto->int32_data_size();
+ default: {
+ ONNX_INVALID_DATA_TYPE(
+ m_tensor_proto->data_type(),
+ "BOOL, BFLOAT16, FLOAT8E4M3FN, FLOAT8E5M2, FLOAT, FLOAT16, DOUBLE, INT4, INT8, INT16, INT32, INT64, "
+ "UINT4, UINT8, UINT16, UINT32, UINT64, STRING");
+ }
}
- ONNX_INVALID_DATA_TYPE(
- m_tensor_proto->data_type(),
- "BOOL, BFLOAT16, FLOAT8E4M3FN, FLOAT8E5M2, FLOAT, FLOAT16, DOUBLE, INT4, INT8, INT16, INT32, INT64, "
- "UINT4, UINT8, UINT16, UINT32, UINT64, STRING");
}
const TensorProto* m_tensor_proto;
diff --git a/src/frontends/onnx/tests/models/bitshift_uint32_y.prototxt b/src/frontends/onnx/tests/models/bitshift_uint32_y.prototxt
new file mode 100644
index 00000000000..0e6f5f6da59
--- /dev/null
+++ b/src/frontends/onnx/tests/models/bitshift_uint32_y.prototxt
@@ -0,0 +1,225 @@
+ir_version: 10
+producer_name: "onnx-example"
+graph {
+ node {
+ output: "add_constant"
+ op_type: "Constant"
+ attribute {
+ name: "value"
+ t {
+ data_type: 1
+ float_data: 2.0
+ name: "add_constant"
+ }
+ type: TENSOR
+ }
+ }
+ node {
+ input: "input"
+ output: "softsign_output"
+ op_type: "Softsign"
+ }
+ node {
+ input: "softsign_output"
+ input: "add_constant"
+ output: "acosh_input"
+ op_type: "Add"
+ }
+ node {
+ input: "acosh_input"
+ output: "acosh_output"
+ op_type: "Acosh"
+ }
+ node {
+ input: "acosh_output"
+ output: "sigmoid_output"
+ op_type: "Sigmoid"
+ }
+ node {
+ input: "sigmoid_output"
+ output: "bitshift_input"
+ op_type: "Cast"
+ attribute {
+ name: "to"
+ i: 12
+ type: INT
+ }
+ }
+ node {
+ output: "bitshift_amount"
+ op_type: "Constant"
+ attribute {
+ name: "value"
+ t {
+ dims: 3
+ dims: 4
+ dims: 4
+ data_type: 12
+ name: "bitshift_amount"
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ uint64_data: 1
+ }
+ type: TENSOR
+ }
+ }
+ node {
+ input: "bitshift_input"
+ input: "bitshift_amount"
+ output: "bitshift_output"
+ op_type: "BitShift"
+ attribute {
+ name: "direction"
+ s: "LEFT"
+ type: STRING
+ }
+ }
+ node {
+ input: "bitshift_output"
+ output: "cast_output"
+ op_type: "Cast"
+ attribute {
+ name: "to"
+ i: 1
+ type: INT
+ }
+ }
+ node {
+ input: "cast_output"
+ output: "unique_output_y"
+ output: "unique_output_indices"
+ output: "unique_output_inverse_indices"
+ output: "unique_output_counts"
+ op_type: "Unique"
+ attribute {
+ name: "axis"
+ i: 1
+ type: INT
+ }
+ attribute {
+ name: "sorted"
+ i: 1
+ type: INT
+ }
+ }
+ name: "complex_model"
+ input {
+ name: "input"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 3
+ }
+ dim {
+ dim_value: 4
+ }
+ dim {
+ dim_value: 4
+ }
+ }
+ }
+ }
+ }
+ output {
+ name: "unique_output_y"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ }
+ dim {
+ }
+ dim {
+ }
+ }
+ }
+ }
+ }
+ output {
+ name: "unique_output_indices"
+ type {
+ tensor_type {
+ elem_type: 7
+ shape {
+ dim {
+ }
+ }
+ }
+ }
+ }
+ output {
+ name: "unique_output_inverse_indices"
+ type {
+ tensor_type {
+ elem_type: 7
+ shape {
+ dim {
+ }
+ }
+ }
+ }
+ }
+ output {
+ name: "unique_output_counts"
+ type {
+ tensor_type {
+ elem_type: 7
+ shape {
+ dim {
+ }
+ }
+ }
+ }
+ }
+}
+opset_import {
+ version: 22
+}
diff --git a/src/frontends/onnx/tests/onnx_import.in.cpp b/src/frontends/onnx/tests/onnx_import.in.cpp
index 7df87aac9fc..0a6a8296a9b 100644
--- a/src/frontends/onnx/tests/onnx_import.in.cpp
+++ b/src/frontends/onnx/tests/onnx_import.in.cpp
@@ -7199,3 +7199,22 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_split_to_sequence_explicit_split_1d) {
test_case.run();
}
+
+/// @brief Testing ONNX BitShift with an Y output of uint32 type
+/// The input model was taken from a bug report, where parsing the type of the Y input
+/// failed.
+OPENVINO_TEST(${BACKEND_NAME}, onnx_bitshift_uint32_y) {
+ const auto model = convert_model("bitshift_uint32_y.onnx");
+ auto test_case = test::TestCase(model, s_device);
+
+ test_case.add_input<float>(
+ Shape{3, 4, 4},
+ {-0.6251511f, -0.5969454f, 0.13909698f, -0.27613088f, 0.00713499f, -0.06079938f, 0.07727996f, 0.09848484f,
+ -1.3456749f, 1.2606536f, -2.1878982f, -0.06534719f, 1.7707846f, -1.3586597f, -1.1241275f, 1.1630629f,
+ 1.5288247f, 1.5974303f, -0.09236689f, 1.2441877f, -0.4477599f, 0.20678943f, 0.2639845f, -0.38207826f,
+ 1.0393754f, 2.0902128f, -0.4672897f, 1.8636966f, 1.2390026f, -0.38409668f, -0.29675618f, -2.113882f,
+ -1.2571493f, 0.19212584f, -0.48622572f, 1.3817313f, 0.2130472f, 0.12426434f, 0.18794645f, -1.4493794f,
+ 0.38522267f, 0.55802476f, -1.0083855f, 0.12431115f, -1.9025584f, -1.1199955f, -0.97456354f, 0.5826947f});
+
+ test_case.run();
+}
\ No newline at end of file