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] Added QLinearReduceMean from com.microsoft domain (#29540)
Vatsala Shanubhag3080b6d00763
diff --git a/src/frontends/onnx/docs/supported_ops.md b/src/frontends/onnx/docs/supported_ops.mdindex 9e23e3ba7a1..736ae3c485c 100644--- a/src/frontends/onnx/docs/supported_ops.md+++ b/src/frontends/onnx/docs/supported_ops.md@@ -278,7 +278,7 @@ OpenVINO provides support for operations of Default Opset (empty in table below)|com.microsoft |QLinearGlobalAveragePool | |1 | ||com.microsoft |QLinearLeakyRelu |1 |1 | ||com.microsoft |QLinearMul |1 |1 | |-|com.microsoft |QLinearReduceMean | |1 | |+|com.microsoft |QLinearReduceMean |1 |1 | ||com.microsoft |QLinearSigmoid |1 |1 | ||com.microsoft |QLinearSoftmax |1 |1 | ||com.microsoft |QLinearWhere | |1 | |diff --git a/src/frontends/onnx/frontend/src/op/com.microsoft/qlinear_activation.cpp b/src/frontends/onnx/frontend/src/op/com.microsoft/qlinear_activation.cppindex ae926e52d1c..78eeccb5c94 100644--- a/src/frontends/onnx/frontend/src/op/com.microsoft/qlinear_activation.cpp+++ b/src/frontends/onnx/frontend/src/op/com.microsoft/qlinear_activation.cpp@@ -12,6 +12,7 @@#include "openvino/op/divide.hpp"#include "openvino/op/maximum.hpp"#include "openvino/op/multiply.hpp"+#include "openvino/op/reduce_mean.hpp"#include "openvino/op/reshape.hpp"#include "openvino/op/shape_of.hpp"#include "openvino/op/sigmoid.hpp"@@ -106,6 +107,16 @@ ov::OutputVector qlinear_avg_pool(const ov::frontend::onnx::Node& node) {});}+ov::OutputVector qlinear_reduce_mean(const ov::frontend::onnx::Node& node) {+ return qlinear_activation(node, [&](const std::shared_ptr<ov::Node>& input_dequantized) {+ auto axes = node.get_attribute_value<std::vector<int64_t>>("axes");+ auto keepdims = node.get_attribute_value<int64_t>("keepdims");+ return std::make_shared<v1::ReduceMean>(input_dequantized,+ v0::Constant::create(element::i64, {axes.size()}, axes),+ keepdims);+ });+}+ov::OutputVector qlinear_softmax(const ov::frontend::onnx::Node& node) {return qlinear_activation(node, [&](const std::shared_ptr<ov::Node>& input_dequantized) {auto axis = node.get_attribute_value<int64_t>("axis", -1);@@ -130,6 +141,7 @@ bool register_multiple_operators(void) {ONNX_OP_M("QLinearSigmoid", OPSET_SINCE(1), com_microsoft::opset_1::qlinear_sigmoid, MICROSOFT_DOMAIN);ONNX_OP_M("QLinearLeakyRelu", OPSET_SINCE(1), com_microsoft::opset_1::qlinear_leaky_relu, MICROSOFT_DOMAIN);ONNX_OP_M("QLinearAveragePool", OPSET_SINCE(1), com_microsoft::opset_1::qlinear_avg_pool, MICROSOFT_DOMAIN);+ ONNX_OP_M("QLinearReduceMean", OPSET_SINCE(1), com_microsoft::opset_1::qlinear_reduce_mean, MICROSOFT_DOMAIN);ONNX_OP_M("QLinearSoftmax", OPSET_SINCE(1), com_microsoft::opset_1::qlinear_softmax, MICROSOFT_DOMAIN);return true;diff --git a/src/frontends/onnx/tests/models/com.microsoft/qlinear_reducemean_i8.prototxt b/src/frontends/onnx/tests/models/com.microsoft/qlinear_reducemean_i8.prototxtnew file mode 100644index 00000000000..3b4ed554472--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/qlinear_reducemean_i8.prototxt@@ -0,0 +1,106 @@+ir_version: 3+producer_name: "OpenVINO ONNX Frontend"+producer_version: ""+model_version: 0+graph {+ name: "test_qlinear_reducemean_i8"++ node {+ input: "data"+ input: "data_scale"+ input: "data_zero_point"+ input: "reduced_scale"+ input: "reduced_zero_point"+ output: "reduced"+ op_type: "QLinearReduceMean"+ attribute {+ name: "axes"+ ints: 1+ type: INTS+ }+ attribute {+ name: "keepdims"+ i: 1+ type: INT+ }+ domain: "com.microsoft"+ }++ input {+ name: "data"+ type {+ tensor_type {+ elem_type: 3+ shape {+ dim { dim_value: 2 }+ dim { dim_value: 3 }+ }+ }+ }+ }++ input {+ name: "data_scale"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 1 }+ }+ }+ }+ }++ input {+ name: "data_zero_point"+ type {+ tensor_type {+ elem_type: 3+ shape {+ dim { dim_value: 1 }+ }+ }+ }+ }++ input {+ name: "reduced_scale"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 1 }+ }+ }+ }+ }++ input {+ name: "reduced_zero_point"+ type {+ tensor_type {+ elem_type: 3+ shape {+ dim { dim_value: 1 }+ }+ }+ }+ }++ output {+ name: "reduced"+ type {+ tensor_type {+ elem_type: 3+ shape {+ dim { dim_value: 2 }+ dim { dim_value: 1 }+ }+ }+ }+ }+}++opset_import {+ 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.cppindex 7d0f564233a..bc3f9c33671 100644--- a/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp+++ b/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp@@ -2145,6 +2145,28 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_past_1_input_1_rotary_interleaved)test_case.run_with_tolerance_as_fp();}+OPENVINO_TEST(${BACKEND_NAME}, onnx_com_microsoft_qlinear_reducemean_i8) {+ const auto model = convert_model("com.microsoft/qlinear_reducemean_i8.onnx");+ auto test_case = ov::test::TestCase(model, s_device);++ const std::vector<int8_t> data{-10, 0, 10, -20, 20, 30};+ const std::vector<float> data_scale{0.1f};+ const std::vector<int8_t> data_zero_point{0};+ const std::vector<float> reduced_scale{0.05f};+ const std::vector<int8_t> reduced_zero_point{5};++ const std::vector<int8_t> expected_output{5, 25};++ test_case.add_input<int8_t>(Shape{2, 3}, data);+ test_case.add_input<float>(Shape{1}, data_scale);+ test_case.add_input<int8_t>(Shape{1}, data_zero_point);+ test_case.add_input<float>(Shape{1}, reduced_scale);+ test_case.add_input<int8_t>(Shape{1}, reduced_zero_point);++ test_case.add_expected_output<int8_t>(Shape{2, 1}, expected_output);+ test_case.run();+}+OPENVINO_TEST(${BACKEND_NAME}, onnx_com_microsoft_qlinear_concat_i8) {const auto model = convert_model("com.microsoft/qlinear_concat_i8.onnx");auto test_case = ov::test::TestCase(model, s_device);