Skip to content

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

[CPU]Enable Paged GatedDeltaNet (#35070)

Zhang Yie1cf5b237d08
diff --git a/src/plugins/intel_cpu/CMakeLists.txt b/src/plugins/intel_cpu/CMakeLists.txt
index e5e8b2f4b63..5c455a57951 100644
--- a/src/plugins/intel_cpu/CMakeLists.txt
+++ b/src/plugins/intel_cpu/CMakeLists.txt
@@ -332,7 +332,7 @@ cross_compiled_file(${TARGET_NAME}
ARCH AVX512F AVX2 ANY
src/nodes/kernels/linear_attn/recurrent_linear_attn.cpp
API src/nodes/kernels/linear_attn/recurrent_linear_attn.hpp
- NAME recurrent_linear_attn
+ NAME recurrent_linear_attn recurrent_linear_attn_paged
NAMESPACE ov::Extensions::Cpu::XARCH
)
diff --git a/src/plugins/intel_cpu/src/cpu_types.cpp b/src/plugins/intel_cpu/src/cpu_types.cpp
index aa4a5d7eee9..df0d25c51ac 100644
--- a/src/plugins/intel_cpu/src/cpu_types.cpp
+++ b/src/plugins/intel_cpu/src/cpu_types.cpp
@@ -264,7 +264,8 @@ static const TypeToNameMap& get_type_to_name_tbl() {
{"LoraSubgraph", Type::LoRA},
{"GatherMatmul", Type::GatherMatmul},
{"GatherMatmulCompressed", Type::GatherMatmul},
- {"GatedDeltaNet", Type::GatedDeltaNet}};
+ {"GatedDeltaNet", Type::GatedDeltaNet},
+ {"PagedGatedDeltaNet", Type::PagedGatedDeltaNet}};
return type_to_name_tbl;
}
@@ -401,6 +402,7 @@ std::string NameFromType(const Type type) {
CASE(LoRA);
CASE(GatherMatmul);
CASE(GatedDeltaNet);
+ CASE(PagedGatedDeltaNet);
CASE(Unknown);
}
#undef CASE
diff --git a/src/plugins/intel_cpu/src/cpu_types.h b/src/plugins/intel_cpu/src/cpu_types.h
index 379e1f9df4e..8c78206c659 100644
--- a/src/plugins/intel_cpu/src/cpu_types.h
+++ b/src/plugins/intel_cpu/src/cpu_types.h
@@ -139,7 +139,8 @@ enum class Type : uint8_t {
SegmentMax,
LoRA,
GatherMatmul,
- GatedDeltaNet
+ GatedDeltaNet,
+ PagedGatedDeltaNet
};
enum class Algorithm : uint8_t {
diff --git a/src/plugins/intel_cpu/src/extension.cpp b/src/plugins/intel_cpu/src/extension.cpp
index 0992f8a1915..37dfe7cb99a 100644
--- a/src/plugins/intel_cpu/src/extension.cpp
+++ b/src/plugins/intel_cpu/src/extension.cpp
@@ -44,6 +44,7 @@
#include "openvino/op/normalize_l2.hpp"
#include "openvino/op/not_equal.hpp"
#include "openvino/op/paged_attention.hpp"
+#include "openvino/op/paged_gated_delta_net.hpp"
#include "openvino/op/prelu.hpp"
#include "openvino/op/prior_box.hpp"
#include "openvino/op/prior_box_clustered.hpp"
@@ -199,6 +200,7 @@ OPENVINO_CREATE_EXTENSIONS(std::vector<ov::Extension::Ptr>({
std::make_shared<ov::OpExtension<ov::op::internal::FullyConnectedQuantized>>(),
std::make_shared<ov::OpExtension<ov::op::PagedAttentionExtension>>(),
std::make_shared<ov::OpExtension<ov::op::internal::GatedDeltaNet>>(),
+ std::make_shared<ov::OpExtension<ov::op::internal::PagedGatedDeltaNet>>(),
// clang-format off
OP_EXTENSION_X64(std::make_shared<ov::OpExtension<ov::intel_cpu::InteractionNode>>())
OP_EXTENSION_X64(std::make_shared<ov::OpExtension<ov::intel_cpu::LLMMLPNode>>())
diff --git a/src/plugins/intel_cpu/src/nodes/kernels/linear_attn/recurrent_linear_attn.cpp b/src/plugins/intel_cpu/src/nodes/kernels/linear_attn/recurrent_linear_attn.cpp
index 4d5f0864df8..ffef0770311 100644
--- a/src/plugins/intel_cpu/src/nodes/kernels/linear_attn/recurrent_linear_attn.cpp
+++ b/src/plugins/intel_cpu/src/nodes/kernels/linear_attn/recurrent_linear_attn.cpp
@@ -86,7 +86,7 @@ void recurrent_linear_attn(const ov::intel_cpu::PlainTensor& query,
const ov::intel_cpu::PlainTensor& beta,
float q_l2_norm_eps,
float k_l2_norm_eps,
- bool fuse_qk_l2norm,
+ bool use_qk_l2norm,
ov::intel_cpu::PlainTensor& output_attn,
ov::intel_cpu::PlainTensor& output_recurrent_state,
float* temp_buffer,
@@ -122,7 +122,7 @@ void recurrent_linear_attn(const ov::intel_cpu::PlainTensor& query,
b_k[j] = k_ptr[i * H * K_HEAD_DIMS + j];
b_q[j] = q_ptr[i * H * K_HEAD_DIMS + j];
}
- if (fuse_qk_l2norm) {
+ if (use_qk_l2norm) {
l2norm(b_k, K_HEAD_DIMS, k_l2_norm_eps);
l2norm(b_q, K_HEAD_DIMS, q_l2_norm_eps);
}
@@ -147,4 +147,195 @@ void recurrent_linear_attn(const ov::intel_cpu::PlainTensor& query,
});
}
+template <typename T>
+static void recurrent_linear_attn_paged_impl(const ov::intel_cpu::PlainTensor& query,
+ const ov::intel_cpu::PlainTensor& key,
+ const ov::intel_cpu::PlainTensor& value,
+ ov::intel_cpu::PlainTensor& recurrent_state_table,
+ const ov::intel_cpu::PlainTensor& gate,
+ const ov::intel_cpu::PlainTensor& beta,
+ const ov::intel_cpu::PlainTensor& subsequence_begins,
+ const ov::intel_cpu::PlainTensor& block_indices,
+ const ov::intel_cpu::PlainTensor& block_indices_begins,
+ const ov::intel_cpu::PlainTensor& past_lens,
+ const ov::intel_cpu::PlainTensor& cache_interval,
+ float q_l2_norm_eps,
+ float k_l2_norm_eps,
+ bool use_qk_l2norm,
+ ov::intel_cpu::PlainTensor& output_attn,
+ float* temp_buffer,
+ const ov::intel_cpu::CpuParallelPtr& cpu_parallel) {
+ const size_t tokens = query.m_dims[0];
+ const size_t qk_heads = query.m_dims[1];
+ const size_t k_head_dims = query.m_dims[2];
+ const size_t v_heads = value.m_dims[1];
+ const size_t v_head_dims = value.m_dims[2];
+
+ OPENVINO_ASSERT(key.m_dims[0] == tokens && key.m_dims[1] == qk_heads && key.m_dims[2] == k_head_dims,
+ "[CPU] paged_gdn: key shape mismatch with query");
+ OPENVINO_ASSERT(value.m_dims[0] == tokens && value.m_dims[1] == v_heads,
+ "[CPU] paged_gdn: value shape mismatch with query tokens/heads");
+ OPENVINO_ASSERT(recurrent_state_table.m_dims[1] == v_heads && recurrent_state_table.m_dims[2] == v_head_dims &&
+ recurrent_state_table.m_dims[3] == k_head_dims,
+ "[CPU] paged_gdn: recurrent_state_table shape mismatch");
+
+ const auto seq_tensor_size = subsequence_begins.m_dims[0];
+ OPENVINO_ASSERT(seq_tensor_size >= 1, "[CPU] paged_gdn: subsequence_begins must be non-empty");
+ const size_t num_sequences = seq_tensor_size - 1;
+ const size_t group_size = v_heads / qk_heads;
+ const float q_scale = 1.0f / std::sqrt(static_cast<float>(k_head_dims));
+
+ cpu_parallel->parallel_for3d(num_sequences, v_heads, v_head_dims, [&](size_t seq, size_t i_h, size_t i_v) {
+ size_t tid = parallel_get_thread_num();
+ float* init_state = temp_buffer + tid * 3 * k_head_dims;
+ float* b_k = temp_buffer + tid * 3 * k_head_dims + k_head_dims;
+ float* b_q = temp_buffer + tid * 3 * k_head_dims + 2 * k_head_dims;
+
+ const int32_t token_begin = subsequence_begins.at<int32_t>({seq});
+ const int32_t token_end = subsequence_begins.at<int32_t>({seq + 1});
+ const int32_t block_begin = block_indices_begins.at<int32_t>({seq});
+ const int32_t block_end = block_indices_begins.at<int32_t>({seq + 1});
+ const int32_t seq_blocks = std::max(block_end - block_begin, 0);
+ const int32_t seq_past_len = past_lens.at<int32_t>({seq});
+ const int32_t seq_interval = cache_interval.at<int32_t>({seq});
+ const int32_t prev_nums = (seq_interval > 0) ? (seq_past_len % seq_interval) : 0;
+ OPENVINO_ASSERT(seq_blocks > 0, "[CPU] paged_gdn: each sequence must have at least one cache block");
+
+ const int32_t block_id = block_indices.at<int32_t>({static_cast<size_t>(block_begin)});
+ auto* initial_state_src = recurrent_state_table.ptr<T>(static_cast<size_t>(block_id), i_h, i_v);
+ cvt_copy(init_state, initial_state_src, 1, k_head_dims, 0, 0);
+
+ const size_t hk = i_h / group_size;
+
+ for (int32_t token = token_begin; token < token_end; token++) {
+ const auto token_u = static_cast<size_t>(token);
+ for (size_t j = 0; j < k_head_dims; j++) {
+ b_k[j] = static_cast<float>(key.at<T>({token_u, hk, j}));
+ b_q[j] = static_cast<float>(query.at<T>({token_u, hk, j}));
+ }
+
+ if (use_qk_l2norm) {
+ l2norm(b_k, k_head_dims, k_l2_norm_eps);
+ l2norm(b_q, k_head_dims, q_l2_norm_eps);
+ }
+
+ multiply_scalar(b_q, b_q, q_scale, k_head_dims);
+
+ float b_g = static_cast<float>(gate.at<T>({token_u, i_h}));
+ float b_beta = static_cast<float>(beta.at<T>({token_u, i_h}));
+ b_g = std::exp(b_g);
+
+ multiply_scalar(init_state, init_state, b_g, k_head_dims);
+
+ float h_k = dot_product(init_state, b_k, k_head_dims, nullptr, nullptr, nullptr, 0);
+
+ float b_v = static_cast<float>(value.at<T>({token_u, i_h, i_v}));
+ b_v = (b_v - h_k) * b_beta;
+
+ multiply_scalar(b_k, b_k, b_v, k_head_dims);
+ cvt_add(init_state, init_state, b_k, 1, k_head_dims, 0, 0, 0);
+
+ const float b_output = dot_product(init_state, b_q, k_head_dims, nullptr, nullptr, nullptr, 0);
+ output_attn.at<T>({token_u, i_h, i_v}) = static_cast<T>(b_output);
+
+ const int32_t processed_tokens = (token - token_begin) + 1;
+ const int32_t cached_tokens = prev_nums + processed_tokens;
+ const bool interval_hit = (seq_interval > 0) && ((cached_tokens % seq_interval) == 0);
+ const bool is_last_token = (token == token_end - 1);
+ const bool should_store = interval_hit || is_last_token;
+ if (should_store) {
+ const int32_t slot = (seq_interval > 0) ? (1 + (cached_tokens - 1) / seq_interval) : 1;
+ if (slot < seq_blocks) {
+ const int32_t block_id = block_indices.at<int32_t>({static_cast<size_t>(block_begin + slot)});
+ auto* updated_state_dst = recurrent_state_table.ptr<T>(static_cast<size_t>(block_id), i_h, i_v);
+ cvt_copy(updated_state_dst, init_state, 1, k_head_dims, 0, 0);
+ }
+ }
+ }
+ });
+}
+
+void recurrent_linear_attn_paged(const ov::intel_cpu::PlainTensor& query,
+ const ov::intel_cpu::PlainTensor& key,
+ const ov::intel_cpu::PlainTensor& value,
+ ov::intel_cpu::PlainTensor& recurrent_state_table,
+ const ov::intel_cpu::PlainTensor& gate,
+ const ov::intel_cpu::PlainTensor& beta,
+ const ov::intel_cpu::PlainTensor& subsequence_begins,
+ const ov::intel_cpu::PlainTensor& block_indices,
+ const ov::intel_cpu::PlainTensor& block_indices_begins,
+ const ov::intel_cpu::PlainTensor& past_lens,
+ const ov::intel_cpu::PlainTensor& cache_interval,
+ float q_l2_norm_eps,
+ float k_l2_norm_eps,
+ bool use_qk_l2norm,
+ ov::intel_cpu::PlainTensor& output_attn,
+ float* temp_buffer,
+ const ov::intel_cpu::CpuParallelPtr& cpu_parallel) {
+ const auto data_prc = query.get_precision();
+ OPENVINO_ASSERT(key.get_precision() == data_prc && value.get_precision() == data_prc &&
+ recurrent_state_table.get_precision() == data_prc && gate.get_precision() == data_prc &&
+ beta.get_precision() == data_prc && output_attn.get_precision() == data_prc,
+ "[CPU] paged_gdn: q/k/v/state/gate/beta/output precisions must match");
+ OPENVINO_ASSERT(temp_buffer != nullptr, "[CPU] paged_gdn: temp_buffer must not be null");
+
+ if (data_prc == ov::element::f32) {
+ recurrent_linear_attn_paged_impl<float>(query,
+ key,
+ value,
+ recurrent_state_table,
+ gate,
+ beta,
+ subsequence_begins,
+ block_indices,
+ block_indices_begins,
+ past_lens,
+ cache_interval,
+ q_l2_norm_eps,
+ k_l2_norm_eps,
+ use_qk_l2norm,
+ output_attn,
+ temp_buffer,
+ cpu_parallel);
+ } else if (data_prc == ov::element::f16) {
+ recurrent_linear_attn_paged_impl<ov::float16>(query,
+ key,
+ value,
+ recurrent_state_table,
+ gate,
+ beta,
+ subsequence_begins,
+ block_indices,
+ block_indices_begins,
+ past_lens,
+ cache_interval,
+ q_l2_norm_eps,
+ k_l2_norm_eps,
+ use_qk_l2norm,
+ output_attn,
+ temp_buffer,
+ cpu_parallel);
+ } else if (data_prc == ov::element::bf16) {
+ recurrent_linear_attn_paged_impl<ov::bfloat16>(query,
+ key,
+ value,
+ recurrent_state_table,
+ gate,
+ beta,
+ subsequence_begins,
+ block_indices,
+ block_indices_begins,
+ past_lens,
+ cache_interval,
+ q_l2_norm_eps,
+ k_l2_norm_eps,
+ use_qk_l2norm,
+ output_attn,
+ temp_buffer,
+ cpu_parallel);
+ } else {
+ OPENVINO_ASSERT(false, "[CPU] paged_gdn: unsupported precision");
+ }
+}
+
} // namespace ov::Extensions::Cpu::XARCH
\ No newline at end of file
diff --git a/src/plugins/intel_cpu/src/nodes/kernels/linear_attn/recurrent_linear_attn.hpp b/src/plugins/intel_cpu/src/nodes/kernels/linear_attn/recurrent_linear_attn.hpp
index b9d9ffa20c6..c2551e61190 100644
--- a/src/plugins/intel_cpu/src/nodes/kernels/linear_attn/recurrent_linear_attn.hpp
+++ b/src/plugins/intel_cpu/src/nodes/kernels/linear_attn/recurrent_linear_attn.hpp
@@ -10,6 +10,27 @@
namespace ov::Extensions::Cpu::XARCH {
+/// \brief Computes recurrent linear attention for a contiguous token batch.
+///
+/// The function consumes query/key/value inputs and recurrent state for the same batch,
+/// optionally applies fused Q/K L2 normalization, and writes both attention output and
+/// updated recurrent state.
+///
+/// \note `output_recurrent_state` is updated by this kernel and must have a preallocated
+/// shape compatible with `recurrent_state`.
+/// \param query Query tensor with shape [tokens, qk_heads, qk_head_size].
+/// \param key Key tensor with shape [tokens, qk_heads, qk_head_size].
+/// \param value Value tensor with shape [tokens, v_heads, v_head_size].
+/// \param recurrent_state Input recurrent state tensor for current step.
+/// \param gate Gate tensor with shape [tokens, v_heads].
+/// \param beta Beta tensor with shape [tokens, v_heads].
+/// \param q_l2_norm_eps Epsilon used for query L2 normalization.
+/// \param k_l2_norm_eps Epsilon used for key L2 normalization.
+/// \param use_qk_l2norm Enables Q/K L2 normalization path.
+/// \param output_attn Output attention tensor [tokens, v_heads, v_head_size].
+/// \param output_recurrent_state Output tensor with updated recurrent state.
+/// \param temp_buffer buffer contains `num_threads * 3 * qk_head_size * sizeof(float)` bytes, 64-byte aligned.
+/// \param cpu_parallel CPU parallel runtime used for threading/work split.
void recurrent_linear_attn(const ov::intel_cpu::PlainTensor& query,
const ov::intel_cpu::PlainTensor& key,
const ov::intel_cpu::PlainTensor& value,
@@ -18,10 +39,52 @@ void recurrent_linear_attn(const ov::intel_cpu::PlainTensor& query,
const ov::intel_cpu::PlainTensor& beta,
float q_l2_norm_eps,
float k_l2_norm_eps,
- bool fuse_qk_l2norm,
+ bool use_qk_l2norm,
ov::intel_cpu::PlainTensor& output_attn,
ov::intel_cpu::PlainTensor& output_recurrent_state,
float* temp_buffer,
const ov::intel_cpu::CpuParallelPtr& cpu_parallel);
+/// \brief Computes recurrent linear attention using paged state storage.
+///
+/// The function processes multiple variable-length subsequences packed into one token batch.
+/// `subsequence_begins`, `block_indices`, `block_indices_begins`, `past_lens`, and
+/// `cache_interval` describe how each subsequence maps to blocks in `recurrent_state_table`.
+///
+/// \note `recurrent_state_table` is updated in place according to paging metadata.
+/// \param query Query tensor with shape [batch_in_tokens, qk_heads, qk_head_size].
+/// \param key Key tensor with shape [batch_in_tokens, qk_heads, qk_head_size].
+/// \param value Value tensor with shape [batch_in_tokens, v_heads, v_head_size].
+/// \param recurrent_state_table Paged recurrent-state table updated in place.
+/// \param gate Gate tensor with shape [batch_in_tokens, v_heads].
+/// \param beta Beta tensor with shape [batch_in_tokens, v_heads].
+/// \param subsequence_begins Prefix offsets for token ranges per sequence.
+/// \param block_indices Flattened block ids used by all sequences.
+/// \param block_indices_begins Prefix offsets into `block_indices` per sequence.
+/// \param past_lens Number of already-processed tokens per sequence.
+/// \param cache_interval Cache update interval per sequence.
+/// \param q_l2_norm_eps Epsilon used for query L2 normalization.
+/// \param k_l2_norm_eps Epsilon used for key L2 normalization.
+/// \param use_qk_l2norm Enables Q/K L2 normalization path.
+/// \param output_attn Output attention tensor [batch_in_tokens, v_heads, v_head_size].
+/// \param temp_buffer buffer contains `num_threads * 3 * qk_head_size * sizeof(float)` bytes, 64-byte aligned.
+/// \param cpu_parallel CPU parallel runtime used for threading/work split.
+void recurrent_linear_attn_paged(const ov::intel_cpu::PlainTensor& query,
+ const ov::intel_cpu::PlainTensor& key,
+ const ov::intel_cpu::PlainTensor& value,
+ ov::intel_cpu::PlainTensor& recurrent_state_table,
+ const ov::intel_cpu::PlainTensor& gate,
+ const ov::intel_cpu::PlainTensor& beta,
+ const ov::intel_cpu::PlainTensor& subsequence_begins,
+ const ov::intel_cpu::PlainTensor& block_indices,
+ const ov::intel_cpu::PlainTensor& block_indices_begins,
+ const ov::intel_cpu::PlainTensor& past_lens,
+ const ov::intel_cpu::PlainTensor& cache_interval,
+ float q_l2_norm_eps,
+ float k_l2_norm_eps,
+ bool use_qk_l2norm,
+ ov::intel_cpu::PlainTensor& output_attn,
+ float* temp_buffer,
+ const ov::intel_cpu::CpuParallelPtr& cpu_parallel);
+
} // namespace ov::Extensions::Cpu::XARCH
diff --git a/src/plugins/intel_cpu/src/nodes/paged_gated_delta_net.cpp b/src/plugins/intel_cpu/src/nodes/paged_gated_delta_net.cpp
new file mode 100644
index 00000000000..934c2ae5ea6
--- /dev/null
+++ b/src/plugins/intel_cpu/src/nodes/paged_gated_delta_net.cpp
@@ -0,0 +1,126 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "paged_gated_delta_net.h"
+
+#include <cstddef>
+#include <memory>
+#include <oneapi/dnnl/dnnl_common.hpp>
+#include <string>
+#include <vector>
+
+#include "cpu_memory.h"
+#include "graph_context.h"
+#include "kernels/linear_attn/recurrent_linear_attn.hpp"
+#include "memory_desc/cpu_blocked_memory_desc.h"
+#include "memory_desc/cpu_memory_desc.h"
+#include "node.h"
+#include "onednn/iml_type_mapper.h"
+#include "openvino/core/except.hpp"
+#include "openvino/core/node.hpp"
+#include "openvino/core/type.hpp"
+#include "openvino/core/type/element_type.hpp"
+#include "openvino/op/paged_gated_delta_net.hpp"
+#include "shape_inference/shape_inference_cpu.hpp"
+#include "utils/plain_tensor.hpp"
+
+using namespace ov::Extensions::Cpu;
+using namespace ov::Extensions::Cpu::XARCH;
+
+namespace ov::intel_cpu::node {
+
+PagedGatedDeltaNet::PagedGatedDeltaNet(const std::shared_ptr<ov::Node>& op, const GraphContext::CPtr& context)
+ : Node(op, context, NgraphShapeInferFactory(op)) {
+ std::string errorMessage;
+ if (!isSupportedOperation(op, errorMessage)) {
+ OPENVINO_THROW_NOT_IMPLEMENTED(errorMessage);
+ }
+
+ const auto& pgdn = ov::as_type_ptr<ov::op::internal::PagedGatedDeltaNet>(op);
+ OPENVINO_ASSERT(pgdn != nullptr, "Expected PagedGatedDeltaNet node");
+ m_use_qk_l2norm = pgdn->get_use_qk_l2norm();
+ m_q_l2_norm_eps = pgdn->get_q_l2_norm_eps();
+ m_k_l2_norm_eps = pgdn->get_k_l2_norm_eps();
+}
+
+void PagedGatedDeltaNet::initSupportedPrimitiveDescriptors() {
+ std::vector<PortConfigurator> inPortConfigs;
+ for (size_t i = 0; i < getParentEdges().size(); ++i) {
+ inPortConfigs.emplace_back(LayoutType::ncsp,
+ getOriginalInputPrecisionAtPort(i),
+ getInputShapeAtPort(i),
+ false,
+ -1);
+ }
+
+ std::vector<PortConfigurator> outPortConfigs = {
+ PortConfigurator{LayoutType::ncsp, getOriginalOutputPrecisionAtPort(0), getOutputShapeAtPort(0), false, -1}};
+ addSupportedPrimDesc(inPortConfigs, outPortConfigs, impl_desc_type::ref_any);
+}
+
+void PagedGatedDeltaNet::createPrimitive() {
+ const auto queryDims = getInputShapeAtPort(0).getDims();
+ auto headSize = *(queryDims.end() - 1);
+ const auto numWorkerThreads = context->getCpuParallel()->get_num_worker_threads();
+ auto newMemDesc = std::make_shared<CpuBlockedMemoryDesc>(
+ ov::element::f32,
+ ov::intel_cpu::Shape{static_cast<size_t>(numWorkerThreads), 3 * headSize});
+ m_tmpInpBuffer = context->getScratchPad()->createScratchPadMem(newMemDesc);
+}
+
+void PagedGatedDeltaNet::execute([[maybe_unused]] const dnnl::stream& strm) {
+ auto originalInputNumber = getOriginalInputsNumber();
+ std::vector<MemoryPtr> inputs(originalInputNumber);
+
+ for (size_t i = 0; i < originalInputNumber; i++) {
+ inputs[i] = getSrcMemoryAtPort(i);
+ }
+
+ auto output = getDstMemoryAtPort(0);
+
+ PlainTensor query(inputs[0]);
+ PlainTensor key(inputs[1]);
+ PlainTensor value(inputs[2]);
+ PlainTensor recurrent_state(inputs[3]);
+ PlainTensor gate(inputs[4]);
+ PlainTensor beta(inputs[5]);
+
+ PlainTensor subsequence_begins(inputs[6]);
+ PlainTensor block_indices(inputs[7]);
+ PlainTensor block_indices_begins(inputs[8]);
+ PlainTensor past_lens(inputs[9]);
+ PlainTensor cache_interval(inputs[10]);
+ PlainTensor output_attn(output);
+
+ auto* temp_buffer = m_tmpInpBuffer->getDataAs<float>();
+
+ recurrent_linear_attn_paged(query,
+ key,
+ value,
+ recurrent_state,
+ gate,
+ beta,
+ subsequence_begins,
+ block_indices,
+ block_indices_begins,
+ past_lens,
+ cache_interval,
+ m_q_l2_norm_eps,
+ m_k_l2_norm_eps,
+ m_use_qk_l2norm,
+ output_attn,
+ temp_buffer,
+ context->getCpuParallel());
+}
+
+bool PagedGatedDeltaNet::isSupportedOperation(const std::shared_ptr<const ov::Node>& op,
+ std::string& errorMessage) noexcept {
+ if (op == nullptr || !ov::is_type<ov::op::internal::PagedGatedDeltaNet>(op)) {
+ errorMessage = "Node is not an instance of ov::op::internal::PagedGatedDeltaNet.";
+ return false;
+ }
+ return true;
+}
+
+} // namespace ov::intel_cpu::node
diff --git a/src/plugins/intel_cpu/src/nodes/paged_gated_delta_net.h b/src/plugins/intel_cpu/src/nodes/paged_gated_delta_net.h
new file mode 100644
index 00000000000..85ace792bf7
--- /dev/null
+++ b/src/plugins/intel_cpu/src/nodes/paged_gated_delta_net.h
@@ -0,0 +1,51 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <memory>
+#include <oneapi/dnnl/dnnl_common.hpp>
+#include <string>
+
+#include "cpu_types.h"
+#include "graph_context.h"
+#include "node.h"
+#include "openvino/core/node.hpp"
+
+namespace ov::intel_cpu::node {
+
+class PagedGatedDeltaNet : public Node {
+public:
+ PagedGatedDeltaNet(const std::shared_ptr<ov::Node>& op, const GraphContext::CPtr& context);
+
+ void getSupportedDescriptors() override {}
+ bool created() const override {
+ return getType() == Type::PagedGatedDeltaNet;
+ }
+
+ bool isExecutable() const override {
+ return true;
+ }
+
+ bool needPrepareParams() const override {
+ return false;
+ }
+
+ void createPrimitive() override;
+
+ void executeDynamicImpl(const dnnl::stream& strm) override {
+ execute(strm);
+ }
+ void initSupportedPrimitiveDescriptors() override;
+ void execute(const dnnl::stream& strm) override;
+ static bool isSupportedOperation(const std::shared_ptr<const ov::Node>& op, std::string& errorMessage) noexcept;
+
+private:
+ MemoryPtr m_tmpInpBuffer = nullptr;
+ bool m_use_qk_l2norm = false;
+ float m_q_l2_norm_eps = 1e-6F;
+ float m_k_l2_norm_eps = 1e-6F;
+};
+
+} // namespace ov::intel_cpu::node
diff --git a/src/plugins/intel_cpu/src/nodes_factory.cpp b/src/plugins/intel_cpu/src/nodes_factory.cpp
index 283607aca42..aca425fca01 100644
--- a/src/plugins/intel_cpu/src/nodes_factory.cpp
+++ b/src/plugins/intel_cpu/src/nodes_factory.cpp
@@ -67,6 +67,7 @@
#include "nodes/normalize.h"
#include "nodes/one_hot.h"
#include "nodes/pad.h"
+#include "nodes/paged_gated_delta_net.h"
#include "nodes/pooling.h"
#include "nodes/priorbox.h"
#include "nodes/priorbox_clustered.h"
@@ -244,6 +245,7 @@ Node::NodesFactory::NodesFactory() : Factory("NodesFactory") {
INTEL_CPU_NODE(LoRA, Type::LoRA);
INTEL_CPU_NODE(GatherMatmul, Type::GatherMatmul);
INTEL_CPU_NODE(GatedDeltaNet, Type::GatedDeltaNet);
+ INTEL_CPU_NODE(PagedGatedDeltaNet, Type::PagedGatedDeltaNet);
#if defined(OPENVINO_ARCH_X86_64)
INTEL_CPU_NODE(FakeQuantize, Type::FakeQuantize);
INTEL_CPU_NODE(GridSample, Type::GridSample);
diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/paged_gated_delta_net.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/paged_gated_delta_net.cpp
new file mode 100644
index 00000000000..c7738d44b01
--- /dev/null
+++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/paged_gated_delta_net.cpp
@@ -0,0 +1,44 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "single_op_tests/paged_gated_delta_net.hpp"
+
+namespace ov::test {
+
+std::vector<PagedGatedDeltaNetLayerParams> paged_gdn_test_cases = {
+ // PagedGatedDeltaNetLayerParams
+ // {int32_t qk_heads,
+ // int32_t v_heads,
+ // int32_t qk_head_size,
+ // int32_t v_head_size,
+ // std::vector<int32_t> seq_lengths,
+ // std::vector<int32_t> cache_intervals,
+ // ov::element::Type element_type,
+ // std::string target_device}
+ {2, 4, 8, 8, {3, 3}, {2, 3}, ov::element::f32, "CPU"},
+ {2, 4, 8, 8, {3, 2}, {0, 0}, ov::element::f32, "CPU"},
+ {1, 4, 16, 8, {2, 5, 1}, {1, 4, 2}, ov::element::f32, "CPU"},
+ {2, 6, 32, 64, {4, 2, 3}, {3, 2, 5}, ov::element::f32, "CPU"},
+ {4, 8, 32, 64, {15, 32, 33}, {16, 16, 16}, ov::element::f32, "CPU"},
+ {8, 8, 128, 128, {15, 32, 33}, {16, 16, 16}, ov::element::f32, "CPU"},
+ {2, 4, 8, 8, {3, 3}, {2, 3}, ov::element::f16, "CPU"},
+ {2, 4, 8, 8, {3, 2}, {0, 0}, ov::element::f16, "CPU"},
+ {1, 4, 16, 8, {2, 5, 1}, {1, 4, 2}, ov::element::f16, "CPU"},
+ {2, 6, 32, 64, {4, 2, 3}, {3, 2, 5}, ov::element::f16, "CPU"},
+ {4, 8, 32, 64, {15, 32, 33}, {16, 16, 16}, ov::element::f16, "CPU"},
+ {8, 8, 128, 128, {15, 32, 33}, {16, 16, 16}, ov::element::f16, "CPU"},
+ {2, 4, 8, 8, {3, 3}, {2, 3}, ov::element::bf16, "CPU"},
+ {2, 4, 8, 8, {3, 2}, {0, 0}, ov::element::bf16, "CPU"},
+ {1, 4, 16, 8, {2, 5, 1}, {1, 4, 2}, ov::element::bf16, "CPU"},
+ {2, 6, 32, 64, {4, 2, 3}, {3, 2, 5}, ov::element::bf16, "CPU"},
+ {4, 8, 32, 64, {15, 32, 33}, {16, 16, 16}, ov::element::bf16, "CPU"},
+ {8, 8, 128, 128, {15, 32, 33}, {16, 16, 16}, ov::element::bf16, "CPU"},
+};
+
+INSTANTIATE_TEST_SUITE_P(smoke_PagedGatedDeltaNet,
+ PagedGatedDeltaNetLayerTest,
+ ::testing::ValuesIn(paged_gdn_test_cases),
+ PagedGatedDeltaNetLayerTest::getTestCaseName);
+
+} // namespace ov::test
diff --git a/src/tests/functional/plugin/shared/include/shared_test_classes/single_op/paged_gated_delta_net.hpp b/src/tests/functional/plugin/shared/include/shared_test_classes/single_op/paged_gated_delta_net.hpp
new file mode 100644
index 00000000000..8fb153bfae4
--- /dev/null
+++ b/src/tests/functional/plugin/shared/include/shared_test_classes/single_op/paged_gated_delta_net.hpp
@@ -0,0 +1,46 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <cstdint>
+#include <map>
+#include <string>
+#include <tuple>
+#include <vector>
+
+#include "gtest/gtest.h"
+#include "shared_test_classes/base/ov_subgraph.hpp"
+
+namespace ov::test {
+
+using PagedGatedDeltaNetLayerParams = std::tuple<int32_t,
+ int32_t,
+ int32_t,
+ int32_t,
+ std::vector<int32_t>,
+ std::vector<int32_t>,
+ ov::element::Type,
+ std::string>; // qk_heads, v_heads, qk_head_size, v_head_size,
+ // seq_lengths, cache_intervals, element_type,
+ // target_device
+
+class PagedGatedDeltaNetLayerTest : public testing::WithParamInterface<PagedGatedDeltaNetLayerParams>,
+ virtual public ov::test::SubgraphBaseTest {
+public:
+ static std::string getTestCaseName(const testing::TestParamInfo<PagedGatedDeltaNetLayerParams>& obj);
+ void generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) override;
+
+protected:
+ std::vector<ov::Tensor> calculate_refs() override;
+ std::vector<ov::Tensor> get_plugin_outputs() override;
+ void compare(const std::vector<ov::Tensor>& expected, const std::vector<ov::Tensor>& actual) override;
+ void SetUp() override;
+
+private:
+ std::map<std::shared_ptr<ov::Node>, ov::Tensor> host_inputs;
+ ov::element::Type data_type;
+};
+
+} // namespace ov::test
\ No newline at end of file
diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/paged_gated_delta_net.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/paged_gated_delta_net.hpp
new file mode 100644
index 00000000000..4a3011ee3b5
--- /dev/null
+++ b/src/tests/functional/plugin/shared/include/single_op_tests/paged_gated_delta_net.hpp
@@ -0,0 +1,15 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include "shared_test_classes/single_op/paged_gated_delta_net.hpp"
+
+namespace ov::test {
+
+TEST_P(PagedGatedDeltaNetLayerTest, Inference) {
+ run();
+}
+
+} // namespace ov::test
diff --git a/src/tests/functional/plugin/shared/src/single_op/paged_gated_delta_net.cpp b/src/tests/functional/plugin/shared/src/single_op/paged_gated_delta_net.cpp
new file mode 100644
index 00000000000..b9522e2982d
--- /dev/null
+++ b/src/tests/functional/plugin/shared/src/single_op/paged_gated_delta_net.cpp
@@ -0,0 +1,506 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "shared_test_classes/single_op/paged_gated_delta_net.hpp"
+
+#include <algorithm>
+#include <cmath>
+#include <cstdint>
+#include <numeric>
+#include <random>
+#include <sstream>
+#include <tuple>
+#include <vector>
+
+#include "common_test_utils/ov_tensor_utils.hpp"
+#include "openvino/core/type/bfloat16.hpp"
+#include "openvino/op/paged_gated_delta_net.hpp"
+#include "openvino/op/parameter.hpp"
+#include "openvino/op/result.hpp"
+#include "openvino/runtime/remote_context.hpp"
+#include "openvino/runtime/remote_tensor.hpp"
+#include "openvino/runtime/tensor.hpp"
+
+namespace {
+
+template <typename T>
+void normalize_and_scale(const T* src, size_t n, float scale, std::vector<float>& dst) {
+ dst.resize(n);
+ float sum = 0.0f;
+ for (size_t i = 0; i < n; i++) {
+ const float value = static_cast<float>(src[i]);
+ dst[i] = value;
+ sum += value * value;
+ }
+ const float inv = 1.0f / std::sqrt(sum + 1e-6f);
+ for (size_t i = 0; i < n; i++) {
+ dst[i] *= inv * scale;
+ }
+}
+
+template <typename T>
+void run_reference(const std::vector<T>& query,
+ const std::vector<T>& key,
+ const std::vector<T>& value,
+ const std::vector<T>& gate,
+ const std::vector<T>& beta,
+ std::vector<T>& recurrent_state_table,
+ const std::vector<int32_t>& subsequence_begins,
+ const std::vector<int32_t>& block_indices,
+ const std::vector<int32_t>& block_indices_begins,
+ const std::vector<int32_t>& past_lens,
+ const std::vector<int32_t>& cache_interval,
+ int32_t qk_heads,
+ int32_t v_heads,
+ int32_t qk_head_size,
+ int32_t v_head_size,
+ std::vector<T>& output) {
+ const int32_t tokens = static_cast<int32_t>(query.size()) / (qk_heads * qk_head_size);
+ output.resize(static_cast<size_t>(tokens) * v_heads * v_head_size);
+
+ const auto state_off = [=](int32_t block, int32_t h, int32_t k_idx, int32_t v_idx) {
+ return ((block * v_heads + h) * v_head_size + v_idx) * qk_head_size + k_idx;
+ };
+
+ const float attn_scale = 1.0f / std::sqrt(static_cast<float>(qk_head_size));
+ const int32_t num_sequences = static_cast<int32_t>(subsequence_begins.size()) - 1;
+ const int32_t group_size = v_heads / qk_heads;
+
+ OPENVINO_ASSERT(static_cast<int32_t>(recurrent_state_table.size()) % (v_heads * qk_head_size * v_head_size) == 0,
+ "State table size is inconsistent with inferred qk/v head sizes");
+
+ for (int32_t seq = 0; seq < num_sequences; seq++) {
+ const int32_t token_begin = subsequence_begins[seq];
+ const int32_t token_end = subsequence_begins[seq + 1];
+ const int32_t block_begin = block_indices_begins[seq];
+ const int32_t block_end = block_indices_begins[seq + 1];
+ const int32_t seq_blocks = std::max(block_end - block_begin, 0);
+ const int32_t past_len = past_lens[seq];
+ const int32_t interval = cache_interval[seq];
+ const int32_t prev_nums = (interval > 0) ? (past_len % interval) : 0;
+
+ for (int32_t h = 0; h < v_heads; h++) {
+ const int32_t hk = h / group_size;
+ std::vector<float> state(static_cast<size_t>(qk_head_size) * v_head_size, 0.0f);
+
+ const int32_t block_id = block_indices[block_begin];
+
+ for (int32_t k_idx = 0; k_idx < qk_head_size; k_idx++) {
+ for (int32_t v_idx = 0; v_idx < v_head_size; v_idx++) {
+ state[k_idx * v_head_size + v_idx] =
+ static_cast<float>(recurrent_state_table[state_off(block_id, h, k_idx, v_idx)]);
+ }
+ }
+
+ for (int32_t token = token_begin; token < token_end; token++) {
+ const auto q_ptr = query.data() + (token * qk_heads + hk) * qk_head_size;
+ const auto k_ptr = key.data() + (token * qk_heads + hk) * qk_head_size;
+
+ std::vector<float> q_norm;
+ std::vector<float> k_norm;
+ normalize_and_scale(q_ptr, qk_head_size, attn_scale, q_norm);
+ normalize_and_scale(k_ptr, qk_head_size, 1.0f, k_norm);
+
+ const float b_g = std::exp(static_cast<float>(gate[token * v_heads + h]));
+ const float b_beta = static_cast<float>(beta[token * v_heads + h]);
+
+ for (int32_t v_idx = 0; v_idx < v_head_size; v_idx++) {
+ const float b_v = static_cast<float>(value[(token * v_heads + h) * v_head_size + v_idx]);
+
+ float h_k = 0.0f;
+ for (int32_t k_idx = 0; k_idx < qk_head_size; k_idx++) {
+ auto& s = state[k_idx * v_head_size + v_idx];
+ s *= b_g;
+ h_k += s * k_norm[k_idx];
+ }
+
+ const float update = (b_v - h_k) * b_beta;
+ float out_v = 0.0f;
+ for (int32_t k_idx = 0; k_idx < qk_head_size; k_idx++) {
+ auto& s = state[k_idx * v_head_size + v_idx];
+ s += k_norm[k_idx] * update;
+ out_v += s * q_norm[k_idx];
+ }
+
+ output[(token * v_heads + h) * v_head_size + v_idx] = static_cast<T>(out_v);
+ }
+
+ const int32_t processed_tokens = (token - token_begin) + 1;
+ const int32_t cached_tokens = prev_nums + processed_tokens;
+ const bool reached_interval_boundary = (interval > 0) && ((cached_tokens % interval) == 0);
+ const bool reached_sequence_end = (token == token_end - 1);
+ if (reached_interval_boundary || reached_sequence_end) {
+ const int32_t slot = interval > 0 ? (1 + (cached_tokens - 1) / interval) : 1;
+ if (slot < seq_blocks) {
+ const int32_t next_block_id = block_indices[block_begin + slot];
+ for (int32_t k_idx = 0; k_idx < qk_head_size; k_idx++) {
+ for (int32_t v_idx = 0; v_idx < v_head_size; v_idx++) {
+ recurrent_state_table[state_off(next_block_id, h, k_idx, v_idx)] =
+ static_cast<T>(state[k_idx * v_head_size + v_idx]);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+template <typename T>
+std::vector<T> tensor_to_vector(const ov::Tensor& tensor) {
+ const auto* ptr = tensor.data<const T>();
+ return std::vector<T>(ptr, ptr + tensor.get_size());
+}
+
+ov::Tensor make_i32_tensor(const std::vector<int32_t>& values) {
+ ov::Tensor tensor(ov::element::i32, ov::Shape{values.size()});
+ std::copy(values.begin(), values.end(), tensor.data<int32_t>());
+ return tensor;
+}
+
+template <typename T>
+std::vector<ov::Tensor> calculate_typed_refs(const std::map<std::shared_ptr<ov::Node>, ov::Tensor>& host_inputs,
+ const std::shared_ptr<ov::Model>& function,
+ int32_t qk_heads,
+ int32_t v_heads,
+ int32_t qk_head_size,
+ int32_t v_head_size,
+ const ov::element::Type& data_type) {
+ const auto& params = function->get_parameters();
+
+ auto query = tensor_to_vector<T>(host_inputs.at(params[0]));
+ auto key = tensor_to_vector<T>(host_inputs.at(params[1]));
+ auto value = tensor_to_vector<T>(host_inputs.at(params[2]));
+ auto state = tensor_to_vector<T>(host_inputs.at(params[3]));
+ auto gate = tensor_to_vector<T>(host_inputs.at(params[4]));
+ auto beta = tensor_to_vector<T>(host_inputs.at(params[5]));
+ auto subsequence_begins = tensor_to_vector<int32_t>(host_inputs.at(params[6]));
+ auto block_indices = tensor_to_vector<int32_t>(host_inputs.at(params[7]));
+ auto block_indices_begins = tensor_to_vector<int32_t>(host_inputs.at(params[8]));
+ auto past_lens = tensor_to_vector<int32_t>(host_inputs.at(params[9]));
+ auto cache_interval = tensor_to_vector<int32_t>(host_inputs.at(params[10]));
+
+ std::vector<T> ref_output;
+ run_reference(query,
+ key,
+ value,
+ gate,
+ beta,
+ state,
+ subsequence_begins,
+ block_indices,
+ block_indices_begins,
+ past_lens,
+ cache_interval,
+ qk_heads,
+ v_heads,
+ qk_head_size,
+ v_head_size,
+ ref_output);
+
+ ov::Tensor output_tensor(data_type, host_inputs.at(params[2]).get_shape());
+ std::copy(ref_output.begin(), ref_output.end(), output_tensor.data<T>());
+
+ ov::Tensor state_tensor(data_type, host_inputs.at(params[3]).get_shape());
+ std::copy(state.begin(), state.end(), state_tensor.data<T>());
+
+ return {output_tensor, state_tensor};
+}
+
+} // namespace
+
+namespace ov::test {
+
+std::string PagedGatedDeltaNetLayerTest::getTestCaseName(
+ const testing::TestParamInfo<PagedGatedDeltaNetLayerParams>& obj) {
+ const auto& [qk_heads,
+ v_heads,
+ qk_head_size,
+ v_head_size,
+ seq_lengths,
+ cache_intervals,
+ element_type,
+ target_device] = obj.param;
+ std::ostringstream result;
+ result << "QKHeads=" << qk_heads;
+ result << "_VHeads=" << v_heads;
+ result << "_QKHeadSize=" << qk_head_size;
+ result << "_VHeadSize=" << v_head_size;
+ result << "_SeqLens=";
+ for (size_t i = 0; i < seq_lengths.size(); i++) {
+ if (i > 0)
+ result << "x";
+ result << seq_lengths[i];
+ }
+ result << "_Intervals=";
+ for (size_t i = 0; i < cache_intervals.size(); i++) {
+ if (i > 0)
+ result << "x";
+ result << cache_intervals[i];
+ }
+ result << "_Type=" << element_type;
+ result << "_Target=" << target_device;
+ return result.str();
+}
+
+void PagedGatedDeltaNetLayerTest::SetUp() {
+ const auto& [qk_heads, v_heads, qk_head_size, v_head_size, seq_lengths, cache_intervals, data_type, device] =
+ GetParam();
+ if (device.find("CPU") != std::string::npos) {
+ // Skip BF16/F16 tests if not support
+ if ((data_type == ov::element::bf16) && !with_cpu_x86_avx512_core_amx_bf16()) {
+ GTEST_SKIP();
+ }
+ if ((data_type == ov::element::f16) && !with_cpu_x86_avx512_core_fp16()) {
+ GTEST_SKIP();
+ }
+ }
+
+ targetDevice = device;
+ this->data_type = data_type;
+ configuration[ov::hint::inference_precision.name()] = data_type;
+ OPENVINO_ASSERT(!seq_lengths.empty());
+ OPENVINO_ASSERT(seq_lengths.size() == cache_intervals.size());
+
+ const int32_t tokens = std::accumulate(seq_lengths.begin(), seq_lengths.end(), 0);
+ const int32_t num_sequences = static_cast<int32_t>(seq_lengths.size());
+
+ int32_t num_blocks = 0;
+ for (size_t i = 0; i < seq_lengths.size(); i++) {
+ OPENVINO_ASSERT(cache_intervals[i] >= 0);
+ const int32_t past_len = 1 + static_cast<int32_t>(i % 3);
+ if (cache_intervals[i] == 0) {
+ // interval == 0: use exactly 2 blocks per sequence
+ // block 0 for read, block 1 for final write.
+ num_blocks += 2;
+ } else {
+ const int32_t prev_nums = past_len % cache_intervals[i];
+ const int32_t write_blocks = (prev_nums + seq_lengths[i] + cache_intervals[i] - 1) / cache_intervals[i];
+ num_blocks += 1 + write_blocks;
+ }
+ }
+
+ const ov::Shape q_shape{static_cast<size_t>(tokens),
+ static_cast<size_t>(qk_heads),
+ static_cast<size_t>(qk_head_size)};
+ const ov::Shape v_shape{static_cast<size_t>(tokens),
+ static_cast<size_t>(v_heads),
+ static_cast<size_t>(v_head_size)};
+ const ov::Shape state_shape{static_cast<size_t>(num_blocks),
+ static_cast<size_t>(v_heads),
+ static_cast<size_t>(v_head_size),
+ static_cast<size_t>(qk_head_size)};
+ const ov::Shape gv_shape{static_cast<size_t>(tokens), static_cast<size_t>(v_heads)};
+
+ init_input_shapes(static_shapes_to_test_representation({q_shape,
+ q_shape,
+ v_shape,
+ state_shape,
+ gv_shape,
+ gv_shape,
+ ov::Shape{static_cast<size_t>(num_sequences + 1)},
+ ov::Shape{static_cast<size_t>(num_blocks)},
+ ov::Shape{static_cast<size_t>(num_sequences + 1)},
+ ov::Shape{static_cast<size_t>(num_sequences)},
+ ov::Shape{static_cast<size_t>(num_sequences)}}));
+
+ auto p_query = std::make_shared<ov::op::v0::Parameter>(data_type, ov::PartialShape{-1, qk_heads, qk_head_size});
+ auto p_key = std::make_shared<ov::op::v0::Parameter>(data_type, ov::PartialShape{-1, qk_heads, qk_head_size});
+ auto p_value = std::make_shared<ov::op::v0::Parameter>(data_type, ov::PartialShape{-1, v_heads, v_head_size});
+ auto p_state =
+ std::make_shared<ov::op::v0::Parameter>(data_type, ov::PartialShape{-1, v_heads, v_head_size, qk_head_size});
+ auto p_gate = std::make_shared<ov::op::v0::Parameter>(data_type, ov::PartialShape{-1, v_heads});
+ auto p_beta = std::make_shared<ov::op::v0::Parameter>(data_type, ov::PartialShape{-1, v_heads});
+ auto p_subseq = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::PartialShape{-1});
+ auto p_blocks = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::PartialShape{-1});
+ auto p_block_begins = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::PartialShape{-1});
+ auto p_past_lens = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::PartialShape{-1});
+ auto p_cache_interval = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::PartialShape{-1});
+ auto pgdn = std::make_shared<ov::op::internal::PagedGatedDeltaNet>(p_query,
+ p_key,
+ p_value,
+ p_state,
+ p_gate,
+ p_beta,
+ p_subseq,
+ p_blocks,
+ p_block_begins,
+ p_past_lens,
+ p_cache_interval,
+ true,
+ 1e-6f,
+ 1e-6f);
+
+ function = std::make_shared<ov::Model>(ov::ResultVector{std::make_shared<ov::op::v0::Result>(pgdn)},
+ ov::ParameterVector{p_query,
+ p_key,
+ p_value,
+ p_state,
+ p_gate,
+ p_beta,
+ p_subseq,
+ p_blocks,
+ p_block_begins,
+ p_past_lens,
+ p_cache_interval});
+}
+
+void PagedGatedDeltaNetLayerTest::generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) {
+ inputs.clear();
+ host_inputs.clear();
+
+ const auto& [qk_heads, v_heads, qk_head_size, v_head_size, seq_lengths, cache_intervals, element_type, device] =
+ GetParam();
+ const auto num_sequences = static_cast<int32_t>(seq_lengths.size());
+
+ std::vector<int32_t> subsequence_begins;
+ std::vector<int32_t> block_indices;
+ std::vector<int32_t> block_indices_begins;
+ std::vector<int32_t> past_lens;
+ std::vector<int32_t> cache_interval;
+
+ subsequence_begins.reserve(static_cast<size_t>(num_sequences + 1));
+ block_indices_begins.reserve(static_cast<size_t>(num_sequences + 1));
+ past_lens.reserve(static_cast<size_t>(num_sequences));
+ cache_interval.reserve(static_cast<size_t>(num_sequences));
+
+ subsequence_begins.push_back(0);
+ block_indices_begins.push_back(0);
+
+ int32_t total_blocks = 0;
+ for (int32_t seq = 0; seq < num_sequences; seq++) {
+ const int32_t seq_len = seq_lengths[seq];
+ const int32_t seq_interval = cache_intervals[seq];
+ const int32_t seq_past_len = 1 + (seq % 3);
+
+ subsequence_begins.push_back(subsequence_begins.back() + seq_len);
+ past_lens.push_back(seq_past_len);
+ cache_interval.push_back(seq_interval);
+
+ int32_t required_slots = 2;
+ if (seq_interval > 0) {
+ const int32_t prev_nums = seq_past_len % seq_interval;
+ const int32_t write_blocks = (prev_nums + seq_len + seq_interval - 1) / seq_interval;
+ required_slots = 1 + write_blocks;
+ }
+ for (int32_t i = 0; i < required_slots; i++) {
+ block_indices.push_back(total_blocks + i);
+ }
+ total_blocks += required_slots;
+ block_indices_begins.push_back(total_blocks);
+ }
+
+ const auto& params = function->get_parameters();
+ const bool use_remote_tensors = targetDevice == "GPU";
+ ov::RemoteContext remote_context;
+ if (use_remote_tensors) {
+ remote_context = compiledModel.get_context();
+ }
+
+ for (size_t i = 0; i < params.size(); i++) {
+ const auto& param = params[i];
+ const auto& shape = targetInputStaticShapes[i];
+ ov::Tensor tensor;
+
+ if (i == 4) {
+ tensor = ov::test::utils::create_and_fill_tensor(param->get_element_type(),
+ shape,
+ ov::test::utils::InputGenerateData(-1, 1, 1000, 1));
+ } else if (i == 5) {
+ tensor = ov::test::utils::create_and_fill_tensor(param->get_element_type(),
+ shape,
+ ov::test::utils::InputGenerateData(0, 1, 1000, 1));
+ } else if (i <= 3) {
+ tensor = ov::test::utils::create_and_fill_tensor(param->get_element_type(),
+ shape,
+ ov::test::utils::InputGenerateData(-1, 1, 1000, 1));
+ } else if (i == 6) {
+ tensor = make_i32_tensor(subsequence_begins);
+ } else if (i == 7) {
+ tensor = make_i32_tensor(block_indices);
+ } else if (i == 8) {
+ tensor = make_i32_tensor(block_indices_begins);
+ } else if (i == 9) {
+ tensor = make_i32_tensor(past_lens);
+ } else if (i == 10) {
+ tensor = make_i32_tensor(cache_interval);
+ }
+
+ host_inputs[param] = tensor;
+
+ if (use_remote_tensors && i <= 5) {
+ auto remote_tensor = remote_context.create_tensor(param->get_element_type(), shape);
+ remote_tensor.copy_from(tensor);
+ inputs[param] = remote_tensor;
+ } else {
+ inputs[param] = tensor;
+ }
+ }
+
+ OPENVINO_ASSERT(qk_heads > 0 && v_heads > 0 && qk_head_size > 0 && v_head_size > 0);
+}
+
+std::vector<ov::Tensor> PagedGatedDeltaNetLayerTest::calculate_refs() {
+ const auto& [qk_heads, v_heads, qk_head_size, v_head_size, seq_lengths, cache_intervals, element_type, device] =
+ GetParam();
+
+ if (element_type == ov::element::f16) {
+ return calculate_typed_refs<ov::float16>(host_inputs,
+ function,
+ qk_heads,
+ v_heads,
+ qk_head_size,
+ v_head_size,
+ element_type);
+ }
+
+ if (element_type == ov::element::bf16) {
+ return calculate_typed_refs<ov::bfloat16>(host_inputs,
+ function,
+ qk_heads,
+ v_heads,
+ qk_head_size,
+ v_head_size,
+ element_type);
+ }
+
+ return calculate_typed_refs<float>(host_inputs,
+ function,
+ qk_heads,
+ v_heads,
+ qk_head_size,
+ v_head_size,
+ element_type);
+}
+
+std::vector<ov::Tensor> PagedGatedDeltaNetLayerTest::get_plugin_outputs() {
+ auto outputs = SubgraphBaseTest::get_plugin_outputs();
+
+ const auto& state_param = function->get_parameters().at(3);
+ const auto actual_state_tensor = inferRequest.get_tensor(state_param);
+ ov::Tensor host_state_tensor(actual_state_tensor.get_element_type(), actual_state_tensor.get_shape());
+ actual_state_tensor.copy_to(host_state_tensor);
+ outputs.push_back(host_state_tensor);
+
+ return outputs;
+}
+
+void PagedGatedDeltaNetLayerTest::compare(const std::vector<ov::Tensor>& expected,
+ const std::vector<ov::Tensor>& actual) {
+ ASSERT_EQ(expected.size(), actual.size());
+ if (data_type == ov::element::bf16) {
+ abs_threshold = 1e-3f;
+ rel_threshold = 1e-2f;
+ } else if (data_type == ov::element::f16) {
+ abs_threshold = 3e-4f;
+ rel_threshold = 1e-5f;
+ } else {
+ abs_threshold = 2e-4f;
+ rel_threshold = 1e-5f;
+ }
+ ov::test::utils::compare(expected[0], actual[0], abs_threshold, rel_threshold);
+ ov::test::utils::compare(expected[1], actual[1], abs_threshold, rel_threshold);
+}
+
+} // namespace ov::test
\ No newline at end of file