OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[ONNX] Qwen2.5-0.5B Fails on Conversion (#37900)
Szymon Gutajaf4b9a947b0f
diff --git a/src/frontends/onnx/frontend/src/op/dequantize_linear.cpp b/src/frontends/onnx/frontend/src/op/dequantize_linear.cppindex 5b9fb0dee2f..18f38f677dc 100644--- a/src/frontends/onnx/frontend/src/op/dequantize_linear.cpp+++ b/src/frontends/onnx/frontend/src/op/dequantize_linear.cpp@@ -254,8 +254,10 @@ ov::OutputVector dequantize_linear(const ov::frontend::onnx::Node& node) {const auto& scale_shape = scale.get_partial_shape();ov::Output<ov::Node> zp;+ const auto block_size = static_cast<size_t>(node.get_attribute_value<int64_t>("block_size", 0));+// When no blocking dequantization is required - use regular DequantizeLinear- if (scale_shape.rank().is_static() && scale_shape.rank().get_length() <= 1) {+ if (block_size == 0 && scale_shape.rank().is_static() && scale_shape.rank().get_length() <= 1) {return ai_onnx::opset_13::dequantize_linear(node);}@@ -266,7 +268,6 @@ ov::OutputVector dequantize_linear(const ov::frontend::onnx::Node& node) {"DequantizeLinear cannot operate with dynamic shapes of input X");auto axis = node.get_attribute_value<int64_t>("axis", 1);- const auto block_size = static_cast<size_t>(node.get_attribute_value<int64_t>("block_size", 0));FRONT_END_GENERAL_CHECK(block_size > 0, "block_size must be greater than zero");@@ -283,6 +284,24 @@ ov::OutputVector dequantize_linear(const ov::frontend::onnx::Node& node) {block_size,")");+ const auto& input_shape = src_x.get_partial_shape();+ FRONT_END_GENERAL_CHECK(scale_shape.rank().get_length() == input_shape.rank().get_length(),+ "DequantizeLinear x_scale shape ",+ scale_shape,+ " is incompatible with the rank of X ",+ input_shape);+ for (int64_t i = 0; i < input_shape.rank().get_length(); ++i) {+ const int64_t expected_dim = i == axis ? static_cast<int64_t>(input_shape[i].get_length() / block_size)+ : static_cast<int64_t>(input_shape[i].get_length());+ FRONT_END_GENERAL_CHECK(scale_shape[i].compatible(expected_dim),+ "DequantizeLinear x_scale shape ",+ scale_shape,+ " is incompatible with the declared axis ",+ axis,+ " for X shape ",+ input_shape);+ }+// Check if this is channel-wise quantization (block_size equals dimension size at axis)bool is_cw_quantize = (src_x.get_shape()[axis] == block_size);if (is_cw_quantize) {@@ -298,7 +317,6 @@ ov::OutputVector dequantize_linear(const ov::frontend::onnx::Node& node) {// - axis=0: [num_blocks, block_size, ...] with block_size at position 1// - axis>0: [..., num_blocks, block_size, ...] with block_size at position axis+1std::vector<size_t> target_shape_vector;- const auto& input_shape = src_x.get_partial_shape();for (int64_t i = 0; i < input_shape.rank().get_length(); i++) {if (i == axis) {// Always num_blocks first, then block_sizediff --git a/src/frontends/onnx/tests/models/dequantize_linear_21_invalid_non_inner_axis.prototxt b/src/frontends/onnx/tests/models/dequantize_linear_21_invalid_non_inner_axis.prototxtnew file mode 100644index 00000000000..0d712e6013d--- /dev/null+++ b/src/frontends/onnx/tests/models/dequantize_linear_21_invalid_non_inner_axis.prototxt@@ -0,0 +1,54 @@+ir_version: 3+producer_name: "OpenVINO ONNX Frontend"+graph {+ name: "test_dequantize_21_invalid_non_inner_axis"+ input {+ name: "x"+ type {+ tensor_type {+ elem_type: 3+ shape {+ dim { dim_value: 2 }+ dim { dim_value: 4 }+ dim { dim_value: 3 }+ }+ }+ }+ }+ input {+ name: "scale"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 2 }+ dim { dim_value: 2 }+ dim { dim_value: 3 }+ }+ }+ }+ }+ output {+ name: "y"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 2 }+ dim { dim_value: 4 }+ dim { dim_value: 3 }+ }+ }+ }+ }+ node {+ input: "x"+ input: "scale"+ output: "y"+ name: "DequantizeNode"+ op_type: "DequantizeLinear"+ attribute { name: "axis" i: 0 type: INT }+ attribute { name: "block_size" i: 2 type: INT }+ }+}+opset_import { version: 21 }\ No newline at end of filediff --git a/src/frontends/onnx/tests/models/dequantize_linear_21_invalid_nonzero_axis.prototxt b/src/frontends/onnx/tests/models/dequantize_linear_21_invalid_nonzero_axis.prototxtnew file mode 100644index 00000000000..34f85b7eee0--- /dev/null+++ b/src/frontends/onnx/tests/models/dequantize_linear_21_invalid_nonzero_axis.prototxt@@ -0,0 +1,53 @@+ir_version: 3+producer_name: "OpenVINO ONNX Frontend"+graph {+ name: "test_dequantize_21_invalid_nonzero_axis"+ input {+ name: "x"+ type {+ tensor_type {+ elem_type: 3+ shape {+ dim { dim_value: 2 }+ dim { dim_value: 4 }+ }+ }+ }+ }+ input {+ name: "scale"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 2 }+ dim { dim_value: 3 }+ dim { dim_value: 2 }+ }+ }+ }+ }+ output {+ name: "y"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 2 }+ dim { dim_value: 3 }+ dim { dim_value: 4 }+ }+ }+ }+ }+ node {+ input: "x"+ input: "scale"+ output: "y"+ name: "DequantizeNode"+ op_type: "DequantizeLinear"+ attribute { name: "axis" i: 1 type: INT }+ attribute { name: "block_size" i: 2 type: INT }+ }+}+opset_import { version: 21 }\ No newline at end of filediff --git a/src/frontends/onnx/tests/models/dequantize_linear_21_nncf_axis.prototxt b/src/frontends/onnx/tests/models/dequantize_linear_21_nncf_axis.prototxtnew file mode 100644index 00000000000..5931165b8c5--- /dev/null+++ b/src/frontends/onnx/tests/models/dequantize_linear_21_nncf_axis.prototxt@@ -0,0 +1,51 @@+ir_version: 3+producer_name: "OpenVINO ONNX Frontend"+graph {+ name: "test_dequantize_21_nncf_axis"+ input {+ name: "x"+ type {+ tensor_type {+ elem_type: 3+ shape {+ dim { dim_value: 2 }+ dim { dim_value: 4 }+ }+ }+ }+ }+ input {+ name: "scale"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 2 }+ dim { dim_value: 2 }+ }+ }+ }+ }+ output {+ name: "y"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 2 }+ dim { dim_value: 4 }+ }+ }+ }+ }+ node {+ input: "x"+ input: "scale"+ output: "y"+ name: "DequantizeNode"+ op_type: "DequantizeLinear"+ attribute { name: "axis" i: 0 type: INT }+ attribute { name: "block_size" i: 2 type: INT }+ }+}+opset_import { version: 21 }\ No newline at end of filediff --git a/src/frontends/onnx/tests/onnx_import_quant.in.cpp b/src/frontends/onnx/tests/onnx_import_quant.in.cppindex 189969c176d..0b9ba6647b1 100644--- a/src/frontends/onnx/tests/onnx_import_quant.in.cpp+++ b/src/frontends/onnx/tests/onnx_import_quant.in.cpp@@ -532,6 +532,20 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_dequantize_linear_opset21_axis_negativtest_case.run();}+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_dequantize_linear_opset21_nncf_axis) {+ OV_EXPECT_THROW(convert_model("dequantize_linear_21_nncf_axis.onnx"),+ ov::Exception,+ testing::HasSubstr("is incompatible with the declared axis"));+}++OPENVINO_TEST(${BACKEND_NAME}, onnx_model_dequantize_linear_opset21_invalid_nonzero_axis) {+ EXPECT_THROW(convert_model("dequantize_linear_21_invalid_nonzero_axis.onnx"), ov::Exception);+}++OPENVINO_TEST(${BACKEND_NAME}, onnx_model_dequantize_linear_opset21_invalid_non_inner_axis) {+ EXPECT_THROW(convert_model("dequantize_linear_21_invalid_non_inner_axis.onnx"), ov::Exception);+}+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_dequantize_linear_scalar_ignore_axis) {auto model = convert_model("dequantize_linear_scalar_ignore_axis.onnx");