Skip to content

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

[Op][GLU] Fix missing attrs in GLU visit_attributes (#28344)

Katarzyna Mitrus068f780900b2
diff --git a/src/common/transformations/include/ov_ops/glu.hpp b/src/common/transformations/include/ov_ops/glu.hpp
index add8c3a0582..ab2c646d7a1 100644
--- a/src/common/transformations/include/ov_ops/glu.hpp
+++ b/src/common/transformations/include/ov_ops/glu.hpp
@@ -77,4 +77,15 @@ private:
} // namespace internal
} // namespace op
+
+std::ostream& operator<<(std::ostream& s, const op::internal::GLU::GluType& reduction);
+
+template <>
+class AttributeAdapter<op::internal::GLU::GluType> : public EnumAttributeAdapterBase<op::internal::GLU::GluType> {
+public:
+ AttributeAdapter(op::internal::GLU::GluType& value) : EnumAttributeAdapterBase<op::internal::GLU::GluType>(value) {}
+
+ OPENVINO_RTTI("AttributeAdapter<op::internal::GLU::GluType>");
+};
+
} // namespace ov
diff --git a/src/common/transformations/src/ov_ops/glu.cpp b/src/common/transformations/src/ov_ops/glu.cpp
index 9b5fb780d36..5aac8489101 100644
--- a/src/common/transformations/src/ov_ops/glu.cpp
+++ b/src/common/transformations/src/ov_ops/glu.cpp
@@ -30,6 +30,8 @@ GLU::GLU(const Output<Node>& data,
bool GLU::visit_attributes(ov::AttributeVisitor& visitor) {
visitor.on_attribute("axis", m_axis);
visitor.on_attribute("split_lengths", m_split_lengths);
+ visitor.on_attribute("glu_type", m_glu_type);
+ visitor.on_attribute("split_to_glu_idx", m_split_to_glu_idx);
visitor.on_attribute("output_type", m_output_type);
return true;
}
@@ -53,4 +55,15 @@ std::shared_ptr<Node> GLU::clone_with_new_inputs(const ov::OutputVector& new_arg
}
} // namespace internal
} // namespace op
+
+template <>
+OPENVINO_API EnumNames<op::internal::GLU::GluType>& EnumNames<op::internal::GLU::GluType>::get() {
+ static auto enum_names =
+ EnumNames<op::internal::GLU::GluType>("op::internal::GLU::GluType",
+ {{"Swish", op::internal::GLU::GluType::Swish},
+ {"Gelu", op::internal::GLU::GluType::Gelu},
+ {"Gelu_Tanh", op::internal::GLU::GluType::Gelu_Tanh}});
+ return enum_names;
+}
+
} // namespace ov
diff --git a/src/core/tests/visitors/op/glu.cpp b/src/core/tests/visitors/op/glu.cpp
new file mode 100644
index 00000000000..f5de54ce9da
--- /dev/null
+++ b/src/core/tests/visitors/op/glu.cpp
@@ -0,0 +1,73 @@
+// Copyright (C) 2018-2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "ov_ops/glu.hpp"
+
+#include <gtest/gtest.h>
+
+#include "visitors/visitors.hpp"
+
+using ov::op::internal::GLU;
+using ov::op::v0::Parameter;
+using ov::test::NodeBuilder;
+
+TEST(attributes, glu_attr_Swish) {
+ NodeBuilder::opset().insert<GLU>();
+
+ int64_t axis = -1;
+ int64_t split_lenghts = 3;
+ auto data = std::make_shared<Parameter>(ov::element::f32, ov::PartialShape{2, 1, 6});
+ auto op = std::make_shared<GLU>(data, axis, split_lenghts, GLU::GluType::Swish, 0);
+
+ NodeBuilder builder(op, {data});
+ auto g_op = ov::as_type_ptr<GLU>(builder.create());
+
+ EXPECT_EQ(g_op->get_axis(), op->get_axis());
+ EXPECT_EQ(g_op->get_split_lengths(), op->get_split_lengths());
+ EXPECT_EQ(g_op->get_glu_type(), op->get_glu_type());
+ EXPECT_EQ(g_op->get_split_to_glu_idx(), op->get_split_to_glu_idx());
+
+ EXPECT_EQ(g_op->get_output_element_type(0), op->get_output_element_type(0));
+ EXPECT_EQ(g_op->get_output_partial_shape(0), op->get_output_partial_shape(0));
+}
+
+TEST(attributes, glu_attr_Gelu) {
+ NodeBuilder::opset().insert<GLU>();
+
+ int64_t axis = 2;
+ int64_t split_lenghts = 3;
+ auto data = std::make_shared<Parameter>(ov::element::f16, ov::PartialShape{2, 1, 6});
+ auto op = std::make_shared<GLU>(data, axis, split_lenghts, GLU::GluType::Gelu, 1, ov::element::f16);
+
+ NodeBuilder builder(op, {data});
+ auto g_op = ov::as_type_ptr<GLU>(builder.create());
+
+ EXPECT_EQ(g_op->get_axis(), op->get_axis());
+ EXPECT_EQ(g_op->get_split_lengths(), op->get_split_lengths());
+ EXPECT_EQ(g_op->get_glu_type(), op->get_glu_type());
+ EXPECT_EQ(g_op->get_split_to_glu_idx(), op->get_split_to_glu_idx());
+
+ EXPECT_EQ(g_op->get_output_element_type(0), op->get_output_element_type(0));
+ EXPECT_EQ(g_op->get_output_partial_shape(0), op->get_output_partial_shape(0));
+}
+
+TEST(attributes, glu_attr_Gelu_Tanh) {
+ NodeBuilder::opset().insert<GLU>();
+
+ int64_t axis = 2;
+ int64_t split_lenghts = 3;
+ auto data = std::make_shared<Parameter>(ov::element::f16, ov::PartialShape{2, 1, 6});
+ auto op = std::make_shared<GLU>(data, axis, split_lenghts, GLU::GluType::Gelu_Tanh, 1, ov::element::f16);
+
+ NodeBuilder builder(op, {data});
+ auto g_op = ov::as_type_ptr<GLU>(builder.create());
+
+ EXPECT_EQ(g_op->get_axis(), op->get_axis());
+ EXPECT_EQ(g_op->get_split_lengths(), op->get_split_lengths());
+ EXPECT_EQ(g_op->get_glu_type(), op->get_glu_type());
+ EXPECT_EQ(g_op->get_split_to_glu_idx(), op->get_split_to_glu_idx());
+
+ EXPECT_EQ(g_op->get_output_element_type(0), op->get_output_element_type(0));
+ EXPECT_EQ(g_op->get_output_partial_shape(0), op->get_output_partial_shape(0));
+}