Skip to content

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

CVS-168808 Cannot recognize the attribute 'epsilon' of SkipLayerNormalization (#32701)

Szymon Gutaj10cf349363ac
diff --git a/src/frontends/onnx/frontend/src/op/com.microsoft/skip_layer_normalization.cpp b/src/frontends/onnx/frontend/src/op/com.microsoft/skip_layer_normalization.cpp
index 62c4caac932..abaef459668 100644
--- a/src/frontends/onnx/frontend/src/op/com.microsoft/skip_layer_normalization.cpp
+++ b/src/frontends/onnx/frontend/src/op/com.microsoft/skip_layer_normalization.cpp
@@ -18,7 +18,7 @@ namespace com_microsoft {
namespace opset_1 {
ov::OutputVector skip_layer_normalization(const ov::frontend::onnx::Node& node) {
auto nodes = node.get_ov_inputs();
- auto num_nodes = nodes.size();
+ const auto num_nodes = nodes.size();
FRONT_END_GENERAL_CHECK(num_nodes >= 3 && num_nodes <= 5,
"SkipLayerNormalization takes 3, 4 or 5 inputs. Provided " + std::to_string(num_nodes));
@@ -28,10 +28,10 @@ ov::OutputVector skip_layer_normalization(const ov::frontend::onnx::Node& node)
if (num_nodes == 5) {
input = std::make_shared<v1::Add>(input, nodes[4]);
}
- float eps = node.get_attribute_value<float>("epsilon");
- // reduce over hidden_size
- int hidden_size_dim = 2;
- const auto reduction_axes = v0::Constant::create(ov::element::i32, ov::Shape{1}, {hidden_size_dim});
+ const float eps = node.get_attribute_value<float>("epsilon", 1e-12f);
+ // reduce over last dimension (default for regular LayerNormalization)
+ const int last_dimension = -1;
+ const auto reduction_axes = v0::Constant::create(ov::element::i32, ov::Shape{1}, {last_dimension});
std::shared_ptr<ov::Node> result =
std::make_shared<v6::MVN>(input, reduction_axes, true, eps, ov::op::MVNEpsMode::INSIDE_SQRT);
// multiply by gamma
diff --git a/src/frontends/onnx/tests/models/skip_layer_normalization_with_default_epsilon.prototxt b/src/frontends/onnx/tests/models/skip_layer_normalization_with_default_epsilon.prototxt
new file mode 100644
index 00000000000..aa1e7c789a2
--- /dev/null
+++ b/src/frontends/onnx/tests/models/skip_layer_normalization_with_default_epsilon.prototxt
@@ -0,0 +1,69 @@
+ir_version: 10
+producer_name: "onnx-example"
+graph {
+ node {
+ input: "input"
+ input: "input"
+ input: "scale"
+ input: "bias"
+ output: "output"
+ op_type: "SkipLayerNormalization"
+ domain: "com.microsoft"
+ }
+ name: "complex_model"
+ initializer {
+ dims: 3
+ data_type: 1
+ name: "scale"
+ raw_data: "\000\000\200?\000\000\200?\000\000\200?"
+ }
+ initializer {
+ dims: 3
+ data_type: 1
+ name: "bias"
+ raw_data: "\000\000\000\000\000\000\000\000\000\000\000\000"
+ }
+ input {
+ name: "input"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 3
+ }
+ }
+ }
+ }
+ }
+ output {
+ name: "output"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 3
+ }
+ }
+ }
+ }
+ }
+}
+opset_import {
+ version: 22
+}
+opset_import {
+ domain: ""
+ version: 13
+}
+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 7f9a0baf173..e97e607afa2 100644
--- a/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp
+++ b/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp
@@ -2480,3 +2480,18 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_com_microsoft_qlinear_where_u8) {
test_case.add_expected_output<uint8_t>(Shape{4, 5, 6}, expected_output);
test_case.run();
}
+
+/// @brief Testing default value assignment to the 'epsilon' attribute of the
+/// SkipLayerNormalization operation. Model and input were taken from a bug report.
+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_skip_layer_normalization_with_default_epsilon) {
+ const auto model = convert_model("skip_layer_normalization_with_default_epsilon.onnx");
+ auto test_case = test::TestCase(model, s_device);
+
+ test_case.add_input<float>(Shape{2, 3},
+ {-0.6251511f, -0.5969454f, 0.13909698f, -0.27613088f, 0.00713499f, -0.06079938f});
+
+ test_case.add_expected_output<float>(Shape{2, 3},
+ {-0.7465922f, -0.6668722f, 1.4134643f, -1.3764048f, 0.96950716f, 0.40689772f});
+
+ test_case.run();
+}