Skip to content

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

[TRANSFORMATIONS] Fuse grouped-query GDN (#35462)

Mikhail Ryzhovcdf56020690e
diff --git a/src/common/transformations/include/transformations/common_optimizations/fuse_gated_delta_net.hpp b/src/common/transformations/include/transformations/common_optimizations/fuse_gated_delta_net.hpp
index ef01e58c2b5..7d6411af4c0 100644
--- a/src/common/transformations/include/transformations/common_optimizations/fuse_gated_delta_net.hpp
+++ b/src/common/transformations/include/transformations/common_optimizations/fuse_gated_delta_net.hpp
@@ -49,6 +49,19 @@ public:
FuseL2NormIntoGDN();
};
+/**
+ * @ingroup ov_transformation_common_api
+ * @brief Verifies that Q, K, and V inputs of GatedDeltaNet are connected to the same
+ * Split/Slice/Concat ancestor through a chain of
+ * Reshape/Transpose/Gather/GatherND/Broadcast/Unsqueeze/Squeeze operations.
+ */
+
+class TRANSFORMATIONS_API FuseGroupedQueryIntoGDN : public ov::pass::MatcherPass {
+public:
+ OPENVINO_MATCHER_PASS_RTTI("FuseGroupedQueryIntoGDN");
+ FuseGroupedQueryIntoGDN();
+};
+
/// This pass transforms a loop-based Gated Delta Net sub-graph to a single internal `GatedDeltaNet` operation.
///
/// Before:
diff --git a/src/common/transformations/src/transformations/common_optimizations/fuse_gated_delta_net.cpp b/src/common/transformations/src/transformations/common_optimizations/fuse_gated_delta_net.cpp
index 40a2d137382..d5fc5ef6348 100644
--- a/src/common/transformations/src/transformations/common_optimizations/fuse_gated_delta_net.cpp
+++ b/src/common/transformations/src/transformations/common_optimizations/fuse_gated_delta_net.cpp
@@ -8,13 +8,17 @@
#include <cstdint>
#include <memory>
#include <string>
+#include <unordered_set>
+#include <vector>
#include "itt.hpp"
#include "openvino/core/graph_util.hpp"
#include "openvino/core/node.hpp"
#include "openvino/core/rt_info.hpp"
+#include "openvino/core/shape.hpp"
#include "openvino/core/type.hpp"
#include "openvino/op/add.hpp"
+#include "openvino/op/broadcast.hpp"
#include "openvino/op/concat.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/convert.hpp"
@@ -22,6 +26,7 @@
#include "openvino/op/exp.hpp"
#include "openvino/op/gated_delta_net.hpp"
#include "openvino/op/gather.hpp"
+#include "openvino/op/gather_nd.hpp"
#include "openvino/op/loop.hpp"
#include "openvino/op/multiply.hpp"
#include "openvino/op/power.hpp"
@@ -30,12 +35,17 @@
#include "openvino/op/scatter_update.hpp"
#include "openvino/op/shape_of.hpp"
#include "openvino/op/slice.hpp"
+#include "openvino/op/split.hpp"
#include "openvino/op/sqrt.hpp"
#include "openvino/op/squeeze.hpp"
#include "openvino/op/subtract.hpp"
#include "openvino/op/transpose.hpp"
#include "openvino/op/unsqueeze.hpp"
+#include "openvino/op/util/gather_base.hpp"
+#include "openvino/op/util/gather_nd_base.hpp"
#include "openvino/op/util/op_types.hpp"
+#include "openvino/op/util/squeeze_base.hpp"
+#include "openvino/op/variadic_split.hpp"
#include "openvino/pass/pattern/matcher.hpp"
#include "openvino/pass/pattern/op/optional.hpp"
#include "openvino/pass/pattern/op/wrap_type.hpp"
@@ -358,6 +368,158 @@ ov::pass::FuseL2NormIntoGDN::FuseL2NormIntoGDN() {
register_matcher(m, callback);
}
+namespace {
+
+bool is_allowed_qk_path_node(const std::shared_ptr<ov::Node>& node) {
+ return ov::is_type<v1::Reshape>(node) || ov::is_type<v1::Transpose>(node) ||
+ ov::is_type<ov::op::util::GatherBase>(node) || ov::is_type<ov::op::v3::Broadcast>(node) ||
+ ov::is_type<v0::Unsqueeze>(node) || ov::is_type<ov::op::util::SqueezeBase>(node) ||
+ ov::is_type<ov::op::util::GatherNDBase>(node);
+}
+
+bool is_qk_anchor_node(const std::shared_ptr<ov::Node>& node) {
+ return ov::is_type<ov::op::v1::Split>(node) || ov::is_type<ov::op::v1::VariadicSplit>(node) ||
+ ov::is_type<ov::op::v8::Slice>(node) || ov::is_type<ov::op::v0::Concat>(node);
+}
+
+// Traverse backward from `start` along input(0), through allowed reshaping ops,
+// until a Split/Slice/Concat anchor is found. Returns the anchor output or {}.
+ov::Output<ov::Node> find_qk_anchor(const ov::Output<ov::Node>& start) {
+ auto current = start;
+ while (true) {
+ const auto node = current.get_node_shared_ptr();
+ if (!node) {
+ break;
+ }
+ if (is_qk_anchor_node(node)) {
+ return current;
+ }
+ if (!is_allowed_qk_path_node(node) || node->inputs().empty()) {
+ break;
+ }
+ current = node->input_value(0);
+ }
+ return {};
+}
+
+ov::Output<ov::Node> align_to_reference_shape(const ov::Output<ov::Node>& src,
+ const ov::Output<ov::Node>& reference,
+ ov::pass::MatcherPass* pass) {
+ const auto& src_ps = src.get_partial_shape();
+ const auto& ref_ps = reference.get_partial_shape();
+ if (src_ps.compatible(ref_ps)) {
+ return src;
+ }
+
+ if (src_ps.is_static() && ref_ps.is_static()) {
+ const auto src_shape = src_ps.to_shape();
+ const auto ref_shape = ref_ps.to_shape();
+ if (ov::shape_size(src_shape) != ov::shape_size(ref_shape)) {
+ return {};
+ }
+ }
+
+ // Accumulate product of all static source dimensions: n.
+ uint64_t n = 1;
+ bool has_static_dims = false;
+ for (const auto& dim : src_ps) {
+ if (!dim.is_static()) {
+ continue;
+ }
+ has_static_dims = true;
+ n *= static_cast<uint64_t>(dim.get_length());
+ }
+
+ const auto ref_rank = ref_ps.rank();
+ if (has_static_dims && ref_rank.is_static() && ref_rank.get_length() >= 2) {
+ const auto head_size_idx = ref_rank.get_length() - 1;
+ const auto head_num_idx = ref_rank.get_length() - 2;
+ const auto& head_size_dim = ref_ps[head_size_idx];
+
+ if (head_size_dim.is_static()) {
+ const auto head_size = static_cast<uint64_t>(head_size_dim.get_length());
+ if (head_size == 0 || n % head_size != 0) {
+ return {};
+ }
+
+ const auto head_num = static_cast<int64_t>(n / head_size);
+ auto ref_shape = std::make_shared<ov::op::v3::ShapeOf>(reference);
+ auto indices = v0::Constant::create(ov::element::i64, {1}, {head_num_idx});
+ auto updates = v0::Constant::create(ov::element::i64, {1}, {head_num});
+ auto axis = v0::Constant::create(ov::element::i64, {}, {0});
+ auto updated_shape = std::make_shared<ov::op::v3::ScatterUpdate>(ref_shape, indices, updates, axis);
+ auto reshaped = std::make_shared<v1::Reshape>(src, updated_shape, false);
+
+ pass->register_new_node(ref_shape);
+ pass->register_new_node(updated_shape);
+ pass->register_new_node(reshaped);
+ return reshaped;
+ }
+ }
+
+ auto ref_shape = std::make_shared<ov::op::v3::ShapeOf>(reference);
+ auto reshaped = std::make_shared<v1::Reshape>(src, ref_shape, false);
+ pass->register_new_node(ref_shape);
+ pass->register_new_node(reshaped);
+ return reshaped;
+}
+
+} // namespace
+
+ov::pass::FuseGroupedQueryIntoGDN::FuseGroupedQueryIntoGDN() {
+ auto gdn = pattern::wrap_type<ov::op::internal::GatedDeltaNet>();
+
+ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {
+ const auto& pattern_map = m.get_pattern_value_map();
+ auto gdn_node = ov::as_type_ptr<ov::op::internal::GatedDeltaNet>(pattern_map.at(gdn).get_node_shared_ptr());
+ if (!gdn_node) {
+ return false;
+ }
+
+ const auto q_anchor = find_qk_anchor(gdn_node->input_value(0));
+ const auto k_anchor = find_qk_anchor(gdn_node->input_value(1));
+ const auto v_anchor = find_qk_anchor(gdn_node->input_value(2));
+
+ // All Q/K/V must trace back to the same anchor node.
+ if (!q_anchor.get_node_shared_ptr() || !k_anchor.get_node_shared_ptr() || !v_anchor.get_node_shared_ptr() ||
+ q_anchor.get_node_shared_ptr() != k_anchor.get_node_shared_ptr() ||
+ k_anchor.get_node_shared_ptr() != v_anchor.get_node_shared_ptr()) {
+ return false;
+ }
+
+ // If already directly connected from anchor outputs, skip.
+ if (gdn_node->input_value(0) == q_anchor && gdn_node->input_value(1) == k_anchor &&
+ gdn_node->input_value(2) == v_anchor) {
+ return false;
+ }
+
+ auto q_aligned = align_to_reference_shape(q_anchor, gdn_node->input_value(0), this);
+ auto k_aligned = align_to_reference_shape(k_anchor, gdn_node->input_value(1), this);
+ auto v_aligned = align_to_reference_shape(v_anchor, gdn_node->input_value(2), this);
+
+ if (!q_aligned.get_node_shared_ptr() || !k_aligned.get_node_shared_ptr() || !v_aligned.get_node_shared_ptr()) {
+ return false;
+ }
+
+ auto new_gdn = std::make_shared<ov::op::internal::GatedDeltaNet>(q_aligned,
+ k_aligned,
+ v_aligned,
+ gdn_node->input_value(3),
+ gdn_node->input_value(4),
+ gdn_node->input_value(5),
+ gdn_node->get_fuse_qk_l2norm(),
+ gdn_node->get_q_l2_norm_eps(),
+ gdn_node->get_k_l2_norm_eps());
+ new_gdn->set_friendly_name(gdn_node->get_friendly_name());
+ ov::copy_runtime_info(gdn_node, new_gdn);
+ ov::replace_node(gdn_node, new_gdn);
+ return true;
+ };
+
+ auto m = std::make_shared<ov::pass::pattern::Matcher>(gdn, "FuseGroupedQueryIntoGDN");
+ register_matcher(m, callback);
+}
+
bool ov::pass::GatedDeltaNetFusion::run_on_model(const std::shared_ptr<ov::Model>& model) {
RUN_ON_MODEL_SCOPE(GatedDeltaNetFusion);
ov::pass::SymbolicOptimizations symbolic_optimizations(false, get_pass_config());
@@ -367,5 +529,6 @@ bool ov::pass::GatedDeltaNetFusion::run_on_model(const std::shared_ptr<ov::Model
// remove redundant transpose after loop fusion, which are inserted by FuseGDNLoop
symbolic_ctx_manager->register_pass<ov::pass::TransposeFuse>();
symbolic_ctx_manager->register_pass<ov::pass::FuseL2NormIntoGDN>();
+ symbolic_ctx_manager->register_pass<ov::pass::FuseGroupedQueryIntoGDN>();
return symbolic_optimizations.run_on_model(model);
-}
\ No newline at end of file
+}
diff --git a/src/common/transformations/tests/common_optimizations/fuse_gated_delta_net.cpp b/src/common/transformations/tests/common_optimizations/fuse_gated_delta_net.cpp
index 12b7e1c2772..8e2acf69204 100644
--- a/src/common/transformations/tests/common_optimizations/fuse_gated_delta_net.cpp
+++ b/src/common/transformations/tests/common_optimizations/fuse_gated_delta_net.cpp
@@ -8,7 +8,11 @@
#include <algorithm>
#include <climits>
+#include <cstdlib>
+#include <cstring>
#include <memory>
+#include <queue>
+#include <set>
#include "common_test_utils/ov_test_utils.hpp"
#include "openvino/op/add.hpp"
@@ -29,11 +33,13 @@
#include "openvino/op/scatter_update.hpp"
#include "openvino/op/shape_of.hpp"
#include "openvino/op/slice.hpp"
+#include "openvino/op/split.hpp"
#include "openvino/op/sqrt.hpp"
#include "openvino/op/squeeze.hpp"
#include "openvino/op/subtract.hpp"
#include "openvino/op/transpose.hpp"
#include "openvino/op/unsqueeze.hpp"
+#include "openvino/runtime/core.hpp"
#include "transformations/convert_precision.hpp"
namespace ov::test {
@@ -339,6 +345,155 @@ TEST_F(TransformationTestsF, GatedDeltaNetFusion_BuildBLHSLoopedGDNMode) {
model_ref = build_fused_gdn_ref(batch, seq_len, qk_head_num, v_head_num, qk_head_size, v_head_size);
}
+namespace {
+
+std::shared_ptr<ov::Model> build_gdn_with_shared_qk_anchor(bool shared_anchor) {
+ using ov::op::v0::Constant;
+ using ov::op::v0::Parameter;
+ using ov::op::v0::Squeeze;
+ using ov::op::v0::Unsqueeze;
+ using ov::op::v1::Reshape;
+ using ov::op::v1::Split;
+ using ov::op::v1::Transpose;
+ using ov::op::v8::Gather;
+
+ auto q_src = std::make_shared<Parameter>(ov::element::f32, ov::PartialShape{1, 4, 4, 8});
+ auto k_src = std::make_shared<Parameter>(ov::element::f32, ov::PartialShape{1, 4, 4, 8});
+ auto v_src = std::make_shared<Parameter>(ov::element::f32, ov::PartialShape{1, 4, 4, 8});
+
+ auto split_axis = Constant::create(ov::element::i64, {}, {1});
+ auto q_split = std::make_shared<Split>(q_src, split_axis, 2);
+ auto k_split = shared_anchor ? q_split : std::make_shared<Split>(k_src, split_axis, 2);
+ auto v_split = shared_anchor ? q_split : std::make_shared<Split>(v_src, split_axis, 2);
+
+ auto q_anchor = q_split->output(0);
+ auto k_anchor = k_split->output(1);
+ auto v_anchor = v_split->output(0);
+
+ auto gather_idx = Constant::create(ov::element::i64, {2}, {0, 1});
+ auto gather_axis = Constant::create(ov::element::i64, {}, {1});
+ auto q_gather = std::make_shared<Gather>(q_anchor, gather_idx, gather_axis);
+ auto k_gather = std::make_shared<Gather>(k_anchor, gather_idx, gather_axis);
+ auto v_gather = std::make_shared<Gather>(v_anchor, gather_idx, gather_axis);
+
+ auto q_shape = Constant::create(ov::element::i64, {4}, {1, 2, 4, 8});
+ auto k_shape = Constant::create(ov::element::i64, {4}, {1, 2, 4, 8});
+ auto v_shape = Constant::create(ov::element::i64, {4}, {1, 2, 4, 8});
+ auto q_reshape = std::make_shared<Reshape>(q_gather, q_shape, false);
+ auto k_reshape = std::make_shared<Reshape>(k_gather, k_shape, false);
+ auto v_reshape = std::make_shared<Reshape>(v_gather, v_shape, false);
+
+ auto perm = Constant::create(ov::element::i64, {4}, {0, 1, 2, 3});
+ auto q_transpose = std::make_shared<Transpose>(q_reshape, perm);
+ auto k_transpose = std::make_shared<Transpose>(k_reshape, perm);
+ auto v_transpose = std::make_shared<Transpose>(v_reshape, perm);
+
+ auto unsq_axis = Constant::create(ov::element::i32, {1}, {0});
+ auto q_unsq = std::make_shared<Unsqueeze>(q_transpose, unsq_axis);
+ auto k_unsq = std::make_shared<Unsqueeze>(k_transpose, unsq_axis);
+ auto v_unsq = std::make_shared<Unsqueeze>(v_transpose, unsq_axis);
+
+ auto sq_axis = Constant::create(ov::element::i32, {1}, {0});
+ auto q = std::make_shared<Squeeze>(q_unsq, sq_axis);
+ auto k = std::make_shared<Squeeze>(k_unsq, sq_axis);
+ auto v = std::make_shared<Squeeze>(v_unsq, sq_axis);
+
+ auto state = std::make_shared<Parameter>(ov::element::f32, ov::PartialShape{1, 4, 8, 8});
+ auto gate = std::make_shared<Parameter>(ov::element::f32, ov::PartialShape{1, 4, 4});
+ auto beta = std::make_shared<Parameter>(ov::element::f32, ov::PartialShape{1, 4, 4});
+
+ auto gdn = std::make_shared<ov::op::internal::GatedDeltaNet>(q, k, v, state, gate, beta);
+ auto result0 = std::make_shared<ov::op::v0::Result>(gdn->output(0));
+ auto result1 = std::make_shared<ov::op::v0::Result>(gdn->output(1));
+
+ ov::ParameterVector params = {q_src, k_src, v_src, state, gate, beta};
+ return std::make_shared<ov::Model>(ov::ResultVector{result0, result1}, params);
+}
+
+} // namespace
+
+TEST(TransformationTests, FuseGroupedQueryIntoGDN_Positive) {
+ auto model = build_gdn_with_shared_qk_anchor(true);
+ ov::pass::Manager manager;
+ manager.register_pass<ov::pass::FuseGroupedQueryIntoGDN>();
+ manager.run_passes(model);
+
+ auto gdn = ov::as_type_ptr<ov::op::internal::GatedDeltaNet>(
+ model->get_results().at(0)->input_value(0).get_node_shared_ptr());
+ ASSERT_NE(gdn, nullptr);
+
+ auto q_input = gdn->input_value(0);
+ auto k_input = gdn->input_value(1);
+ auto v_input = gdn->input_value(2);
+
+ // Find the anchor (Split) node for Q input
+ // It may be wrapped in Reshape/Transpose/etc
+ auto find_split_ancestor = [](const ov::Output<ov::Node>& output) -> std::shared_ptr<ov::Node> {
+ auto node = output.get_node_shared_ptr();
+ std::set<std::shared_ptr<ov::Node>> visited;
+ std::queue<std::shared_ptr<ov::Node>> to_visit;
+ to_visit.push(node);
+
+ while (!to_visit.empty()) {
+ auto current = to_visit.front();
+ to_visit.pop();
+
+ if (visited.count(current))
+ continue;
+ visited.insert(current);
+
+ if (ov::is_type<ov::op::v1::Split>(current)) {
+ return current;
+ }
+
+ // Continue searching upwards
+ for (size_t i = 0; i < current->get_input_size(); ++i) {
+ to_visit.push(current->input_value(i).get_node_shared_ptr());
+ }
+ }
+ return nullptr;
+ };
+
+ auto q_split = find_split_ancestor(q_input);
+ auto k_split = find_split_ancestor(k_input);
+ auto v_split = find_split_ancestor(v_input);
+
+ ASSERT_NE(q_split, nullptr);
+ ASSERT_NE(k_split, nullptr);
+ ASSERT_NE(v_split, nullptr);
+ ASSERT_EQ(q_split, k_split);
+ ASSERT_EQ(k_split, v_split);
+}
+
+TEST(TransformationTests, FuseGroupedQueryIntoGDN_NegativeDifferentAnchors) {
+ auto model = build_gdn_with_shared_qk_anchor(false);
+ ov::pass::Manager manager;
+ manager.register_pass<ov::pass::FuseGroupedQueryIntoGDN>();
+ manager.run_passes(model);
+
+ auto gdn = ov::as_type_ptr<ov::op::internal::GatedDeltaNet>(
+ model->get_results().at(0)->input_value(0).get_node_shared_ptr());
+ ASSERT_NE(gdn, nullptr);
+
+ auto q_input_node = gdn->input_value(0).get_node_shared_ptr();
+ auto k_input_node = gdn->input_value(1).get_node_shared_ptr();
+ auto v_input_node = gdn->input_value(2).get_node_shared_ptr();
+
+ if (ov::is_type<ov::op::v1::Reshape>(q_input_node)) {
+ q_input_node = q_input_node->input_value(0).get_node_shared_ptr();
+ }
+ if (ov::is_type<ov::op::v1::Reshape>(k_input_node)) {
+ k_input_node = k_input_node->input_value(0).get_node_shared_ptr();
+ }
+ if (ov::is_type<ov::op::v1::Reshape>(v_input_node)) {
+ v_input_node = v_input_node->input_value(0).get_node_shared_ptr();
+ }
+
+ // With different anchors, transformation should not apply, so at least one should not be Split
+ ASSERT_FALSE(ov::is_type<ov::op::v1::Split>(q_input_node) && q_input_node == k_input_node &&
+ k_input_node == v_input_node);
+}
+
TEST_F(TransformationTestsF, GatedDeltaNetFusion_BuildBHLSLoopedGDNMode_F16) {
disable_rt_info_check();
disable_result_friendly_names_check();
@@ -402,4 +557,98 @@ TEST_F(TransformationTestsF, GatedDeltaNetFusion_BuildBLHSLoopedGDNMode_F16) {
model_ref =
build_fused_gdn_ref(batch, seq_len, qk_head_num, v_head_num, qk_head_size, v_head_size, ov::element::f16);
}
+
+namespace {
+
+// Build a model where Q, K, V share one Split anchor, each connected via a single Transpose.
+// After FuseGroupedQueryIntoGDN the Transposes are removed and GDN is directly fed from Split outputs.
+std::shared_ptr<ov::Model> build_grouped_query_gdn_before() {
+ // src: {1, 4, 4, 8} — Split along dim=1 (H) into 2 groups → outputs {1, 2, 4, 8}
+ auto src = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{1, 4, 4, 8});
+ auto state = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{1, 4, 8, 8});
+ auto gate = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{1, 2, 4});
+ auto beta = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{1, 2, 4});
+
+ auto split_axis = ov::op::v0::Constant::create(ov::element::i64, {}, {1});
+ auto split = std::make_shared<ov::op::v1::Split>(src, split_axis, 2);
+ // split->output(0) and split->output(1) are both {1, 2, 4, 8}
+
+ auto identity_perm = ov::op::v0::Constant::create(ov::element::i64, {4}, {0, 1, 2, 3});
+ auto q = std::make_shared<ov::op::v1::Transpose>(split->output(0), identity_perm);
+ auto k = std::make_shared<ov::op::v1::Transpose>(split->output(1), identity_perm);
+ auto v = std::make_shared<ov::op::v1::Transpose>(split->output(0), identity_perm);
+
+ auto gdn = std::make_shared<ov::op::internal::GatedDeltaNet>(q, k, v, state, gate, beta);
+ return std::make_shared<ov::Model>(ov::ResultVector{std::make_shared<ov::op::v0::Result>(gdn->output(0)),
+ std::make_shared<ov::op::v0::Result>(gdn->output(1))},
+ ov::ParameterVector{src, state, gate, beta});
+}
+
+// Reference "after" model: GDN directly fed from Split outputs (Transposes removed).
+// align_to_reference_shape: {1,2,4,8} compatible with {1,2,4,8} → no Reshape inserted.
+std::shared_ptr<ov::Model> build_grouped_query_gdn_after() {
+ auto src = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{1, 4, 4, 8});
+ auto state = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{1, 4, 8, 8});
+ auto gate = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{1, 2, 4});
+ auto beta = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{1, 2, 4});
+
+ auto split_axis = ov::op::v0::Constant::create(ov::element::i64, {}, {1});
+ auto split = std::make_shared<ov::op::v1::Split>(src, split_axis, 2);
+
+ auto gdn = std::make_shared<ov::op::internal::GatedDeltaNet>(split->output(0),
+ split->output(1),
+ split->output(0),
+ state,
+ gate,
+ beta);
+ return std::make_shared<ov::Model>(ov::ResultVector{std::make_shared<ov::op::v0::Result>(gdn->output(0)),
+ std::make_shared<ov::op::v0::Result>(gdn->output(1))},
+ ov::ParameterVector{src, state, gate, beta});
+}
+
+// Build a model where Q, K, V each come from their own Split → anchors differ → no transformation.
+std::shared_ptr<ov::Model> build_grouped_query_gdn_different_anchors() {
+ auto src_q = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{1, 4, 4, 8});
+ auto src_k = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{1, 4, 4, 8});
+ auto src_v = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{1, 4, 4, 8});
+ auto state = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{1, 4, 8, 8});
+ auto gate = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{1, 2, 4});
+ auto beta = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{1, 2, 4});
+
+ auto split_axis = ov::op::v0::Constant::create(ov::element::i64, {}, {1});
+ auto q_split = std::make_shared<ov::op::v1::Split>(src_q, split_axis, 2);
+ auto k_split = std::make_shared<ov::op::v1::Split>(src_k, split_axis, 2);
+ auto v_split = std::make_shared<ov::op::v1::Split>(src_v, split_axis, 2);
+
+ auto identity_perm = ov::op::v0::Constant::create(ov::element::i64, {4}, {0, 1, 2, 3});
+ auto q = std::make_shared<ov::op::v1::Transpose>(q_split->output(0), identity_perm);
+ auto k = std::make_shared<ov::op::v1::Transpose>(k_split->output(0), identity_perm);
+ auto v = std::make_shared<ov::op::v1::Transpose>(v_split->output(0), identity_perm);
+
+ auto gdn = std::make_shared<ov::op::internal::GatedDeltaNet>(q, k, v, state, gate, beta);
+ return std::make_shared<ov::Model>(ov::ResultVector{std::make_shared<ov::op::v0::Result>(gdn->output(0)),
+ std::make_shared<ov::op::v0::Result>(gdn->output(1))},
+ ov::ParameterVector{src_q, src_k, src_v, state, gate, beta});
+}
+
+} // namespace
+
+// Positive: all Q/K/V share one Split anchor via a Transpose each → transformation fuses them.
+TEST_F(TransformationTestsF, FuseGroupedQueryIntoGDN_SharedAnchor_Applied) {
+ disable_rt_info_check();
+ disable_result_friendly_names_check();
+ model = build_grouped_query_gdn_before();
+ manager.register_pass<ov::pass::FuseGroupedQueryIntoGDN>();
+ model_ref = build_grouped_query_gdn_after();
+}
+
+// Negative: Q, K, V each come from a distinct Split node → anchors mismatch → transformation skipped.
+TEST_F(TransformationTestsF, FuseGroupedQueryIntoGDN_DifferentAnchors_NotApplied) {
+ disable_rt_info_check();
+ disable_result_friendly_names_check();
+ model = build_grouped_query_gdn_different_anchors();
+ manager.register_pass<ov::pass::FuseGroupedQueryIntoGDN>();
+ model_ref = build_grouped_query_gdn_different_anchors();
+}
+
} // namespace ov::test
\ No newline at end of file