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 FE] Added com.microsoft.GroupNorm support and tests. (#33968)
Nikolay Proshunin3665f8821fbf
diff --git a/src/frontends/onnx/docs/supported_ops.md b/src/frontends/onnx/docs/supported_ops.mdindex c919f8f476c..8a689d32716 100644--- a/src/frontends/onnx/docs/supported_ops.md+++ b/src/frontends/onnx/docs/supported_ops.md@@ -247,7 +247,7 @@ OpenVINO provides support for operations of Default Opset (empty in table below)|com.microsoft |GemmaRotaryEmbedding | |1 | ||com.microsoft |GreedySearch | |1 | ||com.microsoft |GridSample | |1 | |-|com.microsoft |GroupNorm | |1 | |+|com.microsoft |GroupNorm |1 |1 | ||com.microsoft |GroupQueryAttention |1 |1 | ||com.microsoft |Inverse | |1 | ||com.microsoft |Irfft | |1 | |diff --git a/src/frontends/onnx/frontend/src/op/com.microsoft/group_norm.cpp b/src/frontends/onnx/frontend/src/op/com.microsoft/group_norm.cppnew file mode 100644index 00000000000..096ef70fb13--- /dev/null+++ b/src/frontends/onnx/frontend/src/op/com.microsoft/group_norm.cpp@@ -0,0 +1,74 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "core/operator_set.hpp"+#include "openvino/frontend/exception.hpp"+#include "openvino/op/group_normalization.hpp"+#include "openvino/op/squeeze.hpp"+#include "openvino/op/swish.hpp"+#include "openvino/op/transpose.hpp"++using namespace ov::op;+using ov::Shape;++namespace ov {+namespace frontend {+namespace onnx {+namespace com_microsoft {+namespace opset_1 {+ov::OutputVector group_norm(const ov::frontend::onnx::Node& node) {+ const auto inputs = node.get_ov_inputs();+ FRONT_END_GENERAL_CHECK(inputs.size() == 3,+ "Invalid number of inputs. Expected 3, actual " + std::to_string(inputs.size()));++ auto data = inputs[0]; // Shape [N, C, ...]+ auto scale = inputs[1]; // Shape [C]+ auto bias = inputs[2]; // Shape [C]++ const auto eps = node.get_attribute_value<float>("epsilon", 1e-05f);+ const auto num_groups = node.get_attribute_value<int64_t>("groups");+ const auto activation = node.get_attribute_value<int64_t>("activation");+ const auto channels_last = node.get_attribute_value<int64_t>("channels_last", 1);++ FRONT_END_GENERAL_CHECK(activation == 0 || activation == 1,+ "Expected activation to be either 0 or 1, actual value is: " + std::to_string(activation));++ FRONT_END_GENERAL_CHECK(+ channels_last == 0 || channels_last == 1,+ "Expected channels_last to be either 0 or 1, actual value is: " + std::to_string(channels_last));++ if (!scale.get_partial_shape().rank().compatible(1)) {+ scale = std::make_shared<v0::Squeeze>(scale);+ }+ if (!bias.get_partial_shape().rank().compatible(1)) {+ bias = std::make_shared<v0::Squeeze>(bias);+ }++ if (channels_last == 1) {+ // Transpose from NHWC to NCHW+ auto perm = v0::Constant::create(ov::element::i64, ov::Shape{4}, {0, 3, 1, 2});+ data = std::make_shared<v1::Transpose>(data, perm);+ }++ std::shared_ptr<ov::Node> group_norm =+ std::make_shared<v12::GroupNormalization>(data, scale, bias, num_groups, eps);++ if (channels_last == 1) {+ // Transpose back from NCHW to NHWC+ auto perm = v0::Constant::create(ov::element::i64, ov::Shape{4}, {0, 2, 3, 1});+ group_norm = std::make_shared<v1::Transpose>(group_norm, perm);+ }++ if (activation == 1) {+ return {std::make_shared<v4::Swish>(group_norm)};+ }++ return {group_norm};+}+ONNX_OP("GroupNorm", OPSET_SINCE(1), com_microsoft::opset_1::group_norm, MICROSOFT_DOMAIN);+} // namespace opset_1+} // namespace com_microsoft+} // namespace onnx+} // namespace frontend+} // namespace ovdiff --git a/src/frontends/onnx/tests/models/com.microsoft/group_norm.prototxt b/src/frontends/onnx/tests/models/com.microsoft/group_norm.prototxtnew file mode 100644index 00000000000..f4abe96d7e5--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/group_norm.prototxt@@ -0,0 +1,87 @@+ir_version: 3+producer_name: "OpenVINO ONNX Frontend"+graph {+ node {+ op_type: "GroupNorm"+ domain: "com.microsoft"+ input: "X"+ input: "scale"+ input: "bias"+ output: "Y"+ attribute {+ name: "groups"+ i: 4+ type: INT+ }+ attribute {+ name: "epsilon"+ f: 1e-6+ type: FLOAT+ }+ attribute {+ name: "activation"+ i: 0+ type: INT+ }+ attribute {+ name: "channels_last"+ i: 0+ type: INT+ }+ }+ input {+ name: "X"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 2 }+ dim { dim_value: 8 }+ dim { dim_value: 2 }+ dim { dim_value: 2 }+ }+ }+ }+ }+ input {+ name: "scale"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 8 }+ }+ }+ }+ }+ input {+ name: "bias"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 8 }+ }+ }+ }+ }+ output {+ name: "Y"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 2 }+ dim { dim_value: 8 }+ dim { dim_value: 2 }+ dim { dim_value: 2 }+ }+ }+ }+ }+}+opset_import {+ domain: "com.microsoft"+ version: 1+}+diff --git a/src/frontends/onnx/tests/models/com.microsoft/group_norm_channels_last.prototxt b/src/frontends/onnx/tests/models/com.microsoft/group_norm_channels_last.prototxtnew file mode 100644index 00000000000..8963f0d526e--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/group_norm_channels_last.prototxt@@ -0,0 +1,87 @@+ir_version: 3+producer_name: "OpenVINO ONNX Frontend"+graph {+ node {+ op_type: "GroupNorm"+ domain: "com.microsoft"+ input: "X"+ input: "scale"+ input: "bias"+ output: "Y"+ attribute {+ name: "groups"+ i: 4+ type: INT+ }+ attribute {+ name: "epsilon"+ f: 1e-6+ type: FLOAT+ }+ attribute {+ name: "activation"+ i: 0+ type: INT+ }+ attribute {+ name: "channels_last"+ i: 1+ type: INT+ }+ }+ input {+ name: "X"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 2 }+ dim { dim_value: 2 }+ dim { dim_value: 2 }+ dim { dim_value: 8 }+ }+ }+ }+ }+ input {+ name: "scale"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 8 }+ }+ }+ }+ }+ input {+ name: "bias"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 8 }+ }+ }+ }+ }+ output {+ name: "Y"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 2 }+ dim { dim_value: 2 }+ dim { dim_value: 2 }+ dim { dim_value: 8 }+ }+ }+ }+ }+}+opset_import {+ domain: "com.microsoft"+ version: 1+}+diff --git a/src/frontends/onnx/tests/models/com.microsoft/group_norm_silu.prototxt b/src/frontends/onnx/tests/models/com.microsoft/group_norm_silu.prototxtnew file mode 100644index 00000000000..c665df9776d--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/group_norm_silu.prototxt@@ -0,0 +1,87 @@+ir_version: 3+producer_name: "OpenVINO ONNX Frontend"+graph {+ node {+ op_type: "GroupNorm"+ domain: "com.microsoft"+ input: "X"+ input: "scale"+ input: "bias"+ output: "Y"+ attribute {+ name: "groups"+ i: 4+ type: INT+ }+ attribute {+ name: "epsilon"+ f: 1e-6+ type: FLOAT+ }+ attribute {+ name: "activation"+ i: 1+ type: INT+ }+ attribute {+ name: "channels_last"+ i: 0+ type: INT+ }+ }+ input {+ name: "X"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 2 }+ dim { dim_value: 8 }+ dim { dim_value: 2 }+ dim { dim_value: 2 }+ }+ }+ }+ }+ input {+ name: "scale"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 8 }+ }+ }+ }+ }+ input {+ name: "bias"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 8 }+ }+ }+ }+ }+ output {+ name: "Y"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_value: 2 }+ dim { dim_value: 8 }+ dim { dim_value: 2 }+ dim { dim_value: 2 }+ }+ }+ }+ }+}+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.cppindex ced7bb8f51d..ec1dcf92c56 100644--- a/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp+++ b/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp@@ -3100,3 +3100,94 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_skip_layer_normalization_with_default_test_case.run();}++OPENVINO_TEST(${BACKEND_NAME}, onnx_model_group_norm) {+ const auto model = convert_model("com.microsoft/group_norm.onnx");+ auto test_case = ov::test::TestCase(model, s_device);+ Shape shape{2, 8, 2, 2};+ const auto size = shape_size(shape);+ std::vector<float> data(size);+ std::iota(data.begin(), data.end(), 0.f);+ std::vector<float> scale(shape[1]), bias(shape[1]);+ std::iota(scale.begin(), scale.end(), 1.f);+ std::iota(bias.begin(), bias.end(), 1.f);+ std::vector<float> output = {+ -0.52752507f, -0.09108937f, 0.3453464f, 0.78178215f, 2.4364357f, 3.309307f, 4.1821785f, 5.05505f,+ -1.5825753f, -0.27326822f, 1.0360391f, 2.3453465f, 4.8728714f, 6.618614f, 8.364357f, 10.1101f,+ -2.6376252f, -0.45544672f, 1.726732f, 3.9089108f, 7.309307f, 9.927921f, 12.546536f, 15.165151f,+ -3.6926756f, -0.6376257f, 2.4174247f, 5.472475f, 9.745743f, 13.237228f, 16.728714f, 20.2202f,+ -0.52752507f, -0.09108937f, 0.3453464f, 0.78178215f, 2.4364357f, 3.309307f, 4.1821785f, 5.05505f,+ -1.5825753f, -0.27326822f, 1.0360391f, 2.3453465f, 4.8728714f, 6.618614f, 8.364357f, 10.1101f,+ -2.6376252f, -0.45544672f, 1.726732f, 3.9089108f, 7.309307f, 9.927921f, 12.546536f, 15.165151f,+ -3.6926756f, -0.6376257f, 2.4174247f, 5.472475f, 9.745743f, 13.237228f, 16.728714f, 20.2202f,+ };++ test_case.add_input<float>(data);+ test_case.add_input<float>(scale);+ test_case.add_input<float>(bias);+ test_case.add_expected_output<float>(shape, output);+ test_case.run();+}++OPENVINO_TEST(${BACKEND_NAME}, onnx_model_group_norm_silu) {+ const auto model = convert_model("com.microsoft/group_norm_silu.onnx");+ auto test_case = ov::test::TestCase(model, s_device);+ Shape shape{2, 8, 2, 2};+ const auto size = shape_size(shape);+ std::vector<float> data(size);+ std::iota(data.begin(), data.end(), 0.f);+ std::vector<float> scale(shape[1]), bias(shape[1]);+ std::iota(scale.begin(), scale.end(), 1.f);+ std::iota(bias.begin(), bias.end(), 1.f);+ std::vector<float> output = {+ -0.19576156f, -0.0434718f, 0.20219637f, 0.53635263f, 2.2404583f, 3.1926432f, 4.1192966f, 5.0230174f,+ -0.26972f, -0.11808054f, 0.764685f, 2.1402779f, 4.8358707f, 6.6097884f, 8.362408f, 10.109689f,+ -0.17607686f, -0.17674364f, 1.465985f, 3.8320312f, 7.3044186f, 9.927437f, 12.546492f, 15.165147f,+ -0.0897323f, -0.2204804f, 2.21955f, 5.4495826f, 9.7451725f, 13.237205f, 16.728714f, 20.2202f,+ -0.19576156f, -0.0434718f, 0.20219637f, 0.53635263f, 2.2404583f, 3.1926432f, 4.1192966f, 5.0230174f,+ -0.26972f, -0.11808054f, 0.764685f, 2.1402779f, 4.8358707f, 6.6097884f, 8.362408f, 10.109689f,+ -0.17607686f, -0.17674364f, 1.465985f, 3.8320312f, 7.3044186f, 9.927437f, 12.546492f, 15.165147f,+ -0.0897323f, -0.2204804f, 2.21955f, 5.4495826f, 9.7451725f, 13.237205f, 16.728714f, 20.2202f,+ };++ test_case.add_input<float>(data);+ test_case.add_input<float>(scale);+ test_case.add_input<float>(bias);+ test_case.add_expected_output<float>(shape, output);+ test_case.run_with_tolerance_as_fp();+}++OPENVINO_TEST(${BACKEND_NAME}, onnx_model_group_norm_channels_last) {+ const auto model = convert_model("com.microsoft/group_norm_channels_last.onnx");+ auto test_case = ov::test::TestCase(model, s_device);+ Shape shape{2, 2, 2, 8};+ const auto size = shape_size(shape);+ std::vector<float> data(size);+ float value = 0.f;+ for (size_t b = 0; b < shape[0]; b++)+ for (size_t f = 0; f < shape[3]; f++)+ for (size_t y = 0; y < shape[1]; y++)+ for (size_t x = 0; x < shape[2]; x++) {+ data[b * shape[1] * shape[2] * shape[3] + y * shape[2] * shape[3] + x * shape[3] + f] = value;+ value += 1.f;+ }+ std::vector<float> scale(shape[3]), bias(shape[3]);+ std::iota(scale.begin(), scale.end(), 1.f);+ std::iota(bias.begin(), bias.end(), 1.f);+ std::vector<float> output = {+ -0.52752507f, 2.4364357f, -1.5825753f, 4.8728714f, -2.6376252f, 7.309307f, -3.6926756f, 9.745743f,+ -0.09108937f, 3.309307f, -0.27326822f, 6.618614f, -0.45544672f, 9.927921f, -0.6376257f, 13.237228f,+ 0.3453464f, 4.1821785f, 1.0360391f, 8.364357f, 1.726732f, 12.546536f, 2.4174247f, 16.728714f,+ 0.78178215f, 5.05505f, 2.3453465f, 10.1101f, 3.9089108f, 15.165151f, 5.472475f, 20.2202f,+ -0.52752507f, 2.4364357f, -1.5825753f, 4.8728714f, -2.6376252f, 7.309307f, -3.6926756f, 9.745743f,+ -0.09108937f, 3.309307f, -0.27326822f, 6.618614f, -0.45544672f, 9.927921f, -0.6376257f, 13.237228f,+ 0.3453464f, 4.1821785f, 1.0360391f, 8.364357f, 1.726732f, 12.546536f, 2.4174247f, 16.728714f,+ 0.78178215f, 5.05505f, 2.3453465f, 10.1101f, 3.9089108f, 15.165151f, 5.472475f, 20.2202f,+ };++ test_case.add_input<float>(data);+ test_case.add_input<float>(scale);+ test_case.add_input<float>(bias);+ test_case.add_expected_output<float>(shape, output);+ test_case.run();+}