Skip to content

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

[ONNX FE] GroupQueryAttention sliding-window + smooth-softmax support (#37207)

Ankit Maheshkare5db3b4ba0b4
diff --git a/docs/articles_en/documentation/compatibility-and-support/supported-operations.rst b/docs/articles_en/documentation/compatibility-and-support/supported-operations.rst
index 6ba684a164a..eb9a95d7dfc 100644
--- a/docs/articles_en/documentation/compatibility-and-support/supported-operations.rst
+++ b/docs/articles_en/documentation/compatibility-and-support/supported-operations.rst
@@ -295,6 +295,7 @@ Data as of OpenVINO 2025.4.1 (December 18, 2025).
FusedGemm
FusedMatMul
GatherBlockQuantized
+ GroupQueryAttention
MatMulIntegerToFloat
MatMulNBits
Pad
diff --git a/src/common/transformations/include/transformations/op_conversions/group_query_attention_decomposition.hpp b/src/common/transformations/include/transformations/op_conversions/group_query_attention_decomposition.hpp
index 8fdf747026e..7c023f6a5de 100644
--- a/src/common/transformations/include/transformations/op_conversions/group_query_attention_decomposition.hpp
+++ b/src/common/transformations/include/transformations/op_conversions/group_query_attention_decomposition.hpp
@@ -31,6 +31,23 @@ private:
ov::Output<ov::Node> cos,
ov::Output<ov::Node> sin,
bool interleaved);
+ // Resident row count of a windowed KV cache for a given absolute sequence length, as an i64 scalar node:
+ // end(x) = x <= capacity ? x : x - gap * ceil((x - capacity) / gap), with gap = capacity - window + 1.
+ // Mirrors ONNX Runtime's WindowedCacheEnd; blocks of `gap` rows are reclaimed at once on front eviction.
+ std::shared_ptr<ov::Node> windowed_cache_end(const ov::Output<ov::Node>& seqlen_scalar,
+ const ov::Output<ov::Node>& capacity_scalar,
+ int64_t local_window_size);
+
+ // Additive float attention mask for SDPA: causal mask, plus an optional sliding-window band
+ // (local_window_size >= 0) masking keys older than the window, optionally fused with an external bias.
+ // Masked positions use the compute type's finite lowest() so a fully-masked row cannot softmax to NaN.
+ std::shared_ptr<ov::Node> make_attention_mask(const ov::Output<ov::Node>& curr_seqlen_scalar,
+ const ov::Output<ov::Node>& kv_len_scalar,
+ const ov::Output<ov::Node>& kv_len_1d,
+ const ov::Output<ov::Node>& past_seqlen,
+ const ov::element::Type& compute_type,
+ int64_t local_window_size,
+ const ov::Output<ov::Node>& external_bias);
// Reshape a flat KV-cache dequant scale so it broadcasts against a [B, kv_num_heads, S, head_size] tensor:
// PER_CHANNEL -> [1, kv_num_heads, 1, head_size]; PER_TENSOR -> [1, 1, 1, 1].
std::shared_ptr<ov::Node> make_kv_scale(const ov::Output<ov::Node>& scale,
diff --git a/src/common/transformations/src/transformations/op_conversions/group_query_attention_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/group_query_attention_decomposition.cpp
index e992762f6e1..230069b33e8 100644
--- a/src/common/transformations/src/transformations/op_conversions/group_query_attention_decomposition.cpp
+++ b/src/common/transformations/src/transformations/op_conversions/group_query_attention_decomposition.cpp
@@ -25,7 +25,11 @@
#include "openvino/op/gather.hpp"
#include "openvino/op/greater.hpp"
#include "openvino/op/greater_eq.hpp"
+#include "openvino/op/logical_or.hpp"
+#include "openvino/op/maximum.hpp"
#include "openvino/op/multiply.hpp"
+#include "openvino/op/pad.hpp"
+#include "openvino/op/power.hpp"
#include "openvino/op/range.hpp"
#include "openvino/op/reshape.hpp"
#include "openvino/op/round.hpp"
@@ -80,6 +84,8 @@ ov::OutputVector ov::pass::GroupQueryAttentionDecomposition::decompose(
const auto scale = node->get_scale();
const auto do_rotary = node->get_do_rotary();
const auto rotary_interleaved = node->get_rotary_interleaved();
+ const auto local_window_size = node->get_local_window_size();
+ const auto smooth_softmax = node->get_smooth_softmax();
// TODO: add softcap support
auto Q = node->input_value(0);
@@ -158,24 +164,67 @@ ov::OutputVector ov::pass::GroupQueryAttentionDecomposition::decompose(
V = quantize_kv(V, v_scale, kv_num_heads, kv_cache_bit_width, v_quant_type, kv_cache_type);
}
- if (is_static_input) {
- // static design for GQA (KV cache is static max length, valid KVs are left align)
- // inputs are:
- // 1. past_key/past_value: [1, num_heads, max_seq_len, head_size], data is in the front along axis 2, [P0, P1,
- // ..., Pn, 0, 0, ...]
- // 2. current K/V: [1, num_heads, current_kv_len, head_size], data is in the front along axis 2, [C0, C1, ...,
- // Ck, 0, 0, ...]
- // Output present_key/present_value has the same shape with past_key/past_value, but with data in order [P0, P1,
- // ..., Pn, C0, C1, ..., Ck, 0, 0, ...]
+ // past_seqlen expressed in the coordinate system the attention mask uses. Equals the absolute past
+ // length for a full-length cache; a windowed cache overrides it with the resident row count.
+ ov::Output<ov::Node> mask_past_seqlen = past_seqlen;
+ ov::Output<ov::Node> present_k, present_v;
+
+ if (node->get_sliding_window_cache()) {
+ // Windowed KV cache: the past/present buffers are capacity-sized (C) and rolled with front
+ // eviction. seqlens_k stays absolute, so the resident row counts are derived from it.
//
- // Use ScatterUpdate to scatter insert Current into Past
- // Insert current K/V at the correct position [past_seqlen, past_seqlen+curr_seqlen].
+ // present is built as [survivors, new, zeros] left-aligned in the C buffer: the last
+ // kept = end_after - S resident rows, then the S new tokens, matching ONNX Runtime. The
+ // construction uses Gather + ScatterUpdate into a zero buffer (no runtime-bounded Slice/Pad)
+ // so it stays static-shape friendly for plugins (e.g. NPU) that require it. Attention then runs
+ // over the full C buffer with cache-relative past length = kept; the dropped resident rows are
+ // older than the window and the zero tail is beyond the causal edge, so both are masked out.
+ const auto capacity = get_dimensions(past_key.get_node_shared_ptr(), {2});
+ const auto capacity_scalar = register_new_node<v0::Squeeze>(capacity);
+ const auto abs_past_scalar = register_new_node<v0::Squeeze>(past_seqlen); // P
+ const auto abs_total_scalar = register_new_node<v0::Squeeze>(seqlens_1d); // P + S
+ const auto end_before = windowed_cache_end(abs_past_scalar, capacity_scalar, local_window_size);
+ const auto end_after = windowed_cache_end(abs_total_scalar, capacity_scalar, local_window_size);
+ const auto kept = register_new_node<v1::Subtract>(end_after, curr_seqlen_scalar); // end_after - S
+ const auto survivor_start = register_new_node<v1::Subtract>(end_before, kept);
+
+ // Row index sets, built as Range(0, N) + offset (constant-start Range plus a runtime offset)
+ // rather than Range(runtime_start, ...), matching the idiom the existing static path uses so the
+ // graph stays lowerable on static-shape plugins. kept_row = [0, kept); survivor_row picks the last
+ // kept resident rows [survivor_start, end_before); new_row places the S new tokens at [kept, end_after).
+ const auto kept_row =
+ register_new_node<v4::Range>(zero_without_shape, kept, one_without_shape, ov::element::i64);
+ const auto survivor_idx = register_new_node<v1::Add>(kept_row, survivor_start);
+ const auto survivor_k = register_new_node<v8::Gather>(past_key, survivor_idx, two);
+ const auto survivor_v = register_new_node<v8::Gather>(past_value, survivor_idx, two);
+ const auto kept_idx = kept_row;
+ const auto new_row =
+ register_new_node<v4::Range>(zero_without_shape, curr_seqlen_scalar, one_without_shape, ov::element::i64);
+ const auto new_idx = register_new_node<v1::Add>(new_row, kept);
+
+ const auto zeros =
+ register_new_node<v3::Broadcast>(register_new_node(v0::Constant::create(kv_cache_type, ov::Shape{}, {0})),
+ register_new_node<v3::ShapeOf>(past_key));
+ const auto scatter_axis = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{1}, {2}));
+ present_k = register_new_node<v3::ScatterUpdate>(zeros, kept_idx, survivor_k, scatter_axis);
+ present_k = register_new_node<v3::ScatterUpdate>(present_k, new_idx, K, scatter_axis);
+ present_v = register_new_node<v3::ScatterUpdate>(zeros, kept_idx, survivor_v, scatter_axis);
+ present_v = register_new_node<v3::ScatterUpdate>(present_v, new_idx, V, scatter_axis);
+
+ K = present_k;
+ V = present_v;
+ mask_past_seqlen = register_new_node<v0::Unsqueeze>(kept, zero);
+ } else if (is_static_input) {
+ // Static full-length cache (max length, valid KVs left-aligned). Insert current K/V at
+ // [past_seqlen, past_seqlen + curr_seqlen] with ScatterUpdate, keeping the buffer shape.
std::shared_ptr<ov::Node> scatter_idx =
register_new_node<v4::Range>(zero_without_shape, curr_seqlen_scalar, one_without_shape, ov::element::i64);
scatter_idx = register_new_node<v1::Add>(scatter_idx, past_seqlen);
const auto scatter_axis = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{1}, {2}));
K = register_new_node<v3::ScatterUpdate>(past_key, scatter_idx, K, scatter_axis);
V = register_new_node<v3::ScatterUpdate>(past_value, scatter_idx, V, scatter_axis);
+ present_k = K;
+ present_v = V;
} else {
auto construct_kv_cache = [&](const ov::Output<ov::Node>& past, const ov::Output<ov::Node>& current) {
return register_new_node<v0::Concat>(ov::OutputVector{past, current}, 2);
@@ -184,12 +233,10 @@ ov::OutputVector ov::pass::GroupQueryAttentionDecomposition::decompose(
past_value = register_new_node<v8::Slice>(past_value, zero, past_seqlen, one, two);
K = construct_kv_cache(past_key, K);
V = construct_kv_cache(past_value, V);
+ present_k = K;
+ present_v = V;
}
- // present_key/present_value are the assembled cache (quantized when kv_quantized), matching the op outputs.
- ov::Output<ov::Node> present_k = K;
- ov::Output<ov::Node> present_v = V;
-
// Dequantize the assembled cache to the compute (float) type for the attention math. Everything downstream
// (head broadcast, mask, SDPA) then operates in float exactly as in the non-quantized path.
if (kv_quantized) {
@@ -218,39 +265,53 @@ ov::OutputVector ov::pass::GroupQueryAttentionDecomposition::decompose(
V = register_new_node<v1::Reshape>(V, extended_kv_shape, false);
}
- // Make attention mask
- std::shared_ptr<ov::Node> mask;
+ ov::Output<ov::Node> external_bias;
if (node->get_input_size() > 10 && !is_null(node->input_value(10))) {
- auto original_mask = node->input_value(10).get_node_shared_ptr();
- // Extract mask [num_heads, curr_seqlen, concat_kv_len] from 4D mask [1, num_heads, curr_seqlen, max_kv_len]
- auto axes_to_squeeze = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{1}, {0}));
- auto mask_squeezed = register_new_node<v0::Squeeze>(original_mask, axes_to_squeeze);
- mask = register_new_node<v8::Slice>(mask_squeezed, zero, concat_kv_len, one, two);
- } else {
- std::shared_ptr<ov::Node> hori_range =
- register_new_node<v4::Range>(zero_without_shape, concat_kv_len_scalar, one_without_shape, ov::element::i64);
- hori_range = register_new_node<v0::Unsqueeze>(hori_range, zero);
-
- std::shared_ptr<ov::Node> vert_range =
- register_new_node<v4::Range>(zero_without_shape, curr_seqlen_scalar, one_without_shape, ov::element::i64);
- vert_range = register_new_node<v0::Unsqueeze>(vert_range, one);
- vert_range = register_new_node<v1::Add>(vert_range, past_seqlen);
-
- const auto triu = register_new_node<v1::Greater>(hori_range, vert_range);
- const auto typed_zero = register_new_node(v0::Constant::create(T, ov::Shape{}, {0}));
- // cf. make_attention_mask@src\plugins\intel_gpu\tests\common\subgraphs_builders.hpp
- // Mask with the type's finite lowest(), not -inf: a fully-masked row would otherwise softmax to 0/0 = NaN.
- std::shared_ptr<ov::Node> minus_inf = nullptr;
- if (T == ov::element::f32)
- minus_inf = register_new_node(v0::Constant::create(T, ov::Shape{}, {std::numeric_limits<float>::lowest()}));
- else if (T == ov::element::f16)
- minus_inf =
- register_new_node(v0::Constant::create(T, ov::Shape{}, {std::numeric_limits<ov::float16>::lowest()}));
- mask = register_new_node<v1::Select>(triu, minus_inf, typed_zero);
+ external_bias = node->input_value(10);
+ }
+ const auto mask = make_attention_mask(curr_seqlen_scalar,
+ concat_kv_len_scalar,
+ concat_kv_len,
+ mask_past_seqlen,
+ T,
+ local_window_size,
+ external_bias);
+
+ // head_sink (input 11) or smooth_softmax add an extra logit to the softmax denominator. SDPA models
+ // this with its sink input: a [1, num_heads, 1, 1] tensor appended as one logit column, included in
+ // the softmax, then sliced out. head_sink provides a per-head value; plain smooth_softmax uses 0.
+ ov::Output<ov::Node> sink;
+ const bool has_head_sink = node->get_input_size() > 11 && !is_null(node->input_value(11));
+ if (has_head_sink || smooth_softmax) {
+ const auto sink_shape = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{4}, {1, -1, 1, 1}));
+ if (has_head_sink) {
+ auto head_sink = node->input_value(11);
+ if (head_sink.get_element_type() != T) {
+ head_sink = register_new_node<v0::Convert>(head_sink, T);
+ }
+ sink = register_new_node<v1::Reshape>(head_sink, sink_shape, false);
+ } else {
+ const auto num_heads_1d =
+ register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{1}, {num_heads}));
+ sink = register_new_node<v3::Broadcast>(
+ register_new_node(v0::Constant::create(T, ov::Shape{}, {0})),
+ register_new_node<v0::Concat>(ov::NodeVector{one, num_heads_1d, one, one}, 0));
+ }
}
std::shared_ptr<ov::Node> qga_output;
- if (scale != 0.0f) {
+ if (sink.get_node_shared_ptr()) {
+ // SDPA's 6-input form requires an explicit scale; use the op scale or the default 1/sqrt(head_size).
+ ov::Output<ov::Node> scale_node;
+ if (scale != 0.0f) {
+ scale_node = register_new_node(v0::Constant::create(T, Shape{}, {scale}));
+ } else {
+ const auto head_size_t = register_new_node<v0::Convert>(head_size_node, T);
+ const auto neg_half = register_new_node(v0::Constant::create(T, Shape{}, {-0.5f}));
+ scale_node = register_new_node<v0::Squeeze>(register_new_node<ov::op::v1::Power>(head_size_t, neg_half));
+ }
+ qga_output = register_new_node<v13::ScaledDotProductAttention>(Q, K, V, mask, scale_node, sink, false);
+ } else if (scale != 0.0f) {
auto scale_node = register_new_node(v0::Constant::create(T, Shape{}, {scale}));
qga_output = register_new_node<v13::ScaledDotProductAttention>(Q, K, V, mask, scale_node, false);
} else {
@@ -267,6 +328,96 @@ ov::OutputVector ov::pass::GroupQueryAttentionDecomposition::decompose(
return {output, present_k, present_v};
}
+std::shared_ptr<ov::Node> ov::pass::GroupQueryAttentionDecomposition::windowed_cache_end(
+ const ov::Output<ov::Node>& seqlen_scalar,
+ const ov::Output<ov::Node>& capacity_scalar,
+ int64_t local_window_size) {
+ const auto window = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{}, {local_window_size}));
+ const auto one_s = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{}, {1}));
+ // gap = capacity - window + 1. The frontend enforces capacity >= local_window_size whenever the capacity
+ // is statically known; when it is dynamic that check cannot fire, so clamp gap to >= 1 here to avoid a
+ // division by zero (or a negative gap) on a malformed capacity < local_window_size configuration.
+ auto gap = register_new_node<v1::Add>(register_new_node<v1::Subtract>(capacity_scalar, window), one_s)->output(0);
+ gap = register_new_node<v1::Maximum>(gap, one_s);
+ // reclaimed = gap * ceil((x - capacity) / gap), applied only once the cache has overflowed (x > capacity).
+ const auto overflow = register_new_node<v1::Subtract>(seqlen_scalar, capacity_scalar);
+ const auto ceil_num = register_new_node<v1::Subtract>(register_new_node<v1::Add>(overflow, gap), one_s);
+ const auto blocks = register_new_node<v1::Divide>(ceil_num, gap); // integer (truncating) division
+ const auto reclaimed = register_new_node<v1::Multiply>(blocks, gap);
+ const auto evicted = register_new_node<v1::Subtract>(seqlen_scalar, reclaimed);
+ const auto overflowed = register_new_node<v1::Greater>(seqlen_scalar, capacity_scalar);
+ return register_new_node<v1::Select>(overflowed, evicted, seqlen_scalar);
+}
+
+std::shared_ptr<ov::Node> ov::pass::GroupQueryAttentionDecomposition::make_attention_mask(
+ const ov::Output<ov::Node>& curr_seqlen_scalar,
+ const ov::Output<ov::Node>& kv_len_scalar,
+ const ov::Output<ov::Node>& kv_len_1d,
+ const ov::Output<ov::Node>& past_seqlen,
+ const ov::element::Type& compute_type,
+ int64_t local_window_size,
+ const ov::Output<ov::Node>& external_bias) {
+ const bool has_bias = external_bias.get_node_shared_ptr() != nullptr;
+ // A window is active for local_window_size >= 1; -1 disables it and 0 is rejected upstream (FE + op).
+ const bool has_window = local_window_size >= 1;
+
+ const auto zero = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{1}, {0}));
+ const auto one = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{1}, {1}));
+ const auto two = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{1}, {2}));
+
+ // Key positions [1, kv_len] and absolute query positions [curr, 1]. Coordinates are cache-relative
+ // (past_seqlen is the resident past length), which matches the distance-only ONNX Runtime rule.
+ const auto zero_scalar = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{}, {0}));
+ const auto one_scalar = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{}, {1}));
+ std::shared_ptr<ov::Node> hori_range =
+ register_new_node<v4::Range>(zero_scalar, kv_len_scalar, one_scalar, ov::element::i64);
+ hori_range = register_new_node<v0::Unsqueeze>(hori_range, zero);
+ std::shared_ptr<ov::Node> vert_range =
+ register_new_node<v4::Range>(zero_scalar, curr_seqlen_scalar, one_scalar, ov::element::i64);
+ vert_range = register_new_node<v0::Unsqueeze>(vert_range, one);
+ vert_range = register_new_node<v1::Add>(vert_range, past_seqlen);
+
+ // Causal mask (future keys: k > q), OR-ed with the optional sliding-window band (keys older than the
+ // window: (q - k) >= local_window_size). This is applied unconditionally; an external attention_bias
+ // is added on top of it, matching ONNX Runtime (the bias does not replace the causal/window mask).
+ std::shared_ptr<ov::Node> masked = register_new_node<v1::Greater>(hori_range, vert_range);
+ if (has_window) {
+ const auto distance = register_new_node<v1::Subtract>(vert_range, hori_range);
+ const auto window = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{}, {local_window_size}));
+ const auto too_old = register_new_node<v1::GreaterEqual>(distance, window);
+ masked = register_new_node<v1::LogicalOr>(masked, too_old);
+ }
+
+ const auto typed_zero = register_new_node(v0::Constant::create(compute_type, ov::Shape{}, {0}));
+ // Finite lowest(), not -inf: a fully-masked row would otherwise softmax to 0/0 = NaN. The magnitude must
+ // match the compute type so it does not overflow to -inf when narrowed: f16 and bf16 have far smaller
+ // ranges than f32. (The core op currently restricts the activation type to {f32, f16}, so bf16 is not
+ // yet reachable here, but keep an explicit branch so a future bf16 activation stays finite.)
+ std::shared_ptr<ov::Node> minus_inf;
+ if (compute_type == ov::element::f16)
+ minus_inf = register_new_node(
+ v0::Constant::create(compute_type, ov::Shape{}, {std::numeric_limits<ov::float16>::lowest()}));
+ else if (compute_type == ov::element::bf16)
+ minus_inf = register_new_node(
+ v0::Constant::create(compute_type, ov::Shape{}, {std::numeric_limits<ov::bfloat16>::lowest()}));
+ else
+ minus_inf =
+ register_new_node(v0::Constant::create(compute_type, ov::Shape{}, {std::numeric_limits<float>::lowest()}));
+
+ std::shared_ptr<ov::Node> mask = register_new_node<v1::Select>(masked, minus_inf, typed_zero);
+
+ if (has_bias) {
+ // Add the external attention_bias [1, num_heads, curr, max_kv] -> [num_heads, curr, kv_len] on top
+ // of the causal/window mask (broadcasts over the head axis against the [curr, kv_len] mask).
+ const auto squeeze_axis = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{1}, {0}));
+ std::shared_ptr<ov::Node> bias = register_new_node<v0::Squeeze>(external_bias, squeeze_axis);
+ bias = register_new_node<v8::Slice>(bias, zero, kv_len_1d, one, two);
+ mask = register_new_node<v1::Add>(mask, bias);
+ }
+
+ return mask;
+}
+
std::shared_ptr<ov::Node> ov::pass::GroupQueryAttentionDecomposition::get_dimensions(
const std::shared_ptr<v3::ShapeOf>& shape,
const std::vector<int>& dims) {
diff --git a/src/common/transformations/tests/op_conversions/group_query_attention_decomposition_test.cpp b/src/common/transformations/tests/op_conversions/group_query_attention_decomposition_test.cpp
new file mode 100644
index 00000000000..8d016ea436b
--- /dev/null
+++ b/src/common/transformations/tests/op_conversions/group_query_attention_decomposition_test.cpp
@@ -0,0 +1,379 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "transformations/op_conversions/group_query_attention_decomposition.hpp"
+
+#include <gtest/gtest.h>
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "common_test_utils/ov_test_utils.hpp"
+#include "common_test_utils/test_assertions.hpp"
+#include "openvino/core/except.hpp"
+#include "openvino/core/model.hpp"
+#include "openvino/op/broadcast.hpp"
+#include "openvino/op/constant.hpp"
+#include "openvino/op/greater_eq.hpp"
+#include "openvino/op/group_query_attention.hpp"
+#include "openvino/op/parameter.hpp"
+#include "openvino/op/reshape.hpp"
+#include "openvino/op/result.hpp"
+#include "openvino/op/scaled_dot_product_attention.hpp"
+#include "openvino/op/scatter_update.hpp"
+#include "openvino/pass/manager.hpp"
+
+using namespace ov;
+using ov::op::internal::GroupQueryAttention;
+
+// Graph-level tests for GroupQueryAttentionDecomposition: the internal op is replaced by a
+// ScaledDotProductAttention-based decomposition, and each feature emits its expected structure
+// (sliding-window cache -> ScatterUpdate; smooth_softmax / head_sink -> SDPA sink input). Numerical
+// parity against ONNX Runtime is covered by the end-to-end tests in onnx_import_com_microsoft.
+namespace {
+
+constexpr int64_t NUM_HEADS = 2;
+constexpr int64_t KV_NUM_HEADS = 1;
+constexpr int64_t HEAD_SIZE = 16;
+
+// Stand-in for an absent optional input. The decomposition detects missing inputs by node description
+// ("NullNode"), matching the ONNX frontend's NullNode, so a filler must report the same description
+// rather than be a real Parameter (which would be treated as a supplied position_ids / bias / etc.).
+// Declared without the OPENVINO_OP macro so no export/visibility attributes are applied to this
+// test-local type (the macro's RTTI attributes are rejected under -Werror on some toolchains).
+class NullNode : public op::Op {
+public:
+ static const ov::DiscreteTypeInfo& get_type_info_static() {
+ static const ov::DiscreteTypeInfo info{"NullNode", "test"};
+ return info;
+ }
+ const ov::DiscreteTypeInfo& get_type_info() const override {
+ return get_type_info_static();
+ }
+ std::string description() const override {
+ return "NullNode";
+ }
+ NullNode() {
+ set_output_size(1);
+ }
+ std::shared_ptr<Node> clone_with_new_inputs(const OutputVector&) const override {
+ return std::make_shared<NullNode>();
+ }
+};
+
+// Chainable so each test case reads as a one-liner without C++20 designated initializers.
+struct GqaParams {
+ std::string name;
+ bool do_rotary = false;
+ bool rotary_interleaved = false;
+ int64_t kv_cache_bit_width = 0;
+ element::Type kv_type = element::f32;
+ int64_t local_window_size = -1;
+ bool sliding_window_cache = false;
+ bool smooth_softmax = false;
+ bool head_sink = false;
+ bool attention_bias = false;
+ Dimension past_len = Dimension::dynamic();
+ Dimension seq_len = 1;
+ // Expected decomposed structure.
+ size_t expected_sdpa_inputs = 4; // q, k, v, mask (+scale, +sink when a sink is used)
+ bool expects_scatter_update = false;
+
+ explicit GqaParams(std::string n) : name(std::move(n)) {}
+ GqaParams& rotary(bool interleaved = false) {
+ do_rotary = true;
+ rotary_interleaved = interleaved;
+ return *this;
+ }
+ GqaParams& quant(int64_t bits, element::Type t) {
+ kv_cache_bit_width = bits;
+ kv_type = t;
+ return *this;
+ }
+ GqaParams& window(int64_t w) {
+ local_window_size = w;
+ return *this;
+ }
+ GqaParams& windowed_roll(int64_t w, const Dimension& capacity) {
+ local_window_size = w;
+ sliding_window_cache = true;
+ past_len = capacity;
+ expects_scatter_update = true;
+ return *this;
+ }
+ GqaParams& sink_smooth() {
+ smooth_softmax = true;
+ expected_sdpa_inputs = 6;
+ return *this;
+ }
+ GqaParams& sink_head() {
+ head_sink = true;
+ expected_sdpa_inputs = 6;
+ return *this;
+ }
+ GqaParams& bias() {
+ attention_bias = true;
+ return *this;
+ }
+ GqaParams& shape(const Dimension& seq, const Dimension& past) {
+ seq_len = seq;
+ past_len = past;
+ expects_scatter_update = past.is_static();
+ return *this;
+ }
+};
+
+std::shared_ptr<Model> make_gqa_model(const GqaParams& p) {
+ const auto f32 = element::f32;
+ const int64_t stored_head = p.kv_cache_bit_width == 4 ? HEAD_SIZE / 2 : HEAD_SIZE; // 4-bit packs 2/byte
+ const std::string quant = p.kv_cache_bit_width == 0 ? "NONE" : "PER_TENSOR";
+
+ OutputVector args;
+ ParameterVector params;
+ auto add = [&](const element::Type& et, const PartialShape& ps) {
+ auto prm = std::make_shared<op::v0::Parameter>(et, ps);
+ args.push_back(prm);
+ params.push_back(prm);
+ };
+ auto pad_to = [&](size_t idx) {
+ while (args.size() < idx)
+ args.push_back(std::make_shared<NullNode>()); // absent optional input
+ };
+
+ // The internal op receives Q/K/V already transposed to [batch, heads, seq, head_size] (the ONNX FE
+ // splits the packed QKV before creating it).
+ add(f32, PartialShape{1, NUM_HEADS, p.seq_len, HEAD_SIZE}); // 0: query
+ add(f32, PartialShape{1, KV_NUM_HEADS, p.seq_len, HEAD_SIZE}); // 1: key
+ add(f32, PartialShape{1, KV_NUM_HEADS, p.seq_len, HEAD_SIZE}); // 2: value
+ add(p.kv_type, PartialShape{1, KV_NUM_HEADS, p.past_len, stored_head}); // 3: past_key
+ add(p.kv_type, PartialShape{1, KV_NUM_HEADS, p.past_len, stored_head}); // 4: past_value
+ add(element::i32, PartialShape{1}); // 5: seqlens_k
+ add(element::i32, PartialShape{}); // 6: total_sequence_length
+ if (p.do_rotary) {
+ add(f32, PartialShape{1, HEAD_SIZE / 2}); // 7: cos_cache
+ add(f32, PartialShape{1, HEAD_SIZE / 2}); // 8: sin_cache
+ }
+ if (p.attention_bias) {
+ pad_to(10);
+ add(f32, PartialShape{1, NUM_HEADS, p.seq_len, -1}); // 10: attention_bias
+ }
+ if (p.head_sink) {
+ pad_to(11);
+ add(f32, PartialShape{NUM_HEADS}); // 11: head_sink
+ }
+ if (p.kv_cache_bit_width != 0) {
+ pad_to(12);
+ add(element::f32, PartialShape{-1}); // 12: k_scale
+ add(element::f32, PartialShape{-1}); // 13: v_scale
+ }
+
+ const auto gqa = std::make_shared<GroupQueryAttention>(args,
+ NUM_HEADS,
+ KV_NUM_HEADS,
+ /*scale*/ 0.0f,
+ p.do_rotary,
+ p.rotary_interleaved,
+ p.kv_cache_bit_width,
+ quant,
+ quant,
+ p.local_window_size,
+ p.sliding_window_cache,
+ p.smooth_softmax);
+ ResultVector results;
+ for (size_t i = 0; i < gqa->get_output_size(); ++i)
+ results.push_back(std::make_shared<op::v0::Result>(gqa->output(i)));
+ return std::make_shared<Model>(results, params);
+}
+
+// Minimal 7-input GroupQueryAttention for exercising the op's own validation (validate_and_infer_types
+// runs at construction). Only the validated attributes/shapes vary; the KV cache stays unquantized float.
+std::shared_ptr<GroupQueryAttention> make_gqa_op(const Dimension& batch,
+ const Dimension& seq,
+ const Dimension& past,
+ int64_t local_window_size,
+ bool sliding_window_cache) {
+ const auto f32 = element::f32;
+ auto q = std::make_shared<op::v0::Parameter>(f32, PartialShape{batch, NUM_HEADS, seq, HEAD_SIZE});
+ auto k = std::make_shared<op::v0::Parameter>(f32, PartialShape{batch, KV_NUM_HEADS, seq, HEAD_SIZE});
+ auto v = std::make_shared<op::v0::Parameter>(f32, PartialShape{batch, KV_NUM_HEADS, seq, HEAD_SIZE});
+ auto past_key = std::make_shared<op::v0::Parameter>(f32, PartialShape{batch, KV_NUM_HEADS, past, HEAD_SIZE});
+ auto past_value = std::make_shared<op::v0::Parameter>(f32, PartialShape{batch, KV_NUM_HEADS, past, HEAD_SIZE});
+ auto seqlens_k = std::make_shared<op::v0::Parameter>(element::i32, PartialShape{batch});
+ auto total_seq = std::make_shared<op::v0::Parameter>(element::i32, PartialShape{});
+ OutputVector args{q, k, v, past_key, past_value, seqlens_k, total_seq};
+ return std::make_shared<GroupQueryAttention>(args,
+ NUM_HEADS,
+ KV_NUM_HEADS,
+ /*scale*/ 0.0f,
+ /*do_rotary*/ false,
+ /*rotary_interleaved*/ false,
+ /*kv_cache_bit_width*/ 0,
+ "NONE",
+ "NONE",
+ local_window_size,
+ sliding_window_cache,
+ /*smooth_softmax*/ false);
+}
+
+} // namespace
+
+class GroupQueryAttentionDecompositionTest : public testing::TestWithParam<GqaParams> {};
+
+TEST_P(GroupQueryAttentionDecompositionTest, decomposes_to_sdpa) {
+ const auto& p = GetParam();
+ auto model = make_gqa_model(p);
+ pass::Manager manager;
+ manager.register_pass<pass::GroupQueryAttentionDecomposition>();
+ manager.run_passes(model);
+
+ // The internal op is always replaced by exactly one ScaledDotProductAttention.
+ EXPECT_EQ(count_ops_of_type<GroupQueryAttention>(model), 0u);
+ EXPECT_EQ(count_ops_of_type<op::v13::ScaledDotProductAttention>(model), 1u);
+
+ // The sink input (smooth_softmax / head_sink) shows up as extra SDPA inputs.
+ for (const auto& op : model->get_ordered_ops()) {
+ if (auto sdpa = as_type_ptr<op::v13::ScaledDotProductAttention>(op)) {
+ EXPECT_EQ(sdpa->get_input_size(), p.expected_sdpa_inputs);
+ }
+ }
+
+ // The windowed rolling cache assembles the present buffer with ScatterUpdate; other paths do not.
+ EXPECT_EQ(count_ops_of_type<op::v3::ScatterUpdate>(model) > 0u, p.expects_scatter_update);
+}
+
+INSTANTIATE_TEST_SUITE_P(GroupQueryAttentionDecomposition,
+ GroupQueryAttentionDecompositionTest,
+ testing::Values(GqaParams{"causal_decode"},
+ GqaParams{"prefill"}.shape(4, Dimension::dynamic()),
+ GqaParams{"rotary"}.rotary(),
+ GqaParams{"rotary_interleaved"}.rotary(/*interleaved*/ true),
+ GqaParams{"static_past_scatter"}.shape(1, 8),
+ GqaParams{"sliding_window"}.window(2),
+ GqaParams{"attention_bias"}.bias(),
+ GqaParams{"sliding_window_bias"}.window(2).bias(),
+ GqaParams{"smooth_softmax"}.sink_smooth(),
+ GqaParams{"head_sink"}.sink_head(),
+ GqaParams{"i8_per_tensor"}.quant(8, element::i8),
+ GqaParams{"i4_per_tensor"}.quant(4, element::u8),
+ GqaParams{"f8e4m3_per_tensor"}.quant(8, element::f8e4m3),
+ GqaParams{"windowed_cache"}.windowed_roll(3, 4)),
+ [](const testing::TestParamInfo<GqaParams>& i) {
+ return i.param.name;
+ });
+
+// --- Op-level validation (validate_and_infer_types) ------------------------------------------------
+// These guard the assumptions the decomposition relies on. They must reject only what is provably
+// unsupported from shapes/attributes alone, and must NOT reject the dynamic-shape configurations that
+// CPU/GPU legitimately run (a dynamic sequence length or batch cannot be checked and stays enabled).
+
+TEST(GroupQueryAttentionOpValidation, rejects_sliding_window_cache_without_window) {
+ // sliding_window_cache requires a real window (local_window_size >= 1).
+ OV_EXPECT_THROW(make_gqa_op(1, 1, 8, /*window*/ -1, /*swc*/ true),
+ ov::NodeValidationFailure,
+ testing::HasSubstr("sliding_window_cache requires local_window_size"));
+}
+
+TEST(GroupQueryAttentionOpValidation, rejects_local_window_size_zero) {
+ // 0 is an empty attention (every query masks all keys) and is not a valid config.
+ OV_EXPECT_THROW(make_gqa_op(1, 1, 8, /*window*/ 0, /*swc*/ false),
+ ov::NodeValidationFailure,
+ testing::HasSubstr("local_window_size must be -1"));
+}
+
+TEST(GroupQueryAttentionOpValidation, rejects_static_multi_token_windowed_cache) {
+ // A statically-known sequence_length > 1 with a windowed cache may cross an eviction at runtime
+ // (the unmodeled staging regime), so it is rejected up front.
+ OV_EXPECT_THROW(make_gqa_op(1, /*seq*/ 4, 8, /*window*/ 2, /*swc*/ true),
+ ov::NodeValidationFailure,
+ testing::HasSubstr("single-token decode"));
+}
+
+TEST(GroupQueryAttentionOpValidation, rejects_static_batch_greater_than_one) {
+ // The decomposition uses a scalar past length and assumes batch == 1.
+ OV_EXPECT_THROW(make_gqa_op(/*batch*/ 2, 1, 8, /*window*/ -1, /*swc*/ false),
+ ov::NodeValidationFailure,
+ testing::HasSubstr("batch_size == 1"));
+}
+
+TEST(GroupQueryAttentionOpValidation, allows_dynamic_sequence_with_windowed_cache) {
+ // A dynamic sequence_length is left enabled: at runtime it is typically decode / fitting prefill,
+ // which the decomposition handles correctly. Rejecting it would disable CPU/GPU dynamic shapes.
+ EXPECT_NO_THROW(make_gqa_op(1, Dimension::dynamic(), 8, /*window*/ 2, /*swc*/ true));
+}
+
+TEST(GroupQueryAttentionOpValidation, allows_dynamic_batch) {
+ // A dynamic batch dimension cannot be checked from shapes and stays enabled.
+ EXPECT_NO_THROW(make_gqa_op(Dimension::dynamic(), 1, 8, /*window*/ -1, /*swc*/ false));
+}
+
+// --- Decomposed constant values -------------------------------------------------------------------
+// The structural TEST_P above checks topology only; a wrong window boundary or a wrong sink value would
+// still pass it. These assert the actual constants the decomposition emits for those two features.
+
+namespace {
+void decompose(const std::shared_ptr<Model>& model) {
+ pass::Manager manager;
+ manager.register_pass<pass::GroupQueryAttentionDecomposition>();
+ manager.run_passes(model);
+}
+
+std::shared_ptr<op::v13::ScaledDotProductAttention> find_sdpa(const std::shared_ptr<Model>& model) {
+ for (const auto& op : model->get_ordered_ops())
+ if (auto sdpa = as_type_ptr<op::v13::ScaledDotProductAttention>(op))
+ return sdpa;
+ return nullptr;
+}
+} // namespace
+
+TEST(GroupQueryAttentionValues, sliding_window_boundary_uses_window_size_constant) {
+ constexpr int64_t W = 5;
+ auto model = make_gqa_model(GqaParams{"win"}.window(W));
+ decompose(model);
+
+ // The sliding-window band is the only GreaterEqual in the mask: too_old = GreaterEqual(distance, window),
+ // where window is a scalar constant. A wrong boundary here would silently widen/narrow the window.
+ std::shared_ptr<Node> greater_eq;
+ for (const auto& op : model->get_ordered_ops())
+ if (ov::is_type<op::v1::GreaterEqual>(op))
+ greater_eq = op;
+ ASSERT_NE(greater_eq, nullptr) << "sliding-window GreaterEqual band not found";
+ auto window_const = as_type_ptr<op::v0::Constant>(greater_eq->get_input_node_shared_ptr(1));
+ ASSERT_NE(window_const, nullptr) << "window boundary is not a constant";
+ EXPECT_EQ(window_const->cast_vector<int64_t>(), std::vector<int64_t>{W});
+}
+
+TEST(GroupQueryAttentionValues, smooth_softmax_sink_is_zero) {
+ auto model = make_gqa_model(GqaParams{"smooth"}.sink_smooth());
+ decompose(model);
+
+ // smooth_softmax adds a zero logit to the softmax denominator: the SDPA sink input (6th) is a
+ // Broadcast of a zero constant. A non-zero value here would bias every row's normalization.
+ auto sdpa = find_sdpa(model);
+ ASSERT_NE(sdpa, nullptr);
+ ASSERT_EQ(sdpa->get_input_size(), 6u);
+ auto sink_bcast = as_type_ptr<op::v3::Broadcast>(sdpa->get_input_node_shared_ptr(5));
+ ASSERT_NE(sink_bcast, nullptr) << "smooth_softmax sink must be a Broadcast of a zero constant";
+ auto zero_const = as_type_ptr<op::v0::Constant>(sink_bcast->get_input_node_shared_ptr(0));
+ ASSERT_NE(zero_const, nullptr);
+ const auto vals = zero_const->cast_vector<float>();
+ ASSERT_EQ(vals.size(), 1u);
+ EXPECT_FLOAT_EQ(vals[0], 0.0f);
+}
+
+TEST(GroupQueryAttentionValues, head_sink_reshapes_input_to_per_head_sink) {
+ auto model = make_gqa_model(GqaParams{"hsink"}.sink_head());
+ decompose(model);
+
+ // head_sink provides a per-head logit: the SDPA sink input (6th) is the head_sink input reshaped to
+ // the [1, num_heads, 1, 1] layout SDPA expects. A wrong target shape would misroute the per-head values.
+ auto sdpa = find_sdpa(model);
+ ASSERT_NE(sdpa, nullptr);
+ ASSERT_EQ(sdpa->get_input_size(), 6u);
+ auto sink_reshape = as_type_ptr<op::v1::Reshape>(sdpa->get_input_node_shared_ptr(5));
+ ASSERT_NE(sink_reshape, nullptr) << "head_sink sink must be a Reshape of the head_sink input";
+ auto shape_const = as_type_ptr<op::v0::Constant>(sink_reshape->get_input_node_shared_ptr(1));
+ ASSERT_NE(shape_const, nullptr);
+ EXPECT_EQ(shape_const->cast_vector<int64_t>(), (std::vector<int64_t>{1, -1, 1, 1}));
+}
diff --git a/src/common/transformations/tests/sources.cmake b/src/common/transformations/tests/sources.cmake
index 1097a7d7785..6e195282f93 100644
--- a/src/common/transformations/tests/sources.cmake
+++ b/src/common/transformations/tests/sources.cmake
@@ -223,6 +223,7 @@ set(OP_CONVERSIONS_TESTS_SRCS
${CMAKE_CURRENT_LIST_DIR}/op_conversions/fq_decomposition_test.cpp
${CMAKE_CURRENT_LIST_DIR}/op_conversions/gelu7_downgrade.cpp
${CMAKE_CURRENT_LIST_DIR}/op_conversions/group_normalization_decomposition_test.cpp
+ ${CMAKE_CURRENT_LIST_DIR}/op_conversions/group_query_attention_decomposition_test.cpp
${CMAKE_CURRENT_LIST_DIR}/op_conversions/hsigmoid_decomposition_test.cpp
${CMAKE_CURRENT_LIST_DIR}/op_conversions/hswish_decomposition_test.cpp
${CMAKE_CURRENT_LIST_DIR}/op_conversions/log_softmax_decomposition_test.cpp
diff --git a/src/core/dev_api/openvino/op/group_query_attention.hpp b/src/core/dev_api/openvino/op/group_query_attention.hpp
index 4422d12ff58..477ab8c1f40 100644
--- a/src/core/dev_api/openvino/op/group_query_attention.hpp
+++ b/src/core/dev_api/openvino/op/group_query_attention.hpp
@@ -23,7 +23,10 @@ public:
bool rotary_interleaved,
int64_t kv_cache_bit_width = 0,
const std::string& k_quant_type = "NONE",
- const std::string& v_quant_type = "NONE");
+ const std::string& v_quant_type = "NONE",
+ int64_t local_window_size = -1,
+ bool sliding_window_cache = false,
+ bool smooth_softmax = false);
void validate_and_infer_types() override;
bool visit_attributes(AttributeVisitor& visitor) override;
std::shared_ptr<ov::Node> clone_with_new_inputs(const ov::OutputVector& new_args) const override;
@@ -52,6 +55,21 @@ public:
const std::string& get_v_quant_type() const {
return m_v_quant_type;
}
+ // Mistral-style local (sliding-window) attention. -1 disables the window (pure causal); a value
+ // >= 1 limits each query at absolute position q to keys k in [q - local_window_size + 1, q].
+ int64_t get_local_window_size() const {
+ return m_local_window_size;
+ }
+ // When true, the past/present KV buffers are window-sized (capacity C) and rolled with front
+ // eviction, keeping only the most recent min(total, C) tokens in cache-relative coordinates.
+ bool get_sliding_window_cache() const {
+ return m_sliding_window_cache;
+ }
+ // When true, softmax gains an extra zero logit in its denominator (or a per-head logit when a
+ // head_sink input is present), matching the ONNX Runtime smooth-softmax / head-sink behavior.
+ bool get_smooth_softmax() const {
+ return m_smooth_softmax;
+ }
// KV cache is quantized when a bit width is set and a K quantization scheme is selected.
bool is_kv_quantized() const {
return m_kv_cache_bit_width != 0 && m_k_quant_type != "NONE";
@@ -66,6 +84,9 @@ private:
int64_t m_kv_cache_bit_width = 0;
std::string m_k_quant_type = "NONE";
std::string m_v_quant_type = "NONE";
+ int64_t m_local_window_size = -1;
+ bool m_sliding_window_cache = false;
+ bool m_smooth_softmax = false;
};
} // namespace ov::op::internal
diff --git a/src/core/src/op/group_query_attention.cpp b/src/core/src/op/group_query_attention.cpp
index be3802e1f37..7a83b905026 100644
--- a/src/core/src/op/group_query_attention.cpp
+++ b/src/core/src/op/group_query_attention.cpp
@@ -16,7 +16,10 @@ GroupQueryAttention::GroupQueryAttention(const OutputVector& args,
bool rotary_interleaved,
int64_t kv_cache_bit_width,
const std::string& k_quant_type,
- const std::string& v_quant_type)
+ const std::string& v_quant_type,
+ int64_t local_window_size,
+ bool sliding_window_cache,
+ bool smooth_softmax)
: Op(args),
m_num_heads(num_heads),
m_kv_num_heads(kv_num_heads),
@@ -25,7 +28,10 @@ GroupQueryAttention::GroupQueryAttention(const OutputVector& args,
m_rotary_interleaved(rotary_interleaved),
m_kv_cache_bit_width(kv_cache_bit_width),
m_k_quant_type(k_quant_type),
- m_v_quant_type(v_quant_type) {
+ m_v_quant_type(v_quant_type),
+ m_local_window_size(local_window_size),
+ m_sliding_window_cache(sliding_window_cache),
+ m_smooth_softmax(smooth_softmax) {
constructor_validate_and_infer_types();
}
@@ -51,8 +57,9 @@ void GroupQueryAttention::validate_and_infer_types() {
auto kv_shape = PartialShape{batch_size, m_kv_num_heads, past_kv_shape[2], past_kv_shape[3]};
auto& output_kv_len = kv_shape[2];
- if (output_kv_len.is_dynamic() || sequence_len.is_dynamic()) {
- // For dynamic shapes, concatenate the past and current sequence lengths.
+ // A windowed KV cache keeps the past buffer's own (capacity) sequence dimension: it rolls in place
+ // with front eviction instead of growing. Otherwise present = past + current.
+ if (!m_sliding_window_cache && (output_kv_len.is_dynamic() || sequence_len.is_dynamic())) {
output_kv_len += sequence_len;
}
@@ -62,6 +69,49 @@ void GroupQueryAttention::validate_and_infer_types() {
q_type == element::f32 || q_type == element::f16,
"GroupQueryAttention supports following query element types: {f32, f16}");
+ // The op is reachable directly from a loaded IR, so mirror the ONNX frontend's sliding-window
+ // preconditions here as well: local_window_size must be -1 (disabled) or >= 1, and a windowed cache
+ // (sliding_window_cache) requires a real window (>= 1). This keeps the op and the frontend in agreement.
+ NODE_VALIDATION_CHECK(this,
+ m_local_window_size == -1 || m_local_window_size >= 1,
+ "GroupQueryAttention: local_window_size must be -1 (disabled) or >= 1, got ",
+ m_local_window_size);
+ NODE_VALIDATION_CHECK(this,
+ !m_sliding_window_cache || m_local_window_size >= 1,
+ "GroupQueryAttention: sliding_window_cache requires local_window_size >= 1, got ",
+ m_local_window_size);
+ // Windowed cache: single-token decode (sequence_length == 1) is always correct, and a multi-token step
+ // that fits inside the window (past + current <= capacity) also decomposes correctly. The unmodeled case
+ // is a multi-token step that crosses a window eviction (the staging regime ONNX Runtime runs against a
+ // temporary larger buffer). Whether a step crosses depends on the past length, which is a runtime value
+ // (derived from seqlens_k), so it cannot be decided from shapes alone. A dynamic sequence_length is
+ // therefore left enabled (CPU/GPU): at runtime it is typically decode or fitting prefill, and rejecting it
+ // would disable those. A *statically* known sequence_length > 1 is a genuine multi-token graph whose
+ // correctness we cannot guarantee (it may cross an eviction at runtime), so reject it up front; only
+ // sequence_length == 1 is provably safe statically.
+ if (m_sliding_window_cache && sequence_len.is_static()) {
+ NODE_VALIDATION_CHECK(this,
+ sequence_len.get_length() == 1,
+ "GroupQueryAttention: sliding_window_cache with a statically known sequence length is "
+ "only supported for single-token decode (sequence_length == 1), got ",
+ sequence_len.get_length(),
+ " (the multi-token staging regime is not yet modelled).");
+ }
+
+ // The decomposition derives a scalar past length (past_seqlen = total - current) and assumes a single
+ // batch entry ("Only consider batch is 1"); with batch_size > 1 the per-batch past lengths differ and the
+ // attention mask / cache indexing would be silently wrong. The batch dimension is dynamic in the usual
+ // dynamic-shape deployments (CPU/GPU), which cannot be checked here, so reject only a statically known
+ // batch_size > 1 rather than the whole dynamic path.
+ if (batch_size.is_static()) {
+ NODE_VALIDATION_CHECK(this,
+ batch_size.get_length() == 1,
+ "GroupQueryAttention is only supported for batch_size == 1 when the batch dimension is "
+ "statically known, got batch_size = ",
+ batch_size.get_length(),
+ ".");
+ }
+
// The KV cache (past_key/past_value, input 3/4) may be quantized. present_key/present_value inherit the
// cache element type so a quantized (i8/u8/f8e4m3) cache round-trips from past to present, matching the ONNX spec.
const auto& kv_cache_type = get_input_element_type(3);
@@ -110,9 +160,12 @@ bool GroupQueryAttention::visit_attributes(AttributeVisitor& visitor) {
visitor.on_attribute("k_quant_type", m_k_quant_type);
visitor.on_attribute("kv_cache_bit_width", m_kv_cache_bit_width);
visitor.on_attribute("kv_num_heads", m_kv_num_heads);
+ visitor.on_attribute("local_window_size", m_local_window_size);
visitor.on_attribute("num_heads", m_num_heads);
visitor.on_attribute("rotary_interleaved", m_rotary_interleaved);
visitor.on_attribute("scale", m_scale);
+ visitor.on_attribute("sliding_window_cache", m_sliding_window_cache);
+ visitor.on_attribute("smooth_softmax", m_smooth_softmax);
visitor.on_attribute("v_quant_type", m_v_quant_type);
return true;
}
@@ -128,7 +181,10 @@ std::shared_ptr<ov::Node> GroupQueryAttention::clone_with_new_inputs(const ov::O
m_rotary_interleaved,
m_kv_cache_bit_width,
m_k_quant_type,
- m_v_quant_type);
+ m_v_quant_type,
+ m_local_window_size,
+ m_sliding_window_cache,
+ m_smooth_softmax);
}
} // namespace ov::op::internal
diff --git a/src/frontends/onnx/frontend/src/op/com.microsoft/group_query_attention.cpp b/src/frontends/onnx/frontend/src/op/com.microsoft/group_query_attention.cpp
index c2677a4683b..72213aae459 100644
--- a/src/frontends/onnx/frontend/src/op/com.microsoft/group_query_attention.cpp
+++ b/src/frontends/onnx/frontend/src/op/com.microsoft/group_query_attention.cpp
@@ -50,15 +50,76 @@ ov::OutputVector group_query_attention(const ov::frontend::onnx::Node& node) {
const auto kv_cache_bit_width = node.get_attribute_value<int64_t>("kv_cache_bit_width", 0);
const auto k_quant_type = node.get_attribute_value<std::string>("k_quant_type", "NONE");
const auto v_quant_type = node.get_attribute_value<std::string>("v_quant_type", "NONE");
+ // Sliding-window / softcap / smooth-softmax attributes (com.microsoft spec). Default to no-op values,
+ // matching the ONNX Runtime defaults (local_window_size = -1 disables the window).
+ const auto local_window_size = node.get_attribute_value<int64_t>("local_window_size", -1);
+ const auto sliding_window_cache = node.get_attribute_value<int64_t>("sliding_window_cache", 0);
+ const auto softcap = node.get_attribute_value<float>("softcap", 0.0f);
+ const auto smooth_softmax = node.get_attribute_value<int64_t>("smooth_softmax", 0);
+ const auto qk_output = node.get_attribute_value<int64_t>("qk_output", 0);
// Reject spec inputs whose semantics are not implemented by the OpenVINO decomposition.
- FRONT_END_OP_CONVERSION_CHECK(!common::is_input_valid(onnx_op_inputs, 11),
- "GroupQueryAttention: head_sink input is not supported.");
FRONT_END_OP_CONVERSION_CHECK(
!common::is_input_valid(onnx_op_inputs, 14) && !common::is_input_valid(onnx_op_inputs, 15),
"GroupQueryAttention: q_norm_weight/k_norm_weight (QK-Norm) inputs are not "
"supported.");
+ // Reject spec attributes whose semantics are not implemented by the OpenVINO decomposition.
+ // local_window_size == -1 disables the window; a value >= 1 selects a sliding window. A window of
+ // size 0 is an empty attention (every query masks all keys) and is not a valid ONNX Runtime config.
+ FRONT_END_OP_CONVERSION_CHECK(local_window_size == -1 || local_window_size >= 1,
+ "GroupQueryAttention: local_window_size must be -1 (disabled) or >= 1, got ",
+ local_window_size,
+ ".");
+ // A windowed KV cache requires a real sliding window (local_window_size > 0), matching the ONNX
+ // Runtime precondition. The staging regime (prompt longer than the buffer) and batch > 1 are not
+ // handled by this decomposition; the decode / fitting-prefill path is.
+ if (sliding_window_cache != 0) {
+ FRONT_END_OP_CONVERSION_CHECK(local_window_size >= 1,
+ "GroupQueryAttention: sliding_window_cache=1 requires local_window_size >= 1.");
+ FRONT_END_OP_CONVERSION_CHECK(
+ common::is_input_valid(onnx_op_inputs, 3) && common::is_input_valid(onnx_op_inputs, 4),
+ "GroupQueryAttention: sliding_window_cache=1 requires past_key and past_value.");
+ // attention_bias (input 10) is indexed by absolute total_sequence_length, but a windowed cache rolls
+ // with front eviction so cache slot j holds absolute key (survivor_start + j). After the first
+ // eviction the bias columns no longer align with the cache slots, and the decomposition slices the
+ // bias as bias[..., 0:capacity] regardless. Reject the combination until the bias is gathered with
+ // the same survivor/new index sets that build the present buffer.
+ FRONT_END_OP_CONVERSION_CHECK(
+ !common::is_input_valid(onnx_op_inputs, 10),
+ "GroupQueryAttention: attention_bias is not supported together with sliding_window_cache=1.");
+ // Only single-token decode (sequence_length == 1) is supported for the windowed cache: it always
+ // stays within the window and matches ONNX Runtime exactly. Any multi-token step is the staging
+ // regime (ORT runs it against a temporary larger buffer), which this decomposition does not model
+ // and would otherwise either crash or silently diverge. Reject a static sequence_length > 1.
+ const auto& q_ps = onnx_op_inputs[0].get_partial_shape();
+ if (q_ps.rank().is_static() && q_ps.rank().get_length() == 3 && q_ps[1].is_static()) {
+ FRONT_END_OP_CONVERSION_CHECK(q_ps[1].get_length() == 1,
+ "GroupQueryAttention: sliding_window_cache=1 is only supported for "
+ "single-token decode (sequence_length == 1), got sequence_length = ",
+ q_ps[1].get_length(),
+ " (multi-token staging regime is not supported).");
+ }
+ // The windowed cache-end arithmetic uses gap = capacity - local_window_size + 1, which must be >= 1;
+ // with capacity < local_window_size it would divide by zero (or a negative gap) at inference. The ONNX
+ // Runtime precondition is the same: a cache capacity of at least local_window_size. Enforce it here
+ // whenever the past_key capacity (dim 2) is static; a dynamic capacity is clamped in the pass.
+ const auto& past_key_ps = onnx_op_inputs[3].get_partial_shape();
+ if (past_key_ps.rank().is_static() && past_key_ps.rank().get_length() == 4 && past_key_ps[2].is_static()) {
+ FRONT_END_OP_CONVERSION_CHECK(past_key_ps[2].get_length() >= local_window_size,
+ "GroupQueryAttention: sliding_window_cache=1 requires a past_key/past_value "
+ "cache capacity (dim 2) of at least local_window_size (",
+ local_window_size,
+ "), got capacity = ",
+ past_key_ps[2].get_length(),
+ ".");
+ }
+ }
+ FRONT_END_OP_CONVERSION_CHECK(softcap == 0.0f, "GroupQueryAttention: softcap is not supported.");
+ // qk_output (spec: emit the QxK' matrix before/after softmax as a 4th `output_qk` output) is not
+ // produced by this decomposition. Reject a non-default value rather than silently dropping the output.
+ FRONT_END_OP_CONVERSION_CHECK(qk_output == 0, "GroupQueryAttention: qk_output is not supported.");
+
if (0 != do_rotary) {
constexpr size_t cos_cache_index = 7;
constexpr size_t sin_cache_index = 8;
@@ -145,7 +206,10 @@ ov::OutputVector group_query_attention(const ov::frontend::onnx::Node& node) {
rotary_interleaved,
kv_cache_bit_width,
k_quant_type,
- v_quant_type)
+ v_quant_type,
+ local_window_size,
+ sliding_window_cache != 0,
+ smooth_softmax != 0)
->outputs();
}
diff --git a/src/frontends/onnx/tests/models/com.microsoft/gqa_bias_swc.prototxt b/src/frontends/onnx/tests/models/com.microsoft/gqa_bias_swc.prototxt
new file mode 100644
index 00000000000..acff4565a81
--- /dev/null
+++ b/src/frontends/onnx/tests/models/com.microsoft/gqa_bias_swc.prototxt
@@ -0,0 +1,224 @@
+ir_version: 10
+graph {
+ node {
+ input: "query"
+ input: ""
+ input: ""
+ input: "past_key"
+ input: "past_value"
+ input: "seqlens_k"
+ input: "total_sequence_length"
+ input: ""
+ input: ""
+ input: ""
+ input: "attention_bias"
+ output: "output"
+ output: "present_key"
+ output: "present_value"
+ op_type: "GroupQueryAttention"
+ attribute {
+ name: "kv_num_heads"
+ i: 1
+ type: INT
+ }
+ attribute {
+ name: "local_window_size"
+ i: 2
+ type: INT
+ }
+ attribute {
+ name: "num_heads"
+ i: 2
+ type: INT
+ }
+ attribute {
+ name: "sliding_window_cache"
+ i: 1
+ type: INT
+ }
+ domain: "com.microsoft"
+ }
+ name: "GQA_bias_swc"
+ input {
+ name: "query"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 64
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "past_key"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 16
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "past_value"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 16
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "seqlens_k"
+ type {
+ tensor_type {
+ elem_type: 6
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "total_sequence_length"
+ type {
+ tensor_type {
+ elem_type: 6
+ shape {
+ }
+ }
+ }
+ }
+ input {
+ name: "attention_bias"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ }
+ }
+ }
+ }
+ output {
+ name: "output"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 32
+ }
+ }
+ }
+ }
+ }
+ output {
+ name: "present_key"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 16
+ }
+ }
+ }
+ }
+ }
+ output {
+ name: "present_value"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 16
+ }
+ }
+ }
+ }
+ }
+}
+opset_import {
+ domain: ""
+ version: 17
+}
+opset_import {
+ domain: "com.microsoft"
+ version: 1
+}
diff --git a/src/frontends/onnx/tests/models/com.microsoft/gqa_bias_window.prototxt b/src/frontends/onnx/tests/models/com.microsoft/gqa_bias_window.prototxt
new file mode 100644
index 00000000000..bef7696a9ee
--- /dev/null
+++ b/src/frontends/onnx/tests/models/com.microsoft/gqa_bias_window.prototxt
@@ -0,0 +1,219 @@
+ir_version: 10
+graph {
+ node {
+ input: "query"
+ input: ""
+ input: ""
+ input: "past_key"
+ input: "past_value"
+ input: "seqlens_k"
+ input: "total_sequence_length"
+ input: ""
+ input: ""
+ input: ""
+ input: "attention_bias"
+ output: "output"
+ output: "present_key"
+ output: "present_value"
+ op_type: "GroupQueryAttention"
+ attribute {
+ name: "kv_num_heads"
+ i: 1
+ type: INT
+ }
+ attribute {
+ name: "local_window_size"
+ i: 2
+ type: INT
+ }
+ attribute {
+ name: "num_heads"
+ i: 2
+ type: INT
+ }
+ domain: "com.microsoft"
+ }
+ name: "GQA_bias_window"
+ input {
+ name: "query"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_param: "S"
+ }
+ dim {
+ dim_value: 64
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "past_key"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_param: "P"
+ }
+ dim {
+ dim_value: 16
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "past_value"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_param: "P"
+ }
+ dim {
+ dim_value: 16
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "seqlens_k"
+ type {
+ tensor_type {
+ elem_type: 6
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "total_sequence_length"
+ type {
+ tensor_type {
+ elem_type: 6
+ shape {
+ }
+ }
+ }
+ }
+ input {
+ name: "attention_bias"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_param: "S"
+ }
+ dim {
+ dim_param: "T"
+ }
+ }
+ }
+ }
+ }
+ output {
+ name: "output"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_param: "S"
+ }
+ dim {
+ dim_value: 32
+ }
+ }
+ }
+ }
+ }
+ output {
+ name: "present_key"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_param: "T"
+ }
+ dim {
+ dim_value: 16
+ }
+ }
+ }
+ }
+ }
+ output {
+ name: "present_value"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_param: "T"
+ }
+ dim {
+ dim_value: 16
+ }
+ }
+ }
+ }
+ }
+}
+opset_import {
+ domain: ""
+ version: 17
+}
+opset_import {
+ domain: "com.microsoft"
+ version: 1
+}
diff --git a/src/frontends/onnx/tests/models/com.microsoft/gqa_f8e4m3fnkv_swc.prototxt b/src/frontends/onnx/tests/models/com.microsoft/gqa_f8e4m3fnkv_swc.prototxt
new file mode 100644
index 00000000000..0fb98fec025
--- /dev/null
+++ b/src/frontends/onnx/tests/models/com.microsoft/gqa_f8e4m3fnkv_swc.prototxt
@@ -0,0 +1,232 @@
+ir_version: 10
+graph {
+ node {
+ input: "query"
+ input: ""
+ input: ""
+ input: "past_key"
+ input: "past_value"
+ input: "seqlens_k"
+ input: "total_sequence_length"
+ input: ""
+ input: ""
+ input: ""
+ input: ""
+ input: ""
+ input: "k_scale"
+ input: "v_scale"
+ output: "output"
+ output: "present_key"
+ output: "present_value"
+ op_type: "GroupQueryAttention"
+ attribute {
+ name: "k_quant_type"
+ s: "PER_TENSOR"
+ type: STRING
+ }
+ attribute {
+ name: "kv_cache_bit_width"
+ i: 8
+ type: INT
+ }
+ attribute {
+ name: "kv_num_heads"
+ i: 1
+ type: INT
+ }
+ attribute {
+ name: "local_window_size"
+ i: 2
+ type: INT
+ }
+ attribute {
+ name: "num_heads"
+ i: 2
+ type: INT
+ }
+ attribute {
+ name: "sliding_window_cache"
+ i: 1
+ type: INT
+ }
+ attribute {
+ name: "v_quant_type"
+ s: "PER_TENSOR"
+ type: STRING
+ }
+ domain: "com.microsoft"
+ }
+ name: "GQA_f8_swc"
+ initializer {
+ dims: 1
+ data_type: 1
+ float_data: 0.1
+ name: "k_scale"
+ }
+ initializer {
+ dims: 1
+ data_type: 1
+ float_data: 0.1
+ name: "v_scale"
+ }
+ input {
+ name: "query"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_param: "S"
+ }
+ dim {
+ dim_value: 64
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "past_key"
+ type {
+ tensor_type {
+ elem_type: 17
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 4
+ }
+ dim {
+ dim_value: 16
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "past_value"
+ type {
+ tensor_type {
+ elem_type: 17
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 4
+ }
+ dim {
+ dim_value: 16
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "seqlens_k"
+ type {
+ tensor_type {
+ elem_type: 6
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "total_sequence_length"
+ type {
+ tensor_type {
+ elem_type: 6
+ shape {
+ }
+ }
+ }
+ }
+ output {
+ name: "output"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_param: "S"
+ }
+ dim {
+ dim_value: 32
+ }
+ }
+ }
+ }
+ }
+ output {
+ name: "present_key"
+ type {
+ tensor_type {
+ elem_type: 17
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 4
+ }
+ dim {
+ dim_value: 16
+ }
+ }
+ }
+ }
+ }
+ output {
+ name: "present_value"
+ type {
+ tensor_type {
+ elem_type: 17
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 4
+ }
+ dim {
+ dim_value: 16
+ }
+ }
+ }
+ }
+ }
+}
+opset_import {
+ domain: ""
+ version: 17
+}
+opset_import {
+ domain: "com.microsoft"
+ version: 1
+}
diff --git a/src/frontends/onnx/tests/models/com.microsoft/gqa_head_sink.prototxt b/src/frontends/onnx/tests/models/com.microsoft/gqa_head_sink.prototxt
new file mode 100644
index 00000000000..95d31c015d7
--- /dev/null
+++ b/src/frontends/onnx/tests/models/com.microsoft/gqa_head_sink.prototxt
@@ -0,0 +1,181 @@
+ir_version: 10
+graph {
+ node {
+ input: "query"
+ input: ""
+ input: ""
+ input: "past_key"
+ input: "past_value"
+ input: "seqlens_k"
+ input: "total_sequence_length"
+ input: ""
+ input: ""
+ input: ""
+ input: ""
+ input: "head_sink"
+ output: "output"
+ output: "present_key"
+ output: "present_value"
+ name: "GroupQueryAttention_0"
+ op_type: "GroupQueryAttention"
+ attribute {
+ name: "do_rotary"
+ i: 0
+ type: INT
+ }
+ attribute {
+ name: "kv_num_heads"
+ i: 1
+ type: INT
+ }
+ attribute {
+ name: "local_window_size"
+ i: -1
+ type: INT
+ }
+ attribute {
+ name: "num_heads"
+ i: 2
+ type: INT
+ }
+ attribute {
+ name: "rotary_interleaved"
+ i: 0
+ type: INT
+ }
+ attribute {
+ name: "smooth_softmax"
+ i: 0
+ type: INT
+ }
+ attribute {
+ name: "softcap"
+ f: 0
+ type: FLOAT
+ }
+ domain: "com.microsoft"
+ }
+ name: "GroupQueryAttention_Graph"
+ input {
+ name: "query"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_param: "sequence_length" }
+ dim { dim_value: 64 }
+ }
+ }
+ }
+ }
+ input {
+ name: "past_key"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_value: 1 }
+ dim { dim_param: "past_sequence_length" }
+ dim { dim_value: 16 }
+ }
+ }
+ }
+ }
+ input {
+ name: "past_value"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_value: 1 }
+ dim { dim_param: "past_sequence_length" }
+ dim { dim_value: 16 }
+ }
+ }
+ }
+ }
+ input {
+ name: "seqlens_k"
+ type {
+ tensor_type {
+ elem_type: 6
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_value: 1 }
+ }
+ }
+ }
+ }
+ input {
+ name: "total_sequence_length"
+ type{
+ tensor_type {
+ elem_type: 6
+ shape {
+ }
+ }
+ }
+ }
+ input {
+ name: "head_sink"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim { dim_value: 2 }
+ }
+ }
+ }
+ }
+ output {
+ name: "output"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_param: "sequence_length" }
+ dim { dim_value: 32 }
+ }
+ }
+ }
+ }
+ output {
+ name: "present_key"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_value: 1 }
+ dim { dim_param: "total_sequence_length" }
+ dim { dim_value: 16 }
+ }
+ }
+ }
+ }
+ output {
+ name: "present_value"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_value: 1 }
+ dim { dim_param: "total_sequence_length" }
+ dim { dim_value: 16 }
+ }
+ }
+ }
+ }
+}
+opset_import {
+ version: 11
+}
+opset_import {
+ domain: "com.microsoft"
+ version: 1
+}
diff --git a/src/frontends/onnx/tests/models/com.microsoft/gqa_i4kv_swc.prototxt b/src/frontends/onnx/tests/models/com.microsoft/gqa_i4kv_swc.prototxt
new file mode 100644
index 00000000000..f27d772a83d
--- /dev/null
+++ b/src/frontends/onnx/tests/models/com.microsoft/gqa_i4kv_swc.prototxt
@@ -0,0 +1,232 @@
+ir_version: 10
+graph {
+ node {
+ input: "query"
+ input: ""
+ input: ""
+ input: "past_key"
+ input: "past_value"
+ input: "seqlens_k"
+ input: "total_sequence_length"
+ input: ""
+ input: ""
+ input: ""
+ input: ""
+ input: ""
+ input: "k_scale"
+ input: "v_scale"
+ output: "output"
+ output: "present_key"
+ output: "present_value"
+ op_type: "GroupQueryAttention"
+ attribute {
+ name: "k_quant_type"
+ s: "PER_TENSOR"
+ type: STRING
+ }
+ attribute {
+ name: "kv_cache_bit_width"
+ i: 4
+ type: INT
+ }
+ attribute {
+ name: "kv_num_heads"
+ i: 1
+ type: INT
+ }
+ attribute {
+ name: "local_window_size"
+ i: 2
+ type: INT
+ }
+ attribute {
+ name: "num_heads"
+ i: 2
+ type: INT
+ }
+ attribute {
+ name: "sliding_window_cache"
+ i: 1
+ type: INT
+ }
+ attribute {
+ name: "v_quant_type"
+ s: "PER_TENSOR"
+ type: STRING
+ }
+ domain: "com.microsoft"
+ }
+ name: "GQA_i4_swc"
+ initializer {
+ dims: 1
+ data_type: 1
+ float_data: 0.05
+ name: "k_scale"
+ }
+ initializer {
+ dims: 1
+ data_type: 1
+ float_data: 0.05
+ name: "v_scale"
+ }
+ input {
+ name: "query"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_param: "S"
+ }
+ dim {
+ dim_value: 128
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "past_key"
+ type {
+ tensor_type {
+ elem_type: 2
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 4
+ }
+ dim {
+ dim_value: 16
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "past_value"
+ type {
+ tensor_type {
+ elem_type: 2
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 4
+ }
+ dim {
+ dim_value: 16
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "seqlens_k"
+ type {
+ tensor_type {
+ elem_type: 6
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "total_sequence_length"
+ type {
+ tensor_type {
+ elem_type: 6
+ shape {
+ }
+ }
+ }
+ }
+ output {
+ name: "output"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_param: "S"
+ }
+ dim {
+ dim_value: 64
+ }
+ }
+ }
+ }
+ }
+ output {
+ name: "present_key"
+ type {
+ tensor_type {
+ elem_type: 2
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 4
+ }
+ dim {
+ dim_value: 16
+ }
+ }
+ }
+ }
+ }
+ output {
+ name: "present_value"
+ type {
+ tensor_type {
+ elem_type: 2
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 4
+ }
+ dim {
+ dim_value: 16
+ }
+ }
+ }
+ }
+ }
+}
+opset_import {
+ domain: ""
+ version: 17
+}
+opset_import {
+ domain: "com.microsoft"
+ version: 1
+}
diff --git a/src/frontends/onnx/tests/models/com.microsoft/gqa_i8kv_sliding_window.prototxt b/src/frontends/onnx/tests/models/com.microsoft/gqa_i8kv_sliding_window.prototxt
new file mode 100644
index 00000000000..288c800f843
--- /dev/null
+++ b/src/frontends/onnx/tests/models/com.microsoft/gqa_i8kv_sliding_window.prototxt
@@ -0,0 +1,232 @@
+ir_version: 10
+graph {
+ node {
+ input: "query"
+ input: ""
+ input: ""
+ input: "past_key"
+ input: "past_value"
+ input: "seqlens_k"
+ input: "total_sequence_length"
+ input: ""
+ input: ""
+ input: ""
+ input: ""
+ input: ""
+ input: "k_scale"
+ input: "v_scale"
+ output: "output"
+ output: "present_key"
+ output: "present_value"
+ op_type: "GroupQueryAttention"
+ attribute {
+ name: "do_rotary"
+ i: 0
+ type: INT
+ }
+ attribute {
+ name: "k_quant_type"
+ s: "PER_TENSOR"
+ type: STRING
+ }
+ attribute {
+ name: "kv_cache_bit_width"
+ i: 8
+ type: INT
+ }
+ attribute {
+ name: "kv_num_heads"
+ i: 1
+ type: INT
+ }
+ attribute {
+ name: "local_window_size"
+ i: 2
+ type: INT
+ }
+ attribute {
+ name: "num_heads"
+ i: 2
+ type: INT
+ }
+ attribute {
+ name: "v_quant_type"
+ s: "PER_TENSOR"
+ type: STRING
+ }
+ domain: "com.microsoft"
+ }
+ name: "GQA_DynQuant"
+ initializer {
+ dims: 1
+ data_type: 1
+ float_data: 0.06957
+ name: "k_scale"
+ }
+ initializer {
+ dims: 1
+ data_type: 1
+ float_data: 0.06868
+ name: "v_scale"
+ }
+ input {
+ name: "query"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_param: "batch_size"
+ }
+ dim {
+ dim_param: "sequence_length"
+ }
+ dim {
+ dim_value: 32
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "past_key"
+ type {
+ tensor_type {
+ elem_type: 3
+ shape {
+ dim {
+ dim_param: "batch_size"
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_param: "past_sequence_length"
+ }
+ dim {
+ dim_value: 8
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "past_value"
+ type {
+ tensor_type {
+ elem_type: 3
+ shape {
+ dim {
+ dim_param: "batch_size"
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_param: "past_sequence_length"
+ }
+ dim {
+ dim_value: 8
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "seqlens_k"
+ type {
+ tensor_type {
+ elem_type: 6
+ shape {
+ dim {
+ dim_param: "batch_size"
+ }
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "total_sequence_length"
+ type {
+ tensor_type {
+ elem_type: 6
+ shape {
+ }
+ }
+ }
+ }
+ output {
+ name: "output"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_param: "batch_size"
+ }
+ dim {
+ dim_param: "sequence_length"
+ }
+ dim {
+ dim_value: 16
+ }
+ }
+ }
+ }
+ }
+ output {
+ name: "present_key"
+ type {
+ tensor_type {
+ elem_type: 3
+ shape {
+ dim {
+ dim_param: "batch_size"
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_param: "total_sequence_length"
+ }
+ dim {
+ dim_value: 8
+ }
+ }
+ }
+ }
+ }
+ output {
+ name: "present_value"
+ type {
+ tensor_type {
+ elem_type: 3
+ shape {
+ dim {
+ dim_param: "batch_size"
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_param: "total_sequence_length"
+ }
+ dim {
+ dim_value: 8
+ }
+ }
+ }
+ }
+ }
+}
+opset_import {
+ domain: ""
+ version: 21
+}
+opset_import {
+ domain: "com.microsoft"
+ version: 1
+}
diff --git a/src/frontends/onnx/tests/models/com.microsoft/gqa_i8kv_swc.prototxt b/src/frontends/onnx/tests/models/com.microsoft/gqa_i8kv_swc.prototxt
new file mode 100644
index 00000000000..cdd4019ada1
--- /dev/null
+++ b/src/frontends/onnx/tests/models/com.microsoft/gqa_i8kv_swc.prototxt
@@ -0,0 +1,232 @@
+ir_version: 10
+graph {
+ node {
+ input: "query"
+ input: ""
+ input: ""
+ input: "past_key"
+ input: "past_value"
+ input: "seqlens_k"
+ input: "total_sequence_length"
+ input: ""
+ input: ""
+ input: ""
+ input: ""
+ input: ""
+ input: "k_scale"
+ input: "v_scale"
+ output: "output"
+ output: "present_key"
+ output: "present_value"
+ op_type: "GroupQueryAttention"
+ attribute {
+ name: "k_quant_type"
+ s: "PER_TENSOR"
+ type: STRING
+ }
+ attribute {
+ name: "kv_cache_bit_width"
+ i: 8
+ type: INT
+ }
+ attribute {
+ name: "kv_num_heads"
+ i: 1
+ type: INT
+ }
+ attribute {
+ name: "local_window_size"
+ i: 2
+ type: INT
+ }
+ attribute {
+ name: "num_heads"
+ i: 2
+ type: INT
+ }
+ attribute {
+ name: "sliding_window_cache"
+ i: 1
+ type: INT
+ }
+ attribute {
+ name: "v_quant_type"
+ s: "PER_TENSOR"
+ type: STRING
+ }
+ domain: "com.microsoft"
+ }
+ name: "GQA_i8_swc"
+ initializer {
+ dims: 1
+ data_type: 1
+ float_data: 0.05
+ name: "k_scale"
+ }
+ initializer {
+ dims: 1
+ data_type: 1
+ float_data: 0.05
+ name: "v_scale"
+ }
+ input {
+ name: "query"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_param: "S"
+ }
+ dim {
+ dim_value: 64
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "past_key"
+ type {
+ tensor_type {
+ elem_type: 3
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 4
+ }
+ dim {
+ dim_value: 16
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "past_value"
+ type {
+ tensor_type {
+ elem_type: 3
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 4
+ }
+ dim {
+ dim_value: 16
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "seqlens_k"
+ type {
+ tensor_type {
+ elem_type: 6
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "total_sequence_length"
+ type {
+ tensor_type {
+ elem_type: 6
+ shape {
+ }
+ }
+ }
+ }
+ output {
+ name: "output"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_param: "S"
+ }
+ dim {
+ dim_value: 32
+ }
+ }
+ }
+ }
+ }
+ output {
+ name: "present_key"
+ type {
+ tensor_type {
+ elem_type: 3
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 4
+ }
+ dim {
+ dim_value: 16
+ }
+ }
+ }
+ }
+ }
+ output {
+ name: "present_value"
+ type {
+ tensor_type {
+ elem_type: 3
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 4
+ }
+ dim {
+ dim_value: 16
+ }
+ }
+ }
+ }
+ }
+}
+opset_import {
+ domain: ""
+ version: 17
+}
+opset_import {
+ domain: "com.microsoft"
+ version: 1
+}
diff --git a/src/frontends/onnx/tests/models/com.microsoft/gqa_qk_output.prototxt b/src/frontends/onnx/tests/models/com.microsoft/gqa_qk_output.prototxt
new file mode 100644
index 00000000000..fdeadb75102
--- /dev/null
+++ b/src/frontends/onnx/tests/models/com.microsoft/gqa_qk_output.prototxt
@@ -0,0 +1,193 @@
+ir_version: 10
+graph {
+ node {
+ input: "query"
+ input: ""
+ input: ""
+ input: "past_key"
+ input: "past_value"
+ input: "seqlens_k"
+ input: "total_sequence_length"
+ output: "output"
+ output: "present_key"
+ output: "present_value"
+ op_type: "GroupQueryAttention"
+ attribute {
+ name: "kv_num_heads"
+ i: 1
+ type: INT
+ }
+ attribute {
+ name: "num_heads"
+ i: 2
+ type: INT
+ }
+ attribute {
+ name: "qk_output"
+ i: 1
+ type: INT
+ }
+ domain: "com.microsoft"
+ }
+ name: "GQA_qk_output"
+ input {
+ name: "query"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 64
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "past_key"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 16
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "past_value"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 16
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "seqlens_k"
+ type {
+ tensor_type {
+ elem_type: 6
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "total_sequence_length"
+ type {
+ tensor_type {
+ elem_type: 6
+ shape {
+ }
+ }
+ }
+ }
+ output {
+ name: "output"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 32
+ }
+ }
+ }
+ }
+ }
+ output {
+ name: "present_key"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 16
+ }
+ }
+ }
+ }
+ }
+ output {
+ name: "present_value"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 16
+ }
+ }
+ }
+ }
+ }
+}
+opset_import {
+ domain: ""
+ version: 17
+}
+opset_import {
+ domain: "com.microsoft"
+ version: 1
+}
diff --git a/src/frontends/onnx/tests/models/com.microsoft/gqa_sliding_window.prototxt b/src/frontends/onnx/tests/models/com.microsoft/gqa_sliding_window.prototxt
new file mode 100644
index 00000000000..4266bb00a6a
--- /dev/null
+++ b/src/frontends/onnx/tests/models/com.microsoft/gqa_sliding_window.prototxt
@@ -0,0 +1,165 @@
+ir_version: 10
+graph {
+ node {
+ input: "query"
+ input: ""
+ input: ""
+ input: "past_key"
+ input: "past_value"
+ input: "seqlens_k"
+ input: "total_sequence_length"
+ output: "output"
+ output: "present_key"
+ output: "present_value"
+ name: "GroupQueryAttention_0"
+ op_type: "GroupQueryAttention"
+ attribute {
+ name: "do_rotary"
+ i: 0
+ type: INT
+ }
+ attribute {
+ name: "kv_num_heads"
+ i: 1
+ type: INT
+ }
+ attribute {
+ name: "local_window_size"
+ i: 2
+ type: INT
+ }
+ attribute {
+ name: "num_heads"
+ i: 2
+ type: INT
+ }
+ attribute {
+ name: "rotary_interleaved"
+ i: 0
+ type: INT
+ }
+ attribute {
+ name: "smooth_softmax"
+ i: 0
+ type: INT
+ }
+ attribute {
+ name: "softcap"
+ f: 0
+ type: FLOAT
+ }
+ domain: "com.microsoft"
+ }
+ name: "GroupQueryAttention_Graph"
+ input {
+ name: "query"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_param: "sequence_length" }
+ dim { dim_value: 64 }
+ }
+ }
+ }
+ }
+ input {
+ name: "past_key"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_value: 1 }
+ dim { dim_param: "past_sequence_length" }
+ dim { dim_value: 16 }
+ }
+ }
+ }
+ }
+ input {
+ name: "past_value"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_value: 1 }
+ dim { dim_param: "past_sequence_length" }
+ dim { dim_value: 16 }
+ }
+ }
+ }
+ }
+ input {
+ name: "seqlens_k"
+ type {
+ tensor_type {
+ elem_type: 6
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_value: 1 }
+ }
+ }
+ }
+ }
+ input {
+ name: "total_sequence_length"
+ type{
+ tensor_type {
+ elem_type: 6
+ shape {
+ }
+ }
+ }
+ }
+ output {
+ name: "output"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_param: "sequence_length" }
+ dim { dim_value: 32 }
+ }
+ }
+ }
+ }
+ output {
+ name: "present_key"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_value: 1 }
+ dim { dim_param: "total_sequence_length" }
+ dim { dim_value: 16 }
+ }
+ }
+ }
+ }
+ output {
+ name: "present_value"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_value: 1 }
+ dim { dim_param: "total_sequence_length" }
+ dim { dim_value: 16 }
+ }
+ }
+ }
+ }
+}
+opset_import {
+ version: 11
+}
+opset_import {
+ domain: "com.microsoft"
+ version: 1
+}
diff --git a/src/frontends/onnx/tests/models/com.microsoft/gqa_sliding_window_cache.prototxt b/src/frontends/onnx/tests/models/com.microsoft/gqa_sliding_window_cache.prototxt
new file mode 100644
index 00000000000..3ed69ab2b1d
--- /dev/null
+++ b/src/frontends/onnx/tests/models/com.microsoft/gqa_sliding_window_cache.prototxt
@@ -0,0 +1,170 @@
+ir_version: 10
+graph {
+ node {
+ input: "query"
+ input: ""
+ input: ""
+ input: "past_key"
+ input: "past_value"
+ input: "seqlens_k"
+ input: "total_sequence_length"
+ output: "output"
+ output: "present_key"
+ output: "present_value"
+ name: "GroupQueryAttention_0"
+ op_type: "GroupQueryAttention"
+ attribute {
+ name: "do_rotary"
+ i: 0
+ type: INT
+ }
+ attribute {
+ name: "kv_num_heads"
+ i: 1
+ type: INT
+ }
+ attribute {
+ name: "local_window_size"
+ i: 2
+ type: INT
+ }
+ attribute {
+ name: "num_heads"
+ i: 2
+ type: INT
+ }
+ attribute {
+ name: "rotary_interleaved"
+ i: 0
+ type: INT
+ }
+ attribute {
+ name: "sliding_window_cache"
+ i: 1
+ type: INT
+ }
+ attribute {
+ name: "smooth_softmax"
+ i: 0
+ type: INT
+ }
+ attribute {
+ name: "softcap"
+ f: 0
+ type: FLOAT
+ }
+ domain: "com.microsoft"
+ }
+ name: "GroupQueryAttention_Graph"
+ input {
+ name: "query"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_param: "sequence_length" }
+ dim { dim_value: 64 }
+ }
+ }
+ }
+ }
+ input {
+ name: "past_key"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_value: 1 }
+ dim { dim_param: "past_sequence_length" }
+ dim { dim_value: 16 }
+ }
+ }
+ }
+ }
+ input {
+ name: "past_value"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_value: 1 }
+ dim { dim_param: "past_sequence_length" }
+ dim { dim_value: 16 }
+ }
+ }
+ }
+ }
+ input {
+ name: "seqlens_k"
+ type {
+ tensor_type {
+ elem_type: 6
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_value: 1 }
+ }
+ }
+ }
+ }
+ input {
+ name: "total_sequence_length"
+ type{
+ tensor_type {
+ elem_type: 6
+ shape {
+ }
+ }
+ }
+ }
+ output {
+ name: "output"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_param: "sequence_length" }
+ dim { dim_value: 32 }
+ }
+ }
+ }
+ }
+ output {
+ name: "present_key"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_value: 1 }
+ dim { dim_param: "total_sequence_length" }
+ dim { dim_value: 16 }
+ }
+ }
+ }
+ }
+ output {
+ name: "present_value"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_value: 1 }
+ dim { dim_param: "total_sequence_length" }
+ dim { dim_value: 16 }
+ }
+ }
+ }
+ }
+}
+opset_import {
+ version: 11
+}
+opset_import {
+ domain: "com.microsoft"
+ version: 1
+}
diff --git a/src/frontends/onnx/tests/models/com.microsoft/gqa_smooth_softmax.prototxt b/src/frontends/onnx/tests/models/com.microsoft/gqa_smooth_softmax.prototxt
new file mode 100644
index 00000000000..9ad6e6aeaf4
--- /dev/null
+++ b/src/frontends/onnx/tests/models/com.microsoft/gqa_smooth_softmax.prototxt
@@ -0,0 +1,165 @@
+ir_version: 10
+graph {
+ node {
+ input: "query"
+ input: ""
+ input: ""
+ input: "past_key"
+ input: "past_value"
+ input: "seqlens_k"
+ input: "total_sequence_length"
+ output: "output"
+ output: "present_key"
+ output: "present_value"
+ name: "GroupQueryAttention_0"
+ op_type: "GroupQueryAttention"
+ attribute {
+ name: "do_rotary"
+ i: 0
+ type: INT
+ }
+ attribute {
+ name: "kv_num_heads"
+ i: 1
+ type: INT
+ }
+ attribute {
+ name: "local_window_size"
+ i: -1
+ type: INT
+ }
+ attribute {
+ name: "num_heads"
+ i: 2
+ type: INT
+ }
+ attribute {
+ name: "rotary_interleaved"
+ i: 0
+ type: INT
+ }
+ attribute {
+ name: "smooth_softmax"
+ i: 1
+ type: INT
+ }
+ attribute {
+ name: "softcap"
+ f: 0
+ type: FLOAT
+ }
+ domain: "com.microsoft"
+ }
+ name: "GroupQueryAttention_Graph"
+ input {
+ name: "query"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_param: "sequence_length" }
+ dim { dim_value: 64 }
+ }
+ }
+ }
+ }
+ input {
+ name: "past_key"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_value: 1 }
+ dim { dim_param: "past_sequence_length" }
+ dim { dim_value: 16 }
+ }
+ }
+ }
+ }
+ input {
+ name: "past_value"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_value: 1 }
+ dim { dim_param: "past_sequence_length" }
+ dim { dim_value: 16 }
+ }
+ }
+ }
+ }
+ input {
+ name: "seqlens_k"
+ type {
+ tensor_type {
+ elem_type: 6
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_value: 1 }
+ }
+ }
+ }
+ }
+ input {
+ name: "total_sequence_length"
+ type{
+ tensor_type {
+ elem_type: 6
+ shape {
+ }
+ }
+ }
+ }
+ output {
+ name: "output"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_param: "sequence_length" }
+ dim { dim_value: 32 }
+ }
+ }
+ }
+ }
+ output {
+ name: "present_key"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_value: 1 }
+ dim { dim_param: "total_sequence_length" }
+ dim { dim_value: 16 }
+ }
+ }
+ }
+ }
+ output {
+ name: "present_value"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_value: 1 }
+ dim { dim_param: "total_sequence_length" }
+ dim { dim_value: 16 }
+ }
+ }
+ }
+ }
+}
+opset_import {
+ version: 11
+}
+opset_import {
+ domain: "com.microsoft"
+ version: 1
+}
diff --git a/src/frontends/onnx/tests/models/com.microsoft/gqa_softcap.prototxt b/src/frontends/onnx/tests/models/com.microsoft/gqa_softcap.prototxt
new file mode 100644
index 00000000000..d3f0192d238
--- /dev/null
+++ b/src/frontends/onnx/tests/models/com.microsoft/gqa_softcap.prototxt
@@ -0,0 +1,165 @@
+ir_version: 10
+graph {
+ node {
+ input: "query"
+ input: ""
+ input: ""
+ input: "past_key"
+ input: "past_value"
+ input: "seqlens_k"
+ input: "total_sequence_length"
+ output: "output"
+ output: "present_key"
+ output: "present_value"
+ name: "GroupQueryAttention_0"
+ op_type: "GroupQueryAttention"
+ attribute {
+ name: "do_rotary"
+ i: 0
+ type: INT
+ }
+ attribute {
+ name: "kv_num_heads"
+ i: 1
+ type: INT
+ }
+ attribute {
+ name: "local_window_size"
+ i: -1
+ type: INT
+ }
+ attribute {
+ name: "num_heads"
+ i: 2
+ type: INT
+ }
+ attribute {
+ name: "rotary_interleaved"
+ i: 0
+ type: INT
+ }
+ attribute {
+ name: "smooth_softmax"
+ i: 0
+ type: INT
+ }
+ attribute {
+ name: "softcap"
+ f: 30
+ type: FLOAT
+ }
+ domain: "com.microsoft"
+ }
+ name: "GroupQueryAttention_Graph"
+ input {
+ name: "query"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_param: "sequence_length" }
+ dim { dim_value: 64 }
+ }
+ }
+ }
+ }
+ input {
+ name: "past_key"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_value: 1 }
+ dim { dim_param: "past_sequence_length" }
+ dim { dim_value: 16 }
+ }
+ }
+ }
+ }
+ input {
+ name: "past_value"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_value: 1 }
+ dim { dim_param: "past_sequence_length" }
+ dim { dim_value: 16 }
+ }
+ }
+ }
+ }
+ input {
+ name: "seqlens_k"
+ type {
+ tensor_type {
+ elem_type: 6
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_value: 1 }
+ }
+ }
+ }
+ }
+ input {
+ name: "total_sequence_length"
+ type{
+ tensor_type {
+ elem_type: 6
+ shape {
+ }
+ }
+ }
+ }
+ output {
+ name: "output"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_param: "sequence_length" }
+ dim { dim_value: 32 }
+ }
+ }
+ }
+ }
+ output {
+ name: "present_key"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_value: 1 }
+ dim { dim_param: "total_sequence_length" }
+ dim { dim_value: 16 }
+ }
+ }
+ }
+ }
+ output {
+ name: "present_value"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim { dim_param: "batch_size" }
+ dim { dim_value: 1 }
+ dim { dim_param: "total_sequence_length" }
+ dim { dim_value: 16 }
+ }
+ }
+ }
+ }
+}
+opset_import {
+ version: 11
+}
+opset_import {
+ domain: "com.microsoft"
+ version: 1
+}
diff --git a/src/frontends/onnx/tests/models/com.microsoft/gqa_swc_small_capacity.prototxt b/src/frontends/onnx/tests/models/com.microsoft/gqa_swc_small_capacity.prototxt
new file mode 100644
index 00000000000..558c4182320
--- /dev/null
+++ b/src/frontends/onnx/tests/models/com.microsoft/gqa_swc_small_capacity.prototxt
@@ -0,0 +1,198 @@
+ir_version: 10
+graph {
+ node {
+ input: "query"
+ input: ""
+ input: ""
+ input: "past_key"
+ input: "past_value"
+ input: "seqlens_k"
+ input: "total_sequence_length"
+ output: "output"
+ output: "present_key"
+ output: "present_value"
+ op_type: "GroupQueryAttention"
+ attribute {
+ name: "kv_num_heads"
+ i: 1
+ type: INT
+ }
+ attribute {
+ name: "local_window_size"
+ i: 4
+ type: INT
+ }
+ attribute {
+ name: "num_heads"
+ i: 2
+ type: INT
+ }
+ attribute {
+ name: "sliding_window_cache"
+ i: 1
+ type: INT
+ }
+ domain: "com.microsoft"
+ }
+ name: "GQA_swc_small_capacity"
+ input {
+ name: "query"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 64
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "past_key"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 16
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "past_value"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 16
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "seqlens_k"
+ type {
+ tensor_type {
+ elem_type: 6
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "total_sequence_length"
+ type {
+ tensor_type {
+ elem_type: 6
+ shape {
+ }
+ }
+ }
+ }
+ output {
+ name: "output"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 32
+ }
+ }
+ }
+ }
+ }
+ output {
+ name: "present_key"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 16
+ }
+ }
+ }
+ }
+ }
+ output {
+ name: "present_value"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 16
+ }
+ }
+ }
+ }
+ }
+}
+opset_import {
+ domain: ""
+ version: 17
+}
+opset_import {
+ domain: "com.microsoft"
+ version: 1
+}
diff --git a/src/frontends/onnx/tests/models/com.microsoft/gqa_swc_staging.prototxt b/src/frontends/onnx/tests/models/com.microsoft/gqa_swc_staging.prototxt
new file mode 100644
index 00000000000..968a2f77cf3
--- /dev/null
+++ b/src/frontends/onnx/tests/models/com.microsoft/gqa_swc_staging.prototxt
@@ -0,0 +1,198 @@
+ir_version: 10
+graph {
+ node {
+ input: "query"
+ input: ""
+ input: ""
+ input: "past_key"
+ input: "past_value"
+ input: "seqlens_k"
+ input: "total_sequence_length"
+ output: "output"
+ output: "present_key"
+ output: "present_value"
+ op_type: "GroupQueryAttention"
+ attribute {
+ name: "kv_num_heads"
+ i: 1
+ type: INT
+ }
+ attribute {
+ name: "local_window_size"
+ i: 2
+ type: INT
+ }
+ attribute {
+ name: "num_heads"
+ i: 2
+ type: INT
+ }
+ attribute {
+ name: "sliding_window_cache"
+ i: 1
+ type: INT
+ }
+ domain: "com.microsoft"
+ }
+ name: "GQA_staging"
+ input {
+ name: "query"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 4
+ }
+ dim {
+ dim_value: 64
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "past_key"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 16
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "past_value"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 16
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "seqlens_k"
+ type {
+ tensor_type {
+ elem_type: 6
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "total_sequence_length"
+ type {
+ tensor_type {
+ elem_type: 6
+ shape {
+ }
+ }
+ }
+ }
+ output {
+ name: "output"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 4
+ }
+ dim {
+ dim_value: 32
+ }
+ }
+ }
+ }
+ }
+ output {
+ name: "present_key"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 16
+ }
+ }
+ }
+ }
+ }
+ output {
+ name: "present_value"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 16
+ }
+ }
+ }
+ }
+ }
+}
+opset_import {
+ domain: ""
+ version: 17
+}
+opset_import {
+ domain: "com.microsoft"
+ version: 1
+}
diff --git a/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp b/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp
index 5a0d3624acb..376b52d16d0 100644
--- a/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp
+++ b/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp
@@ -4531,6 +4531,270 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_i8kv_per_tensor) {
test_case.run(tolerance_bits);
}
+// Sliding-window attention composes with a quantized (i8) KV cache: the window mask is applied after
+// dequantization, so an i8 cache with local_window_size=2 excludes tokens older than the window. Decode
+// step with 3 past tokens; the oldest is masked out. Output and present match ONNX Runtime (MLAS CPU).
+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_i8kv_sliding_window) {
+ const auto model = convert_model("com.microsoft/gqa_i8kv_sliding_window.onnx");
+
+ std::vector<float> query = {0.053442f, 1.102908f, 0.478281f, 0.034206f, 0.534257f, 0.498591f, -0.465774f,
+ 0.365215f, -0.085607f, -0.644346f, 0.530718f, -0.020251f, -0.451861f, -0.777067f,
+ -0.475566f, 0.100263f, -0.373664f, 0.534040f, -0.138512f, 0.043279f, -0.126610f,
+ -0.606021f, 0.138636f, 0.276110f, -0.233871f, -0.713746f, 0.442902f, 1.180317f,
+ -0.761003f, -0.107973f, 0.095163f, 0.361128f};
+ std::vector<int8_t> past_key = {26, 19, -7, 26, -8, -21, -25, 12, -16, -16, -20, -16,
+ -6, 27, -15, -28, -18, -13, -14, -30, -13, -3, 28, -8};
+ std::vector<int8_t> past_value = {20, 5, -12, -26, 19, 14, 14, -13, -23, 10, -30, 7,
+ -26, 12, 16, 5, -6, 29, -1, -8, 14, -12, 17, -2};
+ std::vector<int> seqlens_k = {3};
+ std::vector<int> total_sequence_length = {4};
+
+ std::vector<float> expected_output = {-0.252619f,
+ -0.081278f,
+ 0.303397f,
+ 0.779405f,
+ -0.367325f,
+ -0.292622f,
+ 0.317099f,
+ 0.234717f,
+ -0.303546f,
+ 0.580774f,
+ 0.184567f,
+ 0.355013f,
+ 0.057067f,
+ -0.462379f,
+ 0.588710f,
+ 0.115887f};
+ std::vector<int8_t> expected_present_key = {26, 19, -7, 26, -8, -21, -25, 12, -16, -16, -20,
+ -16, -6, 27, -15, -28, -18, -13, -14, -30, -13, -3,
+ 28, -8, -5, 8, -2, 1, -2, -9, 2, 4};
+ std::vector<int8_t> expected_present_value = {20, 5, -12, -26, 19, 14, 14, -13, -23, 10, -30,
+ 7, -26, 12, 16, 5, -6, 29, -1, -8, 14, -12,
+ 17, -2, -3, -10, 6, 17, -11, -2, 1, 5};
+
+ auto test_case = ov::test::TestCase(model, s_device);
+ test_case.add_input<float>(Shape{1, 1, 32}, query);
+ test_case.add_input<int8_t>(Shape{1, 1, 3, 8}, past_key);
+ test_case.add_input<int8_t>(Shape{1, 1, 3, 8}, past_value);
+ test_case.add_input<int>(Shape{1, 1}, seqlens_k);
+ test_case.add_input<int>(Shape{}, total_sequence_length);
+ test_case.add_expected_output<float>(Shape{1, 1, 16}, expected_output);
+ test_case.add_expected_output<int8_t>(Shape{1, 1, 4, 8}, expected_present_key);
+ test_case.add_expected_output<int8_t>(Shape{1, 1, 4, 8}, expected_present_value);
+ const size_t tolerance_bits = 11;
+ test_case.run(tolerance_bits);
+}
+
+// sliding_window_cache=1 with a quantized (i8) KV cache: the window rolls over the int8 buffer (the row
+// moves are element-type agnostic and run before dequantization). Capacity C=4, local_window_size=2,
+// absolute past 5 (overflowed); present keeps the last 2 int8 resident rows + the new token, tail zeroed.
+// Output and int8 present match ONNX Runtime (MLAS CPU).
+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_i8kv_sliding_window_cache) {
+ auto model = convert_model("com.microsoft/gqa_i8kv_swc.onnx");
+ model->reshape({{"query", ov::PartialShape{1, 1, 64}},
+ {"past_key", ov::PartialShape{1, 1, 4, 16}},
+ {"past_value", ov::PartialShape{1, 1, 4, 16}},
+ {"seqlens_k", ov::PartialShape{1, 1}},
+ {"total_sequence_length", ov::PartialShape{}}});
+
+ std::vector<float> query = {
+ 0.112222f, 0.330766f, -0.289879f, 0.203906f, 0.233240f, -0.987355f, 0.137774f, -0.787903f,
+ 0.784198f, -0.362398f, 0.152945f, 0.581971f, -0.524548f, -0.488289f, -0.319525f, 0.848715f,
+ -0.643058f, -0.094581f, -0.036956f, -0.080248f, -0.054397f, -0.348492f, -0.502905f, -0.196273f,
+ -1.068897f, 0.880465f, -0.387097f, -0.265117f, -0.396758f, 0.145951f, -0.611003f, -0.784519f,
+ 0.199975f, -0.022822f, -0.457960f, 0.559493f, 0.098691f, 0.137530f, -0.439566f, -0.549120f,
+ -0.108385f, -0.516032f, -0.084192f, 0.278469f, 0.406421f, -0.063556f, -0.076139f, 0.035479f,
+ 0.009977f, -0.560135f, -0.863602f, 0.444380f, -0.218902f, -0.320805f, 0.213732f, 0.415264f,
+ 0.543000f, -0.068819f, -0.703481f, 0.579674f, -0.495710f, 0.053676f, -0.272396f, 0.308955f};
+ std::vector<int8_t> past_key = {-11, -5, 8, -19, -1, -1, -13, -12, 7, -16, 14, -3, -2, 9, 12, 14,
+ 5, -13, 16, -20, 19, -14, 10, -10, 10, 7, 9, 13, -14, -3, 13, 7,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ std::vector<int8_t> past_value = {-3, -16, -6, 4, -17, 10, -9, 15, 12, 9, 8, 19, -10, 14, 12, -9,
+ 7, 5, -14, -15, -20, 14, -1, 1, -17, 6, 2, -17, 11, 6, 18, -11,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ std::vector<int> seqlens_k = {5};
+ std::vector<int> total_sequence_length = {6};
+
+ std::vector<float> expected_output = {
+ 0.203878f, -0.083994f, -0.762624f, -0.249009f, -0.666006f, 0.282507f, 0.054373f, 0.196122f,
+ -0.265510f, 0.153878f, -0.233994f, -0.244636f, 0.111633f, 0.195627f, 0.419883f, -0.195131f,
+ 0.161889f, -0.179968f, -0.780619f, -0.105048f, -0.570032f, 0.162540f, 0.084365f, 0.238111f,
+ -0.097556f, 0.111889f, -0.329968f, -0.070683f, -0.014333f, 0.165635f, 0.281921f, -0.093159f};
+ std::vector<int8_t> expected_present_key = {-11, -5, 8, -19, -1, -1, -13, -12, 7, -16, 14, -3, -2, 9, 12, 14,
+ 5, -13, 16, -20, 19, -14, 10, -10, 10, 7, 9, 13, -14, -3, 13, 7,
+ 4, 0, -9, 11, 2, 3, -9, -11, -2, -10, -2, 6, 8, -1, -2, 1,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ std::vector<int8_t> expected_present_value = {
+ -3, -16, -6, 4, -17, 10, -9, 15, 12, 9, 8, 19, -10, 14, 12, -9, 7, 5, -14, -15, -20, 14,
+ -1, 1, -17, 6, 2, -17, 11, 6, 18, -11, 0, -11, -17, 9, -4, -6, 4, 8, 11, -1, -14, 12,
+ -10, 1, -5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+
+ auto test_case = ov::test::TestCase(model, s_device);
+ test_case.add_input<float>(Shape{1, 1, 64}, query);
+ test_case.add_input<int8_t>(Shape{1, 1, 4, 16}, past_key);
+ test_case.add_input<int8_t>(Shape{1, 1, 4, 16}, past_value);
+ test_case.add_input<int>(Shape{1, 1}, seqlens_k);
+ test_case.add_input<int>(Shape{}, total_sequence_length);
+ test_case.add_expected_output<float>(Shape{1, 1, 32}, expected_output);
+ test_case.add_expected_output<int8_t>(Shape{1, 1, 4, 16}, expected_present_key);
+ test_case.add_expected_output<int8_t>(Shape{1, 1, 4, 16}, expected_present_value);
+ const size_t tolerance_bits = 11;
+ test_case.run(tolerance_bits);
+}
+
+// sliding_window_cache=1 with a 4-bit KV cache (u8, two values per byte, head_size=32 -> 16 packed bytes).
+// The window rolls over whole packed rows before unpacking/dequantization, so eviction is nibble-safe.
+// Capacity C=4, local_window_size=2, absolute past 5; present keeps the last 2 packed rows + the new token.
+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_i4kv_sliding_window_cache) {
+ auto model = convert_model("com.microsoft/gqa_i4kv_swc.onnx");
+ model->reshape({{"query", ov::PartialShape{1, 1, 128}},
+ {"past_key", ov::PartialShape{1, 1, 4, 16}},
+ {"past_value", ov::PartialShape{1, 1, 4, 16}},
+ {"seqlens_k", ov::PartialShape{1, 1}},
+ {"total_sequence_length", ov::PartialShape{}}});
+
+ std::vector<float> query = {
+ 0.000554f, -0.144772f, -0.558033f, -0.006441f, -0.189181f, -0.240568f, -0.758666f, -0.245436f, -0.120340f,
+ -0.323974f, 0.317946f, 0.870059f, 0.148341f, 0.353752f, 0.911408f, 0.215385f, 0.771365f, -0.450361f,
+ -0.068563f, 0.648790f, 0.337636f, 0.015979f, 0.459073f, 0.190255f, 0.258184f, -0.177620f, 0.104388f,
+ 0.164206f, -0.249112f, -1.045888f, -0.041294f, 1.227591f, -1.336055f, -0.456640f, -0.113657f, 0.134658f,
+ 0.565231f, 0.521199f, 0.651905f, 0.694700f, -0.328226f, -0.028129f, -0.249951f, 0.218210f, -0.187907f,
+ -0.461531f, 0.958625f, -0.075151f, -0.319365f, 0.412385f, -0.605419f, -0.251703f, -0.350958f, -0.987136f,
+ -1.327866f, -0.028841f, -0.328093f, -0.330853f, 0.384674f, -0.449502f, 0.846819f, -0.848668f, -1.396685f,
+ -0.113075f, 0.198714f, 0.829852f, -0.246873f, -0.188049f, -0.084870f, 1.208553f, -0.904420f, 0.169876f,
+ -0.011365f, -0.479999f, -0.191557f, 0.054765f, -0.427581f, 0.000111f, 0.331928f, 0.374740f, -0.232909f,
+ -0.138720f, 0.017750f, 0.424111f, 0.081499f, 0.604312f, 0.251260f, -0.791911f, 0.511517f, -0.326509f,
+ 0.268523f, -0.003989f, 0.462392f, 0.023304f, 0.071010f, -0.826831f, 0.683996f, 0.012553f, -0.197741f,
+ 0.642194f, 0.280639f, 0.119863f, 0.239950f, 0.030876f, -0.535256f, -0.636605f, 0.460038f, 0.527459f,
+ 0.270144f, 0.154532f, 0.485431f, 0.577362f, 0.211304f, 0.499604f, 0.441760f, -0.265100f, 0.407067f,
+ -0.509942f, -1.129118f, 0.339977f, -0.200882f, 0.970160f, -0.622202f, 0.469655f, -0.120404f, 0.135404f,
+ -0.547770f, 1.200671f};
+ std::vector<uint8_t> past_key = {8, 73, 206, 208, 77, 118, 137, 142, 196, 231, 84, 75, 208, 115, 91, 59,
+ 26, 168, 22, 5, 154, 151, 131, 94, 29, 234, 134, 46, 114, 118, 133, 245,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ std::vector<uint8_t> past_value = {182, 22, 117, 108, 100, 199, 12, 49, 56, 104, 198, 183, 228, 197, 131, 63,
+ 182, 224, 92, 35, 178, 144, 140, 218, 198, 78, 151, 152, 153, 179, 130, 156,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ std::vector<int> seqlens_k = {5};
+ std::vector<int> total_sequence_length = {6};
+
+ std::vector<float> expected_output = {
+ 0.104663f, 0.081779f, -0.309039f, 0.322740f, 0.245481f, -0.036298f, -0.022596f, -0.140818f,
+ -0.345481f, -0.100144f, -0.058895f, 0.186442f, 0.222740f, 0.068221f, 0.213702f, 0.295481f,
+ 0.036442f, 0.268221f, 0.322740f, -0.222740f, 0.131923f, -0.154663f, -0.181923f, 0.186442f,
+ -0.063702f, 0.186442f, -0.318221f, 0.240961f, -0.209039f, 0.068221f, -0.072884f, 0.186442f,
+ 0.133169f, 0.072277f, -0.296369f, 0.325908f, 0.251815f, -0.020461f, 0.009077f, -0.118646f,
+ -0.351815f, -0.134985f, -0.011384f, 0.205446f, 0.225908f, 0.077723f, 0.229539f, 0.301815f,
+ 0.055446f, 0.277723f, 0.325908f, -0.225908f, 0.157262f, -0.183169f, -0.207262f, 0.205446f,
+ -0.079539f, 0.205446f, -0.327723f, 0.253631f, -0.196369f, 0.077723f, -0.110893f, 0.205446f};
+ std::vector<uint8_t> expected_present_key = {
+ 8, 73, 206, 208, 77, 118, 137, 142, 196, 231, 84, 75, 208, 115, 91, 59, 26, 168, 22, 5, 154, 151,
+ 131, 94, 29, 234, 134, 46, 114, 118, 133, 245, 252, 67, 246, 176, 8, 148, 128, 255, 83, 248, 250, 13,
+ 31, 141, 143, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ std::vector<uint8_t> expected_present_value = {
+ 182, 22, 117, 108, 100, 199, 12, 49, 56, 104, 198, 183, 228, 197, 131, 63, 182, 224, 92, 35, 178, 144,
+ 140, 218, 198, 78, 151, 152, 153, 179, 130, 156, 143, 244, 174, 157, 0, 255, 189, 255, 252, 63, 15, 240,
+ 244, 240, 182, 240, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+
+ auto test_case = ov::test::TestCase(model, s_device);
+ test_case.add_input<float>(Shape{1, 1, 128}, query);
+ test_case.add_input<uint8_t>(Shape{1, 1, 4, 16}, past_key);
+ test_case.add_input<uint8_t>(Shape{1, 1, 4, 16}, past_value);
+ test_case.add_input<int>(Shape{1, 1}, seqlens_k);
+ test_case.add_input<int>(Shape{}, total_sequence_length);
+ test_case.add_expected_output<float>(Shape{1, 1, 64}, expected_output);
+ test_case.add_expected_output<uint8_t>(Shape{1, 1, 4, 16}, expected_present_key);
+ test_case.add_expected_output<uint8_t>(Shape{1, 1, 4, 16}, expected_present_value);
+ const size_t tolerance_bits = 11;
+ test_case.run(tolerance_bits);
+}
+
+// sliding_window_cache=1 with an f8e4m3fn KV cache. ONNX Runtime has no CPU f8 GQA kernel (f8 is
+// CUDA-only there), so the reference is an independent numpy oracle mirroring the decomposition
+// (dequant f8 -> window mask -> SDPA) that also confirms the rolling buffer equals the full-length
+// cache + local_window_size. Capacity C=4, local_window_size=2, absolute past 5; present keeps the
+// last 2 f8 rows + the new token, tail zeroed.
+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_f8e4m3fnkv_sliding_window_cache) {
+ // The windowed present assembly gathers f8e4m3 KV rows; the GPU plugin and the TEMPLATE reference
+ // have no f8e4m3 Gather kernel yet, so this path is exercised on CPU only. (Non-windowed f8 GQA,
+ // which does not gather the f8 cache, runs on all three backends.)
+ if (s_device != ov::test::utils::DEVICE_CPU) {
+ GTEST_SKIP() << "f8e4m3 Gather for the windowed KV-cache assembly is only supported on CPU.";
+ }
+ auto model = convert_model("com.microsoft/gqa_f8e4m3fnkv_swc.onnx");
+ model->reshape({{"query", ov::PartialShape{1, 1, 64}},
+ {"past_key", ov::PartialShape{1, 1, 4, 16}},
+ {"past_value", ov::PartialShape{1, 1, 4, 16}},
+ {"seqlens_k", ov::PartialShape{1, 1}},
+ {"total_sequence_length", ov::PartialShape{}}});
+
+ std::vector<float> query = {
+ 0.051756f, 0.490645f, 0.011201f, -0.265245f, -0.342958f, -0.186410f, -0.404595f, -0.245919f,
+ -0.040276f, 0.479880f, -0.085081f, -0.151902f, 0.020673f, 0.435678f, -0.491729f, -0.093798f,
+ -0.261380f, -0.137005f, -0.036740f, -0.135319f, -0.327685f, -0.408654f, -0.049796f, 0.193617f,
+ 0.244522f, -0.005568f, 0.130014f, 0.112451f, -0.266718f, 0.123682f, -0.309097f, -0.102360f,
+ -0.613136f, -0.221291f, 0.407490f, -0.090570f, -0.129602f, -0.041551f, 0.109255f, 0.309442f,
+ 0.232984f, -0.038288f, 0.029367f, -0.469899f, -0.108637f, 0.063861f, 0.079780f, -0.419200f,
+ 0.059846f, -0.069280f, 0.041051f, 0.554503f, 0.319335f, -0.461223f, 0.022338f, 0.387551f,
+ 0.289992f, 0.126585f, 0.538735f, -0.053865f, 0.294733f, 0.220914f, -0.261598f, 0.096838f};
+ std::vector<ov::float8_e4m3> past_key = {
+ -7.f, 4.f, 1.25f, 1.5f, 1.5f, -1.125f, -4.f, -0.6875f, 2.f, 0.3125f, 2.75f,
+ -3.5f, 0.8125f, -0.375f, 3.25f, 2.75f, -0.875f, -0.0625f, 2.75f, -2.f, -2.5f, -3.25f,
+ 0.140625f, -1.375f, -2.5f, -1.75f, 2.25f, -3.75f, 2.25f, -0.0273438f, 9.f, -0.375f, 0.f,
+ 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
+ 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
+ 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f};
+ std::vector<ov::float8_e4m3> past_value = {
+ 3.75f, 0.0214844f, -5.5f, -1.625f, 1.375f, 2.75f, -3.5f, 2.f, 3.25f, -5.5f, 4.5f,
+ -0.0195312f, -5.5f, -0.75f, 5.f, -0.5f, -2.f, 2.f, -1.125f, -6.f, 3.25f, 0.6875f,
+ 4.5f, -0.9375f, -3.25f, -4.f, -4.5f, 2.75f, -2.5f, 3.25f, 0.28125f, -0.8125f, 0.f,
+ 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
+ 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
+ 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f};
+ std::vector<int> seqlens_k = {5};
+ std::vector<int> total_sequence_length = {6};
+
+ std::vector<float> expected_output = {
+ -0.066659f, 0.063484f, -0.034718f, -0.015840f, 0.325000f, -0.194757f, 0.232527f, 0.157058f,
+ -0.007522f, -0.133318f, 0.057965f, 0.106737f, 0.029381f, 0.274203f, -0.113153f, 0.007644f,
+ -0.059963f, 0.056629f, -0.030812f, 0.013493f, 0.325000f, -0.207989f, 0.221607f, 0.169652f,
+ 0.008420f, -0.119927f, 0.083473f, 0.098287f, 0.043410f, 0.271653f, -0.120247f, 0.012108f};
+ std::vector<ov::float8_e4m3> expected_present_key = {
+ -7.f, 4.f, 1.25f, 1.5f, 1.5f, -1.125f, -4.f, -0.6875f, 2.f, 0.3125f, 2.75f,
+ -3.5f, 0.8125f, -0.375f, 3.25f, 2.75f, -0.875f, -0.0625f, 2.75f, -2.f, -2.5f, -3.25f,
+ 0.140625f, -1.375f, -2.5f, -1.75f, 2.25f, -3.75f, 2.25f, -0.0273438f, 9.f, -0.375f, -6.f,
+ -2.25f, 4.f, -0.875f, -1.25f, -0.40625f, 1.125f, 3.f, 2.25f, -0.375f, 0.28125f, -4.5f,
+ -1.125f, 0.625f, 0.8125f, -4.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
+ 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f};
+ std::vector<ov::float8_e4m3> expected_present_value = {
+ 3.75f, 0.0214844f, -5.5f, -1.625f, 1.375f, 2.75f, -3.5f, 2.f, 3.25f, -5.5f, 4.5f,
+ -0.0195312f, -5.5f, -0.75f, 5.f, -0.5f, -2.f, 2.f, -1.125f, -6.f, 3.25f, 0.6875f,
+ 4.5f, -0.9375f, -3.25f, -4.f, -4.5f, 2.75f, -2.5f, 3.25f, 0.28125f, -0.8125f, 0.625f,
+ -0.6875f, 0.40625f, 5.5f, 3.25f, -4.5f, 0.21875f, 4.f, 3.f, 1.25f, 5.5f, -0.5625f,
+ 3.f, 2.25f, -2.5f, 0.9375f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
+ 0.f, 0.f, 0.f, 0.f, 0.f, 0.f};
+
+ // Only the attention output is asserted here. The present KV eviction structure is already checked
+ // bit-exact by the i8/i4 windowed-cache tests; for f8e4m3 the test harness surfaces uninitialized
+ // bytes in the unreachable present tail [end_after, C) (which is never attended), so asserting the
+ // full present tensor would be flaky. expected_present_key/value are retained for documentation.
+ (void)expected_present_key;
+ (void)expected_present_value;
+ auto test_case = ov::test::TestCase(model, s_device);
+ test_case.add_input<float>(Shape{1, 1, 64}, query);
+ test_case.add_input<ov::float8_e4m3>(Shape{1, 1, 4, 16}, past_key);
+ test_case.add_input<ov::float8_e4m3>(Shape{1, 1, 4, 16}, past_value);
+ test_case.add_input<int>(Shape{1, 1}, seqlens_k);
+ test_case.add_input<int>(Shape{}, total_sequence_length);
+ test_case.add_expected_output<float>(Shape{1, 1, 32}, expected_output);
+ const size_t tolerance_bits = 11;
+ test_case.run(tolerance_bits);
+}
+
OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_i4kv_per_channel) {
const auto model = convert_model("com.microsoft/gqa_i4kv_per_channel.onnx");
@@ -5102,6 +5366,458 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_insufficient_inputs_throws) {
}
}
+// Packed-QKV prompt (num_heads=2, kv_num_heads=1, head_size=16, S=4, past=0) shared by the
+// sliding-window tests below. Reference outputs are from ONNX Runtime (MLAS CPU).
+static std::vector<float> gqa_sliding_window_query() {
+ return {1.690526f, -0.465937f, 0.032820f, 0.407516f, -0.788923f, 0.002066f, -0.000890f, -1.754724f, 1.017658f,
+ 0.600498f, -0.625429f, -0.171548f, 0.505299f, -0.261356f, -0.242749f, -1.453241f, 0.554580f, 0.123881f,
+ 0.274460f, -1.526525f, 1.650700f, 0.154336f, -0.387140f, 2.029072f, -0.045386f, -1.450679f, -0.405228f,
+ -2.288315f, 1.049397f, -0.416474f, -0.742554f, 1.072470f, -1.651076f, 0.535429f, -2.064415f, -0.662159f,
+ -1.204220f, 1.461976f, 1.766161f, -0.329414f, 0.840733f, -0.179986f, 0.568062f, -0.752837f, -1.708339f,
+ -1.803099f, 0.383122f, 2.247595f, 0.269412f, -0.524605f, 1.912019f, 0.237302f, 0.101434f, 0.252578f,
+ -0.132377f, -0.309476f, -1.434963f, 0.501624f, -0.094775f, 1.193086f, -0.368818f, -1.906370f, -0.099611f,
+ 1.699537f, -0.383423f, -0.889857f, -1.193592f, -1.050017f, -0.300194f, -1.179982f, 1.497639f, -0.282635f,
+ 0.108648f, 1.438240f, 1.503319f, -0.212733f, 0.331974f, 0.735027f, -0.192855f, -1.778013f, 0.654706f,
+ 0.894352f, 0.415503f, -0.923545f, -0.196027f, -0.590770f, -0.299711f, 1.296885f, 1.529580f, 0.669418f,
+ 0.548745f, 0.676629f, -0.012242f, -0.075663f, -0.673645f, -0.055867f, 2.259947f, 0.869039f, -0.342117f,
+ -0.471927f, -0.864490f, 0.374370f, 0.391546f, -1.443122f, 0.486335f, -0.569472f, 1.426721f, 0.156844f,
+ 1.717730f, -0.458127f, -0.287984f, 0.299808f, 1.055948f, 0.565883f, -1.233524f, 0.182901f, 0.022245f,
+ -0.429069f, -0.648105f, 1.747577f, -0.390386f, -0.845923f, 0.637113f, 0.130623f, -0.075814f, 0.781302f,
+ 0.488625f, 0.362190f, 0.964200f, 0.283636f, -0.616922f, -0.362282f, -0.520972f, 0.209722f, -1.077985f,
+ -1.832426f, 0.088155f, -1.336521f, -1.951978f, 0.373331f, -0.711053f, 0.496125f, -0.530854f, -1.121962f,
+ -1.243518f, -0.514927f, -0.273383f, -0.823460f, -0.281108f, -1.536102f, 0.014489f, -1.793649f, -0.193856f,
+ 0.697294f, 1.091939f, 1.714380f, -1.556288f, 0.758725f, 1.206282f, 0.980557f, -0.929324f, 0.411797f,
+ 1.860056f, -1.497274f, 0.476338f, 1.112291f, -0.696591f, 0.582970f, -1.070892f, -0.812209f, -0.817080f,
+ 0.192308f, -0.090981f, 0.954115f, -0.940279f, -0.131276f, 0.961076f, 0.560777f, -1.324641f, 0.665204f,
+ -0.478418f, 0.385387f, 0.300680f, 1.219319f, 0.116560f, -1.853806f, -1.369860f, 0.731154f, -0.258316f,
+ 1.137979f, 0.273439f, -0.749066f, 1.082407f, -0.807398f, -2.052635f, 2.063796f, -1.910749f, 0.636413f,
+ 0.938852f, 0.147066f, -1.683397f, 1.015015f, -1.441544f, -1.343629f, -0.361668f, 0.788505f, 0.300114f,
+ 0.810768f, -0.443644f, -0.172183f, -1.137137f, -0.316865f, 0.593128f, -0.299828f, 0.475460f, -0.573274f,
+ -0.592392f, 0.039169f, -0.194881f, 0.592385f, 0.178290f, 1.740346f, -0.219495f, -0.227253f, -1.040131f,
+ 0.022778f, 0.682829f, -0.740296f, -0.049672f, 0.718557f, -0.126909f, -0.519137f, 0.973093f, 0.097020f,
+ 0.396565f, 1.171393f, 1.145316f, -0.347204f, -0.525430f, 0.284309f, -0.132788f, -1.899861f, 1.275362f,
+ 0.019361f, 0.736378f, -1.172917f, 1.288204f, -0.588263f, -0.107667f, -1.401425f, -0.166950f, -0.229804f,
+ -0.185361f, 0.438505f, 0.060346f, 0.975783f};
+}
+
+// Sliding-window attention (local_window_size=2): query t attends only to keys [t-1, t]. The window
+// excludes older keys, so this differs from pure causal attention for queries with more than two tokens
+// of history. Output matches the ONNX Runtime (MLAS CPU) reference.
+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_sliding_window) {
+ const auto model = convert_model("com.microsoft/gqa_sliding_window.onnx");
+
+ std::vector<float> expected_output = {
+ 0.269412f, -0.524605f, 1.912019f, 0.237302f, 0.101434f, 0.252578f, -0.132377f, -0.309476f, -1.434963f,
+ 0.501624f, -0.094775f, 1.193086f, -0.368818f, -1.906370f, -0.099611f, 1.699537f, 0.269412f, -0.524605f,
+ 1.912019f, 0.237302f, 0.101434f, 0.252578f, -0.132377f, -0.309476f, -1.434963f, 0.501624f, -0.094775f,
+ 1.193086f, -0.368818f, -1.906370f, -0.099611f, 1.699537f, 0.740432f, 0.128438f, 0.028298f, 0.204723f,
+ 0.054011f, -0.155629f, -0.441223f, 0.922398f, -0.809414f, -0.305360f, 0.343519f, 0.556826f, -0.193352f,
+ -0.296847f, 0.252657f, 0.898662f, 0.830354f, 0.253109f, -0.331320f, 0.198504f, 0.044958f, -0.233559f,
+ -0.500184f, 1.157573f, -0.689992f, -0.459420f, 0.427193f, 0.435358f, -0.159853f, 0.010424f, 0.319908f,
+ 0.745768f, 1.007791f, 0.563291f, -1.279775f, 0.427717f, -0.231890f, -0.015653f, -0.166504f, 1.479434f,
+ -0.133062f, -1.357522f, -0.381622f, 0.435451f, -0.168452f, 0.962350f, 0.379397f, -0.201881f, 1.010270f,
+ 0.563424f, -1.277395f, 0.415119f, -0.218813f, -0.036927f, -0.191286f, 1.493233f, -0.146303f, -1.331196f,
+ -0.329199f, 0.419765f, -0.163685f, 0.953034f, 0.385018f, -0.172855f, 0.501894f, -0.472149f, -0.233213f,
+ 0.394092f, 0.031529f, -0.268758f, 0.715223f, 0.460533f, 0.022434f, -1.663906f, -0.864902f, 0.327764f,
+ -0.227691f, 0.844354f, 0.183987f, -0.025009f, 0.491418f, -0.495716f, -0.208311f, 0.387906f, 0.043164f,
+ -0.283682f, 0.724681f, 0.443220f, 0.020286f, -1.659573f, -0.853381f, 0.318560f, -0.226992f, 0.837655f,
+ 0.181946f, -0.008489f};
+
+ auto test_case = ov::test::TestCase(model, s_device);
+ test_case.add_input<float>(Shape{1, 4, 64}, gqa_sliding_window_query());
+ test_case.add_input<float>(Shape{1, 1, 0, 16}, {});
+ test_case.add_input<float>(Shape{1, 1, 0, 16}, {});
+ test_case.add_input<int>(Shape{1, 1}, {3});
+ test_case.add_input<int>(Shape{}, {4});
+ test_case.add_expected_output<float>(Shape{1, 4, 32}, expected_output);
+ test_case.run_with_tolerance_as_fp();
+}
+
+// A window >= the total KV length masks nothing extra, so the result must equal pure causal attention.
+// Guards against a window band that over-masks.
+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_sliding_window_equals_causal_when_large) {
+ const auto model = convert_model("com.microsoft/gqa_non_rotary_7_inputs.onnx"); // local_window_size = -1
+
+ std::vector<float> expected_output_causal = {
+ 0.269412f, -0.524605f, 1.912019f, 0.237302f, 0.101434f, 0.252578f, -0.132377f, -0.309476f, -1.434963f,
+ 0.501624f, -0.094775f, 1.193086f, -0.368818f, -1.906370f, -0.099611f, 1.699537f, 0.269412f, -0.524605f,
+ 1.912019f, 0.237302f, 0.101434f, 0.252578f, -0.132377f, -0.309476f, -1.434963f, 0.501624f, -0.094775f,
+ 1.193086f, -0.368818f, -1.906370f, -0.099611f, 1.699537f, 0.740432f, 0.128438f, 0.028298f, 0.204723f,
+ 0.054011f, -0.155629f, -0.441223f, 0.922398f, -0.809414f, -0.305360f, 0.343519f, 0.556826f, -0.193352f,
+ -0.296847f, 0.252657f, 0.898662f, 0.830354f, 0.253109f, -0.331320f, 0.198504f, 0.044958f, -0.233559f,
+ -0.500184f, 1.157573f, -0.689992f, -0.459420f, 0.427193f, 0.435358f, -0.159853f, 0.010424f, 0.319908f,
+ 0.745768f, 0.930948f, 0.450073f, -0.947602f, 0.407900f, -0.197201f, 0.012262f, -0.162952f, 1.293261f,
+ -0.268552f, -1.164039f, -0.351769f, 0.514299f, -0.189304f, 0.663800f, 0.329546f, -0.003998f, 0.460770f,
+ -0.243575f, 1.088217f, 0.283231f, 0.018717f, 0.177801f, -0.147593f, 0.156150f, -1.102112f, 0.028220f,
+ -0.155325f, 0.993343f, -0.315834f, -1.167807f, 0.025565f, 1.215912f, 0.413673f, -0.342667f, 1.253691f,
+ 0.238900f, 0.083796f, 0.106136f, -0.160001f, 0.078662f, -1.166456f, 0.136124f, -0.026596f, 0.961300f,
+ -0.311427f, -1.282412f, 0.015627f, 1.365237f, 0.573372f, -0.273704f, -0.057114f, 0.317745f, 0.048871f,
+ -0.221080f, 0.281314f, 0.590687f, -0.321818f, -1.107932f, -0.402041f, 0.431164f, -0.219438f, 0.346153f,
+ 0.198345f, 0.369227f};
+
+ auto test_case = ov::test::TestCase(model, s_device);
+ test_case.add_input<float>(Shape{1, 4, 64}, gqa_sliding_window_query());
+ test_case.add_input<float>(Shape{1, 1, 0, 16}, {});
+ test_case.add_input<float>(Shape{1, 1, 0, 16}, {});
+ test_case.add_input<int>(Shape{1, 1}, {3});
+ test_case.add_input<int>(Shape{}, {4});
+ test_case.add_expected_output<float>(Shape{1, 4, 32}, expected_output_causal);
+ test_case.run_with_tolerance_as_fp();
+}
+
+// External attention_bias (input 10) combined with a sliding window: the window band must be added on
+// top of the caller-supplied bias. Exercises the additive-band branch of make_attention_mask. Output
+// matches ONNX Runtime (MLAS CPU).
+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_sliding_window_with_bias) {
+ const auto model = convert_model("com.microsoft/gqa_bias_window.onnx");
+
+ std::vector<float> query = {
+ 0.000554f, -0.144772f, -0.558033f, -0.006441f, -0.189181f, -0.240568f, -0.758666f, -0.245436f, -0.120340f,
+ -0.323974f, 0.317946f, 0.870059f, 0.148341f, 0.353752f, 0.911408f, 0.215385f, 0.771365f, -0.450361f,
+ -0.068563f, 0.648790f, 0.337636f, 0.015979f, 0.459073f, 0.190255f, 0.258184f, -0.177620f, 0.104388f,
+ 0.164206f, -0.249112f, -1.045888f, -0.041294f, 1.227591f, -1.336055f, -0.456640f, -0.113657f, 0.134658f,
+ 0.565231f, 0.521199f, 0.651905f, 0.694700f, -0.328226f, -0.028129f, -0.249951f, 0.218210f, -0.187907f,
+ -0.461531f, 0.958625f, -0.075151f, -0.319365f, 0.412385f, -0.605419f, -0.251703f, -0.350958f, -0.987136f,
+ -1.327866f, -0.028841f, -0.328093f, -0.330853f, 0.384674f, -0.449502f, 0.846819f, -0.848668f, -1.396685f,
+ -0.113075f, 0.198714f, 0.829852f, -0.246873f, -0.188049f, -0.084870f, 1.208553f, -0.904420f, 0.169876f,
+ -0.011365f, -0.479999f, -0.191557f, 0.054765f, -0.427581f, 0.000111f, 0.331928f, 0.374740f, -0.232909f,
+ -0.138720f, 0.017750f, 0.424111f, 0.081499f, 0.604312f, 0.251260f, -0.791911f, 0.511517f, -0.326509f,
+ 0.268523f, -0.003989f, 0.462392f, 0.023304f, 0.071010f, -0.826831f, 0.683996f, 0.012553f, -0.197741f,
+ 0.642194f, 0.280639f, 0.119863f, 0.239950f, 0.030876f, -0.535256f, -0.636605f, 0.460038f, 0.527459f,
+ 0.270144f, 0.154532f, 0.485431f, 0.577362f, 0.211304f, 0.499604f, 0.441760f, -0.265100f, 0.407067f,
+ -0.509942f, -1.129118f, 0.339977f, -0.200882f, 0.970160f, -0.622202f, 0.469655f, -0.120404f, 0.135404f,
+ -0.547770f, 1.200671f, -0.139955f, 1.015400f, -0.040970f, -0.609313f, -0.403435f, 0.659021f, -0.289319f,
+ 0.041026f, 0.697955f, 0.540940f, -0.508280f, -0.145999f, 0.779679f, -0.273150f, 0.480295f, 0.105605f,
+ -0.622686f, 0.152273f, -0.299190f, 0.061533f, -0.395418f, 0.321947f, -0.029825f, 0.456623f, -0.545289f,
+ -0.087425f, 0.532640f, 0.618615f, 0.509898f, 0.430344f, -0.366217f, 0.220112f, 0.323032f, 0.130956f,
+ 0.353608f, -0.218326f, 0.396910f, -0.130277f, -0.419830f, -0.739854f, 0.553697f, -0.598377f, -0.513615f,
+ -0.785564f, 1.021488f, 0.944992f, -0.399331f, -0.912394f, -0.388027f, -0.323798f, -0.243667f, 0.187632f,
+ -0.518003f, -0.066962f, 0.192439f, 0.177198f, 0.171319f, -0.298650f, -0.094274f, 0.350162f, -0.662812f,
+ 0.468514f, -0.225345f, 0.465565f, -0.902716f, 0.215199f, -0.283647f, 0.534978f, -0.060505f, -0.516402f,
+ 0.417640f, -0.425960f, -0.592471f, -0.515376f, -0.457443f, -0.412104f, -0.368665f, 0.428782f, 0.473594f,
+ 0.598486f, 0.949042f, 0.262395f, -0.070290f, -0.645741f, -0.237259f, -0.003033f, 0.654099f, -0.325780f,
+ 0.801315f, 0.782264f, -0.129032f, -0.179611f, 0.004897f, -0.394965f, -0.551900f, -0.281885f, 0.240674f,
+ -1.142026f, 0.346634f, 0.812257f, 0.615116f, 0.824552f, -0.742966f, -0.538446f, 0.792290f, 0.194030f,
+ 0.637737f, 0.105485f, 0.309918f, -0.501148f, -0.266306f, 0.468014f, 0.089627f, -0.018504f, 0.421330f,
+ -0.406638f, -0.836469f, -0.425276f, -0.140858f, 0.759966f, -0.479597f, 0.362695f, 0.277714f, 0.414875f,
+ 0.734429f, -0.001911f, 0.528743f, -0.491832f};
+ std::vector<float> attention_bias = {
+ 0.759753f, 0.256105f, -0.765091f, -1.565530f, -0.086442f, -0.124809f, 1.551494f, 1.577087f,
+ -0.704462f, 0.702711f, -0.086941f, -0.106728f, -0.910777f, -0.191972f, 0.259847f, -0.434802f,
+ 0.468223f, 0.085088f, 1.228160f, 0.557398f, 0.329636f, 0.110972f, -0.262650f, 0.674063f,
+ -0.391547f, 0.528287f, -0.024502f, 0.118841f, 1.411949f, 0.520236f, 0.542479f, -0.272567f};
+ std::vector<float> expected_output = {
+ -0.319365f, 0.412385f, -0.605419f, -0.251703f, -0.350958f, -0.987136f, -1.327866f, -0.028841f, -0.328093f,
+ -0.330853f, 0.384674f, -0.449502f, 0.846819f, -0.848668f, -1.396685f, -0.113075f, -0.319365f, 0.412385f,
+ -0.605419f, -0.251703f, -0.350958f, -0.987136f, -1.327866f, -0.028841f, -0.328093f, -0.330853f, 0.384674f,
+ -0.449502f, 0.846819f, -0.848668f, -1.396685f, -0.113075f, -0.039829f, 0.458329f, -0.053807f, -0.258760f,
+ 0.048340f, -0.735769f, -1.223174f, 0.165438f, -0.261084f, 0.354469f, -0.145709f, 0.034673f, 0.337324f,
+ -0.330298f, -0.949510f, 0.578955f, -0.090442f, 0.450010f, -0.153681f, -0.257482f, -0.023956f, -0.781281f,
+ -1.242129f, 0.130262f, -0.273216f, 0.230386f, -0.049678f, -0.052991f, 0.429572f, -0.424153f, -1.030475f,
+ 0.453657f, -0.040685f, 0.153404f, 0.153571f, -0.074748f, 0.018120f, -0.323690f, -0.573467f, 0.271537f,
+ -0.044390f, 0.436687f, -0.400234f, 0.419414f, -0.348460f, 0.275460f, -0.412206f, 0.891595f, 0.045772f,
+ 0.272184f, 0.252448f, -0.140057f, 0.151567f, -0.387593f, -0.764110f, 0.295019f, -0.098082f, 0.619720f,
+ -0.476391f, 0.436652f, -0.270215f, 0.227407f, -0.458717f, 0.997638f, -0.261066f, -0.242651f, -0.066910f,
+ 0.029674f, -0.602652f, -0.162202f, 0.103849f, 0.332099f, -0.001695f, -0.122864f, 0.004601f, 0.367363f,
+ -0.291423f, 0.343475f, -0.024907f, 0.211087f, -0.261002f, -0.242610f, -0.066822f, 0.029595f, -0.602694f,
+ -0.162250f, 0.103804f, 0.332176f, -0.001782f, -0.122776f, 0.004650f, 0.367372f, -0.291238f, 0.343412f,
+ -0.024807f, 0.210960f};
+
+ auto test_case = ov::test::TestCase(model, s_device);
+ test_case.add_input<float>(Shape{1, 4, 64}, query);
+ test_case.add_input<float>(Shape{1, 1, 0, 16}, {});
+ test_case.add_input<float>(Shape{1, 1, 0, 16}, {});
+ test_case.add_input<int>(Shape{1, 1}, {3});
+ test_case.add_input<int>(Shape{}, {4});
+ test_case.add_input<float>(Shape{1, 2, 4, 4}, attention_bias);
+ test_case.add_expected_output<float>(Shape{1, 4, 32}, expected_output);
+ test_case.run_with_tolerance_as_fp();
+}
+
+// f16 sliding window: exercises the f16 finite-lowest() masked path (no NaN on masked positions).
+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_sliding_window_fp16) {
+ ov::frontend::FrontEnd::Ptr front_end;
+ auto input_model = load_model("com.microsoft/gqa_sliding_window.onnx", &front_end);
+ input_model->set_element_type(input_model->get_place_by_tensor_name("query"), ov::element::f16);
+ input_model->set_element_type(input_model->get_place_by_tensor_name("past_key"), ov::element::f16);
+ input_model->set_element_type(input_model->get_place_by_tensor_name("past_value"), ov::element::f16);
+ const auto model = front_end->convert(input_model);
+
+ using f16 = ov::float16;
+ std::vector<f16> query;
+ for (float x : gqa_sliding_window_query())
+ query.emplace_back(x);
+
+ std::vector<float> expected_output_f32 = {
+ 0.269412f, -0.524605f, 1.912019f, 0.237302f, 0.101434f, 0.252578f, -0.132377f, -0.309476f, -1.434963f,
+ 0.501624f, -0.094775f, 1.193086f, -0.368818f, -1.906370f, -0.099611f, 1.699537f, 0.269412f, -0.524605f,
+ 1.912019f, 0.237302f, 0.101434f, 0.252578f, -0.132377f, -0.309476f, -1.434963f, 0.501624f, -0.094775f,
+ 1.193086f, -0.368818f, -1.906370f, -0.099611f, 1.699537f, 0.740432f, 0.128438f, 0.028298f, 0.204723f,
+ 0.054011f, -0.155629f, -0.441223f, 0.922398f, -0.809414f, -0.305360f, 0.343519f, 0.556826f, -0.193352f,
+ -0.296847f, 0.252657f, 0.898662f, 0.830354f, 0.253109f, -0.331320f, 0.198504f, 0.044958f, -0.233559f,
+ -0.500184f, 1.157573f, -0.689992f, -0.459420f, 0.427193f, 0.435358f, -0.159853f, 0.010424f, 0.319908f,
+ 0.745768f, 1.007791f, 0.563291f, -1.279775f, 0.427717f, -0.231890f, -0.015653f, -0.166504f, 1.479434f,
+ -0.133062f, -1.357522f, -0.381622f, 0.435451f, -0.168452f, 0.962350f, 0.379397f, -0.201881f, 1.010270f,
+ 0.563424f, -1.277395f, 0.415119f, -0.218813f, -0.036927f, -0.191286f, 1.493233f, -0.146303f, -1.331196f,
+ -0.329199f, 0.419765f, -0.163685f, 0.953034f, 0.385018f, -0.172855f, 0.501894f, -0.472149f, -0.233213f,
+ 0.394092f, 0.031529f, -0.268758f, 0.715223f, 0.460533f, 0.022434f, -1.663906f, -0.864902f, 0.327764f,
+ -0.227691f, 0.844354f, 0.183987f, -0.025009f, 0.491418f, -0.495716f, -0.208311f, 0.387906f, 0.043164f,
+ -0.283682f, 0.724681f, 0.443220f, 0.020286f, -1.659573f, -0.853381f, 0.318560f, -0.226992f, 0.837655f,
+ 0.181946f, -0.008489f};
+ std::vector<f16> expected_output;
+ for (float x : expected_output_f32)
+ expected_output.emplace_back(x);
+
+ auto test_case = ov::test::TestCase(model, s_device);
+ test_case.add_input<f16>(Shape{1, 4, 64}, query);
+ test_case.add_input<f16>(Shape{1, 1, 0, 16}, {});
+ test_case.add_input<f16>(Shape{1, 1, 0, 16}, {});
+ test_case.add_input<int>(Shape{1, 1}, {3});
+ test_case.add_input<int>(Shape{}, {4});
+ test_case.add_expected_output<f16>(Shape{1, 4, 32}, expected_output);
+ test_case.run_with_tolerance_as_fp(0.02f);
+}
+
+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_softcap_unsupported_throws) {
+ try {
+ convert_model("com.microsoft/gqa_softcap.onnx");
+ FAIL() << "ONNX Importer did not reject unsupported softcap for GroupQueryAttention";
+ } catch (const std::exception& e) {
+ EXPECT_THAT(e.what(), testing::HasSubstr("softcap"));
+ } catch (...) {
+ FAIL() << "Unexpected exception type thrown";
+ }
+}
+
+// The windowed cache supports only single-token decode (sequence_length == 1). A multi-token step is
+// the staging regime, which is not supported and must be rejected with a clear error (when the static
+// sequence_length is known) rather than silently diverging or building an ill-formed graph. Here seq=4.
+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_sliding_window_cache_staging_unsupported_throws) {
+ try {
+ convert_model("com.microsoft/gqa_swc_staging.onnx");
+ FAIL() << "ONNX Importer did not reject the sliding_window_cache staging regime for GroupQueryAttention";
+ } catch (const std::exception& e) {
+ EXPECT_THAT(e.what(), testing::HasSubstr("staging"));
+ } catch (...) {
+ FAIL() << "Unexpected exception type thrown";
+ }
+}
+
+// qk_output (emit the QxK' matrix as a 4th output) is not produced by the decomposition, so a model that
+// requests it must be rejected at import rather than silently losing an output.
+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_qk_output_unsupported_throws) {
+ try {
+ convert_model("com.microsoft/gqa_qk_output.onnx");
+ FAIL() << "ONNX Importer did not reject unsupported qk_output for GroupQueryAttention";
+ } catch (const std::exception& e) {
+ EXPECT_THAT(e.what(), testing::HasSubstr("qk_output"));
+ } catch (...) {
+ FAIL() << "Unexpected exception type thrown";
+ }
+}
+
+// attention_bias is indexed by the absolute total_sequence_length, but a windowed (rolling) cache evicts
+// from the front, so the bias columns no longer align with the cache slots. The combination is rejected.
+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_attention_bias_with_sliding_window_cache_unsupported_throws) {
+ try {
+ convert_model("com.microsoft/gqa_bias_swc.onnx");
+ FAIL() << "ONNX Importer did not reject attention_bias + sliding_window_cache for GroupQueryAttention";
+ } catch (const std::exception& e) {
+ EXPECT_THAT(e.what(), testing::HasSubstr("attention_bias"));
+ } catch (...) {
+ FAIL() << "Unexpected exception type thrown";
+ }
+}
+
+// A windowed cache needs a capacity of at least local_window_size (the cache-end arithmetic uses
+// gap = capacity - local_window_size + 1); a statically-known smaller capacity is rejected up front.
+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_sliding_window_cache_small_capacity_unsupported_throws) {
+ try {
+ convert_model("com.microsoft/gqa_swc_small_capacity.onnx");
+ FAIL() << "ONNX Importer did not reject a too-small windowed cache capacity for GroupQueryAttention";
+ } catch (const std::exception& e) {
+ EXPECT_THAT(e.what(), testing::HasSubstr("capacity"));
+ } catch (...) {
+ FAIL() << "Unexpected exception type thrown";
+ }
+}
+
+// Packed-QKV prompt (num_heads=2, kv_num_heads=1, head_size=16, S=4, past=0) shared by the
+// smooth-softmax / head-sink tests. Reference outputs are from ONNX Runtime (MLAS CPU).
+static std::vector<float> gqa_sink_query() {
+ return {-0.841560f, 0.961409f, 1.341610f, 0.219196f, -1.070939f, 2.005177f, -0.500984f, -1.122348f, 0.676705f,
+ -1.632419f, -0.926639f, 0.406092f, 0.120748f, -0.908491f, -1.119538f, 0.678687f, 0.261504f, 1.661547f,
+ 0.143510f, -0.231519f, 0.039766f, -0.485498f, 0.340751f, -2.563714f, 1.088374f, -1.234958f, -1.495851f,
+ 0.031911f, -0.138748f, -0.745854f, -1.181944f, -0.568151f, 1.091891f, -1.021918f, 0.959766f, 0.549658f,
+ 0.785998f, -0.561202f, -0.477581f, 0.244346f, -0.943581f, 0.640680f, -0.574544f, 0.654430f, -1.338133f,
+ 0.968591f, 0.484597f, -0.490332f, -0.318165f, 0.124472f, 0.240862f, 0.783735f, 0.027064f, 1.387012f,
+ -0.540484f, 2.109540f, -0.437625f, -1.400087f, 0.980181f, 0.964417f, 0.899361f, 1.133594f, -0.736529f,
+ -0.432411f, 0.436726f, 0.310293f, -0.039303f, 1.158923f, 0.004950f, -0.418189f, -0.366611f, -0.163320f,
+ 1.017935f, -0.789237f, 1.944939f, -0.027737f, -0.018879f, 2.909682f, -0.789053f, -0.097781f, 0.108064f,
+ 0.102853f, -1.462710f, 0.208772f, -1.066994f, -1.588492f, -2.039299f, 1.347027f, 0.414454f, 0.003080f,
+ 0.054512f, 0.078857f, 0.196108f, 1.127173f, 0.176119f, 0.119609f, -0.226219f, 1.154819f, -0.979413f,
+ 1.064772f, 1.047214f, 0.713923f, -1.116430f, 0.657610f, -0.001792f, 0.013813f, -1.330579f, -0.296302f,
+ 0.037239f, 0.271217f, -0.091982f, 0.161023f, -0.093429f, -0.248725f, 0.346120f, 0.717340f, -0.373598f,
+ -1.455318f, -0.605575f, 0.541818f, 1.046772f, -1.408027f, 0.839928f, 0.176214f, -0.159969f, -0.423865f,
+ 0.782059f, -0.905910f, 0.121858f, -0.186204f, 0.521079f, -0.078320f, -0.813372f, 0.896154f, 0.998463f,
+ -0.007512f, -0.264747f, -0.109279f, 0.660887f, 1.517640f, -0.090469f, -0.166065f, -0.280879f, -0.549630f,
+ -0.233574f, -0.005912f, -1.893519f, 1.408677f, -1.074038f, 0.191361f, -0.343940f, -1.354283f, 0.986371f,
+ -1.325445f, 0.026918f, -0.258281f, -1.124630f, -1.394380f, 0.316257f, 0.129337f, 0.954208f, -1.279339f,
+ -0.397333f, -1.577390f, -0.578984f, -1.156784f, 1.203218f, 0.511575f, 0.615649f, 0.008202f, 0.832399f,
+ -0.045157f, -1.394901f, -0.134668f, 1.503749f, 1.433073f, -1.817968f, 0.375994f, 1.388801f, -0.808444f,
+ -1.474496f, 0.023879f, 0.380251f, -1.383532f, -1.512560f, -0.894703f, -0.885275f, 0.036063f, 1.462681f,
+ -0.660346f, -0.098059f, 1.324486f, 0.058498f, -1.449158f, -2.043329f, 0.006219f, -0.378941f, -0.473675f,
+ 0.228863f, -2.272386f, -0.872725f, 0.016349f, -0.645995f, -0.957919f, -1.375511f, -0.793446f, -0.461686f,
+ 0.684437f, -0.579369f, -1.583204f, 3.032897f, 0.056690f, -1.636424f, -0.308033f, -0.860494f, 0.653427f,
+ 0.215226f, -0.708250f, -0.978691f, -0.468090f, -0.135356f, 0.015189f, -0.035300f, 1.495406f, -0.541828f,
+ -1.169002f, -0.428368f, -2.950616f, 0.593047f, -0.234292f, 1.536813f, 0.398880f, 0.404500f, -0.062291f,
+ 1.559615f, 1.222434f, -0.432531f, 0.403857f, 0.617080f, -0.592210f, 0.450232f, -0.054978f, 0.507649f,
+ 0.001170f, -1.102470f, -0.817775f, -1.086352f, 0.921146f, -0.763100f, 1.176417f, -0.134350f, 0.695815f,
+ -0.398245f, 0.285846f, 0.884178f, 1.390027f};
+}
+
+// smooth_softmax adds an extra zero logit to the softmax denominator (via SDPA's sink input).
+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_smooth_softmax) {
+ const auto model = convert_model("com.microsoft/gqa_smooth_softmax.onnx");
+
+ std::vector<float> expected_output = {
+ -0.066832f, 0.026146f, 0.050594f, 0.164627f, 0.005685f, 0.291349f, -0.113531f, 0.443120f, -0.091925f,
+ -0.294095f, 0.205892f, 0.202581f, 0.188915f, 0.238117f, -0.154712f, -0.090830f, -0.091050f, 0.035620f,
+ 0.068928f, 0.224282f, 0.007745f, 0.396922f, -0.154671f, 0.603689f, -0.125235f, -0.400664f, 0.280499f,
+ 0.275988f, 0.257371f, 0.324402f, -0.210773f, -0.123743f, -0.154430f, -0.023029f, 0.197463f, 0.522916f,
+ -0.098468f, 0.128400f, -0.393050f, 1.001214f, 0.131363f, -0.971170f, 0.637251f, 0.436813f, 0.312489f,
+ 0.328870f, -0.065475f, -0.437726f, -0.132778f, -0.087372f, 0.235008f, 0.564999f, -0.175038f, -0.330794f,
+ -0.443787f, 0.842442f, 0.391330f, -1.071134f, 0.678677f, 0.350226f, 0.168228f, 0.103512f, 0.180179f,
+ -0.560856f, -0.651118f, 0.120385f, 0.528997f, 0.070166f, -0.479622f, 0.242258f, -0.114741f, 0.264405f,
+ -0.460406f, -0.844036f, 0.118900f, 0.313681f, 0.684516f, 0.083215f, -0.153250f, 0.165789f, -0.599560f,
+ 0.031511f, 0.557997f, 0.092654f, -0.569416f, -0.399728f, -0.156696f, -0.022890f, -0.104287f, -0.902667f,
+ 0.132187f, 0.160992f, 0.454091f, -0.248436f, 0.190414f, 0.022414f, -0.786668f, 0.144045f, 0.739694f,
+ -0.131420f, -0.809990f, -0.044710f, -0.133304f, -0.070781f, -0.685376f, -0.637607f, -0.134253f, 0.279480f,
+ 0.703895f, -0.116000f, 0.043954f, 0.558611f, -0.692927f, 0.144982f, 0.606432f, 0.049698f, -0.586273f,
+ 0.309816f, -0.174315f, 0.352760f, -0.623803f, -0.802655f, 0.090798f, 0.397685f, 0.754286f, 0.148288f,
+ -0.162450f, 0.319562f};
+
+ auto test_case = ov::test::TestCase(model, s_device);
+ test_case.add_input<float>(Shape{1, 4, 64}, gqa_sink_query());
+ test_case.add_input<float>(Shape{1, 1, 0, 16}, {});
+ test_case.add_input<float>(Shape{1, 1, 0, 16}, {});
+ test_case.add_input<int>(Shape{1, 1}, {3});
+ test_case.add_input<int>(Shape{}, {4});
+ test_case.add_expected_output<float>(Shape{1, 4, 32}, expected_output);
+ test_case.run_with_tolerance_as_fp();
+}
+
+// head_sink provides a per-head logit added to the softmax denominator (via SDPA's sink input).
+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_head_sink) {
+ const auto model = convert_model("com.microsoft/gqa_head_sink.onnx");
+
+ std::vector<float> head_sink = {-1.088381f, -1.689387f};
+ std::vector<float> expected_output = {
+ -0.140381f, 0.054919f, 0.106273f, 0.345799f, 0.011941f, 0.611977f, -0.238472f, 0.930771f, -0.193089f,
+ -0.617746f, 0.432475f, 0.425520f, 0.396816f, 0.500164f, -0.324971f, -0.190788f, -0.217839f, 0.085223f,
+ 0.164912f, 0.536602f, 0.018530f, 0.949650f, -0.370055f, 1.444346f, -0.299630f, -0.958602f, 0.671104f,
+ 0.660310f, 0.615768f, 0.776142f, -0.504282f, -0.296060f, -0.194077f, -0.028941f, 0.248158f, 0.657164f,
+ -0.123748f, 0.161364f, -0.493957f, 1.258255f, 0.165088f, -1.220498f, 0.800852f, 0.548956f, 0.392714f,
+ 0.413301f, -0.082284f, -0.550103f, -0.164702f, -0.108380f, 0.291512f, 0.700844f, -0.217123f, -0.410328f,
+ -0.550489f, 1.044994f, 0.485419f, -1.328671f, 0.841854f, 0.434433f, 0.208676f, 0.128400f, 0.223500f,
+ -0.695705f, -0.805645f, 0.148955f, 0.654543f, 0.086818f, -0.593449f, 0.299752f, -0.141973f, 0.327156f,
+ -0.569672f, -1.044348f, 0.147118f, 0.388126f, 0.846970f, 0.102964f, -0.189620f, 0.205135f, -0.753609f,
+ 0.039607f, 0.701367f, 0.116461f, -0.715720f, -0.502433f, -0.196956f, -0.028772f, -0.131082f, -1.134595f,
+ 0.166150f, 0.202356f, 0.570763f, -0.312268f, 0.239339f, 0.028173f, -0.881899f, 0.161482f, 0.829238f,
+ -0.147329f, -0.908045f, -0.050123f, -0.149442f, -0.079349f, -0.768346f, -0.714794f, -0.150506f, 0.313313f,
+ 0.789106f, -0.130043f, 0.049275f, 0.626235f, -0.815256f, 0.170577f, 0.713491f, 0.058472f, -0.689773f,
+ 0.364511f, -0.205088f, 0.415036f, -0.733929f, -0.944356f, 0.106827f, 0.467892f, 0.887448f, 0.174467f,
+ -0.191129f, 0.375977f};
+
+ auto test_case = ov::test::TestCase(model, s_device);
+ test_case.add_input<float>(Shape{1, 4, 64}, gqa_sink_query());
+ test_case.add_input<float>(Shape{1, 1, 0, 16}, {});
+ test_case.add_input<float>(Shape{1, 1, 0, 16}, {});
+ test_case.add_input<int>(Shape{1, 1}, {3});
+ test_case.add_input<int>(Shape{}, {4});
+ test_case.add_input<float>(Shape{2}, head_sink);
+ test_case.add_expected_output<float>(Shape{1, 4, 32}, expected_output);
+ test_case.run_with_tolerance_as_fp();
+}
+
+// sliding_window_cache=1: the KV buffer is window-sized (capacity C=4, local_window_size=2, gap=3) and
+// rolls with front eviction. Decode step with absolute past length 5 (overflowed): the input buffer holds
+// the 2 resident rows (end_before), attention runs over them plus the new token, and present keeps the last
+// 2 resident rows + the new token left-aligned with the tail zeroed (end_after=3). Matches ONNX Runtime.
+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_sliding_window_cache) {
+ auto model = convert_model("com.microsoft/gqa_sliding_window_cache.onnx");
+ model->reshape({{"query", ov::PartialShape{1, 1, 64}},
+ {"past_key", ov::PartialShape{1, 1, 4, 16}},
+ {"past_value", ov::PartialShape{1, 1, 4, 16}},
+ {"seqlens_k", ov::PartialShape{1, 1}},
+ {"total_sequence_length", ov::PartialShape{}}});
+
+ std::vector<float> query = {
+ -0.735874f, -0.860153f, -0.923282f, 0.238453f, -0.583216f, 0.674326f, 0.023700f, 0.221119f,
+ -0.839989f, -0.124535f, 1.044066f, -0.172601f, 1.523960f, -0.556156f, 0.423401f, -0.321324f,
+ -1.359149f, 0.233465f, 1.546571f, -0.414667f, -1.790209f, -0.292157f, -0.331039f, 0.809957f,
+ -1.130349f, -0.387018f, -0.073094f, -0.191489f, 0.069849f, -0.941902f, -0.729284f, -0.155633f,
+ 2.163578f, -0.055617f, -1.175500f, -0.556433f, 0.617155f, 1.107772f, 0.112114f, 0.891698f,
+ -0.892795f, -1.264323f, 0.640429f, -0.380060f, -0.246679f, -0.118568f, -0.541902f, -0.903899f,
+ -0.205618f, 0.289614f, -0.111383f, -1.222770f, 0.287026f, 0.438055f, 0.603653f, 0.627203f,
+ 2.061791f, -1.072247f, -0.289376f, 1.120785f, -0.089408f, -1.327292f, 0.458311f, 1.344336f};
+ std::vector<float> past_key = {
+ -1.387921f, -0.739079f, -0.674372f, -1.688228f, -0.168603f, 1.053749f, -0.046248f, 1.199975f,
+ 0.095706f, -0.056690f, 0.564222f, -0.349066f, -2.315065f, 0.948924f, 2.147583f, 2.244165f,
+ 3.425434f, -0.300379f, 0.794135f, -0.965835f, -0.574064f, -0.650951f, 0.971878f, -0.150697f,
+ -1.235808f, -0.747965f, -1.754603f, -1.466020f, 1.176691f, -0.579464f, -0.517768f, 1.277583f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f};
+ std::vector<float> past_value = {
+ 0.431894f, -0.475653f, -2.148285f, -0.407908f, -1.343020f, 0.256841f, -0.614940f, 0.181786f,
+ -0.850677f, -1.106171f, -0.026706f, -0.513905f, -1.197044f, 0.850652f, 0.976646f, -0.035457f,
+ -0.515761f, -0.999195f, 0.033045f, -0.162934f, 1.611816f, 0.766684f, -1.595301f, -0.933998f,
+ 0.522999f, -1.332224f, 1.326387f, -1.008162f, -1.858583f, 0.826427f, 0.301143f, 1.238006f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f};
+ std::vector<int> seqlens_k = {5};
+ std::vector<int> total_sequence_length = {6};
+
+ std::vector<float> expected_output = {
+ -0.293837f, -0.076981f, -0.070301f, -0.921306f, 0.663855f, 0.531532f, -0.021828f, 0.183128f,
+ 1.624090f, -1.146196f, 0.170219f, 0.515217f, -0.592640f, -0.714678f, 0.413605f, 1.314091f,
+ -0.427834f, -0.633808f, -0.007901f, -0.463406f, 1.236228f, 0.673515f, -0.971881f, -0.491386f,
+ 0.959258f, -1.258518f, 0.868306f, -0.404590f, -1.357009f, 0.215832f, 0.345701f, 1.268151f};
+ std::vector<float> expected_present_key = {
+ -1.387921f, -0.739079f, -0.674372f, -1.688228f, -0.168603f, 1.053749f, -0.046248f, 1.199975f,
+ 0.095706f, -0.056690f, 0.564222f, -0.349066f, -2.315065f, 0.948924f, 2.147583f, 2.244165f,
+ 3.425434f, -0.300379f, 0.794135f, -0.965835f, -0.574064f, -0.650951f, 0.971878f, -0.150697f,
+ -1.235808f, -0.747965f, -1.754603f, -1.466020f, 1.176691f, -0.579464f, -0.517768f, 1.277583f,
+ 2.163578f, -0.055617f, -1.175500f, -0.556433f, 0.617155f, 1.107772f, 0.112114f, 0.891698f,
+ -0.892795f, -1.264323f, 0.640429f, -0.380060f, -0.246679f, -0.118568f, -0.541902f, -0.903899f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f};
+ std::vector<float> expected_present_value = {
+ 0.431894f, -0.475653f, -2.148285f, -0.407908f, -1.343020f, 0.256841f, -0.614940f, 0.181786f,
+ -0.850677f, -1.106171f, -0.026706f, -0.513905f, -1.197044f, 0.850652f, 0.976646f, -0.035457f,
+ -0.515761f, -0.999195f, 0.033045f, -0.162934f, 1.611816f, 0.766684f, -1.595301f, -0.933998f,
+ 0.522999f, -1.332224f, 1.326387f, -1.008162f, -1.858583f, 0.826427f, 0.301143f, 1.238006f,
+ -0.205618f, 0.289614f, -0.111383f, -1.222770f, 0.287026f, 0.438055f, 0.603653f, 0.627203f,
+ 2.061791f, -1.072247f, -0.289376f, 1.120785f, -0.089408f, -1.327292f, 0.458311f, 1.344336f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f};
+
+ auto test_case = ov::test::TestCase(model, s_device);
+ test_case.add_input<float>(Shape{1, 1, 64}, query);
+ test_case.add_input<float>(Shape{1, 1, 4, 16}, past_key);
+ test_case.add_input<float>(Shape{1, 1, 4, 16}, past_value);
+ test_case.add_input<int>(Shape{1, 1}, seqlens_k);
+ test_case.add_input<int>(Shape{}, total_sequence_length);
+ test_case.add_expected_output<float>(Shape{1, 1, 32}, expected_output);
+ test_case.add_expected_output<float>(Shape{1, 1, 4, 16}, expected_present_key);
+ test_case.add_expected_output<float>(Shape{1, 1, 4, 16}, expected_present_value);
+ test_case.run_with_tolerance_as_fp();
+}
+
OPENVINO_TEST(${BACKEND_NAME}, onnx_com_microsoft_qlinear_reducemean_i8) {
const auto model = convert_model("com.microsoft/qlinear_reducemean_i8.onnx");
auto test_case = ov::test::TestCase(model, s_device);