From 9d3d061d60c17b71159bb07046a65ccabdcc36c1 Mon Sep 17 00:00:00 2001 From: vatsalas Date: Tue, 28 Jan 2025 15:14:37 +0530 Subject: [PATCH] test dequantize linear operator --- ...d_linear_with_axis_and_zero_point.prototxt | 86 +++++++++++++++++++ ...inear_without_axis_and_zero_point.prototxt | 58 +++++++++++++ .../tests/onnx_import_com_microsoft.in.cpp | 36 ++++++++ 3 files changed, 180 insertions(+) create mode 100644 src/frontends/onnx/tests/models/com.microsoft/dequantized_linear_with_axis_and_zero_point.prototxt create mode 100644 src/frontends/onnx/tests/models/com.microsoft/dequantized_linear_without_axis_and_zero_point.prototxt diff --git a/src/frontends/onnx/tests/models/com.microsoft/dequantized_linear_with_axis_and_zero_point.prototxt b/src/frontends/onnx/tests/models/com.microsoft/dequantized_linear_with_axis_and_zero_point.prototxt new file mode 100644 index 00000000000000..41ae600cd811ce --- /dev/null +++ b/src/frontends/onnx/tests/models/com.microsoft/dequantized_linear_with_axis_and_zero_point.prototxt @@ -0,0 +1,86 @@ +ir_version: 3 +producer_name: "OpenVINO ONNX Frontend" +graph { + node { + input: "x" + input: "x_scale" + input: "x_zero_point" + output: "output" + name: "dequantizelinear_op" + op_type: "DequantizeLinear" + attribute { + name: "axis" + i: 1 + type: INT + } + domain: "com.microsoft" + } + input { + name: "x" + type { + tensor_type { + elem_type: 3 + shape { + dim { + dim_value: 2 + } + dim { + dim_value: 4 + } + dim { + dim_value: 3 + } + } + } + } + } + input { + name: "x_scale" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 1 + } + } + } + } + } + input { + name: "x_zero_point" + type { + tensor_type { + elem_type: 3 + shape { + dim { + dim_value: 1 + } + } + } + } + } + output { + name: "output" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 2 + } + dim { + dim_value: 4 + } + dim { + dim_value: 3 + } + } + } + } + } +} +opset_import { + domain: "com.microsoft" + version: 1 +} diff --git a/src/frontends/onnx/tests/models/com.microsoft/dequantized_linear_without_axis_and_zero_point.prototxt b/src/frontends/onnx/tests/models/com.microsoft/dequantized_linear_without_axis_and_zero_point.prototxt new file mode 100644 index 00000000000000..e1d6b6208ccf4e --- /dev/null +++ b/src/frontends/onnx/tests/models/com.microsoft/dequantized_linear_without_axis_and_zero_point.prototxt @@ -0,0 +1,58 @@ +ir_version: 3 +producer_name: "OpenVINO ONNX Frontend" +graph { + node { + input: "x" + input: "x_scale" + output: "output" + name: "dequantizelinear_op" + op_type: "DequantizeLinear" + domain: "com.microsoft" + } + input { + name: "x" + type { + tensor_type { + elem_type: 3 + shape { + dim { + dim_value: 2 + } + dim { + dim_value: 4 + } + } + } + } + } + input { + name: "x_scale" + type { + tensor_type { + elem_type: 1 + shape { + } + } + } + } + output { + name: "output" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 2 + } + dim { + dim_value: 4 + } + } + } + } + } +} +opset_import { + domain: "com.microsoft" + version: 1 +} diff --git a/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp b/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp index 7775f06d62ca93..2dc2a4e1359220 100644 --- a/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp +++ b/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp @@ -1702,3 +1702,39 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_com_microsoft_fast_gelu) { test_case.add_expected_output(Shape{2, 4, 3}, expected_output); test_case.run_with_tolerance_as_fp(0.0055f); } + +OPENVINO_TEST(${BACKEND_NAME}, onnx_com_microsoft_dequantize_linear_with_required_params) { + const auto model = convert_model("com.microsoft/dequantized_linear_with_axis_and_zero_point.onnx"); + auto test_case = ov::test::TestCase(model, s_device); + + const std::vector X = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}; + const std::vector scale = {0.1f}; + const std::vector zero_point = {0}; + + const std::vector expected_output = {0.0f, 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1.0f, 1.1f, + 1.2f, 1.3f, 1.4f, 1.5f, 1.6f, 1.7f, 1.8f, 1.9f, 2.0f, 2.1f, 2.2f, 2.3f}; + + = test_case.add_input(Shape{2, 4, 3}, X); + test_case.add_input(Shape{1}, scale); + test_case.add_input(Shape{1}, zero_point); + + test_case.add_expected_output(Shape{2, 4, 3}, expected_output); + test_case.run(); +} + +OPENVINO_TEST(${BACKEND_NAME}, onnx_com_microsoft_dequantize_linear_without_required_params) { + const auto model = convert_model("com.microsoft/dequantized_linear_without_axis_and_zero_point.onnx"); + auto test_case = ov::test::TestCase(model, s_device); + + const std::vector X = {10, 20, 30, 40, 50, 60, 70, 80}; + const float scale = 0.2f; + + const std::vector expected_output = {2.f, 4.f, 6.f, 8.f, 10.f, 12.f, 14.f, 16.f}; + + test_case.add_input(Shape{2, 4}, X); + test_case.add_input(Shape{}, {scale}); + + test_case.add_expected_output(Shape{2, 4}, expected_output); + test_case.run(); +}