Skip to content

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

[ONNX] Made a skip of dimension check for quanize linear with shape=[1] (#30489)

Michal Miotkee6103ab4b4f
diff --git a/src/frontends/onnx/frontend/src/op/quantize_linear.cpp b/src/frontends/onnx/frontend/src/op/quantize_linear.cpp
index 935f24f9d08..86735102275 100644
--- a/src/frontends/onnx/frontend/src/op/quantize_linear.cpp
+++ b/src/frontends/onnx/frontend/src/op/quantize_linear.cpp
@@ -222,8 +222,12 @@ ov::OutputVector quantize_linear(const ov::frontend::onnx::Node& node) {
const auto zero_point = ai_onnx::detail::get_zero_point(inputs);
// per-tensor quantization, axis attribute ignored
- if (scale.get_partial_shape().rank().is_static() && scale.get_partial_shape().rank().get_length() == 0 &&
- zero_point.get_partial_shape().rank().is_static() && zero_point.get_partial_shape().rank().get_length() == 0) {
+ if (scale.get_partial_shape().rank().is_static() &&
+ (scale.get_partial_shape().rank().get_length() == 0 ||
+ (scale.get_partial_shape().rank().get_length() == 1 && scale.get_partial_shape()[0] == 1)) &&
+ zero_point.get_partial_shape().rank().is_static() &&
+ (zero_point.get_partial_shape().rank().get_length() == 0 ||
+ (zero_point.get_partial_shape().rank().get_length() == 1 && zero_point.get_partial_shape()[0] == 1))) {
return ai_onnx::opset_1::quantize_linear(node);
}
diff --git a/src/frontends/onnx/tests/models/quantize_linear_one_dim_scale.prototxt b/src/frontends/onnx/tests/models/quantize_linear_one_dim_scale.prototxt
new file mode 100644
index 00000000000..dbc701732c5
--- /dev/null
+++ b/src/frontends/onnx/tests/models/quantize_linear_one_dim_scale.prototxt
@@ -0,0 +1,68 @@
+ir_version: 3
+producer_name: "OpenVINO ONNX Frontend"
+graph {
+ node {
+ input: "x"
+ input: "y_scale"
+ input: "y_zero_point"
+ output: "y"
+ name: "node1"
+ op_type: "QuantizeLinear"
+ }
+ name: "test"
+ input {
+ name: "x"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 2
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "y_scale"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape{
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "y_zero_point"
+ type {
+ tensor_type {
+ elem_type: 2
+ shape {
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ output {
+ name: "y"
+ type {
+ tensor_type {
+ elem_type: 2
+ shape {
+ }
+ }
+ }
+ }
+}
+opset_import {
+ version: 13
+}
diff --git a/src/frontends/onnx/tests/onnx_import_quant.in.cpp b/src/frontends/onnx/tests/onnx_import_quant.in.cpp
index dac3e6e9e1e..2f5f06b5dbd 100644
--- a/src/frontends/onnx/tests/onnx_import_quant.in.cpp
+++ b/src/frontends/onnx/tests/onnx_import_quant.in.cpp
@@ -191,6 +191,18 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_dequantize_linear_no_zero_point) {
test_case.run();
}
+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_quantize_linear_one_dim_scale) {
+ auto model = convert_model("quantize_linear_one_dim_scale.onnx");
+
+ auto test_case = ov::test::TestCase(model, s_device);
+ test_case.add_input(std::vector<float>{18, 100, 20, 10}); // x
+ test_case.add_input(std::vector<float>{2.0f}); // scale
+ test_case.add_input(std::vector<std::uint8_t>{1}); // zero_point
+
+ test_case.add_expected_output<std::uint8_t>(std::vector<std::uint8_t>{10, 51, 11, 6});
+ test_case.run();
+}
+
OPENVINO_TEST(${BACKEND_NAME}, onnx_model_dequantize_linear_21_no_zero_point) {
auto model = convert_model("dequantize_linear_21_no_zero_point.onnx");