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
[Op][Core] SparseAttention, SparseAttentionIndexer, QSAPrepare (#39035)
Katarzyna Mitrus8214ba7ea594
diff --git a/src/bindings/python/src/openvino/opset17/__init__.py b/src/bindings/python/src/openvino/opset17/__init__.pyindex 367d747ceb4..231adf698c0 100644--- a/src/bindings/python/src/openvino/opset17/__init__.py+++ b/src/bindings/python/src/openvino/opset17/__init__.py@@ -6,7 +6,10 @@from openvino.opset17.ops import bgr_to_nv12from openvino.opset17.ops import erfinvfrom openvino.opset17.ops import grouped_matmul+from openvino.opset17.ops import qsa_preparefrom openvino.opset17.ops import rgb_to_nv12+from openvino.opset17.ops import sparse_attention+from openvino.opset17.ops import sparse_attention_indexer# Operators from previous opsets# TODO (ticket: 179247): Add previous opset operators at the end of opset17 developmentdiff --git a/src/bindings/python/src/openvino/opset17/ops.py b/src/bindings/python/src/openvino/opset17/ops.pyindex 5de149061b9..c1e780aee8d 100644--- a/src/bindings/python/src/openvino/opset17/ops.py+++ b/src/bindings/python/src/openvino/opset17/ops.py@@ -105,3 +105,156 @@ def bgr_to_nv12(as_nodes(arg, name=name),{"single_plane": single_plane},)+++@nameable_op+def qsa_prepare(+ raw_index_keys: NodeInput,+ past_block_index_keys: NodeInput,+ key_length: NodeInput,+ rope_cos: NodeInput,+ rope_sin: NodeInput,+ k_norm_weight: NodeInput,+ past_incomplete_raw_keys: NodeInput,+ past_incomplete_rope: NodeInput,+ key_block_size: int,+ epsilon: float = 1e-6,+ name: Optional[str] = None,+) -> Node:+ """Return a node which builds one index key per complete key block for sparse attention.++ A block key is the mean of the raw index keys of the ``key_block_size`` consecutive key tokens+ of the block, RMS-normalized with ``k_norm_weight`` and rotated with the RoPE of the first token+ of the block. Only the blocks completed by the new tokens are computed. All inputs are+ positional; a feature is disabled by connecting an empty constant.++ :param raw_index_keys: Raw index key of every new token, shape [N, L, Di].+ :param past_block_index_keys: Block index keys computed by the previous calls, shape [N, Bp, Di].+ :param key_length: Number of valid key tokens of every sequence, shape [N] or [1].+ :param rope_cos: RoPE cos of every new token, shape [N, L, Dr]; empty constant disables the rotation.+ :param rope_sin: RoPE sin of every new token, shape [N, L, Dr]; empty constant disables the rotation.+ :param k_norm_weight: Scale of the block key normalization, shape [Di]; empty constant disables it.+ :param past_incomplete_raw_keys: Raw keys of the past tokens of the incomplete block,+ shape [N, key_block_size - 1, Di].+ :param past_incomplete_rope: RoPE cos and sin of the first token of the incomplete block,+ shape [N, 2 * Dr]; empty constant if and only if rope_cos and rope_sin are.+ :param key_block_size: Number of consecutive key tokens forming one key block, greater than 1.+ :param epsilon: Value added to the mean square in the RMS normalization.+ :param name: The optional name for the new output node.++ :return: The new node performing QSAPrepare operation.+ """+ inputs = [+ raw_index_keys,+ past_block_index_keys,+ key_length,+ rope_cos,+ rope_sin,+ k_norm_weight,+ past_incomplete_raw_keys,+ past_incomplete_rope,+ ]+ return _get_node_factory_opset17().create(+ "QSAPrepare",+ as_nodes(*inputs, name=name),+ {"key_block_size": key_block_size, "epsilon": epsilon},+ )+++@nameable_op+def sparse_attention_indexer(+ index_query: NodeInput,+ block_index_keys: NodeInput,+ key_length: NodeInput,+ index_weights: Optional[NodeInput] = None,+ *,+ key_block_size: int,+ token_budget: int,+ num_selection_heads: int = 1,+ name: Optional[str] = None,+) -> Node:+ """Return a node which selects the key blocks every query token attends to.++ For every query token the operation scores the complete key blocks visible to it and returns the+ indices of the ``token_budget / key_block_size`` best-scoring blocks together with their number.++ :param index_query: Index query heads of shape [N, Hi, L, Di].+ :param block_index_keys: One index key per complete key block, shape [N, B, Di].+ :param key_length: Number of valid key tokens of every sequence, shape [N] or [1].+ :param index_weights: Weight of every index query head for every query token, shape [N, L, Hi].+ :param key_block_size: Number of consecutive key tokens forming one key block.+ :param token_budget: Maximum number of tokens selected from complete blocks for one query.+ :param num_selection_heads: Number of selections per query token.+ :param name: The optional name for the new output node.++ :return: The new node performing SparseAttentionIndexer operation.+ """+ inputs = [index_query, block_index_keys, key_length]+ if index_weights is not None:+ inputs.append(index_weights)+ return _get_node_factory_opset17().create(+ "SparseAttentionIndexer",+ as_nodes(*inputs, name=name),+ {+ "key_block_size": key_block_size,+ "token_budget": token_budget,+ "num_selection_heads": num_selection_heads,+ },+ )+++@nameable_op+def sparse_attention(+ query: NodeInput,+ key: NodeInput,+ value: NodeInput,+ block_indices: NodeInput,+ block_count: NodeInput,+ key_length: Optional[NodeInput] = None,+ scale: Optional[NodeInput] = None,+ sinks: Optional[NodeInput] = None,+ *,+ key_block_size: int,+ query_block_size: int = 1,+ causal: bool = True,+ name: Optional[str] = None,+) -> Node:+ """Return a node which computes attention over the key blocks selected for each query.++ Every query token attends only to the tokens of its selected key blocks and, in the causal mode,+ to the tokens of the incomplete block that contains it.++ :param query: Attention query of shape [N, H, L, E].+ :param key: Attention key of shape [N, Hkv, S, E].+ :param value: Attention value of shape [N, Hkv, S, Ev].+ :param block_indices: Selected key blocks of shape [N, Hs, Lq, KB].+ :param block_count: Number of valid entries of every row of block_indices, shape [N, Hs, Lq].+ :param key_length: Number of valid key tokens of every sequence, shape [N] or [1].+ :param scale: Attention scale factor used instead of the default 1 / sqrt(E).+ :param sinks: Attention sink logit of every query head, shape [H]. Requires ``scale``.+ :param key_block_size: Number of consecutive key tokens forming one key block.+ :param query_block_size: Number of consecutive query tokens sharing one selection.+ :param causal: Whether the query tokens are the last key tokens and attend to their+ incomplete block.+ :param name: The optional name for the new output node.++ :return: The new node performing SparseAttention operation.+ """+ inputs = [query, key, value, block_indices, block_count]+ optional_inputs = [key_length, scale, sinks]+ for position, optional_input in enumerate(optional_inputs):+ if optional_input is None:+ if any(following is not None for following in optional_inputs[position + 1:]):+ raise ValueError("SparseAttention inputs are positional: key_length, scale and sinks "+ "can only be omitted from the end.")+ break+ inputs.append(optional_input)+ return _get_node_factory_opset17().create(+ "SparseAttention",+ as_nodes(*inputs, name=name),+ {+ "key_block_size": key_block_size,+ "query_block_size": query_block_size,+ "causal": causal,+ },+ )diff --git a/src/bindings/python/tests/test_graph/test_sparse_attention.py b/src/bindings/python/tests/test_graph/test_sparse_attention.pynew file mode 100644index 00000000000..a384c552f99--- /dev/null+++ b/src/bindings/python/tests/test_graph/test_sparse_attention.py@@ -0,0 +1,133 @@+# -*- coding: utf-8 -*-+# Copyright (C) 2018-2026 Intel Corporation+# SPDX-License-Identifier: Apache-2.0++from openvino import Type, PartialShape+from openvino.opset15 import constant, parameter+import numpy as np+import openvino.opset17 as ov+import pytest+++def test_sparse_attention():+ query = parameter([2, 24, 5, 64], name="query", dtype=Type.f32)+ key = parameter([2, 2, 12, 64], name="key", dtype=Type.f32)+ value = parameter([2, 2, 12, 32], name="value", dtype=Type.f32)+ block_indices = parameter([2, 1, 5, 4], name="block_indices", dtype=Type.i32)+ block_count = parameter([2, 1, 5], name="block_count", dtype=Type.i32)+ node = ov.sparse_attention(query, key, value, block_indices, block_count, key_block_size=4)++ assert node.get_type_name() == "SparseAttention"+ assert node.get_output_size() == 1+ assert node.get_output_element_type(0) == Type.f32+ assert node.get_output_partial_shape(0) == PartialShape([2, 24, 5, 32])++[email protected]("dtype_indices", [Type.i32, Type.i64])+def test_sparse_attention_with_key_length_scale_and_sinks(dtype_indices):+ query = parameter([2, 24, 1, 64], name="query", dtype=Type.f32)+ key = parameter([2, 2, 12, 64], name="key", dtype=Type.f32)+ value = parameter([2, 2, 12, 32], name="value", dtype=Type.f32)+ block_indices = parameter([2, 1, 1, 4], name="block_indices", dtype=dtype_indices)+ block_count = parameter([2, 1, 1], name="block_count", dtype=dtype_indices)+ key_length = parameter([2], name="key_length", dtype=dtype_indices)+ scale = parameter([], name="scale", dtype=Type.f32)+ sinks = parameter([24], name="sinks", dtype=Type.f32)+ node = ov.sparse_attention(query, key, value, block_indices, block_count,+ key_length, scale, sinks, key_block_size=4)++ assert node.get_type_name() == "SparseAttention"+ assert len(node.inputs()) == 8+ assert node.get_output_partial_shape(0) == PartialShape([2, 24, 1, 32])+++def test_sparse_attention_non_causal():+ query = parameter([1, 12, 256, 128], name="query", dtype=Type.f32)+ key = parameter([1, 12, 512, 128], name="key", dtype=Type.f32)+ value = parameter([1, 12, 512, 128], name="value", dtype=Type.f32)+ block_indices = parameter([1, 12, 2, 4], name="block_indices", dtype=Type.i32)+ block_count = parameter([1, 12, 2], name="block_count", dtype=Type.i32)+ node = ov.sparse_attention(query, key, value, block_indices, block_count,+ key_block_size=128, query_block_size=128, causal=False)++ assert node.get_type_name() == "SparseAttention"+ assert node.get_output_partial_shape(0) == PartialShape([1, 12, 256, 128])+++def test_sparse_attention_skipped_optional_input():+ query = parameter([2, 24, 5, 64], name="query", dtype=Type.f32)+ key = parameter([2, 2, 12, 64], name="key", dtype=Type.f32)+ value = parameter([2, 2, 12, 32], name="value", dtype=Type.f32)+ block_indices = parameter([2, 1, 5, 4], name="block_indices", dtype=Type.i32)+ block_count = parameter([2, 1, 5], name="block_count", dtype=Type.i32)+ sinks = parameter([24], name="sinks", dtype=Type.f32)++ with pytest.raises(ValueError, match="positional"):+ ov.sparse_attention(query, key, value, block_indices, block_count,+ sinks=sinks, key_block_size=4)+++def test_sparse_attention_indexer():+ index_query = parameter([2, 4, 7, 128], name="index_query", dtype=Type.f32)+ block_index_keys = parameter([2, 2500, 128], name="block_index_keys", dtype=Type.f32)+ key_length = parameter([2], name="key_length", dtype=Type.i32)+ node = ov.sparse_attention_indexer(index_query, block_index_keys, key_length,+ key_block_size=4, token_budget=2048)++ assert node.get_type_name() == "SparseAttentionIndexer"+ assert node.get_output_size() == 2+ assert node.get_output_element_type(0) == Type.i32+ assert node.get_output_element_type(1) == Type.i32+ assert node.get_output_partial_shape(0) == PartialShape([2, 1, 7, 512])+ assert node.get_output_partial_shape(1) == PartialShape([2, 1, 7])+++def test_sparse_attention_indexer_with_weights_and_selection_heads():+ index_query = parameter([1, 8, 7, 128], name="index_query", dtype=Type.f32)+ block_index_keys = parameter([1, 100, 128], name="block_index_keys", dtype=Type.f32)+ key_length = parameter([1], name="key_length", dtype=Type.i64)+ index_weights = parameter([1, 7, 8], name="index_weights", dtype=Type.f32)+ node = ov.sparse_attention_indexer(index_query, block_index_keys, key_length, index_weights,+ key_block_size=4, token_budget=64, num_selection_heads=2)++ assert node.get_type_name() == "SparseAttentionIndexer"+ assert len(node.inputs()) == 4+ assert node.get_output_partial_shape(0) == PartialShape([1, 2, 7, 16])+ assert node.get_output_partial_shape(1) == PartialShape([1, 2, 7])+++def test_qsa_prepare():+ raw_index_keys = parameter([2, 8, 128], name="raw_index_keys", dtype=Type.f32)+ past_block_index_keys = parameter([2, -1, 128], name="past_block_index_keys", dtype=Type.f32)+ key_length = parameter([2], name="key_length", dtype=Type.i32)+ rope_cos = parameter([2, 8, 64], name="rope_cos", dtype=Type.f32)+ rope_sin = parameter([2, 8, 64], name="rope_sin", dtype=Type.f32)+ k_norm_weight = parameter([128], name="k_norm_weight", dtype=Type.f32)+ past_incomplete_raw_keys = parameter([2, 3, 128], name="past_incomplete_raw_keys", dtype=Type.f32)+ past_incomplete_rope = parameter([2, 128], name="past_incomplete_rope", dtype=Type.f32)+ node = ov.qsa_prepare(raw_index_keys, past_block_index_keys, key_length, rope_cos, rope_sin,+ k_norm_weight, past_incomplete_raw_keys, past_incomplete_rope,+ key_block_size=4)++ assert node.get_type_name() == "QSAPrepare"+ assert node.get_output_size() == 3+ assert node.get_output_element_type(0) == Type.f32+ # The number of complete blocks follows from the key_length values, unknown here.+ assert node.get_output_partial_shape(0) == PartialShape([2, -1, 128])+ assert node.get_output_partial_shape(1) == PartialShape([2, 3, 128])+ assert node.get_output_partial_shape(2) == PartialShape([2, 128])+++def test_qsa_prepare_without_rotation():+ raw_index_keys = parameter([1, 8, 128], name="raw_index_keys", dtype=Type.f32)+ past_block_index_keys = parameter([1, 0, 128], name="past_block_index_keys", dtype=Type.f32)+ key_length = parameter([1], name="key_length", dtype=Type.i64)+ empty = constant(np.empty(0, dtype=np.float32))+ k_norm_weight = parameter([128], name="k_norm_weight", dtype=Type.f32)+ past_incomplete_raw_keys = parameter([1, 3, 128], name="past_incomplete_raw_keys", dtype=Type.f32)+ node = ov.qsa_prepare(raw_index_keys, past_block_index_keys, key_length, empty, empty,+ k_norm_weight, past_incomplete_raw_keys, empty,+ key_block_size=4, epsilon=1e-5)++ assert node.get_type_name() == "QSAPrepare"+ assert node.get_output_partial_shape(2) == PartialShape([1, 0])diff --git a/src/core/dev_api/openvino/op/ops_decl.hpp b/src/core/dev_api/openvino/op/ops_decl.hppindex aea086c0c7d..0bccc6c89b4 100644--- a/src/core/dev_api/openvino/op/ops_decl.hpp+++ b/src/core/dev_api/openvino/op/ops_decl.hpp@@ -294,4 +294,7 @@ class SparseFillEmptyRows;namespace ov::op::v17 {class ErfInv;class GroupedMatMul;+class QSAPrepare;+class SparseAttention;+class SparseAttentionIndexer;} // namespace ov::op::v17diff --git a/src/core/include/openvino/op/ops.hpp b/src/core/include/openvino/op/ops.hppindex c3b74102bb4..f7c38d50700 100644--- a/src/core/include/openvino/op/ops.hpp+++ b/src/core/include/openvino/op/ops.hpp@@ -143,6 +143,7 @@#include "openvino/op/prior_box_clustered.hpp"#include "openvino/op/proposal.hpp"#include "openvino/op/psroi_pooling.hpp"+#include "openvino/op/qsa_prepare.hpp"#include "openvino/op/random_uniform.hpp"#include "openvino/op/range.hpp"#include "openvino/op/rdft.hpp"@@ -192,6 +193,8 @@#include "openvino/op/softsign.hpp"#include "openvino/op/space_to_batch.hpp"#include "openvino/op/space_to_depth.hpp"+#include "openvino/op/sparse_attention.hpp"+#include "openvino/op/sparse_attention_indexer.hpp"#include "openvino/op/sparse_fill_empty_rows.hpp"#include "openvino/op/split.hpp"#include "openvino/op/sqrt.hpp"diff --git a/src/core/include/openvino/op/qsa_prepare.hpp b/src/core/include/openvino/op/qsa_prepare.hppnew file mode 100644index 00000000000..1737268ab1d--- /dev/null+++ b/src/core/include/openvino/op/qsa_prepare.hpp@@ -0,0 +1,81 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "openvino/op/op.hpp"++namespace ov::op::v17 {+/// \brief Builds one index key per complete key block for sparse attention selection.+///+/// A block key is the mean of the raw index keys of the `key_block_size` consecutive key tokens of+/// the block, RMS-normalized with `k_norm_weight` and rotated with the RoPE of the first token of+/// the block. Only the blocks completed by the new tokens are computed: the keys of the earlier+/// blocks are passed in through `past_block_index_keys`, and the raw keys and the RoPE row of the+/// tokens of the still incomplete block through `past_incomplete_raw_keys` / `past_incomplete_rope`,+/// which the operation returns updated for the next call. The result feeds SparseAttentionIndexer.+///+/// Inputs are positional and cannot be skipped; a feature is disabled by connecting an empty constant.+///+/// \ingroup ov_ops_cpp_api+class OPENVINO_API QSAPrepare : public Op {+public:+ OPENVINO_OP("QSAPrepare", "opset17", Op);++ QSAPrepare() = default;++ /// \brief Constructs a QSAPrepare operation from an ordered list of inputs.+ ///+ /// \param inputs raw_index_keys, past_block_index_keys, key_length, rope_cos, rope_sin,+ /// k_norm_weight, past_incomplete_raw_keys and past_incomplete_rope+ /// \param key_block_size Number of consecutive key tokens forming one key block+ /// \param epsilon Value added to the mean square in the RMS normalization+ QSAPrepare(const OutputVector& inputs, int64_t key_block_size, float epsilon = 1e-6f);++ /// \brief Constructs a QSAPrepare operation.+ ///+ /// \param raw_index_keys Raw index key of every new token, shape [N, L, Di]+ /// \param past_block_index_keys Block index keys computed by the previous calls, shape [N, Bp, Di]+ /// \param key_length Number of valid key tokens of every sequence, shape [N] or [1]+ /// \param rope_cos RoPE cos of every new token, shape [N, L, Dr], empty constant to disable the rotation+ /// \param rope_sin RoPE sin of every new token, shape [N, L, Dr], empty constant to disable the rotation+ /// \param k_norm_weight Scale of the block key normalization, shape [Di], empty constant to disable it+ /// \param past_incomplete_raw_keys Raw keys of the past tokens of the incomplete block,+ /// shape [N, key_block_size - 1, Di]+ /// \param past_incomplete_rope RoPE cos and sin of the first token of the incomplete block,+ /// shape [N, 2 * Dr], empty constant if and only if rope_cos and rope_sin are+ QSAPrepare(const Output<Node>& raw_index_keys,+ const Output<Node>& past_block_index_keys,+ const Output<Node>& key_length,+ const Output<Node>& rope_cos,+ const Output<Node>& rope_sin,+ const Output<Node>& k_norm_weight,+ const Output<Node>& past_incomplete_raw_keys,+ const Output<Node>& past_incomplete_rope,+ int64_t key_block_size,+ float epsilon = 1e-6f);++ void validate_and_infer_types() override;+ bool visit_attributes(AttributeVisitor& visitor) override;+ std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& new_args) const override;++ int64_t get_key_block_size() const {+ return m_key_block_size;+ }+ void set_key_block_size(int64_t key_block_size) {+ m_key_block_size = key_block_size;+ }++ float get_epsilon() const {+ return m_epsilon;+ }+ void set_epsilon(float epsilon) {+ m_epsilon = epsilon;+ }++private:+ int64_t m_key_block_size = 0;+ float m_epsilon = 1e-6f;+};+} // namespace ov::op::v17diff --git a/src/core/include/openvino/op/sparse_attention.hpp b/src/core/include/openvino/op/sparse_attention.hppnew file mode 100644index 00000000000..f6bc977dfef--- /dev/null+++ b/src/core/include/openvino/op/sparse_attention.hpp@@ -0,0 +1,126 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "openvino/op/op.hpp"++namespace ov::op::v17 {+/// \brief SparseAttention - Scaled dot-product attention computed only over the key blocks selected for each query.+///+/// Computes grouped-query scaled dot-product attention in which every query token attends only to+/// the tokens of its selected key blocks, instead of to the whole key sequence. Key blocks are+/// groups of `key_block_size` consecutive key tokens; the ones a query attends to are listed in+/// `block_indices` and, in the causal mode, the incomplete block containing the query is added.+/// Query tokens share a selection in groups of `query_block_size` tokens. The selected blocks+/// differ per query token and are normally produced by SparseAttentionIndexer.+/// The optional `sinks` hold one learnable logit per query head.+///+/// \ingroup ov_ops_cpp_api+class OPENVINO_API SparseAttention : public Op {+public:+ OPENVINO_OP("SparseAttention", "opset17", Op);++ SparseAttention() = default;++ /// \brief Constructs a SparseAttention operation from an ordered list of inputs.+ ///+ /// \param inputs query, key, value, block_indices, block_count and optionally key_length and scale+ /// \param key_block_size Number of consecutive key tokens forming one key block+ /// \param query_block_size Number of consecutive query tokens sharing one selection+ /// \param causal Whether the query tokens are the last key tokens and attend to their incomplete block+ SparseAttention(const OutputVector& inputs,+ int64_t key_block_size,+ int64_t query_block_size = 1,+ bool causal = true);++ /// \brief Constructs a SparseAttention operation without padding and with the default scale.+ ///+ /// \param query Attention query of shape [N, H, L, E]+ /// \param key Attention key of shape [N, Hkv, S, E]+ /// \param value Attention value of shape [N, Hkv, S, Ev]+ /// \param block_indices Selected key blocks of shape [N, Hs, Lq, KB]+ /// \param block_count Number of valid entries of every row of block_indices, shape [N, Hs, Lq]+ SparseAttention(const Output<Node>& query,+ const Output<Node>& key,+ const Output<Node>& value,+ const Output<Node>& block_indices,+ const Output<Node>& block_count,+ int64_t key_block_size,+ int64_t query_block_size = 1,+ bool causal = true);++ /// \brief Constructs a SparseAttention operation for a batch with padding.+ ///+ /// \param key_length Number of valid key tokens of every sequence, shape [N] or [1]+ SparseAttention(const Output<Node>& query,+ const Output<Node>& key,+ const Output<Node>& value,+ const Output<Node>& block_indices,+ const Output<Node>& block_count,+ const Output<Node>& key_length,+ int64_t key_block_size,+ int64_t query_block_size = 1,+ bool causal = true);++ /// \brief Constructs a SparseAttention operation with an explicit attention scale.+ ///+ /// \param scale Attention scale factor used instead of the default 1 / sqrt(E)+ SparseAttention(const Output<Node>& query,+ const Output<Node>& key,+ const Output<Node>& value,+ const Output<Node>& block_indices,+ const Output<Node>& block_count,+ const Output<Node>& key_length,+ const Output<Node>& scale,+ int64_t key_block_size,+ int64_t query_block_size = 1,+ bool causal = true);++ /// \brief Constructs a SparseAttention operation with attention sinks.+ ///+ /// \param sinks Attention sink logit of every query head, shape [H]+ SparseAttention(const Output<Node>& query,+ const Output<Node>& key,+ const Output<Node>& value,+ const Output<Node>& block_indices,+ const Output<Node>& block_count,+ const Output<Node>& key_length,+ const Output<Node>& scale,+ const Output<Node>& sinks,+ int64_t key_block_size,+ int64_t query_block_size = 1,+ bool causal = true);++ void validate_and_infer_types() override;+ bool visit_attributes(AttributeVisitor& visitor) override;+ std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& new_args) const override;++ int64_t get_key_block_size() const {+ return m_key_block_size;+ }+ void set_key_block_size(int64_t key_block_size) {+ m_key_block_size = key_block_size;+ }++ int64_t get_query_block_size() const {+ return m_query_block_size;+ }+ void set_query_block_size(int64_t query_block_size) {+ m_query_block_size = query_block_size;+ }++ bool get_causal() const {+ return m_causal;+ }+ void set_causal(bool causal) {+ m_causal = causal;+ }++private:+ int64_t m_key_block_size = 0;+ int64_t m_query_block_size = 1;+ bool m_causal = true;+};+} // namespace ov::op::v17diff --git a/src/core/include/openvino/op/sparse_attention_indexer.hpp b/src/core/include/openvino/op/sparse_attention_indexer.hppnew file mode 100644index 00000000000..83fc21d99e7--- /dev/null+++ b/src/core/include/openvino/op/sparse_attention_indexer.hpp@@ -0,0 +1,89 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "openvino/op/op.hpp"++namespace ov::op::v17 {+/// \brief Sparse attention indexer - picks the key blocks that SparseAttention attends to.+///+/// For every query token the operation scores the complete key blocks visible to it with the+/// multi-head, ReLU-rectified dot product of the index query heads and the block index key, and+/// returns the indices of the `token_budget / key_block_size` best-scoring blocks together with+/// their number. These indices are the sparsity pattern consumed by SparseAttention, recomputed+/// per query token instead of being fixed.+///+/// \ingroup ov_ops_cpp_api+class OPENVINO_API SparseAttentionIndexer : public Op {+public:+ OPENVINO_OP("SparseAttentionIndexer", "opset17", Op);++ SparseAttentionIndexer() = default;++ /// \brief Constructs a SparseAttentionIndexer operation from an ordered list of inputs.+ ///+ /// \param inputs index_query, block_index_keys, key_length and optionally index_weights+ /// \param key_block_size Number of consecutive key tokens forming one key block+ /// \param token_budget Maximum number of tokens selected from complete blocks for one query+ /// \param num_selection_heads Number of selections per query token+ SparseAttentionIndexer(const OutputVector& inputs,+ int64_t key_block_size,+ int64_t token_budget,+ int64_t num_selection_heads = 1);++ /// \brief Constructs a SparseAttentionIndexer operation with unit index weights.+ ///+ /// \param index_query Index query heads of shape [N, Hi, L, Di]+ /// \param block_index_keys One index key per complete key block, shape [N, B, Di]+ /// \param key_length Number of valid key tokens of every sequence, shape [N] or [1]+ SparseAttentionIndexer(const Output<Node>& index_query,+ const Output<Node>& block_index_keys,+ const Output<Node>& key_length,+ int64_t key_block_size,+ int64_t token_budget,+ int64_t num_selection_heads = 1);++ /// \brief Constructs a SparseAttentionIndexer operation with per-head index weights.+ ///+ /// \param index_weights Weight of every index query head for every query token, shape [N, L, Hi]+ SparseAttentionIndexer(const Output<Node>& index_query,+ const Output<Node>& block_index_keys,+ const Output<Node>& key_length,+ const Output<Node>& index_weights,+ int64_t key_block_size,+ int64_t token_budget,+ int64_t num_selection_heads = 1);++ void validate_and_infer_types() override;+ bool visit_attributes(AttributeVisitor& visitor) override;+ std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& new_args) const override;++ int64_t get_key_block_size() const {+ return m_key_block_size;+ }+ void set_key_block_size(int64_t key_block_size) {+ m_key_block_size = key_block_size;+ }++ int64_t get_token_budget() const {+ return m_token_budget;+ }+ void set_token_budget(int64_t token_budget) {+ m_token_budget = token_budget;+ }++ int64_t get_num_selection_heads() const {+ return m_num_selection_heads;+ }+ void set_num_selection_heads(int64_t num_selection_heads) {+ m_num_selection_heads = num_selection_heads;+ }++private:+ int64_t m_key_block_size = 0;+ int64_t m_token_budget = 0;+ int64_t m_num_selection_heads = 1;+};+} // namespace ov::op::v17diff --git a/src/core/include/openvino/opsets/opset17_tbl.hpp b/src/core/include/openvino/opsets/opset17_tbl.hppindex 06648b9153c..a8de565b3df 100644--- a/src/core/include/openvino/opsets/opset17_tbl.hpp+++ b/src/core/include/openvino/opsets/opset17_tbl.hpp@@ -18,3 +18,6 @@ _OPENVINO_OP_REG(ErfInv, ov::op::v17)_OPENVINO_OP_REG(GroupedMatMul, ov::op::v17)_OPENVINO_OP_REG(RGBtoNV12, ov::op::v17)_OPENVINO_OP_REG(BGRtoNV12, ov::op::v17)+_OPENVINO_OP_REG(QSAPrepare, ov::op::v17)+_OPENVINO_OP_REG(SparseAttention, ov::op::v17)+_OPENVINO_OP_REG(SparseAttentionIndexer, ov::op::v17)diff --git a/src/core/shape_inference/CMakeLists.txt b/src/core/shape_inference/CMakeLists.txtindex 98dc3ceae87..d3f05ff4130 100644--- a/src/core/shape_inference/CMakeLists.txt+++ b/src/core/shape_inference/CMakeLists.txt@@ -107,6 +107,7 @@ target_sources(${TARGET_NAME}${SHAPE_INFER_INCLUDE_DIR}/prior_box_shape_inference_util.hpp${SHAPE_INFER_INCLUDE_DIR}/proposal_shape_inference.hpp${SHAPE_INFER_INCLUDE_DIR}/psroi_pooling_shape_inference.hpp+ ${SHAPE_INFER_INCLUDE_DIR}/qsa_prepare_shape_inference.hpp${SHAPE_INFER_INCLUDE_DIR}/random_uniform_shape_inference.hpp${SHAPE_INFER_INCLUDE_DIR}/range_shape_inference.hpp${SHAPE_INFER_INCLUDE_DIR}/rdft_shape_inference.hpp@@ -142,6 +143,8 @@ target_sources(${TARGET_NAME}${SHAPE_INFER_INCLUDE_DIR}/slice_shape_inference_utils.hpp${SHAPE_INFER_INCLUDE_DIR}/space_to_batch_shape_inference.hpp${SHAPE_INFER_INCLUDE_DIR}/space_to_depth_shape_inference.hpp+ ${SHAPE_INFER_INCLUDE_DIR}/sparse_attention_indexer_shape_inference.hpp+ ${SHAPE_INFER_INCLUDE_DIR}/sparse_attention_shape_inference.hpp${SHAPE_INFER_INCLUDE_DIR}/sparse_fill_empty_rows_shape_inference.hpp${SHAPE_INFER_INCLUDE_DIR}/split_shape_inference.hpp${SHAPE_INFER_INCLUDE_DIR}/squeeze_shape_inference.hppdiff --git a/src/core/shape_inference/include/qsa_prepare_shape_inference.hpp b/src/core/shape_inference/include/qsa_prepare_shape_inference.hppnew file mode 100644index 00000000000..846e060eefc--- /dev/null+++ b/src/core/shape_inference/include/qsa_prepare_shape_inference.hpp@@ -0,0 +1,235 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "dimension_util.hpp"+#include "openvino/core/validation_util.hpp"+#include "openvino/op/qsa_prepare.hpp"+#include "utils.hpp"++namespace ov::op::v17 {+/// \brief Checks whether the optional input of QSAPrepare at the given port is disabled.+///+/// An optional input is disabled by an empty Constant.+inline bool qsa_prepare_input_disabled(const Node* op, size_t port) {+ return port < op->get_input_size() && ov::util::is_empty_constant_tensor(op->input_value(port));+}++template <class TShape, class TRShape = result_shape_t<TShape>>+std::vector<TRShape> shape_infer(const QSAPrepare* op,+ const std::vector<TShape>& input_shapes,+ const ITensorAccessor& ta = make_tensor_accessor()) {+ using TDim = typename TShape::value_type;++ NODE_VALIDATION_CHECK(op, input_shapes.size() == 8);++ const auto key_block_size = op->get_key_block_size();+ NODE_VALIDATION_CHECK(op,+ key_block_size > 1,+ "The attribute key_block_size must be an integer greater than 1. Got: ",+ key_block_size);++ const auto& raw_index_keys_shape = input_shapes[0];+ const auto& past_block_index_keys_shape = input_shapes[1];+ const auto& key_length_shape = input_shapes[2];+ const auto& rope_cos_shape = input_shapes[3];+ const auto& rope_sin_shape = input_shapes[4];+ const auto& k_norm_weight_shape = input_shapes[5];+ const auto& past_incomplete_raw_keys_shape = input_shapes[6];+ const auto& past_incomplete_rope_shape = input_shapes[7];++ const auto k_norm_weight_disabled = qsa_prepare_input_disabled(op, 5);+ const auto rope_disabled = qsa_prepare_input_disabled(op, 3);+ const auto is_raw_keys_rank_static = raw_index_keys_shape.rank().is_static();++ NODE_SHAPE_INFER_CHECK(+ op,+ input_shapes,+ qsa_prepare_input_disabled(op, 4) == rope_disabled && qsa_prepare_input_disabled(op, 7) == rope_disabled,+ "The inputs rope_cos, rope_sin and past_incomplete_rope must be empty constants "+ "together to disable the rotation.");++ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ raw_index_keys_shape.rank().compatible(3),+ "The shape of raw_index_keys must be 3D [N, L, Di].");+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ past_block_index_keys_shape.rank().compatible(3),+ "The shape of past_block_index_keys must be 3D [N, Bp, Di].");+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ key_length_shape.rank().compatible(1),+ "The shape of key_length must be 1D [N] or [1].");+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ k_norm_weight_disabled || k_norm_weight_shape.rank().compatible(1),+ "The shape of k_norm_weight must be 1D [Di], or an empty constant to disable "+ "the normalization.");+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ past_incomplete_raw_keys_shape.rank().compatible(3),+ "The shape of past_incomplete_raw_keys must be 3D [N, key_block_size - 1, Di].");+ if (!rope_disabled) {+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ rope_cos_shape.rank().compatible(3) && rope_sin_shape.rank().compatible(3),+ "The shape of rope_cos and rope_sin must be 3D [N, L, Dr].");+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ past_incomplete_rope_shape.rank().compatible(2),+ "The shape of past_incomplete_rope must be 2D [N, 2 * Dr].");+ }++ TDim batch{};+ TDim head_size{};+ if (is_raw_keys_rank_static) {+ batch = raw_index_keys_shape[0];+ head_size = raw_index_keys_shape[2];+ }++ if (past_block_index_keys_shape.rank().is_static()) {+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ TDim::merge(batch, batch, past_block_index_keys_shape[0]),+ "The batch dimension of raw_index_keys and past_block_index_keys must be the same.");+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ TDim::merge(head_size, head_size, past_block_index_keys_shape[2]),+ "The head size of raw_index_keys and past_block_index_keys must be the same.");+ }++ if (past_incomplete_raw_keys_shape.rank().is_static()) {+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ TDim::merge(batch, batch, past_incomplete_raw_keys_shape[0]),+ "The batch dimension of raw_index_keys and past_incomplete_raw_keys must be the same.");+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ TDim::merge(head_size, head_size, past_incomplete_raw_keys_shape[2]),+ "The head size of raw_index_keys and past_incomplete_raw_keys must be the same.");+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ past_incomplete_raw_keys_shape[1].compatible(key_block_size - 1),+ "The second dimension of past_incomplete_raw_keys must be key_block_size - 1, "+ "expected: ",+ key_block_size - 1,+ ", got: ",+ past_incomplete_raw_keys_shape[1]);+ }++ if (!k_norm_weight_disabled && k_norm_weight_shape.rank().is_static()) {+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ TDim::merge(head_size, head_size, k_norm_weight_shape[0]),+ "The size of k_norm_weight must be equal to the head size of raw_index_keys.");+ }++ // Rotated dimensions, doubled by the cos / sin packing of the incomplete block RoPE row.+ auto rotated_size = rope_disabled ? TDim(0) : TDim(ov::util::dim::inf_bound);+ if (!rope_disabled && rope_cos_shape.rank().is_static() && rope_sin_shape.rank().is_static()) {+ TDim merged;+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ TDim::merge(merged, rope_cos_shape[2], rope_sin_shape[2]),+ "The number of rotated dimensions of rope_cos and rope_sin must be the same.");+ if (merged.is_static()) {+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ merged.get_length() > 0 && merged.get_length() % 2 == 0,+ "The number of rotated dimensions must be a positive even integer. Got: ",+ merged);+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ head_size.is_dynamic() || merged.get_length() <= head_size.get_length(),+ "The number of rotated dimensions must not exceed the head size of "+ "raw_index_keys.");+ }+ rotated_size = merged + merged;+ // The RoPE inputs broadcast over the batch, so the dimension is checked, not merged into it.+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ rope_cos_shape[0].compatible(1) || rope_cos_shape[0].compatible(batch),+ "The batch dimension of rope_cos must be 1 or the batch of raw_index_keys.");+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ rope_sin_shape[0].compatible(1) || rope_sin_shape[0].compatible(batch),+ "The batch dimension of rope_sin must be 1 or the batch of raw_index_keys.");+ if (is_raw_keys_rank_static) {+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ TDim::merge(merged, rope_cos_shape[1], raw_index_keys_shape[1]),+ "The number of new tokens of rope_cos and raw_index_keys must be the same.");+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ TDim::merge(merged, rope_sin_shape[1], raw_index_keys_shape[1]),+ "The number of new tokens of rope_sin and raw_index_keys must be the same.");+ }+ if (past_incomplete_rope_shape.rank().is_static()) {+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ TDim::merge(rotated_size, rotated_size, past_incomplete_rope_shape[1]),+ "The second dimension of past_incomplete_rope must be 2 * Dr.");+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ TDim::merge(batch, batch, past_incomplete_rope_shape[0]),+ "The batch dimension of raw_index_keys and past_incomplete_rope must be the same.");+ }+ }++ // The number of complete blocks of the longest sequence is known only from the key_length values.+ auto num_blocks = TDim(ov::util::dim::inf_bound);+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ key_length_shape.rank().is_dynamic() || key_length_shape[0].compatible(1) ||+ key_length_shape[0].compatible(batch),+ "The size of key_length must be 1 or the batch of raw_index_keys.");+ if (const auto key_lengths = get_input_const_data_as<TRShape, int64_t>(op, 2, ta)) {+ int64_t longest = 0;+ for (const auto& length : *key_lengths) {+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ length >= 0,+ "The key_length values must be non-negative. Got: ",+ length);+ const auto blocks = length / key_block_size;+ longest = blocks > longest ? blocks : longest;+ }+ num_blocks = TDim(longest);++ if (is_raw_keys_rank_static && raw_index_keys_shape[1].is_static() &&+ past_block_index_keys_shape.rank().is_static() && past_block_index_keys_shape[1].is_static()) {+ const auto new_tokens = raw_index_keys_shape[1].get_length();+ int64_t cached = 0;+ for (const auto& length : *key_lengths) {+ const auto past = length - new_tokens;+ const auto blocks = past > 0 ? past / key_block_size : 0;+ cached = blocks > cached ? blocks : cached;+ }+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ past_block_index_keys_shape[1].get_length() >= cached,+ "The second dimension of past_block_index_keys must cover the complete "+ "blocks of the past tokens, at least: ",+ cached,+ ", got: ",+ past_block_index_keys_shape[1]);+ }+ } else if (is_raw_keys_rank_static && past_block_index_keys_shape.rank().is_static()) {+ // Without the key_length values only the upper bound is known: the cached blocks plus the new tokens,+ // as the past incomplete block contributes at most key_block_size - 1 tokens.+ const auto upper =+ past_block_index_keys_shape[1] ++ ov::util::dim::ceil_div(raw_index_keys_shape[1], static_cast<typename TDim::value_type>(key_block_size));+ if (upper.is_static()) {+ num_blocks = TDim(0, upper.get_length());+ }+ }++ return {TRShape{batch, std::move(num_blocks), head_size},+ TRShape{batch, TDim(key_block_size - 1), head_size},+ TRShape{batch, std::move(rotated_size)}};+}+} // namespace ov::op::v17diff --git a/src/core/shape_inference/include/sparse_attention_indexer_shape_inference.hpp b/src/core/shape_inference/include/sparse_attention_indexer_shape_inference.hppnew file mode 100644index 00000000000..5d6ee79bee8--- /dev/null+++ b/src/core/shape_inference/include/sparse_attention_indexer_shape_inference.hpp@@ -0,0 +1,131 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "openvino/op/sparse_attention_indexer.hpp"+#include "utils.hpp"++namespace ov::op::v17 {+template <class TShape, class TRShape = result_shape_t<TShape>>+std::vector<TRShape> shape_infer(const SparseAttentionIndexer* op,+ const std::vector<TShape>& input_shapes,+ const ITensorAccessor& ta = make_tensor_accessor()) {+ using TDim = typename TShape::value_type;++ const auto inputs_count = input_shapes.size();+ NODE_VALIDATION_CHECK(op, inputs_count == 3 || inputs_count == 4);++ const auto key_block_size = op->get_key_block_size();+ const auto token_budget = op->get_token_budget();+ const auto num_selection_heads = op->get_num_selection_heads();+ NODE_VALIDATION_CHECK(op,+ key_block_size > 0,+ "The attribute key_block_size must be a positive integer. Got: ",+ key_block_size);+ NODE_VALIDATION_CHECK(op,+ token_budget > 0,+ "The attribute token_budget must be a positive integer. Got: ",+ token_budget);+ NODE_VALIDATION_CHECK(op,+ token_budget % key_block_size == 0,+ "The attribute token_budget must be divisible by key_block_size. Got: ",+ token_budget,+ " and ",+ key_block_size);+ NODE_VALIDATION_CHECK(op,+ num_selection_heads > 0,+ "The attribute num_selection_heads must be a positive integer. Got: ",+ num_selection_heads);++ const auto& index_query_shape = input_shapes[0];+ const auto& block_index_keys_shape = input_shapes[1];+ const auto& key_length_shape = input_shapes[2];++ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ index_query_shape.rank().compatible(4),+ "The shape of index_query must be 4D [N, Hi, L, Di].");+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ block_index_keys_shape.rank().compatible(3),+ "The shape of block_index_keys must be 3D [N, B, Di].");+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ key_length_shape.rank().compatible(1),+ "The shape of key_length must be 1D [N] or [1].");++ TDim batch{};+ TDim num_queries{};+ TDim index_heads{};+ if (index_query_shape.rank().is_static()) {+ batch = index_query_shape[0];+ index_heads = index_query_shape[1];+ num_queries = index_query_shape[2];+ }++ if (block_index_keys_shape.rank().is_static()) {+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ TDim::merge(batch, batch, block_index_keys_shape[0]),+ "The batch dimension of index_query and block_index_keys must be the same.");+ if (index_query_shape.rank().is_static()) {+ TDim merged;+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ TDim::merge(merged, index_query_shape[3], block_index_keys_shape[2]),+ "The head size of index_query and block_index_keys must be the same.");+ }+ }++ if (inputs_count == 4) {+ const auto& index_weights_shape = input_shapes[3];+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ index_weights_shape.rank().compatible(3),+ "The shape of index_weights must be 3D [N, L, Hi].");+ if (index_weights_shape.rank().is_static()) {+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ TDim::merge(batch, batch, index_weights_shape[0]),+ "The batch dimension of index_query, block_index_keys and index_weights "+ "must be compatible.");+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ TDim::merge(num_queries, num_queries, index_weights_shape[1]),+ "The number of query tokens of index_query and index_weights must be the same.");+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ TDim::merge(index_heads, index_heads, index_weights_shape[2]),+ "The number of index query heads of index_query and index_weights "+ "must be the same.");+ }+ }++ if (index_heads.is_static()) {+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ index_heads.get_length() % num_selection_heads == 0,+ "The number of index query heads must be divisible by num_selection_heads.");+ }++ const auto num_selected_blocks = token_budget / key_block_size;+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ key_length_shape.rank().is_dynamic() || key_length_shape[0].compatible(1) ||+ key_length_shape[0].compatible(batch),+ "The size of key_length must be 1 or the batch dimension of index_query.");+ if (const auto key_lengths = get_input_const_data_as<TRShape, int64_t>(op, 2, ta)) {+ for (const auto& length : *key_lengths) {+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ length >= 0,+ "The key_length values must be non-negative. Got: ",+ length);+ }+ }+ return {TRShape{batch, TDim(num_selection_heads), num_queries, TDim(num_selected_blocks)},+ TRShape{batch, TDim(num_selection_heads), num_queries}};+}+} // namespace ov::op::v17diff --git a/src/core/shape_inference/include/sparse_attention_shape_inference.hpp b/src/core/shape_inference/include/sparse_attention_shape_inference.hppnew file mode 100644index 00000000000..39d9d23b8b1--- /dev/null+++ b/src/core/shape_inference/include/sparse_attention_shape_inference.hpp@@ -0,0 +1,232 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "openvino/op/sparse_attention.hpp"+#include "openvino/util/math_util.hpp"+#include "utils.hpp"++namespace ov::op::v17 {+template <class TShape, class TRShape = result_shape_t<TShape>>+std::vector<TRShape> shape_infer(const SparseAttention* op,+ const std::vector<TShape>& input_shapes,+ const ITensorAccessor& ta = make_tensor_accessor()) {+ using TDim = typename TShape::value_type;++ const auto inputs_count = input_shapes.size();+ NODE_VALIDATION_CHECK(op, 5 <= inputs_count && inputs_count <= 8);++ const auto key_block_size = op->get_key_block_size();+ const auto query_block_size = op->get_query_block_size();+ NODE_VALIDATION_CHECK(op,+ key_block_size > 0,+ "The attribute key_block_size must be a positive integer. Got: ",+ key_block_size);+ NODE_VALIDATION_CHECK(op,+ query_block_size > 0,+ "The attribute query_block_size must be a positive integer. Got: ",+ query_block_size);++ const auto& query_shape = input_shapes[0];+ const auto& key_shape = input_shapes[1];+ const auto& value_shape = input_shapes[2];+ const auto& block_indices_shape = input_shapes[3];+ const auto& block_count_shape = input_shapes[4];++ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ query_shape.rank().compatible(4),+ "The shape of query must be 4D [N, H, L, E].");+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ key_shape.rank().compatible(4),+ "The shape of key must be 4D [N, Hkv, S, E].");+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ value_shape.rank().compatible(4),+ "The shape of value must be 4D [N, Hkv, S, Ev].");+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ block_indices_shape.rank().compatible(4),+ "The shape of block_indices must be 4D [N, Hs, Lq, KB].");+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ block_count_shape.rank().compatible(3),+ "The shape of block_count must be 3D [N, Hs, Lq].");++ // Output is [N, H, L, Ev]: the query shape with the value head size as the last dimension.+ auto output_shapes = std::vector<TRShape>{input_shapes[0]};+ auto& out_shape = output_shapes[0];+ const auto is_out_rank_static = out_shape.rank().is_static();++ // Batch size, shared by all the data and selection inputs+ if (is_out_rank_static) {+ for (size_t i = 1; i < 5; ++i) {+ NODE_SHAPE_INFER_CHECK(+ op,+ input_shapes,+ input_shapes[i].rank().is_dynamic() || TDim::merge(out_shape[0], out_shape[0], input_shapes[i][0]),+ "The batch dimension of all the inputs must be the same.");+ }+ }++ if (key_shape.rank().is_static() && value_shape.rank().is_static()) {+ TDim merged;+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ TDim::merge(merged, key_shape[0], value_shape[0]),+ "The batch dimension of all the inputs must be the same.");+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ TDim::merge(merged, key_shape[1], value_shape[1]),+ "The number of key and value heads must be the same.");+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ TDim::merge(merged, key_shape[2], value_shape[2]),+ "The number of key and value positions must be the same.");+ }++ if (query_shape.rank().is_static() && key_shape.rank().is_static()) {+ TDim merged;+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ TDim::merge(merged, query_shape[3], key_shape[3]),+ "The head size of query and key must be the same.");+ if (query_shape[1].is_static() && key_shape[1].is_static()) {+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ key_shape[1].get_length() > 0,+ "The number of key and value heads must be a positive integer. Got: ",+ key_shape[1]);+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ query_shape[1].get_length() % key_shape[1].get_length() == 0,+ "The number of query heads must be divisible by the number of key heads.");+ }+ if (op->get_causal() && query_shape[2].is_static() && key_shape[2].is_static()) {+ NODE_SHAPE_INFER_CHECK(+ op,+ input_shapes,+ query_shape[2].get_length() <= key_shape[2].get_length(),+ "In the causal mode the number of query tokens must not exceed the number of key positions.");+ }+ }++ TDim selection_heads{};+ TDim query_rows{};+ if (block_indices_shape.rank().is_static()) {+ selection_heads = block_indices_shape[1];+ query_rows = block_indices_shape[2];+ }++ if (block_count_shape.rank().is_static()) {+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ TDim::merge(selection_heads, selection_heads, block_count_shape[1]),+ "The number of selection heads of block_indices and block_count must be the same.");+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ TDim::merge(query_rows, query_rows, block_count_shape[2]),+ "The number of query rows of block_indices and block_count must be the same.");+ if (block_indices_shape.rank().is_static()) {+ TDim merged;+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ TDim::merge(merged, block_indices_shape[0], block_count_shape[0]),+ "The batch dimension of all the inputs must be the same.");+ }+ }++ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ selection_heads.is_dynamic() || selection_heads.get_length() > 0,+ "The number of selection heads must be a positive integer. Got: ",+ selection_heads);++ if (query_shape.rank().is_static()) {+ if (query_shape[1].is_static() && selection_heads.is_static()) {+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ query_shape[1].get_length() % selection_heads.get_length() == 0,+ "The number of query heads must be divisible by the number of selection heads.");+ }+ if (query_shape[2].is_static() && query_rows.is_static()) {+ const auto expected_rows = ov::util::ceil_div(query_shape[2].get_length(), query_block_size);+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ query_rows.get_length() == expected_rows,+ "The number of query rows must be ceil(L / query_block_size), expected: ",+ expected_rows,+ ", got: ",+ query_rows);+ }+ }++ if (inputs_count > 5) {+ const auto& key_length_shape = input_shapes[5];+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ key_length_shape.rank().compatible(1),+ "The shape of key_length must be 1D [N] or [1].");+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ !is_out_rank_static || key_length_shape.rank().is_dynamic() ||+ key_length_shape[0].compatible(1) || key_length_shape[0].compatible(out_shape[0]),+ "The size of key_length must be 1 or the batch dimension of the other inputs.");+ if (key_shape.rank().is_static() && key_shape[2].is_static()) {+ if (const auto key_lengths = get_input_const_data_as<TRShape, int64_t>(op, 5, ta)) {+ const auto num_positions = static_cast<int64_t>(key_shape[2].get_length());+ for (const auto& length : *key_lengths) {+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ 0 <= length && length <= num_positions,+ "The key_length values must be in [0, S], S = ",+ num_positions,+ ". Got: ",+ length);+ }+ }+ }+ }++ if (inputs_count > 6) {+ const auto& scale_shape = input_shapes[6];+ const auto& scale_rank = scale_shape.rank();+ if (scale_rank.is_static()) {+ const auto scale_is_scalar = scale_rank.get_length() == 0;+ const auto scale_has_one_elem = scale_rank.get_length() == 1 && scale_shape[0].compatible(1);+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ scale_is_scalar || scale_has_one_elem,+ "The scale input must be a scalar or a single element 1D tensor.");+ }+ }++ if (inputs_count > 7) {+ const auto& sinks_shape = input_shapes[7];+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ sinks_shape.rank().compatible(1),+ "The shape of sinks must be 1D [H].");+ if (sinks_shape.rank().is_static() && query_shape.rank().is_static()) {+ TDim merged;+ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ TDim::merge(merged, sinks_shape[0], query_shape[1]),+ "The number of sinks must be equal to the number of query heads.");+ }+ }++ TDim value_head_size{};+ if (value_shape.rank().is_static()) {+ value_head_size = value_shape[3];+ }+ if (is_out_rank_static) {+ out_shape.resize(3);+ out_shape.push_back(std::move(value_head_size));+ }+ return output_shapes;+}+} // namespace ov::op::v17diff --git a/src/core/src/op/qsa_prepare.cpp b/src/core/src/op/qsa_prepare.cppnew file mode 100644index 00000000000..a88e474f25c--- /dev/null+++ b/src/core/src/op/qsa_prepare.cpp@@ -0,0 +1,99 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "openvino/op/qsa_prepare.hpp"++#include "itt.hpp"+#include "qsa_prepare_shape_inference.hpp"++namespace ov::op::v17 {++QSAPrepare::QSAPrepare(const OutputVector& inputs, int64_t key_block_size, float epsilon)+ : Op(inputs),+ m_key_block_size(key_block_size),+ m_epsilon(epsilon) {+ constructor_validate_and_infer_types();+}++QSAPrepare::QSAPrepare(const Output<Node>& raw_index_keys,+ const Output<Node>& past_block_index_keys,+ const Output<Node>& key_length,+ const Output<Node>& rope_cos,+ const Output<Node>& rope_sin,+ const Output<Node>& k_norm_weight,+ const Output<Node>& past_incomplete_raw_keys,+ const Output<Node>& past_incomplete_rope,+ int64_t key_block_size,+ float epsilon)+ : QSAPrepare(OutputVector{raw_index_keys,+ past_block_index_keys,+ key_length,+ rope_cos,+ rope_sin,+ k_norm_weight,+ past_incomplete_raw_keys,+ past_incomplete_rope},+ key_block_size,+ epsilon) {}++void QSAPrepare::validate_and_infer_types() {+ OV_OP_SCOPE(v17_QSAPrepare_validate_and_infer_types);+ const auto input_count = get_input_size();+ NODE_VALIDATION_CHECK(this, input_count == 8, "The number of inputs must be 8. Got: ", input_count);+ NODE_VALIDATION_CHECK(this,+ m_epsilon > 0.0f,+ "The attribute epsilon must be a positive floating point number. Got: ",+ m_epsilon);++ static constexpr const char* data_input_names[] = {"raw_index_keys",+ "past_block_index_keys",+ nullptr,+ "rope_cos",+ "rope_sin",+ "k_norm_weight",+ "past_incomplete_raw_keys",+ "past_incomplete_rope"};+ element::Type data_et = get_input_element_type(0);+ for (size_t i = 1; i < input_count; ++i) {+ if (data_input_names[i] == nullptr) {+ continue;+ }+ NODE_VALIDATION_CHECK(this,+ element::Type::merge(data_et, data_et, get_input_element_type(i)),+ "The element type of ",+ data_input_names[i],+ " must be the same as of raw_index_keys. Got: ",+ get_input_element_type(i));+ }+ NODE_VALIDATION_CHECK(this,+ data_et.is_dynamic() || data_et.is_real(),+ "The element type of the index key inputs must be a floating point type. Got: ",+ data_et);++ const auto& key_length_et = get_input_element_type(2);+ NODE_VALIDATION_CHECK(this,+ key_length_et.is_dynamic() || key_length_et == element::i32 || key_length_et == element::i64,+ "The element type of key_length must be i32 or i64. Got: ",+ key_length_et);++ const auto output_shapes = shape_infer(this, ov::util::get_node_input_partial_shapes(*this));+ set_output_type(0, data_et, output_shapes[0]);+ set_output_type(1, data_et, output_shapes[1]);+ set_output_type(2, data_et, output_shapes[2]);+}++bool QSAPrepare::visit_attributes(AttributeVisitor& visitor) {+ OV_OP_SCOPE(v17_QSAPrepare_visit_attributes);+ visitor.on_attribute("key_block_size", m_key_block_size);+ visitor.on_attribute("epsilon", m_epsilon);+ return true;+}++std::shared_ptr<Node> QSAPrepare::clone_with_new_inputs(const OutputVector& new_args) const {+ OV_OP_SCOPE(v17_QSAPrepare_clone_with_new_inputs);+ check_new_args_count(this, new_args);+ return std::make_shared<QSAPrepare>(new_args, m_key_block_size, m_epsilon);+}++} // namespace ov::op::v17diff --git a/src/core/src/op/sparse_attention.cpp b/src/core/src/op/sparse_attention.cppnew file mode 100644index 00000000000..e7a78f7ab84--- /dev/null+++ b/src/core/src/op/sparse_attention.cpp@@ -0,0 +1,152 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "openvino/op/sparse_attention.hpp"++#include "itt.hpp"+#include "sparse_attention_shape_inference.hpp"++namespace ov::op::v17 {++SparseAttention::SparseAttention(const OutputVector& inputs,+ int64_t key_block_size,+ int64_t query_block_size,+ bool causal)+ : Op(inputs),+ m_key_block_size(key_block_size),+ m_query_block_size(query_block_size),+ m_causal(causal) {+ constructor_validate_and_infer_types();+}++SparseAttention::SparseAttention(const Output<Node>& query,+ const Output<Node>& key,+ const Output<Node>& value,+ const Output<Node>& block_indices,+ const Output<Node>& block_count,+ int64_t key_block_size,+ int64_t query_block_size,+ bool causal)+ : SparseAttention(OutputVector{query, key, value, block_indices, block_count},+ key_block_size,+ query_block_size,+ causal) {}++SparseAttention::SparseAttention(const Output<Node>& query,+ const Output<Node>& key,+ const Output<Node>& value,+ const Output<Node>& block_indices,+ const Output<Node>& block_count,+ const Output<Node>& key_length,+ int64_t key_block_size,+ int64_t query_block_size,+ bool causal)+ : SparseAttention(OutputVector{query, key, value, block_indices, block_count, key_length},+ key_block_size,+ query_block_size,+ causal) {}++SparseAttention::SparseAttention(const Output<Node>& query,+ const Output<Node>& key,+ const Output<Node>& value,+ const Output<Node>& block_indices,+ const Output<Node>& block_count,+ const Output<Node>& key_length,+ const Output<Node>& scale,+ int64_t key_block_size,+ int64_t query_block_size,+ bool causal)+ : SparseAttention(OutputVector{query, key, value, block_indices, block_count, key_length, scale},+ key_block_size,+ query_block_size,+ causal) {}++SparseAttention::SparseAttention(const Output<Node>& query,+ const Output<Node>& key,+ const Output<Node>& value,+ const Output<Node>& block_indices,+ const Output<Node>& block_count,+ const Output<Node>& key_length,+ const Output<Node>& scale,+ const Output<Node>& sinks,+ int64_t key_block_size,+ int64_t query_block_size,+ bool causal)+ : SparseAttention(OutputVector{query, key, value, block_indices, block_count, key_length, scale, sinks},+ key_block_size,+ query_block_size,+ causal) {}++void SparseAttention::validate_and_infer_types() {+ OV_OP_SCOPE(v17_SparseAttention_validate_and_infer_types);+ const auto input_count = get_input_size();+ NODE_VALIDATION_CHECK(this,+ 5 <= input_count && input_count <= 8,+ "The number of inputs must be from 5 to 8. Got: ",+ input_count);++ element::Type data_et = get_input_element_type(0);+ NODE_VALIDATION_CHECK(this,+ element::Type::merge(data_et, data_et, get_input_element_type(1)) &&+ element::Type::merge(data_et, data_et, get_input_element_type(2)),+ "The element types of query, key and value must be the same. Got: ",+ get_input_element_type(0),+ ", ",+ get_input_element_type(1),+ ", ",+ get_input_element_type(2));+ NODE_VALIDATION_CHECK(this,+ data_et.is_dynamic() || data_et.is_real(),+ "The element type of query, key and value must be a floating point type. Got: ",+ data_et);++ static constexpr const char* index_input_names[] = {"block_indices", "block_count", "key_length"};+ for (size_t i = 3; i < input_count && i < 6; ++i) {+ const auto& et = get_input_element_type(i);+ NODE_VALIDATION_CHECK(this,+ et.is_dynamic() || et == element::i32 || et == element::i64,+ "The element type of ",+ index_input_names[i - 3],+ " must be i32 or i64. Got: ",+ et);+ }++ if (input_count >= 7) {+ const auto& scale_et = get_input_element_type(6);+ NODE_VALIDATION_CHECK(+ this,+ (scale_et.is_dynamic() || scale_et.is_real()) && element::Type::merge(data_et, data_et, scale_et),+ "The element type of scale must be a floating point type, the same as of query, key "+ "and value. Got: ",+ scale_et);+ }++ // The sink logits are not scaled and may be kept in a higher precision than the activations.+ if (input_count == 8) {+ const auto& sinks_et = get_input_element_type(7);+ NODE_VALIDATION_CHECK(this,+ sinks_et.is_dynamic() || sinks_et.is_real(),+ "The element type of sinks must be a floating point type. Got: ",+ sinks_et);+ }++ const auto output_shapes = shape_infer(this, ov::util::get_node_input_partial_shapes(*this));+ set_output_type(0, data_et, output_shapes[0]);+}++bool SparseAttention::visit_attributes(AttributeVisitor& visitor) {+ OV_OP_SCOPE(v17_SparseAttention_visit_attributes);+ visitor.on_attribute("key_block_size", m_key_block_size);+ visitor.on_attribute("query_block_size", m_query_block_size);+ visitor.on_attribute("causal", m_causal);+ return true;+}++std::shared_ptr<Node> SparseAttention::clone_with_new_inputs(const OutputVector& new_args) const {+ OV_OP_SCOPE(v17_SparseAttention_clone_with_new_inputs);+ check_new_args_count(this, new_args);+ return std::make_shared<SparseAttention>(new_args, m_key_block_size, m_query_block_size, m_causal);+}++} // namespace ov::op::v17diff --git a/src/core/src/op/sparse_attention_indexer.cpp b/src/core/src/op/sparse_attention_indexer.cppnew file mode 100644index 00000000000..359a7a811f4--- /dev/null+++ b/src/core/src/op/sparse_attention_indexer.cpp@@ -0,0 +1,97 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "openvino/op/sparse_attention_indexer.hpp"++#include "itt.hpp"+#include "sparse_attention_indexer_shape_inference.hpp"++namespace ov::op::v17 {++SparseAttentionIndexer::SparseAttentionIndexer(const OutputVector& inputs,+ int64_t key_block_size,+ int64_t token_budget,+ int64_t num_selection_heads)+ : Op(inputs),+ m_key_block_size(key_block_size),+ m_token_budget(token_budget),+ m_num_selection_heads(num_selection_heads) {+ constructor_validate_and_infer_types();+}++SparseAttentionIndexer::SparseAttentionIndexer(const Output<Node>& index_query,+ const Output<Node>& block_index_keys,+ const Output<Node>& key_length,+ int64_t key_block_size,+ int64_t token_budget,+ int64_t num_selection_heads)+ : SparseAttentionIndexer(OutputVector{index_query, block_index_keys, key_length},+ key_block_size,+ token_budget,+ num_selection_heads) {}++SparseAttentionIndexer::SparseAttentionIndexer(const Output<Node>& index_query,+ const Output<Node>& block_index_keys,+ const Output<Node>& key_length,+ const Output<Node>& index_weights,+ int64_t key_block_size,+ int64_t token_budget,+ int64_t num_selection_heads)+ : SparseAttentionIndexer(OutputVector{index_query, block_index_keys, key_length, index_weights},+ key_block_size,+ token_budget,+ num_selection_heads) {}++void SparseAttentionIndexer::validate_and_infer_types() {+ OV_OP_SCOPE(v17_SparseAttentionIndexer_validate_and_infer_types);+ const auto input_count = get_input_size();+ NODE_VALIDATION_CHECK(this,+ input_count == 3 || input_count == 4,+ "The number of inputs must be 3 or 4. Got: ",+ input_count);++ element::Type data_et = get_input_element_type(0);+ NODE_VALIDATION_CHECK(this,+ element::Type::merge(data_et, data_et, get_input_element_type(1)),+ "The element types of index_query and block_index_keys must be the same. Got: ",+ get_input_element_type(0),+ ", ",+ get_input_element_type(1));+ if (input_count == 4) {+ NODE_VALIDATION_CHECK(this,+ element::Type::merge(data_et, data_et, get_input_element_type(3)),+ "The element type of index_weights must be the same as of index_query. Got: ",+ get_input_element_type(3));+ }+ NODE_VALIDATION_CHECK(this,+ data_et.is_dynamic() || data_et.is_real(),+ "The element type of index_query and block_index_keys must be a floating point type. Got: ",+ data_et);++ const auto& key_length_et = get_input_element_type(2);+ NODE_VALIDATION_CHECK(this,+ key_length_et.is_dynamic() || key_length_et == element::i32 || key_length_et == element::i64,+ "The element type of key_length must be i32 or i64. Got: ",+ key_length_et);++ const auto output_shapes = shape_infer(this, ov::util::get_node_input_partial_shapes(*this));+ set_output_type(0, element::i32, output_shapes[0]);+ set_output_type(1, element::i32, output_shapes[1]);+}++bool SparseAttentionIndexer::visit_attributes(AttributeVisitor& visitor) {+ OV_OP_SCOPE(v17_SparseAttentionIndexer_visit_attributes);+ visitor.on_attribute("key_block_size", m_key_block_size);+ visitor.on_attribute("token_budget", m_token_budget);+ visitor.on_attribute("num_selection_heads", m_num_selection_heads);+ return true;+}++std::shared_ptr<Node> SparseAttentionIndexer::clone_with_new_inputs(const OutputVector& new_args) const {+ OV_OP_SCOPE(v17_SparseAttentionIndexer_clone_with_new_inputs);+ check_new_args_count(this, new_args);+ return std::make_shared<SparseAttentionIndexer>(new_args, m_key_block_size, m_token_budget, m_num_selection_heads);+}++} // namespace ov::op::v17diff --git a/src/core/src/sources.cmake b/src/core/src/sources.cmakeindex af17061ebdc..c71168e7d3b 100644--- a/src/core/src/sources.cmake+++ b/src/core/src/sources.cmake@@ -196,6 +196,7 @@ set(LIBRARY_SRC${CMAKE_CURRENT_LIST_DIR}/op/prior_box_clustered.cpp${CMAKE_CURRENT_LIST_DIR}/op/proposal.cpp${CMAKE_CURRENT_LIST_DIR}/op/psroi_pooling.cpp+ ${CMAKE_CURRENT_LIST_DIR}/op/qsa_prepare.cpp${CMAKE_CURRENT_LIST_DIR}/op/random_uniform.cpp${CMAKE_CURRENT_LIST_DIR}/op/range.cpp${CMAKE_CURRENT_LIST_DIR}/op/rdft.cpp@@ -248,6 +249,8 @@ set(LIBRARY_SRC${CMAKE_CURRENT_LIST_DIR}/op/softsign.cpp${CMAKE_CURRENT_LIST_DIR}/op/space_to_batch.cpp${CMAKE_CURRENT_LIST_DIR}/op/space_to_depth.cpp+ ${CMAKE_CURRENT_LIST_DIR}/op/sparse_attention.cpp+ ${CMAKE_CURRENT_LIST_DIR}/op/sparse_attention_indexer.cpp${CMAKE_CURRENT_LIST_DIR}/op/sparse_fill_empty_rows.cpp${CMAKE_CURRENT_LIST_DIR}/op/split.cpp${CMAKE_CURRENT_LIST_DIR}/op/sqrt.cppdiff --git a/src/core/tests/opset.cpp b/src/core/tests/opset.cppindex 966ed66b1b1..401880f209f 100644--- a/src/core/tests/opset.cpp+++ b/src/core/tests/opset.cpp@@ -79,7 +79,7 @@ INSTANTIATE_TEST_SUITE_P(opset,OpsetTestParams{ov::get_opset14, 188},OpsetTestParams{ov::get_opset15, 199},OpsetTestParams{ov::get_opset16, 203},- OpsetTestParams{ov::get_opset17, 7}),+ OpsetTestParams{ov::get_opset17, 10}),OpsetTestNameGenerator{});class MyOpOld : public ov::op::Op {diff --git a/src/core/tests/type_prop/qsa_prepare.cpp b/src/core/tests/type_prop/qsa_prepare.cppnew file mode 100644index 00000000000..f38e586b8e4--- /dev/null+++ b/src/core/tests/type_prop/qsa_prepare.cpp@@ -0,0 +1,520 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "openvino/op/qsa_prepare.hpp"++#include <gtest/gtest.h>++#include "common_test_utils/test_assertions.hpp"+#include "common_test_utils/type_prop.hpp"+#include "openvino/op/constant.hpp"++namespace ov::test {+using op::v0::Constant, op::v0::Parameter;+using testing::HasSubstr;++class TypePropQSAPrepareTest : public TypePropOpTest<op::v17::QSAPrepare> {+protected:+ static std::shared_ptr<Parameter> param(element::Type et, const PartialShape& shape) {+ return std::make_shared<Parameter>(et, shape);+ }++ static std::shared_ptr<Constant> disabled(element::Type et = element::f32) {+ return Constant::create(et, Shape{0}, std::vector<float>{});+ }+};++TEST_F(TypePropQSAPrepareTest, default_ctor) {+ const auto op = make_op();+ op->set_key_block_size(4);+ op->set_arguments(OutputVector{param(element::f32, PartialShape{1, 1, 128}),+ param(element::f32, PartialShape{1, 2500, 128}),+ Constant::create(element::i64, Shape{1}, {10004}),+ param(element::f32, PartialShape{1, 1, 64}),+ param(element::f32, PartialShape{1, 1, 64}),+ param(element::f32, PartialShape{128}),+ param(element::f32, PartialShape{1, 3, 128}),+ param(element::f32, PartialShape{1, 128})});+ op->validate_and_infer_types();++ EXPECT_EQ(op->get_input_size(), 8);+ EXPECT_EQ(op->get_output_size(), 3);+ EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{1, 2501, 128}));+ EXPECT_EQ(op->get_output_partial_shape(1), (PartialShape{1, 3, 128}));+ EXPECT_EQ(op->get_output_partial_shape(2), (PartialShape{1, 128}));+}++TEST_F(TypePropQSAPrepareTest, static_shapes_with_constant_key_length) {+ // The previous call ended with key_length [32, 15], so it cached 8 and 3 complete blocks.+ const auto op = make_op(param(element::f32, PartialShape{2, 8, 128}),+ param(element::f32, PartialShape{2, 8, 128}),+ Constant::create(element::i32, Shape{2}, {40, 23}),+ param(element::f32, PartialShape{2, 8, 64}),+ param(element::f32, PartialShape{2, 8, 64}),+ param(element::f32, PartialShape{128}),+ param(element::f32, PartialShape{2, 3, 128}),+ param(element::f32, PartialShape{2, 128}),+ 4);++ EXPECT_EQ(op->get_key_block_size(), 4);+ EXPECT_EQ(op->get_epsilon(), 1e-6f);+ EXPECT_EQ(op->get_output_element_type(0), element::f32);+ EXPECT_EQ(op->get_output_element_type(1), element::f32);+ EXPECT_EQ(op->get_output_element_type(2), element::f32);+ // The longest sequence has 40 valid tokens, that is 10 complete blocks.+ EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{2, 10, 128}));+ EXPECT_EQ(op->get_output_partial_shape(1), (PartialShape{2, 3, 128}));+ EXPECT_EQ(op->get_output_partial_shape(2), (PartialShape{2, 128}));+}++TEST_F(TypePropQSAPrepareTest, insufficient_cached_block_keys) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{2, 8, 128}),+ param(element::f32, PartialShape{2, 4, 128}),+ Constant::create(element::i32, Shape{2}, {40, 23}),+ param(element::f32, PartialShape{2, 8, 64}),+ param(element::f32, PartialShape{2, 8, 64}),+ param(element::f32, PartialShape{128}),+ param(element::f32, PartialShape{2, 3, 128}),+ param(element::f32, PartialShape{2, 128}),+ 4),+ NodeValidationFailure,+ HasSubstr("The second dimension of past_block_index_keys must cover the complete blocks"));+}++TEST_F(TypePropQSAPrepareTest, dynamic_key_length_keeps_block_count_dynamic) {+ const auto op = make_op(param(element::f16, PartialShape{2, 8, 128}),+ param(element::f16, PartialShape{2, -1, 128}),+ param(element::i32, PartialShape{2}),+ param(element::f16, PartialShape{2, 8, 64}),+ param(element::f16, PartialShape{2, 8, 64}),+ param(element::f16, PartialShape{128}),+ param(element::f16, PartialShape{2, 3, 128}),+ param(element::f16, PartialShape{2, 128}),+ 4);++ EXPECT_EQ(op->get_output_element_type(0), element::f16);+ EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{2, -1, 128}));+ EXPECT_EQ(op->get_output_partial_shape(1), (PartialShape{2, 3, 128}));+ EXPECT_EQ(op->get_output_partial_shape(2), (PartialShape{2, 128}));+}++TEST_F(TypePropQSAPrepareTest, dynamic_key_length_is_bounded_by_the_cached_blocks) {+ const auto op = make_op(param(element::f32, PartialShape{1, 8, 128}),+ param(element::f32, PartialShape{1, 10, 128}),+ param(element::i32, PartialShape{1}),+ param(element::f32, PartialShape{1, 8, 64}),+ param(element::f32, PartialShape{1, 8, 64}),+ param(element::f32, PartialShape{128}),+ param(element::f32, PartialShape{1, 3, 128}),+ param(element::f32, PartialShape{1, 128}),+ 4);++ // At most the 10 cached blocks plus ceil(8 / 4) completed by the new tokens.+ EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{1, Dimension(0, 12), 128}));+}++TEST_F(TypePropQSAPrepareTest, negative_key_length_value) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{1, 8, 128}),+ param(element::f32, PartialShape{1, 8, 128}),+ Constant::create(element::i32, Shape{1}, {-5}),+ param(element::f32, PartialShape{1, 8, 64}),+ param(element::f32, PartialShape{1, 8, 64}),+ param(element::f32, PartialShape{128}),+ param(element::f32, PartialShape{1, 3, 128}),+ param(element::f32, PartialShape{1, 128}),+ 4),+ NodeValidationFailure,+ HasSubstr("The key_length values must be non-negative."));+}++TEST_F(TypePropQSAPrepareTest, rotation_disabled_by_empty_rope) {+ const auto op = make_op(param(element::f32, PartialShape{1, 8, 128}),+ param(element::f32, PartialShape{1, 0, 128}),+ param(element::i32, PartialShape{1}),+ disabled(),+ disabled(),+ param(element::f32, PartialShape{128}),+ param(element::f32, PartialShape{1, 3, 128}),+ disabled(),+ 4);++ EXPECT_EQ(op->get_output_partial_shape(2), (PartialShape{1, 0}));+}++TEST_F(TypePropQSAPrepareTest, normalization_disabled_by_empty_weight) {+ const auto op = make_op(param(element::f32, PartialShape{1, 8, 128}),+ param(element::f32, PartialShape{1, 0, 128}),+ param(element::i32, PartialShape{1}),+ param(element::f32, PartialShape{1, 8, 64}),+ param(element::f32, PartialShape{1, 8, 64}),+ disabled(),+ param(element::f32, PartialShape{1, 3, 128}),+ param(element::f32, PartialShape{1, 128}),+ 4);++ EXPECT_EQ(op->get_output_partial_shape(1), (PartialShape{1, 3, 128}));+}++TEST_F(TypePropQSAPrepareTest, empty_rope_parameter_does_not_disable_the_rotation) {+ // A [0] Parameter is not an empty Constant, so the rotation stays enabled.+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{1, 8, 128}),+ param(element::f32, PartialShape{1, 0, 128}),+ param(element::i32, PartialShape{1}),+ param(element::f32, PartialShape{0}),+ param(element::f32, PartialShape{0}),+ param(element::f32, PartialShape{128}),+ param(element::f32, PartialShape{1, 3, 128}),+ param(element::f32, PartialShape{0}),+ 4),+ NodeValidationFailure,+ HasSubstr("The shape of rope_cos and rope_sin must be 3D [N, L, Dr]."));+}++TEST_F(TypePropQSAPrepareTest, normalization_disabled_by_multi_dim_empty_constant) {+ const auto op = make_op(param(element::f32, PartialShape{1, 8, 128}),+ param(element::f32, PartialShape{1, 0, 128}),+ param(element::i32, PartialShape{1}),+ param(element::f32, PartialShape{1, 8, 64}),+ param(element::f32, PartialShape{1, 8, 64}),+ Constant::create(element::f32, Shape{1, 0}, std::vector<float>{}),+ param(element::f32, PartialShape{1, 3, 128}),+ param(element::f32, PartialShape{1, 128}),+ 4);++ EXPECT_EQ(op->get_output_partial_shape(1), (PartialShape{1, 3, 128}));+}++TEST_F(TypePropQSAPrepareTest, multi_dim_empty_k_norm_weight_parameter_is_rejected) {+ // A [1, 0] Parameter is not an empty Constant, so the normalization stays enabled.+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{1, 8, 128}),+ param(element::f32, PartialShape{1, 0, 128}),+ param(element::i32, PartialShape{1}),+ param(element::f32, PartialShape{1, 8, 64}),+ param(element::f32, PartialShape{1, 8, 64}),+ param(element::f32, PartialShape{1, 0}),+ param(element::f32, PartialShape{1, 3, 128}),+ param(element::f32, PartialShape{1, 128}),+ 4),+ NodeValidationFailure,+ HasSubstr("The shape of k_norm_weight must be 1D [Di], or an empty constant"));+}++TEST_F(TypePropQSAPrepareTest, possibly_empty_k_norm_weight_must_match_head_size) {+ // An interval containing 0 is not an empty Constant, so the input is enabled.+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{1, 8, 128}),+ param(element::f32, PartialShape{1, 0, 128}),+ param(element::i32, PartialShape{1}),+ param(element::f32, PartialShape{1, 8, 64}),+ param(element::f32, PartialShape{1, 8, 64}),+ param(element::f32, PartialShape{Dimension(0, 64)}),+ param(element::f32, PartialShape{1, 3, 128}),+ param(element::f32, PartialShape{1, 128}),+ 4),+ NodeValidationFailure,+ HasSubstr("The size of k_norm_weight must be equal to the head size of raw_index_keys."));+}++TEST_F(TypePropQSAPrepareTest, dynamic_rope_must_not_be_mixed_with_a_disabled_state) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{1, 8, 128}),+ param(element::f32, PartialShape{1, 0, 128}),+ param(element::i32, PartialShape{1}),+ param(element::f32, PartialShape{1, 8, -1}),+ param(element::f32, PartialShape{1, 8, -1}),+ param(element::f32, PartialShape{128}),+ param(element::f32, PartialShape{1, 3, 128}),+ disabled(),+ 4),+ NodeValidationFailure,+ HasSubstr("must be empty constants together to disable the rotation."));+}++TEST_F(TypePropQSAPrepareTest, rope_batch_may_broadcast) {+ const auto op = make_op(param(element::f32, PartialShape{2, 8, 128}),+ param(element::f32, PartialShape{2, 0, 128}),+ param(element::i32, PartialShape{2}),+ param(element::f32, PartialShape{1, 8, 64}),+ param(element::f32, PartialShape{1, 8, 64}),+ param(element::f32, PartialShape{128}),+ param(element::f32, PartialShape{2, 3, 128}),+ param(element::f32, PartialShape{2, 128}),+ 4);++ EXPECT_EQ(op->get_output_partial_shape(1), (PartialShape{2, 3, 128}));+}++TEST_F(TypePropQSAPrepareTest, incorrect_rope_batch) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{2, 8, 128}),+ param(element::f32, PartialShape{2, 0, 128}),+ param(element::i32, PartialShape{2}),+ param(element::f32, PartialShape{3, 8, 64}),+ param(element::f32, PartialShape{3, 8, 64}),+ param(element::f32, PartialShape{128}),+ param(element::f32, PartialShape{2, 3, 128}),+ param(element::f32, PartialShape{2, 128}),+ 4),+ NodeValidationFailure,+ HasSubstr("The batch dimension of rope_cos must be 1 or the batch of raw_index_keys."));+}++TEST_F(TypePropQSAPrepareTest, odd_number_of_rotated_dimensions) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{1, 8, 128}),+ param(element::f32, PartialShape{1, 0, 128}),+ param(element::i32, PartialShape{1}),+ param(element::f32, PartialShape{1, 8, 65}),+ param(element::f32, PartialShape{1, 8, 65}),+ param(element::f32, PartialShape{128}),+ param(element::f32, PartialShape{1, 3, 128}),+ param(element::f32, PartialShape{1, 130}),+ 4),+ NodeValidationFailure,+ HasSubstr("The number of rotated dimensions must be a positive even integer."));+}++TEST_F(TypePropQSAPrepareTest, zero_rotated_dimensions) {+ // An enabled rotation of zero dimensions would be indistinguishable from a disabled one.+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{1, 8, 128}),+ param(element::f32, PartialShape{1, 0, 128}),+ param(element::i32, PartialShape{1}),+ param(element::f32, PartialShape{1, 8, 0}),+ param(element::f32, PartialShape{1, 8, 0}),+ param(element::f32, PartialShape{128}),+ param(element::f32, PartialShape{1, 3, 128}),+ param(element::f32, PartialShape{1, 0}),+ 4),+ NodeValidationFailure,+ HasSubstr("The number of rotated dimensions must be a positive even integer."));+}++TEST_F(TypePropQSAPrepareTest, too_many_rotated_dimensions) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{1, 8, 128}),+ param(element::f32, PartialShape{1, 0, 128}),+ param(element::i32, PartialShape{1}),+ param(element::f32, PartialShape{1, 8, 256}),+ param(element::f32, PartialShape{1, 8, 256}),+ param(element::f32, PartialShape{128}),+ param(element::f32, PartialShape{1, 3, 128}),+ param(element::f32, PartialShape{1, 512}),+ 4),+ NodeValidationFailure,+ HasSubstr("The number of rotated dimensions must not exceed the head size"));+}++TEST_F(TypePropQSAPrepareTest, incorrect_key_length_size) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{2, 8, 128}),+ param(element::f32, PartialShape{2, 0, 128}),+ Constant::create(element::i32, Shape{3}, {8, 8, 400}),+ param(element::f32, PartialShape{2, 8, 64}),+ param(element::f32, PartialShape{2, 8, 64}),+ param(element::f32, PartialShape{128}),+ param(element::f32, PartialShape{2, 3, 128}),+ param(element::f32, PartialShape{2, 128}),+ 4),+ NodeValidationFailure,+ HasSubstr("The size of key_length must be 1 or the batch of raw_index_keys."));+}++TEST_F(TypePropQSAPrepareTest, dynamic_rank_raw_index_keys) {+ const auto op = make_op(param(element::f32, PartialShape::dynamic()),+ param(element::f32, PartialShape{1, 0, 128}),+ param(element::i32, PartialShape{1}),+ param(element::f32, PartialShape{1, 8, 64}),+ param(element::f32, PartialShape{1, 8, 64}),+ param(element::f32, PartialShape{128}),+ param(element::f32, PartialShape{1, 3, 128}),+ param(element::f32, PartialShape{1, 128}),+ 4);++ // The batch and the head size are still recovered from the other inputs.+ EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{1, -1, 128}));+ EXPECT_EQ(op->get_output_partial_shape(1), (PartialShape{1, 3, 128}));+ EXPECT_EQ(op->get_output_partial_shape(2), (PartialShape{1, 128}));+}++TEST_F(TypePropQSAPrepareTest, symbols_propagation) {+ auto raw_index_keys_shape = PartialShape{-1, 8, -1};+ const auto symbols = set_shape_symbols(raw_index_keys_shape);++ const auto op = make_op(param(element::f32, raw_index_keys_shape),+ param(element::f32, PartialShape{-1, -1, -1}),+ param(element::i32, PartialShape{-1}),+ param(element::f32, PartialShape{-1, 8, 64}),+ param(element::f32, PartialShape{-1, 8, 64}),+ param(element::f32, PartialShape{-1}),+ param(element::f32, PartialShape{-1, 3, -1}),+ param(element::f32, PartialShape{-1, 128}),+ 4);++ EXPECT_THAT(get_shape_symbols(op->get_output_partial_shape(1)),+ testing::ElementsAre(symbols[0], nullptr, symbols[2]));+}++TEST_F(TypePropQSAPrepareTest, incorrect_raw_index_keys_rank) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{8, 128}),+ param(element::f32, PartialShape{1, 0, 128}),+ param(element::i32, PartialShape{1}),+ param(element::f32, PartialShape{1, 8, 64}),+ param(element::f32, PartialShape{1, 8, 64}),+ param(element::f32, PartialShape{128}),+ param(element::f32, PartialShape{1, 3, 128}),+ param(element::f32, PartialShape{1, 128}),+ 4),+ NodeValidationFailure,+ HasSubstr("The shape of raw_index_keys must be 3D [N, L, Di]."));+}++TEST_F(TypePropQSAPrepareTest, head_size_mismatch) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{1, 8, 128}),+ param(element::f32, PartialShape{1, 0, 64}),+ param(element::i32, PartialShape{1}),+ param(element::f32, PartialShape{1, 8, 64}),+ param(element::f32, PartialShape{1, 8, 64}),+ param(element::f32, PartialShape{128}),+ param(element::f32, PartialShape{1, 3, 128}),+ param(element::f32, PartialShape{1, 128}),+ 4),+ NodeValidationFailure,+ HasSubstr("The head size of raw_index_keys and past_block_index_keys must be the same."));+}++TEST_F(TypePropQSAPrepareTest, incorrect_past_incomplete_raw_keys_size) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{1, 8, 128}),+ param(element::f32, PartialShape{1, 0, 128}),+ param(element::i32, PartialShape{1}),+ param(element::f32, PartialShape{1, 8, 64}),+ param(element::f32, PartialShape{1, 8, 64}),+ param(element::f32, PartialShape{128}),+ param(element::f32, PartialShape{1, 4, 128}),+ param(element::f32, PartialShape{1, 128}),+ 4),+ NodeValidationFailure,+ HasSubstr("The second dimension of past_incomplete_raw_keys must be key_block_size - 1"));+}++TEST_F(TypePropQSAPrepareTest, incorrect_past_incomplete_rope_size) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{1, 8, 128}),+ param(element::f32, PartialShape{1, 0, 128}),+ param(element::i32, PartialShape{1}),+ param(element::f32, PartialShape{1, 8, 64}),+ param(element::f32, PartialShape{1, 8, 64}),+ param(element::f32, PartialShape{128}),+ param(element::f32, PartialShape{1, 3, 128}),+ param(element::f32, PartialShape{1, 64}),+ 4),+ NodeValidationFailure,+ HasSubstr("The second dimension of past_incomplete_rope must be 2 * Dr."));+}++TEST_F(TypePropQSAPrepareTest, rope_cos_and_rope_sin_must_be_empty_together) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{1, 8, 128}),+ param(element::f32, PartialShape{1, 0, 128}),+ param(element::i32, PartialShape{1}),+ disabled(),+ param(element::f32, PartialShape{1, 8, 64}),+ param(element::f32, PartialShape{128}),+ param(element::f32, PartialShape{1, 3, 128}),+ disabled(),+ 4),+ NodeValidationFailure,+ HasSubstr("must be empty constants together to disable the rotation."));+}++TEST_F(TypePropQSAPrepareTest, past_incomplete_rope_must_be_empty_with_the_rope_inputs) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{1, 8, 128}),+ param(element::f32, PartialShape{1, 0, 128}),+ param(element::i32, PartialShape{1}),+ disabled(),+ disabled(),+ param(element::f32, PartialShape{128}),+ param(element::f32, PartialShape{1, 3, 128}),+ param(element::f32, PartialShape{1, 128}),+ 4),+ NodeValidationFailure,+ HasSubstr("must be empty constants together to disable the rotation."));+}++TEST_F(TypePropQSAPrepareTest, past_incomplete_rope_must_not_be_empty_with_the_rotation) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{1, 8, 128}),+ param(element::f32, PartialShape{1, 0, 128}),+ param(element::i32, PartialShape{1}),+ param(element::f32, PartialShape{1, 8, 64}),+ param(element::f32, PartialShape{1, 8, 64}),+ param(element::f32, PartialShape{128}),+ param(element::f32, PartialShape{1, 3, 128}),+ disabled(),+ 4),+ NodeValidationFailure,+ HasSubstr("must be empty constants together to disable the rotation."));+}++TEST_F(TypePropQSAPrepareTest, incorrect_data_element_type) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::i32, PartialShape{1, 8, 128}),+ param(element::i32, PartialShape{1, 0, 128}),+ param(element::i32, PartialShape{1}),+ param(element::i32, PartialShape{1, 8, 64}),+ param(element::i32, PartialShape{1, 8, 64}),+ param(element::i32, PartialShape{128}),+ param(element::i32, PartialShape{1, 3, 128}),+ param(element::i32, PartialShape{1, 128}),+ 4),+ NodeValidationFailure,+ HasSubstr("must be a floating point type"));+}++TEST_F(TypePropQSAPrepareTest, mismatched_data_element_types) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{1, 8, 128}),+ param(element::f16, PartialShape{1, 0, 128}),+ param(element::i32, PartialShape{1}),+ param(element::f32, PartialShape{1, 8, 64}),+ param(element::f32, PartialShape{1, 8, 64}),+ param(element::f32, PartialShape{128}),+ param(element::f32, PartialShape{1, 3, 128}),+ param(element::f32, PartialShape{1, 128}),+ 4),+ NodeValidationFailure,+ HasSubstr("The element type of past_block_index_keys must be the same as of raw_index_keys."));+}++TEST_F(TypePropQSAPrepareTest, incorrect_key_length_element_type) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{1, 8, 128}),+ param(element::f32, PartialShape{1, 0, 128}),+ param(element::f32, PartialShape{1}),+ param(element::f32, PartialShape{1, 8, 64}),+ param(element::f32, PartialShape{1, 8, 64}),+ param(element::f32, PartialShape{128}),+ param(element::f32, PartialShape{1, 3, 128}),+ param(element::f32, PartialShape{1, 128}),+ 4),+ NodeValidationFailure,+ HasSubstr("The element type of key_length must be i32 or i64."));+}++TEST_F(TypePropQSAPrepareTest, single_token_blocks_are_rejected) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{1, 8, 128}),+ param(element::f32, PartialShape{1, 0, 128}),+ param(element::i32, PartialShape{1}),+ param(element::f32, PartialShape{1, 8, 64}),+ param(element::f32, PartialShape{1, 8, 64}),+ param(element::f32, PartialShape{128}),+ param(element::f32, PartialShape{1, 0, 128}),+ param(element::f32, PartialShape{1, 128}),+ 1),+ NodeValidationFailure,+ HasSubstr("The attribute key_block_size must be an integer greater than 1."));+}++TEST_F(TypePropQSAPrepareTest, incorrect_epsilon) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{1, 8, 128}),+ param(element::f32, PartialShape{1, 0, 128}),+ param(element::i32, PartialShape{1}),+ param(element::f32, PartialShape{1, 8, 64}),+ param(element::f32, PartialShape{1, 8, 64}),+ param(element::f32, PartialShape{128}),+ param(element::f32, PartialShape{1, 3, 128}),+ param(element::f32, PartialShape{1, 128}),+ 4,+ 0.0f),+ NodeValidationFailure,+ HasSubstr("The attribute epsilon must be a positive floating point number."));+}+} // namespace ov::testdiff --git a/src/core/tests/type_prop/sources.cmake b/src/core/tests/type_prop/sources.cmakeindex 7585d2596bd..f46e27b0cca 100644--- a/src/core/tests/type_prop/sources.cmake+++ b/src/core/tests/type_prop/sources.cmake@@ -148,6 +148,7 @@ set(OV_CORE_TESTS_TYPE_PROP_SRCS${CMAKE_CURRENT_LIST_DIR}/prior_box_clustered.cpp${CMAKE_CURRENT_LIST_DIR}/proposal.cpp${CMAKE_CURRENT_LIST_DIR}/psroi_pooling.cpp+ ${CMAKE_CURRENT_LIST_DIR}/qsa_prepare.cpp${CMAKE_CURRENT_LIST_DIR}/random_uniform.cpp${CMAKE_CURRENT_LIST_DIR}/range.cpp${CMAKE_CURRENT_LIST_DIR}/rdft.cpp@@ -199,6 +200,8 @@ set(OV_CORE_TESTS_TYPE_PROP_SRCS${CMAKE_CURRENT_LIST_DIR}/softsign.cpp${CMAKE_CURRENT_LIST_DIR}/space_to_batch.cpp${CMAKE_CURRENT_LIST_DIR}/space_to_depth.cpp+ ${CMAKE_CURRENT_LIST_DIR}/sparse_attention.cpp+ ${CMAKE_CURRENT_LIST_DIR}/sparse_attention_indexer.cpp${CMAKE_CURRENT_LIST_DIR}/sparse_fill_empty_rows.cpp${CMAKE_CURRENT_LIST_DIR}/split.cpp${CMAKE_CURRENT_LIST_DIR}/sqrt.cppdiff --git a/src/core/tests/type_prop/sparse_attention.cpp b/src/core/tests/type_prop/sparse_attention.cppnew file mode 100644index 00000000000..a4a6f75be8a--- /dev/null+++ b/src/core/tests/type_prop/sparse_attention.cpp@@ -0,0 +1,458 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "openvino/op/sparse_attention.hpp"++#include <gtest/gtest.h>++#include <limits>++#include "common_test_utils/test_assertions.hpp"+#include "common_test_utils/type_prop.hpp"+#include "openvino/op/constant.hpp"++namespace ov::test {+using op::v0::Constant, op::v0::Parameter;+using testing::HasSubstr;++class TypePropSparseAttentionTest : public TypePropOpTest<op::v17::SparseAttention> {+protected:+ static std::shared_ptr<Parameter> param(element::Type et, const PartialShape& shape) {+ return std::make_shared<Parameter>(et, shape);+ }+};++TEST_F(TypePropSparseAttentionTest, default_ctor) {+ const auto op = make_op();+ op->set_key_block_size(4);+ op->set_arguments(OutputVector{param(element::f32, PartialShape{2, 24, 5, 64}),+ param(element::f32, PartialShape{2, 2, 12, 64}),+ param(element::f32, PartialShape{2, 2, 12, 32}),+ param(element::i32, PartialShape{2, 1, 5, 4}),+ param(element::i32, PartialShape{2, 1, 5})});+ op->validate_and_infer_types();++ EXPECT_EQ(op->get_input_size(), 5);+ EXPECT_EQ(op->get_output_size(), 1);+ EXPECT_EQ(op->get_output_element_type(0), element::f32);+ EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{2, 24, 5, 32}));+}++TEST_F(TypePropSparseAttentionTest, static_shapes) {+ const auto op = make_op(param(element::f32, PartialShape{2, 24, 5, 64}),+ param(element::f32, PartialShape{2, 2, 12, 64}),+ param(element::f32, PartialShape{2, 2, 12, 32}),+ param(element::i32, PartialShape{2, 1, 5, 4}),+ param(element::i32, PartialShape{2, 1, 5}),+ 4);++ EXPECT_EQ(op->get_key_block_size(), 4);+ EXPECT_EQ(op->get_query_block_size(), 1);+ EXPECT_TRUE(op->get_causal());+ EXPECT_EQ(op->get_output_element_type(0), element::f32);+ EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{2, 24, 5, 32}));+}++TEST_F(TypePropSparseAttentionTest, with_key_length_and_scale) {+ const auto op = make_op(param(element::f16, PartialShape{2, 24, 1, 64}),+ param(element::f16, PartialShape{2, 2, 12, 64}),+ param(element::f16, PartialShape{2, 2, 12, 32}),+ param(element::i64, PartialShape{2, 1, 1, 4}),+ param(element::i64, PartialShape{2, 1, 1}),+ param(element::i64, PartialShape{2}),+ param(element::f16, PartialShape{}),+ 4);++ EXPECT_EQ(op->get_input_size(), 7);+ EXPECT_EQ(op->get_output_element_type(0), element::f16);+ EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{2, 24, 1, 32}));+}++TEST_F(TypePropSparseAttentionTest, with_sinks) {+ const auto op = make_op(param(element::f16, PartialShape{2, 24, 1, 64}),+ param(element::f16, PartialShape{2, 2, 12, 64}),+ param(element::f16, PartialShape{2, 2, 12, 32}),+ param(element::i64, PartialShape{2, 1, 1, 4}),+ param(element::i64, PartialShape{2, 1, 1}),+ param(element::i64, PartialShape{2}),+ param(element::f16, PartialShape{}),+ param(element::f32, PartialShape{24}),+ 4);++ EXPECT_EQ(op->get_input_size(), 8);+ EXPECT_EQ(op->get_output_element_type(0), element::f16);+ EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{2, 24, 1, 32}));+}++TEST_F(TypePropSparseAttentionTest, sinks_count_mismatch) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{2, 24, 5, 64}),+ param(element::f32, PartialShape{2, 2, 12, 64}),+ param(element::f32, PartialShape{2, 2, 12, 32}),+ param(element::i32, PartialShape{2, 1, 5, 4}),+ param(element::i32, PartialShape{2, 1, 5}),+ param(element::i32, PartialShape{2}),+ param(element::f32, PartialShape{}),+ param(element::f32, PartialShape{12}),+ 4),+ NodeValidationFailure,+ HasSubstr("The number of sinks must be equal to the number of query heads."));+}++TEST_F(TypePropSparseAttentionTest, incorrect_sinks_rank) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{2, 24, 5, 64}),+ param(element::f32, PartialShape{2, 2, 12, 64}),+ param(element::f32, PartialShape{2, 2, 12, 32}),+ param(element::i32, PartialShape{2, 1, 5, 4}),+ param(element::i32, PartialShape{2, 1, 5}),+ param(element::i32, PartialShape{2}),+ param(element::f32, PartialShape{}),+ param(element::f32, PartialShape{1, 24}),+ 4),+ NodeValidationFailure,+ HasSubstr("The shape of sinks must be 1D [H]."));+}++TEST_F(TypePropSparseAttentionTest, incorrect_sinks_element_type) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{2, 24, 5, 64}),+ param(element::f32, PartialShape{2, 2, 12, 64}),+ param(element::f32, PartialShape{2, 2, 12, 32}),+ param(element::i32, PartialShape{2, 1, 5, 4}),+ param(element::i32, PartialShape{2, 1, 5}),+ param(element::i32, PartialShape{2}),+ param(element::f32, PartialShape{}),+ param(element::i32, PartialShape{24}),+ 4),+ NodeValidationFailure,+ HasSubstr("The element type of sinks must be a floating point type."));+}++TEST_F(TypePropSparseAttentionTest, query_block_size_groups_query_tokens) {+ const auto op = make_op(param(element::f32, PartialShape{1, 12, 8448, 128}),+ param(element::f32, PartialShape{1, 12, 33792, 128}),+ param(element::f32, PartialShape{1, 12, 33792, 128}),+ param(element::i32, PartialShape{1, 12, 66, 264}),+ param(element::i32, PartialShape{1, 12, 66}),+ 128,+ 128,+ false);++ EXPECT_EQ(op->get_query_block_size(), 128);+ EXPECT_FALSE(op->get_causal());+ EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{1, 12, 8448, 128}));+}++TEST_F(TypePropSparseAttentionTest, dynamic_dimensions_are_merged) {+ const auto op = make_op(param(element::f32, PartialShape{-1, 24, -1, 64}),+ param(element::f32, PartialShape{2, 2, -1, -1}),+ param(element::f32, PartialShape{-1, -1, 12, 32}),+ param(element::i32, PartialShape{-1, 1, -1, 4}),+ param(element::i32, PartialShape{-1, -1, -1}),+ 4);++ EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{2, 24, -1, 32}));+}++TEST_F(TypePropSparseAttentionTest, interval_dimensions) {+ const auto op = make_op(param(element::f32, PartialShape{Dimension(1, 4), 24, Dimension(2, 8), 64}),+ param(element::f32, PartialShape{Dimension(2, 6), 2, 12, 64}),+ param(element::f32, PartialShape{-1, 2, 12, Dimension(16, 32)}),+ param(element::i32, PartialShape{-1, 1, -1, 4}),+ param(element::i32, PartialShape{-1, 1, -1}),+ 4);++ EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{Dimension(2, 4), 24, Dimension(2, 8), Dimension(16, 32)}));+}++TEST_F(TypePropSparseAttentionTest, dynamic_rank_query) {+ const auto op = make_op(param(element::f32, PartialShape::dynamic()),+ param(element::f32, PartialShape{2, 2, 12, 64}),+ param(element::f32, PartialShape{2, 2, 12, 32}),+ param(element::i32, PartialShape{2, 1, 5, 4}),+ param(element::i32, PartialShape{2, 1, 5}),+ 4);++ EXPECT_EQ(op->get_output_partial_shape(0), PartialShape::dynamic());+}++TEST_F(TypePropSparseAttentionTest, dynamic_element_type) {+ const auto op = make_op(param(element::dynamic, PartialShape{2, 24, 5, 64}),+ param(element::f32, PartialShape{2, 2, 12, 64}),+ param(element::f32, PartialShape{2, 2, 12, 32}),+ param(element::i32, PartialShape{2, 1, 5, 4}),+ param(element::i32, PartialShape{2, 1, 5}),+ 4);++ EXPECT_EQ(op->get_output_element_type(0), element::f32);+}++TEST_F(TypePropSparseAttentionTest, integer_scale_with_dynamic_data_types) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::dynamic, PartialShape{2, 24, 1, 64}),+ param(element::dynamic, PartialShape{2, 2, 12, 64}),+ param(element::dynamic, PartialShape{2, 2, 12, 32}),+ param(element::i64, PartialShape{2, 1, 1, 4}),+ param(element::i64, PartialShape{2, 1, 1}),+ param(element::i64, PartialShape{2}),+ param(element::i32, PartialShape{}),+ 4),+ NodeValidationFailure,+ HasSubstr("The element type of scale must be a floating point type"));+}++TEST_F(TypePropSparseAttentionTest, largest_query_block_size_needs_one_query_row) {+ // ceil(L / query_block_size) must not overflow for an extreme block size.+ const auto op = make_op(param(element::f32, PartialShape{1, 24, 8, 64}),+ param(element::f32, PartialShape{1, 2, 8, 64}),+ param(element::f32, PartialShape{1, 2, 8, 32}),+ param(element::i32, PartialShape{1, 1, 1, 4}),+ param(element::i32, PartialShape{1, 1, 1}),+ 4,+ std::numeric_limits<int64_t>::max());++ EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{1, 24, 8, 32}));+}++TEST_F(TypePropSparseAttentionTest, batch_mismatch_with_dynamic_rank_query) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape::dynamic()),+ param(element::f32, PartialShape{2, 2, 12, 64}),+ param(element::f32, PartialShape{3, 2, 12, 32}),+ param(element::i32, PartialShape{2, 1, 5, 4}),+ param(element::i32, PartialShape{2, 1, 5}),+ 4),+ NodeValidationFailure,+ HasSubstr("The batch dimension of all the inputs must be the same."));+}++TEST_F(TypePropSparseAttentionTest, key_length_value_exceeding_key_positions) {+ const auto key_length = Constant::create(element::i64, Shape{2}, {12, 13});+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f16, PartialShape{2, 24, 1, 64}),+ param(element::f16, PartialShape{2, 2, 12, 64}),+ param(element::f16, PartialShape{2, 2, 12, 32}),+ param(element::i64, PartialShape{2, 1, 1, 4}),+ param(element::i64, PartialShape{2, 1, 1}),+ key_length,+ 4),+ NodeValidationFailure,+ HasSubstr("The key_length values must be in [0, S], S = 12"));+}++TEST_F(TypePropSparseAttentionTest, incorrect_key_length_size) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f16, PartialShape{2, 24, 1, 64}),+ param(element::f16, PartialShape{2, 2, 12, 64}),+ param(element::f16, PartialShape{2, 2, 12, 32}),+ param(element::i64, PartialShape{2, 1, 1, 4}),+ param(element::i64, PartialShape{2, 1, 1}),+ param(element::i64, PartialShape{3}),+ 4),+ NodeValidationFailure,+ HasSubstr("The size of key_length must be 1 or the batch dimension of the other inputs."));+}++TEST_F(TypePropSparseAttentionTest, single_element_key_length_applies_to_all_sequences) {+ const auto op = make_op(param(element::f16, PartialShape{2, 24, 1, 64}),+ param(element::f16, PartialShape{2, 2, 12, 64}),+ param(element::f16, PartialShape{2, 2, 12, 32}),+ param(element::i64, PartialShape{2, 1, 1, 4}),+ param(element::i64, PartialShape{2, 1, 1}),+ param(element::i64, PartialShape{1}),+ 4);++ EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{2, 24, 1, 32}));+}++TEST_F(TypePropSparseAttentionTest, zero_selection_heads) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{2, 24, 5, 64}),+ param(element::f32, PartialShape{2, 2, 12, 64}),+ param(element::f32, PartialShape{2, 2, 12, 32}),+ param(element::i32, PartialShape{2, 0, 5, 4}),+ param(element::i32, PartialShape{2, 0, 5}),+ 4),+ NodeValidationFailure,+ HasSubstr("The number of selection heads must be a positive integer."));+}++TEST_F(TypePropSparseAttentionTest, zero_key_heads) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{2, 24, 5, 64}),+ param(element::f32, PartialShape{2, 0, 12, 64}),+ param(element::f32, PartialShape{2, 0, 12, 32}),+ param(element::i32, PartialShape{2, 1, 5, 4}),+ param(element::i32, PartialShape{2, 1, 5}),+ 4),+ NodeValidationFailure,+ HasSubstr("The number of key and value heads must be a positive integer."));+}++TEST_F(TypePropSparseAttentionTest, selection_heads_taken_from_block_count) {+ // Hs is dynamic in block_indices, so the divisibility is checked against the merged dimension.+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{2, 24, 5, 64}),+ param(element::f32, PartialShape{2, 2, 12, 64}),+ param(element::f32, PartialShape{2, 2, 12, 32}),+ param(element::i32, PartialShape{2, -1, 5, 4}),+ param(element::i32, PartialShape{2, 5, 5}),+ 4),+ NodeValidationFailure,+ HasSubstr("The number of query heads must be divisible by the number of selection heads."));+}++TEST_F(TypePropSparseAttentionTest, selection_heads_taken_from_block_count_with_dynamic_rank_block_indices) {+ // block_count is the only source of the selection head count.+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{2, 24, 5, 64}),+ param(element::f32, PartialShape{2, 2, 12, 64}),+ param(element::f32, PartialShape{2, 2, 12, 32}),+ param(element::i32, PartialShape::dynamic()),+ param(element::i32, PartialShape{2, 5, 5}),+ 4),+ NodeValidationFailure,+ HasSubstr("The number of query heads must be divisible by the number of selection heads."));+}++TEST_F(TypePropSparseAttentionTest, symbols_propagation) {+ auto query_shape = PartialShape{-1, -1, -1, 64};+ auto value_shape = PartialShape{-1, 2, 12, -1};+ auto query_symbols = set_shape_symbols(query_shape);+ auto value_symbols = set_shape_symbols(value_shape);++ const auto op = make_op(param(element::f32, query_shape),+ param(element::f32, PartialShape{-1, 2, 12, 64}),+ param(element::f32, value_shape),+ param(element::i32, PartialShape{-1, 1, -1, 4}),+ param(element::i32, PartialShape{-1, 1, -1}),+ 4);++ EXPECT_THAT(get_shape_symbols(op->get_output_partial_shape(0)),+ testing::ElementsAre(query_symbols[0], query_symbols[1], query_symbols[2], value_symbols[3]));+}++TEST_F(TypePropSparseAttentionTest, incorrect_query_rank) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{24, 5, 64}),+ param(element::f32, PartialShape{2, 2, 12, 64}),+ param(element::f32, PartialShape{2, 2, 12, 32}),+ param(element::i32, PartialShape{2, 1, 5, 4}),+ param(element::i32, PartialShape{2, 1, 5}),+ 4),+ NodeValidationFailure,+ HasSubstr("The shape of query must be 4D [N, H, L, E]."));+}++TEST_F(TypePropSparseAttentionTest, incorrect_block_count_rank) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{2, 24, 5, 64}),+ param(element::f32, PartialShape{2, 2, 12, 64}),+ param(element::f32, PartialShape{2, 2, 12, 32}),+ param(element::i32, PartialShape{2, 1, 5, 4}),+ param(element::i32, PartialShape{2, 1, 5, 4}),+ 4),+ NodeValidationFailure,+ HasSubstr("The shape of block_count must be 3D [N, Hs, Lq]."));+}++TEST_F(TypePropSparseAttentionTest, batch_mismatch) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{2, 24, 5, 64}),+ param(element::f32, PartialShape{3, 2, 12, 64}),+ param(element::f32, PartialShape{3, 2, 12, 32}),+ param(element::i32, PartialShape{2, 1, 5, 4}),+ param(element::i32, PartialShape{2, 1, 5}),+ 4),+ NodeValidationFailure,+ HasSubstr("The batch dimension of all the inputs must be the same."));+}++TEST_F(TypePropSparseAttentionTest, head_size_mismatch) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{2, 24, 5, 64}),+ param(element::f32, PartialShape{2, 2, 12, 32}),+ param(element::f32, PartialShape{2, 2, 12, 32}),+ param(element::i32, PartialShape{2, 1, 5, 4}),+ param(element::i32, PartialShape{2, 1, 5}),+ 4),+ NodeValidationFailure,+ HasSubstr("The head size of query and key must be the same."));+}++TEST_F(TypePropSparseAttentionTest, query_heads_not_divisible_by_key_heads) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{2, 25, 5, 64}),+ param(element::f32, PartialShape{2, 2, 12, 64}),+ param(element::f32, PartialShape{2, 2, 12, 32}),+ param(element::i32, PartialShape{2, 1, 5, 4}),+ param(element::i32, PartialShape{2, 1, 5}),+ 4),+ NodeValidationFailure,+ HasSubstr("The number of query heads must be divisible by the number of key heads."));+}++TEST_F(TypePropSparseAttentionTest, query_heads_not_divisible_by_selection_heads) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{2, 24, 5, 64}),+ param(element::f32, PartialShape{2, 2, 12, 64}),+ param(element::f32, PartialShape{2, 2, 12, 32}),+ param(element::i32, PartialShape{2, 5, 5, 4}),+ param(element::i32, PartialShape{2, 5, 5}),+ 4),+ NodeValidationFailure,+ HasSubstr("The number of query heads must be divisible by the number of selection heads."));+}++TEST_F(TypePropSparseAttentionTest, incorrect_number_of_query_rows) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{2, 24, 8, 64}),+ param(element::f32, PartialShape{2, 2, 12, 64}),+ param(element::f32, PartialShape{2, 2, 12, 32}),+ param(element::i32, PartialShape{2, 1, 8, 4}),+ param(element::i32, PartialShape{2, 1, 8}),+ 4,+ 4),+ NodeValidationFailure,+ HasSubstr("The number of query rows must be ceil(L / query_block_size)"));+}++TEST_F(TypePropSparseAttentionTest, more_queries_than_keys_in_causal_mode) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{2, 24, 16, 64}),+ param(element::f32, PartialShape{2, 2, 12, 64}),+ param(element::f32, PartialShape{2, 2, 12, 32}),+ param(element::i32, PartialShape{2, 1, 16, 4}),+ param(element::i32, PartialShape{2, 1, 16}),+ 4),+ NodeValidationFailure,+ HasSubstr("In the causal mode the number of query tokens must not exceed"));+}++TEST_F(TypePropSparseAttentionTest, incorrect_data_element_type) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::i32, PartialShape{2, 24, 5, 64}),+ param(element::i32, PartialShape{2, 2, 12, 64}),+ param(element::i32, PartialShape{2, 2, 12, 32}),+ param(element::i32, PartialShape{2, 1, 5, 4}),+ param(element::i32, PartialShape{2, 1, 5}),+ 4),+ NodeValidationFailure,+ HasSubstr("must be a floating point type"));+}++TEST_F(TypePropSparseAttentionTest, mismatched_data_element_types) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{2, 24, 5, 64}),+ param(element::f16, PartialShape{2, 2, 12, 64}),+ param(element::f32, PartialShape{2, 2, 12, 32}),+ param(element::i32, PartialShape{2, 1, 5, 4}),+ param(element::i32, PartialShape{2, 1, 5}),+ 4),+ NodeValidationFailure,+ HasSubstr("The element types of query, key and value must be the same."));+}++TEST_F(TypePropSparseAttentionTest, incorrect_block_indices_element_type) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{2, 24, 5, 64}),+ param(element::f32, PartialShape{2, 2, 12, 64}),+ param(element::f32, PartialShape{2, 2, 12, 32}),+ param(element::f32, PartialShape{2, 1, 5, 4}),+ param(element::i32, PartialShape{2, 1, 5}),+ 4),+ NodeValidationFailure,+ HasSubstr("The element type of block_indices must be i32 or i64."));+}++TEST_F(TypePropSparseAttentionTest, incorrect_key_block_size) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{2, 24, 5, 64}),+ param(element::f32, PartialShape{2, 2, 12, 64}),+ param(element::f32, PartialShape{2, 2, 12, 32}),+ param(element::i32, PartialShape{2, 1, 5, 4}),+ param(element::i32, PartialShape{2, 1, 5}),+ 0),+ NodeValidationFailure,+ HasSubstr("The attribute key_block_size must be a positive integer."));+}+} // namespace ov::testdiff --git a/src/core/tests/type_prop/sparse_attention_indexer.cpp b/src/core/tests/type_prop/sparse_attention_indexer.cppnew file mode 100644index 00000000000..79525788256--- /dev/null+++ b/src/core/tests/type_prop/sparse_attention_indexer.cpp@@ -0,0 +1,334 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "openvino/op/sparse_attention_indexer.hpp"++#include <gtest/gtest.h>++#include "common_test_utils/test_assertions.hpp"+#include "common_test_utils/type_prop.hpp"++namespace ov::test {+using op::v0::Parameter;+using testing::HasSubstr;++class TypePropSparseAttentionIndexerTest : public TypePropOpTest<op::v17::SparseAttentionIndexer> {+protected:+ static std::shared_ptr<Parameter> param(element::Type et, const PartialShape& shape) {+ return std::make_shared<Parameter>(et, shape);+ }+};++TEST_F(TypePropSparseAttentionIndexerTest, default_ctor) {+ const auto op = make_op();+ op->set_key_block_size(4);+ op->set_token_budget(2048);+ op->set_arguments(OutputVector{param(element::f32, PartialShape{1, 4, 7, 128}),+ param(element::f32, PartialShape{1, 2500, 128}),+ param(element::i64, PartialShape{1})});+ op->validate_and_infer_types();++ EXPECT_EQ(op->get_input_size(), 3);+ EXPECT_EQ(op->get_output_size(), 2);+ EXPECT_EQ(op->get_output_element_type(0), element::i32);+ EXPECT_EQ(op->get_output_element_type(1), element::i32);+ EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{1, 1, 7, 512}));+ EXPECT_EQ(op->get_output_partial_shape(1), (PartialShape{1, 1, 7}));+}++TEST_F(TypePropSparseAttentionIndexerTest, static_shapes) {+ const auto op = make_op(param(element::f32, PartialShape{2, 4, 7, 128}),+ param(element::f32, PartialShape{2, 2500, 128}),+ param(element::i32, PartialShape{2}),+ 4,+ 2048);++ EXPECT_EQ(op->get_key_block_size(), 4);+ EXPECT_EQ(op->get_token_budget(), 2048);+ EXPECT_EQ(op->get_num_selection_heads(), 1);+ EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{2, 1, 7, 512}));+ EXPECT_EQ(op->get_output_partial_shape(1), (PartialShape{2, 1, 7}));+}++TEST_F(TypePropSparseAttentionIndexerTest, batch_mismatch_with_dynamic_rank_index_query) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape::dynamic()),+ param(element::f32, PartialShape{2, 2500, 128}),+ param(element::i32, PartialShape{2}),+ param(element::f32, PartialShape{3, 7, 4}),+ 4,+ 2048),+ NodeValidationFailure,+ HasSubstr("The batch dimension of index_query, block_index_keys and index_weights "+ "must be compatible."));+}++TEST_F(TypePropSparseAttentionIndexerTest, key_length_size_checked_against_block_index_keys) {+ // The batch is known from block_index_keys even though index_query has a dynamic rank.+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape::dynamic()),+ param(element::f32, PartialShape{2, 16, 128}),+ param(element::i32, PartialShape{3}),+ 4,+ 2048),+ NodeValidationFailure,+ HasSubstr("The size of key_length must be 1 or the batch dimension of index_query."));+}++TEST_F(TypePropSparseAttentionIndexerTest, incorrect_key_length_size) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{2, 4, 7, 128}),+ param(element::f32, PartialShape{2, 2500, 128}),+ param(element::i32, PartialShape{3}),+ 4,+ 2048),+ NodeValidationFailure,+ HasSubstr("The size of key_length must be 1 or the batch dimension of index_query."));+}++TEST_F(TypePropSparseAttentionIndexerTest, single_element_key_length_applies_to_all_sequences) {+ const auto op = make_op(param(element::f32, PartialShape{2, 4, 7, 128}),+ param(element::f32, PartialShape{2, 2500, 128}),+ param(element::i32, PartialShape{1}),+ 4,+ 2048);++ EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{2, 1, 7, 512}));+}++TEST_F(TypePropSparseAttentionIndexerTest, with_index_weights) {+ const auto op = make_op(param(element::f16, PartialShape{1, 64, 1, 128}),+ param(element::f16, PartialShape{1, 10001, 128}),+ param(element::i32, PartialShape{1}),+ param(element::f16, PartialShape{1, 1, 64}),+ 1,+ 2048);++ EXPECT_EQ(op->get_input_size(), 4);+ EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{1, 1, 1, 2048}));+ EXPECT_EQ(op->get_output_partial_shape(1), (PartialShape{1, 1, 1}));+}++TEST_F(TypePropSparseAttentionIndexerTest, multiple_selection_heads) {+ const auto op = make_op(param(element::f32, PartialShape{1, 8, 7, 128}),+ param(element::f32, PartialShape{1, 100, 128}),+ param(element::i32, PartialShape{1}),+ 4,+ 64,+ 2);++ EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{1, 2, 7, 16}));+ EXPECT_EQ(op->get_output_partial_shape(1), (PartialShape{1, 2, 7}));+}++TEST_F(TypePropSparseAttentionIndexerTest, dynamic_dimensions_are_merged) {+ const auto op = make_op(param(element::f32, PartialShape{-1, 4, -1, 128}),+ param(element::f32, PartialShape{2, -1, -1}),+ param(element::i32, PartialShape{-1}),+ 4,+ 2048);++ EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{2, 1, -1, 512}));+ EXPECT_EQ(op->get_output_partial_shape(1), (PartialShape{2, 1, -1}));+}++TEST_F(TypePropSparseAttentionIndexerTest, interval_dimensions) {+ const auto op = make_op(param(element::f32, PartialShape{Dimension(1, 4), 4, Dimension(2, 8), 128}),+ param(element::f32, PartialShape{Dimension(2, 6), -1, 128}),+ param(element::i32, PartialShape{-1}),+ 4,+ 2048);++ EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{Dimension(2, 4), 1, Dimension(2, 8), 512}));+ EXPECT_EQ(op->get_output_partial_shape(1), (PartialShape{Dimension(2, 4), 1, Dimension(2, 8)}));+}++TEST_F(TypePropSparseAttentionIndexerTest, dynamic_rank_index_query) {+ // The batch is still known, from block_index_keys, which does not broadcast.+ const auto op = make_op(param(element::f32, PartialShape::dynamic()),+ param(element::f32, PartialShape{2, 2500, 128}),+ param(element::i32, PartialShape{2}),+ 4,+ 2048);++ EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{2, 1, -1, 512}));+ EXPECT_EQ(op->get_output_partial_shape(1), (PartialShape{2, 1, -1}));+}++TEST_F(TypePropSparseAttentionIndexerTest, size_one_batch_resolves_dynamic_batch) {+ // Batch dimension is defined as 1 based on the second input - no broadcast.+ const auto op = make_op(param(element::f32, PartialShape{-1, 4, 7, 128}),+ param(element::f32, PartialShape{1, 2500, 128}),+ param(element::i32, PartialShape{1}),+ 4,+ 2048);++ EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{1, 1, 7, 512}));+ EXPECT_EQ(op->get_output_partial_shape(1), (PartialShape{1, 1, 7}));+}++TEST_F(TypePropSparseAttentionIndexerTest, size_one_batch_against_static_batch) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{4, 4, 7, 128}),+ param(element::f32, PartialShape{1, 2500, 128}),+ param(element::i32, PartialShape{4}),+ 4,+ 2048),+ NodeValidationFailure,+ HasSubstr("The batch dimension of index_query and block_index_keys must be the same."));+}++TEST_F(TypePropSparseAttentionIndexerTest, all_dynamic_batch) {+ const auto op = make_op(param(element::f32, PartialShape{-1, 4, -1, 128}),+ param(element::f32, PartialShape{-1, -1, 128}),+ param(element::i32, PartialShape{-1}),+ param(element::f32, PartialShape{-1, -1, 4}),+ 4,+ 2048);++ EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{-1, 1, -1, 512}));+ EXPECT_EQ(op->get_output_partial_shape(1), (PartialShape{-1, 1, -1}));+}++TEST_F(TypePropSparseAttentionIndexerTest, interval_dimensions_with_index_weights) {+ const auto op = make_op(param(element::f32, PartialShape{Dimension(1, 4), 4, Dimension(2, 8), 128}),+ param(element::f32, PartialShape{Dimension(2, 6), -1, 128}),+ param(element::i32, PartialShape{-1}),+ param(element::f32, PartialShape{Dimension(3, 10), Dimension(4, 16), 4}),+ 4,+ 2048);++ EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{Dimension(3, 4), 1, Dimension(4, 8), 512}));+ EXPECT_EQ(op->get_output_partial_shape(1), (PartialShape{Dimension(3, 4), 1, Dimension(4, 8)}));+}++TEST_F(TypePropSparseAttentionIndexerTest, dynamic_rank_index_query_with_index_weights) {+ // index_weights is the only source of the query token count once index_query has a dynamic rank.+ const auto op = make_op(param(element::f32, PartialShape::dynamic()),+ param(element::f32, PartialShape{2, 2500, 128}),+ param(element::i32, PartialShape{2}),+ param(element::f32, PartialShape{2, 7, 4}),+ 4,+ 2048);++ EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{2, 1, 7, 512}));+ EXPECT_EQ(op->get_output_partial_shape(1), (PartialShape{2, 1, 7}));+}++TEST_F(TypePropSparseAttentionIndexerTest, index_heads_taken_from_index_weights) {+ // index_weights is the only source of the index head count once index_query has a dynamic rank.+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape::dynamic()),+ param(element::f32, PartialShape{2, 2500, 128}),+ param(element::i32, PartialShape{2}),+ param(element::f32, PartialShape{2, 7, 5}),+ 4,+ 2048,+ 2),+ NodeValidationFailure,+ HasSubstr("The number of index query heads must be divisible by num_selection_heads."));+}++TEST_F(TypePropSparseAttentionIndexerTest, symbols_propagation) {+ auto index_query_shape = PartialShape{-1, 4, -1, 128};+ auto index_query_symbols = set_shape_symbols(index_query_shape);++ const auto op = make_op(param(element::f32, index_query_shape),+ param(element::f32, PartialShape{-1, -1, 128}),+ param(element::i32, PartialShape{-1}),+ 4,+ 2048);++ EXPECT_THAT(get_shape_symbols(op->get_output_partial_shape(1)),+ testing::ElementsAre(index_query_symbols[0], nullptr, index_query_symbols[2]));+}++TEST_F(TypePropSparseAttentionIndexerTest, incorrect_index_query_rank) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{4, 7, 128}),+ param(element::f32, PartialShape{1, 2500, 128}),+ param(element::i32, PartialShape{1}),+ 4,+ 2048),+ NodeValidationFailure,+ HasSubstr("The shape of index_query must be 4D [N, Hi, L, Di]."));+}++TEST_F(TypePropSparseAttentionIndexerTest, incorrect_block_index_keys_rank) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{1, 4, 7, 128}),+ param(element::f32, PartialShape{1, 1, 2500, 128}),+ param(element::i32, PartialShape{1}),+ 4,+ 2048),+ NodeValidationFailure,+ HasSubstr("The shape of block_index_keys must be 3D [N, B, Di]."));+}++TEST_F(TypePropSparseAttentionIndexerTest, head_size_mismatch) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{1, 4, 7, 128}),+ param(element::f32, PartialShape{1, 2500, 64}),+ param(element::i32, PartialShape{1}),+ 4,+ 2048),+ NodeValidationFailure,+ HasSubstr("The head size of index_query and block_index_keys must be the same."));+}++TEST_F(TypePropSparseAttentionIndexerTest, index_weights_heads_mismatch) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{1, 4, 7, 128}),+ param(element::f32, PartialShape{1, 2500, 128}),+ param(element::i32, PartialShape{1}),+ param(element::f32, PartialShape{1, 7, 8}),+ 4,+ 2048),+ NodeValidationFailure,+ HasSubstr("The number of index query heads of index_query and index_weights must be the same."));+}++TEST_F(TypePropSparseAttentionIndexerTest, index_query_heads_not_divisible_by_selection_heads) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{1, 5, 7, 128}),+ param(element::f32, PartialShape{1, 2500, 128}),+ param(element::i32, PartialShape{1}),+ 4,+ 2048,+ 2),+ NodeValidationFailure,+ HasSubstr("The number of index query heads must be divisible by num_selection_heads."));+}++TEST_F(TypePropSparseAttentionIndexerTest, incorrect_data_element_type) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::i32, PartialShape{1, 4, 7, 128}),+ param(element::i32, PartialShape{1, 2500, 128}),+ param(element::i32, PartialShape{1}),+ 4,+ 2048),+ NodeValidationFailure,+ HasSubstr("must be a floating point type"));+}++TEST_F(TypePropSparseAttentionIndexerTest, incorrect_key_length_element_type) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{1, 4, 7, 128}),+ param(element::f32, PartialShape{1, 2500, 128}),+ param(element::f32, PartialShape{1}),+ 4,+ 2048),+ NodeValidationFailure,+ HasSubstr("The element type of key_length must be i32 or i64."));+}++TEST_F(TypePropSparseAttentionIndexerTest, token_budget_not_divisible_by_key_block_size) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{1, 4, 7, 128}),+ param(element::f32, PartialShape{1, 2500, 128}),+ param(element::i32, PartialShape{1}),+ 4,+ 2046),+ NodeValidationFailure,+ HasSubstr("The attribute token_budget must be divisible by key_block_size."));+}++TEST_F(TypePropSparseAttentionIndexerTest, incorrect_num_selection_heads) {+ OV_EXPECT_THROW(std::ignore = make_op(param(element::f32, PartialShape{1, 4, 7, 128}),+ param(element::f32, PartialShape{1, 2500, 128}),+ param(element::i32, PartialShape{1}),+ 4,+ 2048,+ 0),+ NodeValidationFailure,+ HasSubstr("The attribute num_selection_heads must be a positive integer."));+}+} // namespace ov::testdiff --git a/src/core/tests/visitors/op/qsa_prepare.cpp b/src/core/tests/visitors/op/qsa_prepare.cppnew file mode 100644index 00000000000..00befcc0e73--- /dev/null+++ b/src/core/tests/visitors/op/qsa_prepare.cpp@@ -0,0 +1,51 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "openvino/op/qsa_prepare.hpp"++#include <gtest/gtest.h>++#include "visitors/visitors.hpp"++namespace ov::test {+using ov::op::v0::Parameter, ov::op::v17::QSAPrepare, ov::test::NodeBuilder;++TEST(attributes, qsa_prepare_v17) {+ NodeBuilder::opset().insert<QSAPrepare>();+ const auto raw_index_keys = std::make_shared<Parameter>(element::f32, Shape{1, 8, 128});+ const auto past_block_index_keys = std::make_shared<Parameter>(element::f32, Shape{1, 2, 128});+ const auto key_length = std::make_shared<Parameter>(element::i32, Shape{1});+ const auto rope_cos = std::make_shared<Parameter>(element::f32, Shape{1, 8, 64});+ const auto rope_sin = std::make_shared<Parameter>(element::f32, Shape{1, 8, 64});+ const auto k_norm_weight = std::make_shared<Parameter>(element::f32, Shape{128});+ const auto past_incomplete_raw_keys = std::make_shared<Parameter>(element::f32, Shape{1, 3, 128});+ const auto past_incomplete_rope = std::make_shared<Parameter>(element::f32, Shape{1, 128});++ const auto op = std::make_shared<QSAPrepare>(raw_index_keys,+ past_block_index_keys,+ key_length,+ rope_cos,+ rope_sin,+ k_norm_weight,+ past_incomplete_raw_keys,+ past_incomplete_rope,+ 4,+ 1e-5f);+ NodeBuilder builder(op,+ {raw_index_keys,+ past_block_index_keys,+ key_length,+ rope_cos,+ rope_sin,+ k_norm_weight,+ past_incomplete_raw_keys,+ past_incomplete_rope});+ const auto g_op = ov::as_type_ptr<QSAPrepare>(builder.create());++ constexpr auto expected_attr_count = 2;+ EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);+ EXPECT_EQ(g_op->get_key_block_size(), op->get_key_block_size());+ EXPECT_EQ(g_op->get_epsilon(), op->get_epsilon());+}+} // namespace ov::testdiff --git a/src/core/tests/visitors/op/sparse_attention.cpp b/src/core/tests/visitors/op/sparse_attention.cppnew file mode 100644index 00000000000..9428fd52e70--- /dev/null+++ b/src/core/tests/visitors/op/sparse_attention.cpp@@ -0,0 +1,32 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "openvino/op/sparse_attention.hpp"++#include <gtest/gtest.h>++#include "visitors/visitors.hpp"++namespace ov::test {+using ov::op::v0::Parameter, ov::op::v17::SparseAttention, ov::test::NodeBuilder;++TEST(attributes, sparse_attention_v17) {+ NodeBuilder::opset().insert<SparseAttention>();+ const auto query = std::make_shared<Parameter>(element::f32, Shape{2, 24, 8, 64});+ const auto key = std::make_shared<Parameter>(element::f32, Shape{2, 2, 16, 64});+ const auto value = std::make_shared<Parameter>(element::f32, Shape{2, 2, 16, 32});+ const auto block_indices = std::make_shared<Parameter>(element::i32, Shape{2, 1, 2, 4});+ const auto block_count = std::make_shared<Parameter>(element::i32, Shape{2, 1, 2});++ const auto op = std::make_shared<SparseAttention>(query, key, value, block_indices, block_count, 4, 4, false);+ NodeBuilder builder(op, {query, key, value, block_indices, block_count});+ const auto g_op = ov::as_type_ptr<SparseAttention>(builder.create());++ constexpr auto expected_attr_count = 3;+ EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);+ EXPECT_EQ(g_op->get_key_block_size(), op->get_key_block_size());+ EXPECT_EQ(g_op->get_query_block_size(), op->get_query_block_size());+ EXPECT_EQ(g_op->get_causal(), op->get_causal());+}+} // namespace ov::testdiff --git a/src/core/tests/visitors/op/sparse_attention_indexer.cpp b/src/core/tests/visitors/op/sparse_attention_indexer.cppnew file mode 100644index 00000000000..772f6c2326d--- /dev/null+++ b/src/core/tests/visitors/op/sparse_attention_indexer.cpp@@ -0,0 +1,30 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "openvino/op/sparse_attention_indexer.hpp"++#include <gtest/gtest.h>++#include "visitors/visitors.hpp"++namespace ov::test {+using ov::op::v0::Parameter, ov::op::v17::SparseAttentionIndexer, ov::test::NodeBuilder;++TEST(attributes, sparse_attention_indexer_v17) {+ NodeBuilder::opset().insert<SparseAttentionIndexer>();+ const auto index_query = std::make_shared<Parameter>(element::f32, Shape{1, 8, 7, 128});+ const auto block_index_keys = std::make_shared<Parameter>(element::f32, Shape{1, 100, 128});+ const auto key_length = std::make_shared<Parameter>(element::i32, Shape{1});++ const auto op = std::make_shared<SparseAttentionIndexer>(index_query, block_index_keys, key_length, 4, 64, 2);+ NodeBuilder builder(op, {index_query, block_index_keys, key_length});+ const auto g_op = ov::as_type_ptr<SparseAttentionIndexer>(builder.create());++ constexpr auto expected_attr_count = 3;+ EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);+ EXPECT_EQ(g_op->get_key_block_size(), op->get_key_block_size());+ EXPECT_EQ(g_op->get_token_budget(), op->get_token_budget());+ EXPECT_EQ(g_op->get_num_selection_heads(), op->get_num_selection_heads());+}+} // namespace ov::testdiff --git a/src/core/tests/visitors/sources.cmake b/src/core/tests/visitors/sources.cmakeindex 5407988d89f..eeed5e6b34a 100644--- a/src/core/tests/visitors/sources.cmake+++ b/src/core/tests/visitors/sources.cmake@@ -148,6 +148,7 @@ set(OV_CORE_TESTS_VISITORS_SRCS${CMAKE_CURRENT_LIST_DIR}/op/prior_box_clustered.cpp${CMAKE_CURRENT_LIST_DIR}/op/proposal.cpp${CMAKE_CURRENT_LIST_DIR}/op/psroi_pooling.cpp+ ${CMAKE_CURRENT_LIST_DIR}/op/qsa_prepare.cpp${CMAKE_CURRENT_LIST_DIR}/op/random_uniform.cpp${CMAKE_CURRENT_LIST_DIR}/op/range.cpp${CMAKE_CURRENT_LIST_DIR}/op/rdft.cpp@@ -196,6 +197,8 @@ set(OV_CORE_TESTS_VISITORS_SRCS${CMAKE_CURRENT_LIST_DIR}/op/sorted_search.cpp${CMAKE_CURRENT_LIST_DIR}/op/space_to_batch.cpp${CMAKE_CURRENT_LIST_DIR}/op/space_to_depth.cpp+ ${CMAKE_CURRENT_LIST_DIR}/op/sparse_attention.cpp+ ${CMAKE_CURRENT_LIST_DIR}/op/sparse_attention_indexer.cpp${CMAKE_CURRENT_LIST_DIR}/op/sparse_fill_empty_rows.cpp${CMAKE_CURRENT_LIST_DIR}/op/split.cpp${CMAKE_CURRENT_LIST_DIR}/op/sqrt.cppdiff --git a/src/tests/functional/plugin/conformance/test_runner/op_conformance_runner/src/op_impl_check/single_op_graph.cpp b/src/tests/functional/plugin/conformance/test_runner/op_conformance_runner/src/op_impl_check/single_op_graph.cppindex 33496001e5f..2bc9a631c76 100644--- a/src/tests/functional/plugin/conformance/test_runner/op_conformance_runner/src/op_impl_check/single_op_graph.cpp+++ b/src/tests/functional/plugin/conformance/test_runner/op_conformance_runner/src/op_impl_check/single_op_graph.cpp@@ -588,6 +588,55 @@ std::shared_ptr<ov::Model> generate(const std::shared_ptr<ov::op::v17::GroupedMareturn std::make_shared<ov::Model>(results, ov::ParameterVector{mat_a, mat_b}, "GroupedMatMulGraph");}+std::shared_ptr<ov::Model> generate(const std::shared_ptr<ov::op::v17::QSAPrepare> &node) {+ const auto raw_index_keys = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{1, 8, 16});+ const auto past_block_index_keys = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{1, 0, 16});+ const auto key_length = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::PartialShape{1});+ const auto rope_cos = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{1, 8, 8});+ const auto rope_sin = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{1, 8, 8});+ const auto k_norm_weight = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{16});+ const auto past_incomplete_raw_keys = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{1, 3, 16});+ const auto past_incomplete_rope = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{1, 16});+ const auto qsaPrepareNode = std::make_shared<ov::op::v17::QSAPrepare>(raw_index_keys, past_block_index_keys, key_length,+ rope_cos, rope_sin, k_norm_weight,+ past_incomplete_raw_keys, past_incomplete_rope, 4);+ ov::ResultVector results{+ std::make_shared<ov::op::v0::Result>(qsaPrepareNode->output(0)),+ std::make_shared<ov::op::v0::Result>(qsaPrepareNode->output(1)),+ std::make_shared<ov::op::v0::Result>(qsaPrepareNode->output(2))+ };+ return std::make_shared<ov::Model>(results,+ ov::ParameterVector{raw_index_keys, past_block_index_keys, key_length, rope_cos,+ rope_sin, k_norm_weight, past_incomplete_raw_keys,+ past_incomplete_rope},+ "QSAPrepareGraph");+}++std::shared_ptr<ov::Model> generate(const std::shared_ptr<ov::op::v17::SparseAttentionIndexer> &node) {+ const auto index_query = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{1, 4, 8, 16});+ const auto block_index_keys = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{1, 2, 16});+ const auto key_length = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::PartialShape{1});+ const auto indexerNode = std::make_shared<ov::op::v17::SparseAttentionIndexer>(index_query, block_index_keys, key_length, 4, 8);+ ov::ResultVector results{+ std::make_shared<ov::op::v0::Result>(indexerNode->output(0)),+ std::make_shared<ov::op::v0::Result>(indexerNode->output(1))+ };+ return std::make_shared<ov::Model>(results, ov::ParameterVector{index_query, block_index_keys, key_length},+ "SparseAttentionIndexerGraph");+}++std::shared_ptr<ov::Model> generate(const std::shared_ptr<ov::op::v17::SparseAttention> &node) {+ const auto query = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{1, 4, 8, 16});+ const auto key = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{1, 2, 8, 16});+ const auto value = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{1, 2, 8, 16});+ const auto block_indices = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::PartialShape{1, 1, 8, 2});+ const auto block_count = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::PartialShape{1, 1, 8});+ const auto sparseAttentionNode = std::make_shared<ov::op::v17::SparseAttention>(query, key, value, block_indices, block_count, 4);+ ov::ResultVector results{std::make_shared<ov::op::v0::Result>(sparseAttentionNode)};+ return std::make_shared<ov::Model>(results, ov::ParameterVector{query, key, value, block_indices, block_count},+ "SparseAttentionGraph");+}+std::shared_ptr<ov::Model> generate(const std::shared_ptr<ov::op::v4::Interpolate> &node) {using InterpolateAttrs = op::v4::Interpolate::InterpolateAttrs;using InterpolateMode = op::v4::Interpolate::InterpolateMode;