OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[ONNX FE] GroupQueryAttention: QK-Norm, qk_output and batch > 1 spec parity Support (#38816)
Ankit Maheshkardba551c99567
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.hppindex 9addeb5e39e..17f45415db4 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@@ -41,17 +41,29 @@ protected:bool is_causal,int64_t local_window_size = -1,const std::optional<CompressedKV>& compressed_kv = std::nullopt);- // Explicit attention for softcap > 0 (SDPA cannot soft-cap the logits):- // softmax(softcap * tanh(scale * Q * K^T / softcap) + mask [, sink]) * V. key/value keep kv_num_heads heads;- // query heads are grouped onto them by MatMul broadcasting, so the KV cache is never replicated.- std::shared_ptr<ov::Node> make_softcap_attention(const ov::Output<ov::Node>& query,- const ov::Output<ov::Node>& key,- const ov::Output<ov::Node>& value,- const ov::Output<ov::Node>& mask,- const ov::Output<ov::Node>& scale,- const ov::Output<ov::Node>& sink,- float softcap,- int64_t kv_num_heads);+ // Explicit attention for softcap > 0 or a qk_output request (SDPA can neither soft-cap nor expose the scores):+ // softmax(cap(scale * Q * K^T) + mask [, sink]) * V, cap(x) = softcap * tanh(x / softcap) or x when softcap is 0.+ // key/value keep kv_num_heads heads; query heads are grouped onto them by MatMul broadcasting, so the KV cache is+ // never replicated. Returns {attention [B, N, S, D]} plus, when qk_output is set, the [B, N, S, L] scores taken+ // from the same chain: the logits with masked positions zeroed (BEFORE_SOFTMAX) or the probabilities (AFTER).+ // unbiased_mask is the mask without attention_bias, used to find the masked positions.+ ov::OutputVector make_explicit_attention(const ov::Output<ov::Node>& query,+ const ov::Output<ov::Node>& key,+ const ov::Output<ov::Node>& value,+ const ov::Output<ov::Node>& mask,+ const ov::Output<ov::Node>& unbiased_mask,+ const ov::Output<ov::Node>& scale,+ const ov::Output<ov::Node>& sink,+ float softcap,+ int64_t kv_num_heads,+ ov::op::internal::GroupQueryAttentionQKOutput qk_output);++ // QK-Norm: per-head RMSNorm over head_size, x * rsqrt(mean(x^2) + epsilon) * weight, computed in f32 like+ // ONNX Runtime and cast back to the input type. The base emits the primitive chain RMSFusion recognizes;+ // plugins that fuse RMS before this pass can return their fused op directly.+ virtual ov::Output<ov::Node> make_qk_norm(const ov::Output<ov::Node>& input,+ const ov::Output<ov::Node>& weight,+ float epsilon);virtual std::optional<CompressedKV> prepare_compressed_kv(const std::shared_ptr<ov::op::internal::GroupQueryAttention>& node,@@ -93,6 +105,26 @@ protected:bool sliding_window_cache,float scale,bool has_sink);+ // Additive [B, 1, S, kv_len] mask for a batch with per-batch lengths (batch not statically 1). total and past+ // are [B, 1, 1] (total = seqlens_k + 1, past = causal offset of the first query). Keys at or beyond a batch's+ // total are masked (right-padded prompts), then the causal / sliding-window rules apply per batch, matching+ // ONNX Runtime's per-batch visible length. attention_bias [B or 1, N or 1, S, >= kv_len] is added on top.+ std::shared_ptr<ov::Node> make_batched_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,+ const ov::Output<ov::Node>& total,+ const ov::element::Type& compute_type,+ bool causal,+ int64_t local_window_size,+ const ov::Output<ov::Node>& external_bias);+ // attention_bias aligned to the mask's key columns: [num_heads, S, kv_len] from key col_offset (single batch) or+ // [B or 1, N or 1, S, kv_len] (batched), zero-padded past the bias width.+ std::shared_ptr<ov::Node> align_attention_bias(const ov::Output<ov::Node>& bias,+ const ov::Output<ov::Node>& col_offset,+ const ov::Output<ov::Node>& kv_len_1d,+ const ov::element::Type& compute_type,+ bool batched);// 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.cppindex 9ca817c156a..8450abbbf7b 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@@ -5,6 +5,7 @@#include "transformations/op_conversions/group_query_attention_decomposition.hpp"#include <memory>+#include <numeric>#include "itt.hpp"#include "openvino/core/graph_util.hpp"@@ -26,6 +27,8 @@#include "openvino/op/gather.hpp"#include "openvino/op/greater.hpp"#include "openvino/op/greater_eq.hpp"+#include "openvino/op/less.hpp"+#include "openvino/op/logical_and.hpp"#include "openvino/op/logical_or.hpp"#include "openvino/op/matmul.hpp"#include "openvino/op/maximum.hpp"@@ -34,6 +37,7 @@#include "openvino/op/pad.hpp"#include "openvino/op/power.hpp"#include "openvino/op/range.hpp"+#include "openvino/op/reduce_mean.hpp"#include "openvino/op/reshape.hpp"#include "openvino/op/round.hpp"#include "openvino/op/scaled_dot_product_attention.hpp"@@ -42,6 +46,7 @@#include "openvino/op/shape_of.hpp"#include "openvino/op/slice.hpp"#include "openvino/op/softmax.hpp"+#include "openvino/op/sqrt.hpp"#include "openvino/op/squeeze.hpp"#include "openvino/op/subtract.hpp"#include "openvino/op/tanh.hpp"@@ -60,6 +65,17 @@ namespace v5 = ov::op::v5;namespace v8 = ov::op::v8;namespace v13 = ov::op::v13;namespace v15 = ov::op::v15;++namespace {+// Finite lowest() of the attention compute type: the masked-logit fill (a fully-masked row must not softmax to NaN).+float finite_lowest(const ov::element::Type& type) {+ if (type == ov::element::f16)+ return static_cast<float>(std::numeric_limits<ov::float16>::lowest());+ if (type == ov::element::bf16)+ return static_cast<float>(std::numeric_limits<ov::bfloat16>::lowest());+ return std::numeric_limits<float>::lowest();+}+} // namespaceov::pass::GroupQueryAttentionDecomposition::GroupQueryAttentionDecomposition() {MATCHER_SCOPE(GroupQueryAttentionDecomposition);auto pattern_node = ov::pass::pattern::wrap_type<ov::op::internal::GroupQueryAttention>();@@ -95,7 +111,10 @@ ov::OutputVector ov::pass::GroupQueryAttentionDecomposition::decompose(const auto smooth_softmax = node->get_smooth_softmax();const auto causal = node->get_causal();const auto softcap = node->get_softcap();- const bool use_softcap = softcap > 0.0f;+ const auto qk_output = node->get_qk_output();+ // softcap and qk_output need the explicit attention chain instead of SDPA.+ const bool use_explicit_attention =+ softcap > 0.0f || qk_output != ov::op::internal::GroupQueryAttentionQKOutput::NONE;const auto has_input = [&](const GQAInputs input_pos) {const auto pos = static_cast<size_t>(input_pos);@@ -154,11 +173,45 @@ ov::OutputVector ov::pass::GroupQueryAttentionDecomposition::decompose(const auto seqlens_elemi64 = register_new_node<v0::Convert>(seqlens_k, ov::element::i64);const auto real_seqlens = register_new_node<v1::Add>(seqlens_elemi64, one);- // Only consider batch is 1- const auto seqlens_1d = register_new_node<v1::Reshape>(real_seqlens, one, false);- const auto past_seqlen = register_new_node<v1::Subtract>(seqlens_1d, current_seqlen);+ // Per-batch lengths (ORT: one seqlens_k entry per batch) whenever the batch is not statically 1. A static batch+ // of 1 keeps the scalar-length graph below unchanged, since plugins and the NPU compiler pattern-match it; the+ // windowed cache stays single-batch.+ const auto& q_ps = node->get_input_partial_shape(static_cast<size_t>(GQAInputs::QUERY));+ const bool batched = !node->get_sliding_window_cache() &&+ !(q_ps.rank().is_static() && q_ps[0].is_static() && q_ps[0].get_length() == 1);+ // [B, 1, 1]: total = seqlens_k + 1, the causal offset of the first query (ORT: 0 for a first, right-padded+ // prompt, total - S otherwise), and the row the first new key is written at.+ std::shared_ptr<ov::Node> total_b, q_past_b, kv_past_b;+ if (batched) {+ // [B, 1, 1] with B taken from the query, so a seqlens_k without one entry per batch fails the Reshape+ // instead of broadcasting one length over every batch (ORT requires batch_size elements).+ const auto per_batch = register_new_node<v0::Concat>(+ ov::OutputVector{get_dimensions(q_shape, {0}),+ register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{2}, {1, 1}))},+ 0);+ total_b = register_new_node<v1::Reshape>(real_seqlens, per_batch, false);+ q_past_b = register_new_node<v1::Maximum>(register_new_node<v1::Subtract>(total_b, current_seqlen), zero);+ kv_past_b = independent_kv_len+ ? register_new_node<v1::Maximum>(register_new_node<v1::Subtract>(total_b, kv_seqlen), zero)+ : q_past_b;+ }+ // A single batch entry uses scalar ([1]) lengths; only built when not batched (the [1] reshape needs batch 1).+ std::shared_ptr<ov::Node> seqlens_1d, past_seqlen;+ if (!batched) {+ seqlens_1d = register_new_node<v1::Reshape>(real_seqlens, one, false);+ past_seqlen = register_new_node<v1::Subtract>(seqlens_1d, current_seqlen);+ }const auto curr_seqlen_scalar = register_new_node<v0::Squeeze>(current_seqlen);+ // QK-Norm is applied to the new Q/K heads before RoPE (ORT); shared KV has no new keys.+ if (node->has_qk_norm()) {+ const auto epsilon = node->get_qk_norm_epsilon();+ Q = make_qk_norm(Q, get_input(GQAInputs::Q_NORM_WEIGHT), epsilon);+ if (!shared_kv) {+ K = make_qk_norm(K, get_input(GQAInputs::K_NORM_WEIGHT), epsilon);+ }+ }+if (do_rotary) {// Get cos_cache and sin_cache from their actual input indices (ONNX COS_CACHE and SIN_CACHE).// validate_and_infer_types() already verified these inputs exist and indices are valid when do_rotary is true.@@ -167,8 +220,19 @@ ov::OutputVector ov::pass::GroupQueryAttentionDecomposition::decompose(ov::Output<ov::Node> position_ids =register_new_node<v4::Range>(zero_without_shape, curr_seqlen_scalar, one_without_shape, ov::element::i64);- // Check if position_ids is provided (optional input), using actual input index- if (has_input(GQAInputs::POSITION_IDS)) {+ // Batched: [B, S] positions (past_b + s, or the given [B, S] position_ids); cos/sin become [B, S, D/2].+ const auto pos_axis = batched ? one : zero;+ if (batched) {+ const auto minus_one = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{1}, {-1}));+ const auto rows = register_new_node<v0::Concat>(ov::OutputVector{minus_one, current_seqlen}, 0);+ if (has_input(GQAInputs::POSITION_IDS)) {+ position_ids = register_new_node<v1::Reshape>(get_input(GQAInputs::POSITION_IDS), rows, false);+ } else {+ const auto column = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{2}, {-1, 1}));+ position_ids =+ register_new_node<v1::Add>(register_new_node<v1::Reshape>(q_past_b, column, false), position_ids);+ }+ } else if (has_input(GQAInputs::POSITION_IDS)) {// Flatten position_ids to 1D so that Gather produces 2D [seqlen, head_size/2] output,// ensuring correct 4D shapes after Unsqueeze in rotaryEmbedding.const auto neg_one = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{1}, {-1}));@@ -184,17 +248,17 @@ ov::OutputVector ov::pass::GroupQueryAttentionDecomposition::decompose(if (independent_kv_len) {// The new keys sit at the same positions as the queries; take only the first S_kv rows (all of them// unless S_kv resolves to 0 at runtime).- const auto cos_k = register_new_node<v8::Slice>(cos, zero, kv_seqlen, one, zero);- const auto sin_k = register_new_node<v8::Slice>(sin, zero, kv_seqlen, one, zero);+ const auto cos_k = register_new_node<v8::Slice>(cos, zero, kv_seqlen, one, pos_axis);+ const auto sin_k = register_new_node<v8::Slice>(sin, zero, kv_seqlen, one, pos_axis);K = rotaryEmbedding(K, cos_k, sin_k, rotary_interleaved);} else if (!shared_kv) {K = rotaryEmbedding(K, cos, sin, rotary_interleaved);}}- // A static past is a preallocated max-length buffer written in place. A zero-capacity past (an absent ONNX- // past or an empty cache) has nothing to write into, so it grows by concatenation instead.- const auto is_static_input = K.get_partial_shape().is_static() && past_key.get_partial_shape().is_static() &&- past_key.get_partial_shape()[2].get_length() > 0;+ // A preallocated cache (static capacity and step length, whatever the batch) is written in place. A+ // zero-capacity past (an absent ONNX past or an empty cache) has nothing to write into, so it grows by+ // concatenation instead. Same rule as the op's present shape inference.+ const auto is_static_input = node->has_fixed_kv_capacity();// Quantize-on-write: when the cache is quantized, quantize the (post-RoPE) current K/V into the cache type// before appending them, so the assembled present cache stays quantized and the past bytes are preserved@@ -206,7 +270,7 @@ ov::OutputVector ov::pass::GroupQueryAttentionDecomposition::decompose(// 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> mask_past_seqlen = batched ? ov::Output<ov::Node>() : past_seqlen->output(0);// Absolute key position of the KV buffer's first slot, used to align an external attention_bias (indexed// by absolute key). 0 for a full-length cache (slot j == absolute key j); a windowed cache rolls, so its// first slot holds absolute key P - resident_rows (set in the windowed branches below).@@ -304,6 +368,61 @@ ov::OutputVector ov::pass::GroupQueryAttentionDecomposition::decompose(bias_col_offset =register_new_node<v0::Unsqueeze>(register_new_node<v1::Subtract>(abs_past_scalar, end_before), zero);}+ } else if (batched) {+ // Per-batch cache write (ORT ConcatStateChunkGQA, left-aligned): batch b keeps its first kv_past_b rows and+ // gets its S_kv new rows at [kv_past_b, kv_past_b + S_kv). The cache is viewed as [B * Nkv * L, D] rows and+ // written with one ScatterUpdate(axis 0) at row (b * Nkv + h) * L + kv_past_b + s: in place on a static buffer,+ // after a single Concat(past, new) for a growing cache (L = past rows + S_kv; rows past a batch's total are+ // unspecified, as in ORT). Index arithmetic stays rank 4 ([B, Nkv, S_kv, 1]) so plugins broadcast it in their+ // native layout.+ const auto kv_rows = independent_kv_len ? kv_seqlen : current_seqlen;+ const auto as_shape = [&](std::initializer_list<int64_t> shape) {+ return register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{shape.size()}, shape));+ };+ const auto batch = register_new_node<v0::Squeeze>(get_dimensions(register_new_node<v3::ShapeOf>(K), {0}));+ const auto batch_idx = register_new_node<v1::Reshape>(+ register_new_node<v4::Range>(zero_without_shape, batch, one_without_shape, ov::element::i64),+ as_shape({-1, 1, 1, 1}),+ false);+ std::vector<int64_t> heads(static_cast<size_t>(kv_num_heads));+ std::iota(heads.begin(), heads.end(), int64_t{0});+ const auto head_idx = register_new_node(+ v0::Constant::create(ov::element::i64, ov::Shape{1, static_cast<size_t>(kv_num_heads), 1, 1}, heads));+ const auto bh_idx = register_new_node<v1::Add>(+ register_new_node<v1::Multiply>(+ batch_idx,+ register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{}, {kv_num_heads}))),+ head_idx); // [B, Nkv, 1, 1]+ const auto new_row = register_new_node<v1::Add>(+ register_new_node<v1::Reshape>(kv_past_b, as_shape({-1, 1, 1, 1}), false),+ register_new_node<v1::Reshape>(register_new_node<v4::Range>(zero_without_shape,+ register_new_node<v0::Squeeze>(kv_rows),+ one_without_shape,+ ov::element::i64),+ as_shape({1, 1, -1, 1}),+ false)); // [B, 1, S_kv, 1]+ const auto write = [&](const ov::Output<ov::Node>& past, const ov::Output<ov::Node>& current) {+ const ov::Output<ov::Node> buffer =+ is_static_input ? past : register_new_node<v0::Concat>(ov::OutputVector{past, current}, 2)->output(0);+ const auto buffer_shape = register_new_node<v3::ShapeOf>(buffer);+ const auto rows_per_head = get_dimensions(buffer_shape, {2});+ const auto flat_idx = register_new_node<v1::Reshape>(+ register_new_node<v1::Add>(register_new_node<v1::Multiply>(bh_idx, rows_per_head), new_row),+ as_shape({-1}),+ false); // [B * Nkv * S_kv]+ const auto row_shape =+ register_new_node<v0::Concat>(ov::OutputVector{as_shape({-1}), get_dimensions(buffer_shape, {3})}, 0);+ const auto rows =+ register_new_node<v3::ScatterUpdate>(register_new_node<v1::Reshape>(buffer, row_shape, false),+ flat_idx,+ register_new_node<v1::Reshape>(current, row_shape, false),+ zero);+ return register_new_node<v1::Reshape>(rows, buffer_shape, false);+ };+ K = write(past_key, K);+ V = write(past_value, V);+ present_k = K;+ present_v = V;} 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.@@ -333,9 +452,9 @@ ov::OutputVector ov::pass::GroupQueryAttentionDecomposition::decompose(present_v = V;}- // The explicit softcap attention chain consumes plain (dequantized) K/V, so skip the compressed-KV SDPA form.+ // The explicit attention chain consumes plain (dequantized) K/V, so skip the compressed-KV SDPA form.std::optional<CompressedKV> compressed_kv;- if (!use_softcap) {+ if (!use_explicit_attention) {compressed_kv = prepare_compressed_kv(node, K, V, k_scale, v_scale);}@@ -351,8 +470,8 @@ ov::OutputVector ov::pass::GroupQueryAttentionDecomposition::decompose(// Broadcast KV if grouped query attentionconst size_t kv_num_heads_factor = num_heads / kv_num_heads;- // The softcap chain groups query heads per KV head itself (no KV replication), see make_softcap_attention.- if (kv_num_heads_factor > 1 && !compressed_kv && !use_softcap) {+ // The explicit chain groups query heads per KV head itself (no KV replication), see make_explicit_attention.+ if (kv_num_heads_factor > 1 && !compressed_kv && !use_explicit_attention) {const auto kv_shape = register_new_node<v3::ShapeOf>(K);const auto kv_shape_prev_2 = get_dimensions(kv_shape, {0, 1});const auto kv_shape_last_2 = get_dimensions(kv_shape, {2, 3});@@ -374,34 +493,58 @@ ov::OutputVector ov::pass::GroupQueryAttentionDecomposition::decompose(}const bool has_head_sink = has_input(GQAInputs::HEAD_SINK);const bool has_sink = has_head_sink || smooth_softmax;- // The softcap chain has no is_causal fallback, and shared KV must hide the past rows beyond `total`, so both+ // The explicit chain has no is_causal fallback, and shared KV must hide the past rows beyond `total`, so both// always take the explicit (base) mask; overrides may otherwise drop it in favor of SDPA's causal flag.- const bool explicit_mask = use_softcap || shared_kv;- const auto mask = explicit_mask- ? GroupQueryAttentionDecomposition::make_attention_mask(curr_seqlen_scalar,- concat_kv_len_scalar,- concat_kv_len,- mask_past_seqlen,- T,- causal,- local_window_size,- external_bias,- bias_col_offset,- node->get_sliding_window_cache(),- scale,- has_sink)- : make_attention_mask(curr_seqlen_scalar,- concat_kv_len_scalar,- concat_kv_len,- mask_past_seqlen,- T,- causal,- local_window_size,- external_bias,- bias_col_offset,- node->get_sliding_window_cache(),- scale,- has_sink);+ const bool explicit_mask = use_explicit_attention || shared_kv;+ // qk_output before softmax reports masked positions as 0 (ORT); they are found on the bias-free mask, so a large+ // negative attention_bias reads logit + bias. The mask is then built once without the bias, and the aligned bias+ // is added on top (same op count as the fused form).+ const bool split_bias =+ qk_output == ov::op::internal::GroupQueryAttentionQKOutput::BEFORE_SOFTMAX && external_bias.get_node();+ const auto mask_bias = split_bias ? ov::Output<ov::Node>() : external_bias;+ std::shared_ptr<ov::Node> mask =+ batched ? make_batched_attention_mask(curr_seqlen_scalar,+ concat_kv_len_scalar,+ concat_kv_len,+ q_past_b,+ total_b,+ T,+ causal,+ local_window_size,+ mask_bias)+ : explicit_mask ? GroupQueryAttentionDecomposition::make_attention_mask(curr_seqlen_scalar,+ concat_kv_len_scalar,+ concat_kv_len,+ mask_past_seqlen,+ T,+ causal,+ local_window_size,+ mask_bias,+ bias_col_offset,+ node->get_sliding_window_cache(),+ scale,+ has_sink)+ : make_attention_mask(curr_seqlen_scalar,+ concat_kv_len_scalar,+ concat_kv_len,+ mask_past_seqlen,+ T,+ causal,+ local_window_size,+ mask_bias,+ bias_col_offset,+ node->get_sliding_window_cache(),+ scale,+ has_sink);++ // qk_output before softmax reports masked positions as 0 (ORT). They are found on the mask without+ // attention_bias, so a large negative bias value is reported as logit + bias, not as masked.+ ov::Output<ov::Node> unbiased_mask = mask;+ if (split_bias) {+ mask = register_new_node<v1::Add>(+ mask,+ align_attention_bias(external_bias, batched ? zero : bias_col_offset, concat_kv_len, T, batched));+ }// 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@@ -434,9 +577,30 @@ ov::OutputVector ov::pass::GroupQueryAttentionDecomposition::decompose(return register_new_node<v0::Squeeze>(register_new_node<ov::op::v1::Power>(head_size_t, neg_half));};- std::shared_ptr<ov::Node> qga_output;- if (use_softcap) {- qga_output = make_softcap_attention(Q, K, V, mask, make_scale_node(), sink, softcap, kv_num_heads);+ ov::Output<ov::Node> qga_output;+ ov::Output<ov::Node> qk_scores;+ if (use_explicit_attention) {+ const auto attention = make_explicit_attention(Q,+ K,+ V,+ mask,+ unbiased_mask,+ make_scale_node(),+ sink,+ softcap,+ kv_num_heads,+ qk_output);+ qga_output = attention[0];+ if (qk_output != ov::op::internal::GroupQueryAttentionQKOutput::NONE) {+ // ONNX Runtime lays output_qk out over the total_sequence_length input, which a static or shared cache+ // does not tie to seqlens_k; the per-batch lengths only mask. Extra cache rows are dropped here.+ const auto three = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{1}, {3}));+ const auto total_cols = register_new_node<v1::Reshape>(+ register_new_node<v0::Convert>(get_input(GQAInputs::TOTAL_SEQUENCE_LENGTH), ov::element::i64),+ one,+ false);+ qk_scores = register_new_node<v8::Slice>(attention[1], zero, total_cols, one, three);+ }} else if (sink.get_node_shared_ptr()) {// SDPA's 6-input form requires an explicit scale.qga_output = make_sdpa(Q, K, V, mask, make_scale_node(), sink, false, local_window_size, compressed_kv);@@ -454,6 +618,9 @@ ov::OutputVector ov::pass::GroupQueryAttentionDecomposition::decompose(auto dim_merge_shape = register_new_node(v0::Constant::create(ov::element::i32, ov::Shape{3}, {0, 0, -1}));auto output = register_new_node<v1::Reshape>(qga_output_transposed, dim_merge_shape, true)->output(0);+ if (qk_scores.get_node()) {+ return {output, present_k, present_v, qk_scores};+ }return {output, present_k, present_v};}@@ -481,17 +648,20 @@ std::shared_ptr<ov::Node> ov::pass::GroupQueryAttentionDecomposition::make_sdpa(return register_new_node<v13::ScaledDotProductAttention>(query, key, value, is_causal);}-std::shared_ptr<ov::Node> ov::pass::GroupQueryAttentionDecomposition::make_softcap_attention(+ov::OutputVector ov::pass::GroupQueryAttentionDecomposition::make_explicit_attention(const ov::Output<ov::Node>& query,const ov::Output<ov::Node>& key,const ov::Output<ov::Node>& value,const ov::Output<ov::Node>& mask,+ const ov::Output<ov::Node>& unbiased_mask,const ov::Output<ov::Node>& scale,const ov::Output<ov::Node>& sink,float softcap,- int64_t kv_num_heads) {- // SDPA has no hook between Q*K^T and softmax, so softcap uses the explicit chain in ONNX Runtime order- // (gqa_attention_base.h): scale -> softcap * tanh(x / softcap) -> + bias/mask -> softmax (+ sink) -> * V.+ int64_t kv_num_heads,+ ov::op::internal::GroupQueryAttentionQKOutput qk_output) {+ using QKOutput = ov::op::internal::GroupQueryAttentionQKOutput;+ // SDPA has no hook between Q*K^T and softmax, so this uses the explicit chain in ONNX Runtime order+ // (gqa_attention_base.h): scale -> [softcap * tanh(x / softcap)] -> + bias/mask -> softmax (+ sink) -> * V.const auto T = query.get_element_type();// Grouped-query attention without replicating K/V: view Q [B, N, S, D] as [B, Nkv, G, S, D] (query head// h = kv * G + g, matching ORT) and let MatMul broadcast it against K/V viewed as [B, Nkv, 1, L, D]. The@@ -514,10 +684,15 @@ std::shared_ptr<ov::Node> ov::pass::GroupQueryAttentionDecomposition::make_softcconst auto scores_shape =register_new_node<v0::Concat>(ov::NodeVector{batch, num_heads, get_dimensions(q_shape, {2}), kv_len}, 0);const auto scores = register_new_node<v1::Reshape>(grouped_scores, scores_shape, false);- const auto inv_cap = register_new_node(v0::Constant::create(T, Shape{}, {1.0f / softcap}));- const auto cap = register_new_node(v0::Constant::create(T, Shape{}, {softcap}));- const auto scaled = register_new_node<v1::Multiply>(scores, register_new_node<v1::Multiply>(scale, inv_cap));- std::shared_ptr<ov::Node> logits = register_new_node<v1::Multiply>(register_new_node<v0::Tanh>(scaled), cap);+ std::shared_ptr<ov::Node> logits;+ if (softcap > 0.0f) {+ const auto inv_cap = register_new_node(v0::Constant::create(T, Shape{}, {1.0f / softcap}));+ const auto cap = register_new_node(v0::Constant::create(T, Shape{}, {softcap}));+ const auto scaled = register_new_node<v1::Multiply>(scores, register_new_node<v1::Multiply>(scale, inv_cap));+ logits = register_new_node<v1::Multiply>(register_new_node<v0::Tanh>(scaled), cap);+ } else {+ logits = register_new_node<v1::Multiply>(scores, scale);+ }logits = register_new_node<v1::Add>(logits, mask);if (T != ov::element::f32) {// The mask fills with the type's finite lowest(); keep lowest() + logit from overflowing to -inf in@@ -550,7 +725,19 @@ std::shared_ptr<ov::Node> ov::pass::GroupQueryAttentionDecomposition::make_softcconst auto grouped_out = register_new_node<v0::MatMul>(grouped_probs, grouped_v);// [B, Nkv, G, S, D] -> [B, N, S, D]const auto out_shape = register_new_node<v0::Concat>(ov::NodeVector{batch, num_heads, q_len_head}, 0);- return register_new_node<v1::Reshape>(grouped_out, out_shape, false);+ const auto attention = register_new_node<v1::Reshape>(grouped_out, out_shape, false);+ if (qk_output == QKOutput::AFTER_SOFTMAX) {+ return {attention, probs};+ }+ if (qk_output == QKOutput::BEFORE_SOFTMAX) {+ // ONNX Runtime reports masked (future / out-of-window / beyond-total) logits as 0. Masked entries of the+ // bias-free mask are the type's finite lowest(), so a lowest() / 2 threshold identifies them.+ const auto threshold = register_new_node(v0::Constant::create(T, Shape{}, {finite_lowest(T) / 2}));+ const auto is_masked = register_new_node<v1::Less>(unbiased_mask, threshold);+ const auto typed_zero = register_new_node(v0::Constant::create(T, Shape{}, {0}));+ return {attention, register_new_node<v1::Select>(is_masked, typed_zero, logits)};+ }+ return {attention};}std::shared_ptr<ov::Node> ov::pass::GroupQueryAttentionDecomposition::windowed_cache_end(@@ -661,28 +848,102 @@ std::shared_ptr<ov::Node> ov::pass::GroupQueryAttentionDecomposition::make_atten// of the causal/window mask (broadcasts over the head axis against the [curr, kv_len] mask). The bias// is indexed by absolute key position, so the key window starts at bias_col_offset (0 for a// full-length cache; P - resident_rows for a windowed cache, whose first slot is not absolute key 0).- 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);- const auto bias_stop = register_new_node<v1::Add>(bias_col_offset, kv_len_1d);- bias = register_new_node<v8::Slice>(bias, bias_col_offset, bias_stop, one, two);+ mask = register_new_node<v1::Add>(+ mask,+ align_attention_bias(external_bias, bias_col_offset, kv_len_1d, compute_type, false));+ }- // The bias only spans total_sequence_length columns, narrower than kv_len whenever K keeps unused- // trailing rows (a windowed cache below capacity, or a static full-length cache whose buffer- // exceeds the current total length) - the Slice above then clamps to that narrower width. Zero-pad- // back up to kv_len: the trailing gap is always past the causal/window edge (every branch above- // places resident/new rows before it), so its bias value is never read.- const auto bias_kv_len = get_dimensions(bias, {2});- const auto pad_amount = register_new_node<v1::Subtract>(kv_len_1d, bias_kv_len);- const auto pads_begin = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 0}));- const auto pads_end = register_new_node<v0::Concat>(ov::OutputVector{zero, zero, pad_amount}, 0);- bias = register_new_node<v1::Pad>(bias, pads_begin, pads_end, typed_zero, ov::op::PadMode::CONSTANT);+ return mask;+}- mask = register_new_node<v1::Add>(mask, bias);- }+std::shared_ptr<ov::Node> ov::pass::GroupQueryAttentionDecomposition::make_batched_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,+ const ov::Output<ov::Node>& total,+ const ov::element::Type& compute_type,+ bool causal,+ int64_t local_window_size,+ const ov::Output<ov::Node>& external_bias) {+ const auto zero = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{1}, {0}));+ 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}));+ // Everything stays rank 4 ([B, 1, S or 1, kv_len]) so plugins broadcast it in their native layout.+ const auto as_4d = [&](const ov::Output<ov::Node>& value, std::initializer_list<int64_t> shape) {+ return register_new_node<v1::Reshape>(+ value,+ register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{4}, shape)),+ false);+ };+ const auto keys =+ as_4d(register_new_node<v4::Range>(zero_scalar, kv_len_scalar, one_scalar, ov::element::i64), {1, 1, 1, -1});+ std::shared_ptr<ov::Node> masked = register_new_node<v1::GreaterEqual>(keys, as_4d(total, {-1, 1, 1, 1}));+ if (causal) {+ // Absolute query positions [B, 1, S, 1] = past_b + s.+ const auto queries = register_new_node<v1::Add>(+ as_4d(register_new_node<v4::Range>(zero_scalar, curr_seqlen_scalar, one_scalar, ov::element::i64),+ {1, 1, -1, 1}),+ as_4d(past, {-1, 1, 1, 1}));+ masked = register_new_node<v1::LogicalOr>(masked, register_new_node<v1::Greater>(keys, queries));+ if (local_window_size >= 1) {+ // Window relative to the query position, as in ORT's flash kernel (MLAS flashattn_gqa.cpp).+ 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>(register_new_node<v1::Subtract>(queries, keys), 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}));+ const auto lowest =+ register_new_node(v0::Constant::create(compute_type, ov::Shape{}, {finite_lowest(compute_type)}));+ std::shared_ptr<ov::Node> mask = register_new_node<v1::Select>(masked, lowest, typed_zero);+ if (external_bias.get_node_shared_ptr()) {+ mask =+ register_new_node<v1::Add>(mask, align_attention_bias(external_bias, zero, kv_len_1d, compute_type, true));+ }return mask;}+std::shared_ptr<ov::Node> ov::pass::GroupQueryAttentionDecomposition::align_attention_bias(+ const ov::Output<ov::Node>& bias,+ const ov::Output<ov::Node>& col_offset,+ const ov::Output<ov::Node>& kv_len_1d,+ const ov::element::Type& compute_type,+ bool batched) {+ 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 typed_zero = register_new_node(v0::Constant::create(compute_type, ov::Shape{}, {0}));+ if (batched) {+ // [B or 1, N or 1, S, total_sequence_length]: take kv_len columns, zero-padding past the bias width (those+ // keys are beyond every batch's total and already masked).+ const auto three = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{1}, {3}));+ const auto sliced = register_new_node<v8::Slice>(bias, zero, kv_len_1d, one, three);+ const auto pad_amount = register_new_node<v1::Subtract>(kv_len_1d, get_dimensions(sliced, {3}));+ const auto pads_begin = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{4}, {0, 0, 0, 0}));+ const auto pads_end = register_new_node<v0::Concat>(ov::OutputVector{zero, zero, zero, pad_amount}, 0);+ return register_new_node<v1::Pad>(sliced, pads_begin, pads_end, typed_zero, ov::op::PadMode::CONSTANT);+ }+ // [1, num_heads, curr, max_kv] -> [num_heads, curr, kv_len], broadcasting over the head axis against the+ // [curr, kv_len] mask. The bias is indexed by absolute key position, so the key window starts at col_offset+ // (0 for a full-length cache; P - resident_rows for a windowed cache, whose first slot is not absolute key 0).+ const auto two = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{1}, {2}));+ const auto squeeze_axis = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{1}, {0}));+ const auto squeezed = register_new_node<v0::Squeeze>(bias, squeeze_axis);+ const auto bias_stop = register_new_node<v1::Add>(col_offset, kv_len_1d);+ const auto sliced = register_new_node<v8::Slice>(squeezed, col_offset, bias_stop, one, two);+ // The bias only spans total_sequence_length columns, narrower than kv_len whenever K keeps unused trailing rows+ // (a windowed cache below capacity, or a static full-length cache whose buffer exceeds the current total+ // length) - the Slice above then clamps to that narrower width. Zero-pad back up to kv_len: the trailing gap is+ // always past the causal/window edge, so its bias value is never read.+ const auto pad_amount = register_new_node<v1::Subtract>(kv_len_1d, get_dimensions(sliced, {2}));+ const auto pads_begin = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 0}));+ const auto pads_end = register_new_node<v0::Concat>(ov::OutputVector{zero, zero, pad_amount}, 0);+ return register_new_node<v1::Pad>(sliced, pads_begin, pads_end, typed_zero, ov::op::PadMode::CONSTANT);+}+std::shared_ptr<ov::Node> ov::pass::GroupQueryAttentionDecomposition::get_dimensions(const std::shared_ptr<v3::ShapeOf>& shape,const std::vector<int>& dims) {@@ -697,6 +958,22 @@ std::shared_ptr<ov::Node> ov::pass::GroupQueryAttentionDecomposition::get_dimensreturn get_dimensions(register_new_node<v3::ShapeOf>(node), dims);}+ov::Output<ov::Node> ov::pass::GroupQueryAttentionDecomposition::make_qk_norm(const ov::Output<ov::Node>& input,+ const ov::Output<ov::Node>& weight,+ float epsilon) {+ const auto type = input.get_element_type();+ const bool upcast = type != ov::element::f32;+ const auto x = upcast ? register_new_node<v0::Convert>(input, ov::element::f32)->output(0) : input;+ const auto gamma = upcast ? register_new_node<v0::Convert>(weight, ov::element::f32)->output(0) : weight;+ const auto two = register_new_node(v0::Constant::create(ov::element::f32, ov::Shape{}, {2.0f}));+ const auto axis = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{1}, {-1}));+ const auto eps = register_new_node(v0::Constant::create(ov::element::f32, ov::Shape{}, {epsilon}));+ const auto mean = register_new_node<v1::ReduceMean>(register_new_node<v1::Power>(x, two), axis, true);+ const auto rms = register_new_node<v0::Sqrt>(register_new_node<v1::Add>(mean, eps));+ const auto normed = register_new_node<v1::Multiply>(gamma, register_new_node<v1::Divide>(x, rms));+ return upcast ? register_new_node<v0::Convert>(normed, type)->output(0) : normed->output(0);+}+std::shared_ptr<ov::Node> ov::pass::GroupQueryAttentionDecomposition::rotaryEmbedding(ov::Output<ov::Node> input,ov::Output<ov::Node> cos,ov::Output<ov::Node> sin,@@ -728,7 +1005,10 @@ std::shared_ptr<ov::Node> ov::pass::GroupQueryAttentionDecomposition::rotaryEmbe}// Unsqueeze cos/sin to 4D [1, 1, seqlen, head_size/2] to match RoPE fusion pattern- auto unsqueeze_axes = v0::Constant::create(ov::element::i64, ov::Shape{2}, {0, 1});+ // Batched [B, S, D/2] cos/sin only gain the head axis: [B, 1, S, D/2].+ auto unsqueeze_axes = cos_partial_shape.rank().get_length() == 3+ ? v0::Constant::create(ov::element::i64, ov::Shape{1}, {1})+ : v0::Constant::create(ov::element::i64, ov::Shape{2}, {0, 1});auto cos_4d = register_new_node<v0::Unsqueeze>(cos, unsqueeze_axes);auto sin_4d = register_new_node<v0::Unsqueeze>(sin, unsqueeze_axes);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.cppindex e0beffe4521..aafadde1ae7 100644--- 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@@ -6,6 +6,7 @@#include <gtest/gtest.h>+#include <functional>#include <memory>#include <string>#include <vector>@@ -18,6 +19,7 @@#include "openvino/op/broadcast.hpp"#include "openvino/op/concat.hpp"#include "openvino/op/constant.hpp"+#include "openvino/op/convert.hpp"#include "openvino/op/gather.hpp"#include "openvino/op/greater.hpp"#include "openvino/op/greater_eq.hpp"@@ -26,15 +28,19 @@#include "openvino/op/minimum.hpp"#include "openvino/op/multiply.hpp"#include "openvino/op/parameter.hpp"+#include "openvino/op/reduce_mean.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/op/select.hpp"#include "openvino/op/slice.hpp"#include "openvino/op/softmax.hpp"#include "openvino/op/tanh.hpp"#include "openvino/op/variadic_split.hpp"#include "openvino/pass/manager.hpp"+#include "ov_ops/rms.hpp"+#include "transformations/common_optimizations/rms_fusion.hpp"using namespace ov;using ov::op::internal::GroupQueryAttention;@@ -325,11 +331,15 @@ TEST(GroupQueryAttentionOpValidation, allows_static_multi_token_windowed_cache)EXPECT_NO_THROW(make_gqa_op(1, /*seq*/ 4, 8, /*window*/ 2, /*swc*/ true));}-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),+TEST(GroupQueryAttentionOpValidation, allows_static_batch_greater_than_one) {+ EXPECT_NO_THROW(make_gqa_op(/*batch*/ 2, 1, 8, /*window*/ -1, /*swc*/ false));+}++TEST(GroupQueryAttentionOpValidation, rejects_static_batch_greater_than_one_with_windowed_cache) {+ // The windowed cache's rolling arithmetic is single-batch.+ OV_EXPECT_THROW(make_gqa_op(/*batch*/ 2, 1, 8, /*window*/ 2, /*swc*/ true),ov::NodeValidationFailure,- testing::HasSubstr("batch_size == 1"));+ testing::HasSubstr("sliding_window_cache is only supported for batch_size == 1"));}TEST(GroupQueryAttentionOpValidation, allows_dynamic_sequence_with_windowed_cache) {@@ -620,3 +630,222 @@ TEST(GroupQueryAttentionValues, bidirectional_mask_has_no_causal_comparison) {EXPECT_EQ(count_ops_of_type<op::v1::Greater>(model), 0u);EXPECT_EQ(count_ops_of_type<op::v1::GreaterEqual>(model), 1u);}++namespace {+// Packed QKV + RoPE with QK-Norm weights (Constants, as ONNX initializers are) at inputs 14/15.+std::shared_ptr<Model> make_packed_rotary_qk_norm_gqa_model(const element::Type& type) {+ const auto qkv =+ std::make_shared<op::v0::Parameter>(type, PartialShape{1, NUM_HEADS + 2 * KV_NUM_HEADS, -1, HEAD_SIZE});+ const auto split_lengths =+ op::v0::Constant::create(element::i64, Shape{3}, {NUM_HEADS, KV_NUM_HEADS, KV_NUM_HEADS});+ const auto split = std::make_shared<op::v1::VariadicSplit>(qkv,+ op::v0::Constant::create(element::i64, Shape{}, {1}),+ split_lengths);+ const auto past_k = std::make_shared<op::v0::Parameter>(type, PartialShape{1, KV_NUM_HEADS, -1, HEAD_SIZE});+ const auto past_v = std::make_shared<op::v0::Parameter>(type, PartialShape{1, KV_NUM_HEADS, -1, HEAD_SIZE});+ const auto seqlens = std::make_shared<op::v0::Parameter>(element::i32, PartialShape{1});+ const auto total = std::make_shared<op::v0::Parameter>(element::i32, PartialShape{});+ const auto cos = std::make_shared<op::v0::Parameter>(type, PartialShape{-1, HEAD_SIZE / 2});+ const auto sin = std::make_shared<op::v0::Parameter>(type, PartialShape{-1, HEAD_SIZE / 2});+ const auto empty = op::v0::Constant::create(element::dynamic, Shape{0}, {});+ const auto q_weight = op::v0::Constant::create(type, Shape{HEAD_SIZE}, {0.5f});+ const auto k_weight = op::v0::Constant::create(type, Shape{HEAD_SIZE}, {1.5f});+ const auto gqa = std::make_shared<GroupQueryAttention>(OutputVector{split->output(0),+ split->output(1),+ split->output(2),+ past_k,+ past_v,+ seqlens,+ total,+ cos,+ sin,+ empty,+ empty,+ empty,+ empty,+ empty,+ q_weight,+ k_weight},+ NUM_HEADS,+ KV_NUM_HEADS,+ 0.0f,+ true,+ false,+ 0,+ op::internal::GroupQueryAttentionQuantType::NONE,+ op::internal::GroupQueryAttentionQuantType::NONE,+ -1,+ false,+ false,+ true,+ 0.0f,+ 1e-5f);+ 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, ParameterVector{qkv, past_k, past_v, seqlens, total, cos, sin});+}++// The QK-Norm chain is emitted in the RMSFusion form, so plugins running RMSFusion after the decomposition get one+// fused RMS per Q and K (f32 compute; f16/bf16 inputs are upcast once, as ORT does), feeding RoPE rather than SDPA.+void check_qk_norm_fuses_to_rms(const element::Type& type) {+ auto model = make_packed_rotary_qk_norm_gqa_model(type);+ pass::Manager manager;+ manager.register_pass<pass::GroupQueryAttentionDecomposition>();+ manager.register_pass<pass::RMSFusion>(false);+ manager.run_passes(model);++ size_t rms_count = 0;+ for (const auto& op : model->get_ordered_ops()) {+ if (const auto rms = as_type_ptr<op::internal::RMS>(op)) {+ ++rms_count;+ EXPECT_EQ(rms->get_epsilon(), static_cast<double>(1e-5f));+ EXPECT_EQ(rms->get_output_element_type(0), element::f32);+ for (const auto& in : rms->output(0).get_target_inputs()) {+ const auto consumer = in.get_node();+ EXPECT_FALSE(is_type<op::v13::ScaledDotProductAttention>(consumer)) << "QK-Norm must precede RoPE";+ EXPECT_EQ(is_type<op::v0::Convert>(consumer), type != element::f32) << consumer;+ }+ }+ }+ EXPECT_EQ(rms_count, 2u);+ EXPECT_EQ(count_ops_of_type<op::v1::ReduceMean>(model), 0u);+}+} // namespace++TEST(GroupQueryAttentionValues, qk_norm_fuses_to_rms_f32) {+ check_qk_norm_fuses_to_rms(element::f32);+}++TEST(GroupQueryAttentionValues, qk_norm_fuses_to_rms_f16) {+ check_qk_norm_fuses_to_rms(element::f16);+}++namespace {+std::shared_ptr<Model> make_qk_output_gqa_model(op::internal::GroupQueryAttentionQKOutput qk_output) {+ const auto f32 = element::f32;+ const auto q = std::make_shared<op::v0::Parameter>(f32, PartialShape{1, NUM_HEADS, -1, HEAD_SIZE});+ const auto k = std::make_shared<op::v0::Parameter>(f32, PartialShape{1, KV_NUM_HEADS, -1, HEAD_SIZE});+ const auto v = std::make_shared<op::v0::Parameter>(f32, PartialShape{1, KV_NUM_HEADS, -1, HEAD_SIZE});+ const auto past_k = std::make_shared<op::v0::Parameter>(f32, PartialShape{1, KV_NUM_HEADS, -1, HEAD_SIZE});+ const auto past_v = std::make_shared<op::v0::Parameter>(f32, PartialShape{1, KV_NUM_HEADS, -1, HEAD_SIZE});+ const auto seqlens = std::make_shared<op::v0::Parameter>(element::i32, PartialShape{1});+ const auto total = std::make_shared<op::v0::Parameter>(element::i32, PartialShape{});+ const auto gqa = std::make_shared<GroupQueryAttention>(OutputVector{q, k, v, past_k, past_v, seqlens, total},+ NUM_HEADS,+ KV_NUM_HEADS,+ 0.0f,+ false,+ false,+ 0,+ op::internal::GroupQueryAttentionQuantType::NONE,+ op::internal::GroupQueryAttentionQuantType::NONE,+ -1,+ false,+ false,+ true,+ 0.0f,+ 1e-6f,+ qk_output);+ 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, ParameterVector{q, k, v, past_k, past_v, seqlens, total});+}+} // namespace++// qk_output takes the explicit attention chain (one Q*K^T MatMul shared by the attention and the scores output,+// no SDPA, no KV replication) and exposes the scores sliced to total_sequence_length columns.+TEST(GroupQueryAttentionValues, qk_output_uses_explicit_attention_scores) {+ for (const auto mode : {op::internal::GroupQueryAttentionQKOutput::BEFORE_SOFTMAX,+ op::internal::GroupQueryAttentionQKOutput::AFTER_SOFTMAX}) {+ auto model = make_qk_output_gqa_model(mode);+ decompose(model);+ EXPECT_EQ(count_ops_of_type<op::v13::ScaledDotProductAttention>(model), 0u);+ EXPECT_EQ(count_ops_of_type<op::v0::MatMul>(model), 2u);+ ASSERT_EQ(model->get_results().size(), 4u);+ const auto scores = model->get_results()[3]->get_input_node_shared_ptr(0);+ ASSERT_TRUE(is_type<op::v8::Slice>(scores)) << scores;+ const auto source = scores->get_input_node_shared_ptr(0);+ if (mode == op::internal::GroupQueryAttentionQKOutput::AFTER_SOFTMAX) {+ EXPECT_TRUE(is_type<op::v8::Softmax>(source)) << source;+ } else {+ EXPECT_TRUE(is_type<op::v1::Select>(source)) << source;+ }+ }+}++namespace {+// Decomposes a decode GQA with the given batch / past and counts the ops matching the predicate.+size_t count_decomposed_ops(const Dimension& batch,+ const Dimension& past,+ const std::function<bool(const std::shared_ptr<ov::Node>&)>& predicate) {+ const auto gqa = make_gqa_op(batch, 1, past, /*window*/ -1, /*swc*/ false);+ 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)));+ ParameterVector params;+ for (const auto& in : gqa->input_values())+ params.push_back(as_type_ptr<op::v0::Parameter>(in.get_node_shared_ptr()));+ auto model = std::make_shared<Model>(results, params);+ decompose(model);+ size_t count = 0;+ for (const auto& op : model->get_ordered_ops())+ count += predicate(op) ? 1 : 0;+ return count;+}++// The batched cache write: ScatterUpdate over the cache viewed as [B * Nkv * L, D] rows.+bool is_flat_scatter_update(const std::shared_ptr<ov::Node>& op) {+ return is_type<op::v3::ScatterUpdate>(op) && op->get_input_partial_shape(0).rank() == 2;+}++// The single-batch static cache write: ScatterUpdate on the rank-4 cache along the sequence axis.+bool is_axis_scatter_update(const std::shared_ptr<ov::Node>& op) {+ return is_type<op::v3::ScatterUpdate>(op) && op->get_input_partial_shape(0).rank() == 4;+}+} // namespace++// A static batch of 1 keeps the scalar-length graph (ScatterUpdate / Slice + Concat, which plugins and the NPU compiler+// pattern-match); any other batch writes each batch's rows with one flat ScatterUpdate per K/V.+TEST(GroupQueryAttentionValues, batch_one_keeps_scalar_cache_update) {+ for (const auto& past : {Dimension(8), Dimension::dynamic()}) {+ EXPECT_EQ(count_decomposed_ops(1, past, is_flat_scatter_update), 0u) << past;+ }+ EXPECT_EQ(count_decomposed_ops(1, 8, is_axis_scatter_update), 2u);+}++TEST(GroupQueryAttentionValues, batched_cache_update_is_per_batch) {+ for (const auto& batch : {Dimension(2), Dimension::dynamic()}) {+ for (const auto& past : {Dimension(8), Dimension::dynamic()}) {+ EXPECT_EQ(count_decomposed_ops(batch, past, is_flat_scatter_update), 2u) << batch << " " << past;+ EXPECT_EQ(count_decomposed_ops(batch, past, is_axis_scatter_update), 0u) << batch << " " << past;+ }+ }+}++// A preallocated cache with a dynamic batch is written in place: the decomposed present keeps the op's inferred+// capacity (no Concat growth).+TEST(GroupQueryAttentionValues, batched_fixed_capacity_cache_keeps_capacity) {+ const auto gqa = make_gqa_op(Dimension::dynamic(), 1, 8, /*window*/ -1, /*swc*/ false);+ const auto inferred_present = gqa->get_output_partial_shape(1);+ ASSERT_EQ(inferred_present[2], Dimension(8));+ 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)));+ ParameterVector params;+ for (const auto& in : gqa->input_values())+ params.push_back(as_type_ptr<op::v0::Parameter>(in.get_node_shared_ptr()));+ auto model = std::make_shared<Model>(results, params);+ decompose(model);+ EXPECT_EQ(model->get_results()[1]->get_input_partial_shape(0), inferred_present);+ EXPECT_EQ(model->get_results()[2]->get_input_partial_shape(0), inferred_present);+ // A cache-growth Concat would join rank-4 [B, Nkv, L, D] tensors on the sequence axis (the rank-5 KV-head+ // replication Concat is unrelated).+ for (const auto& op : model->get_ordered_ops()) {+ if (const auto concat = as_type_ptr<op::v0::Concat>(op)) {+ EXPECT_FALSE(concat->get_output_partial_shape(0).rank() == 4 && concat->get_axis() == 2)+ << "fixed-capacity cache must not grow by Concat: " << concat;+ }+ }+}diff --git a/src/core/dev_api/openvino/op/group_query_attention.hpp b/src/core/dev_api/openvino/op/group_query_attention.hppindex 603619c0b30..34f27d0e979 100644--- a/src/core/dev_api/openvino/op/group_query_attention.hpp+++ b/src/core/dev_api/openvino/op/group_query_attention.hpp@@ -26,7 +26,8 @@ enum class GroupQueryAttentionInputs : size_t {HEAD_SINK = 11, // Head sink (optional, required if smooth_softmax=1)K_SCALE = 12, // Quantization scale for K (optional, required if kv_cache_bit_width != 0)V_SCALE = 13, // Quantization scale for V (optional, required if kv_cache_bit_width != 0)- // Positions 14-15 are reserved (QK-Norm, not supported)+ Q_NORM_WEIGHT = 14, // Per-head Q RMSNorm weight [head_size] (optional, paired with K_NORM_WEIGHT)+ K_NORM_WEIGHT = 15, // Per-head K RMSNorm weight [head_size] (optional, paired with Q_NORM_WEIGHT)};enum class GroupQueryAttentionQuantType {@@ -35,9 +36,19 @@ enum class GroupQueryAttentionQuantType {PER_CHANNEL,};+// Optional 4th output (ONNX qk_output): the attention scores before or after softmax.+enum class GroupQueryAttentionQKOutput {+ NONE,+ BEFORE_SOFTMAX,+ AFTER_SOFTMAX,+};+OPENVINO_APIstd::ostream& operator<<(std::ostream& s, const GroupQueryAttentionQuantType& quant_type);+OPENVINO_API+std::ostream& operator<<(std::ostream& s, const GroupQueryAttentionQKOutput& qk_output);+} // namespace ov::op::internalnamespace ov {@@ -54,6 +65,18 @@ public:OPENVINO_RTTI("AttributeAdapter<ov::op::internal::GroupQueryAttentionQuantType>");};+template <>+class OPENVINO_API AttributeAdapter<op::internal::GroupQueryAttentionQKOutput>+ : public EnumAttributeAdapterBase<op::internal::GroupQueryAttentionQKOutput> {+public:+ AttributeAdapter(op::internal::GroupQueryAttentionQKOutput& value)+ : EnumAttributeAdapterBase<op::internal::GroupQueryAttentionQKOutput>(value) {}++ ~AttributeAdapter() override;++ OPENVINO_RTTI("AttributeAdapter<ov::op::internal::GroupQueryAttentionQKOutput>");+};+} // namespace ovnamespace ov::op::internal {@@ -77,7 +100,9 @@ public:bool sliding_window_cache = false,bool smooth_softmax = false,bool causal = true,- float softcap = 0.0f);+ float softcap = 0.0f,+ float qk_norm_epsilon = 1e-6f,+ GroupQueryAttentionQKOutput qk_output = GroupQueryAttentionQKOutput::NONE);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;@@ -138,11 +163,26 @@ public:// length, e.g. 0 for ORT shared KV), so the cache arithmetic must use the key's own length. Packed QKV is// excluded: Q/K/V are split from one tensor, so S_kv == S_q even when that length is dynamic.bool has_independent_kv_length() const;+ // True when present keeps the past buffer's own capacity (a preallocated cache written in place): the past is+ // non-empty and the past, query and key sequence lengths are static. Batch and head dimensions do not matter.+ // Shape inference and the decomposition both use it, so the inferred and the decomposed present agree.+ bool has_fixed_kv_capacity() const;// Logit soft-capping (Gemma-style): when > 0, scaled scores become softcap * tanh(score / softcap)// before the attention bias/mask and softmax. 0 disables it (the ONNX frontend maps ORT's "<= 0 disables" to 0).float get_softcap() const {return m_softcap;}+ // QK-Norm (Qwen3/Gemma3-style): when q_norm_weight/k_norm_weight are present, the new Q and K heads are+ // RMS-normalized over head_size before RoPE: x * rsqrt(mean(x^2) + qk_norm_epsilon) * weight.+ bool has_qk_norm() const;+ float get_qk_norm_epsilon() const {+ return m_qk_norm_epsilon;+ }+ // When not NONE, output 3 holds the [B, num_heads, S, total_sequence_length] attention scores before softmax+ // (scaled, soft-capped, plus attention_bias; masked positions are 0) or after it, as in ONNX Runtime.+ GroupQueryAttentionQKOutput get_qk_output() const {+ return m_qk_output;+ }private:int64_t m_num_heads = 0;@@ -158,6 +198,8 @@ private:bool m_smooth_softmax = false;bool m_causal = true;float m_softcap = 0.0f;+ float m_qk_norm_epsilon = 1e-6f;+ GroupQueryAttentionQKOutput m_qk_output = GroupQueryAttentionQKOutput::NONE;};} // namespace ov::op::internaldiff --git a/src/core/src/op/group_query_attention.cpp b/src/core/src/op/group_query_attention.cppindex f3222e8e689..4d2d70c71f5 100644--- a/src/core/src/op/group_query_attention.cpp+++ b/src/core/src/op/group_query_attention.cpp@@ -5,6 +5,7 @@#include "openvino/op/group_query_attention.hpp"#include <algorithm>+#include <cmath>#include "itt.hpp"#include "openvino/core/except.hpp"@@ -17,6 +18,10 @@ std::ostream& operator<<(std::ostream& s, const GroupQueryAttentionQuantType& qureturn s << as_string(quant_type);}+std::ostream& operator<<(std::ostream& s, const GroupQueryAttentionQKOutput& qk_output) {+ return s << as_string(qk_output);+}+} // namespace ov::op::internalnamespace ov {@@ -34,6 +39,19 @@ EnumNames<op::internal::GroupQueryAttentionQuantType>::get() {AttributeAdapter<op::internal::GroupQueryAttentionQuantType>::~AttributeAdapter() = default;+template <>+OPENVINO_API EnumNames<op::internal::GroupQueryAttentionQKOutput>&+EnumNames<op::internal::GroupQueryAttentionQKOutput>::get() {+ static auto enum_names = EnumNames<op::internal::GroupQueryAttentionQKOutput>(+ "op::internal::GroupQueryAttentionQKOutput",+ {{"NONE", op::internal::GroupQueryAttentionQKOutput::NONE},+ {"BEFORE_SOFTMAX", op::internal::GroupQueryAttentionQKOutput::BEFORE_SOFTMAX},+ {"AFTER_SOFTMAX", op::internal::GroupQueryAttentionQKOutput::AFTER_SOFTMAX}});+ return enum_names;+}++AttributeAdapter<op::internal::GroupQueryAttentionQKOutput>::~AttributeAdapter() = default;+} // namespace ovnamespace ov::op::internal {@@ -51,7 +69,9 @@ GroupQueryAttention::GroupQueryAttention(const OutputVector& args,bool sliding_window_cache,bool smooth_softmax,bool causal,- float softcap)+ float softcap,+ float qk_norm_epsilon,+ GroupQueryAttentionQKOutput qk_output): Op(args),m_num_heads(num_heads),m_kv_num_heads(kv_num_heads),@@ -65,7 +85,9 @@ GroupQueryAttention::GroupQueryAttention(const OutputVector& args,m_sliding_window_cache(sliding_window_cache),m_smooth_softmax(smooth_softmax),m_causal(causal),- m_softcap(softcap) {+ m_softcap(softcap),+ m_qk_norm_epsilon(qk_norm_epsilon),+ m_qk_output(qk_output) {constructor_validate_and_infer_types();}@@ -111,6 +133,10 @@ void GroupQueryAttention::validate_and_infer_types() {return "k_scale";case GroupQueryAttentionInputs::V_SCALE:return "v_scale";+ case GroupQueryAttentionInputs::Q_NORM_WEIGHT:+ return "q_norm_weight";+ case GroupQueryAttentionInputs::K_NORM_WEIGHT:+ return "k_norm_weight";}return "unknown";};@@ -188,7 +214,11 @@ void GroupQueryAttention::validate_and_infer_types() {{4},{element::f32, element::f16, element::bf16, element::i8, element::u8, element::f8e4m3});check_input(GroupQueryAttentionInputs::SEQLENS_K, {1, 2}, integral_types);- check_input(GroupQueryAttentionInputs::TOTAL_SEQUENCE_LENGTH, {0, 1}, integral_types, false);+ // output_qk is laid out over total_sequence_length (ORT), so qk_output needs it.+ check_input(GroupQueryAttentionInputs::TOTAL_SEQUENCE_LENGTH,+ {0, 1},+ integral_types,+ m_qk_output != GroupQueryAttentionQKOutput::NONE);if (m_do_rotary) {check_input(GroupQueryAttentionInputs::COS_CACHE, {2}, {}, true);@@ -212,6 +242,41 @@ void GroupQueryAttention::validate_and_infer_types() {}const auto q_shape = get_input_partial_shape(static_cast<size_t>(GroupQueryAttentionInputs::QUERY));+ // QK-Norm weights (ONNX spec shape [head_size], type T) must be provided together, as in ONNX Runtime.+ check_input(GroupQueryAttentionInputs::Q_NORM_WEIGHT, {1}, float_types, false);+ check_input(GroupQueryAttentionInputs::K_NORM_WEIGHT, {1}, float_types, false);+ const auto k_norm_pos = static_cast<size_t>(GroupQueryAttentionInputs::K_NORM_WEIGHT);+ NODE_VALIDATION_CHECK(this,+ has_qk_norm() == (k_norm_pos < get_input_size() &&+ !ov::util::is_empty_constant_tensor(input_value(k_norm_pos))),+ "GroupQueryAttention: q_norm_weight and k_norm_weight must be provided together.");+ // Validated with or without QK-Norm weights, as ONNX Runtime does.+ NODE_VALIDATION_CHECK(this,+ std::isfinite(m_qk_norm_epsilon) && m_qk_norm_epsilon > 0.0f,+ "GroupQueryAttention expects a finite qk_norm_epsilon > 0, got: ",+ m_qk_norm_epsilon);+ if (has_qk_norm()) {+ for (const auto input : {GroupQueryAttentionInputs::Q_NORM_WEIGHT, GroupQueryAttentionInputs::K_NORM_WEIGHT}) {+ const auto pos = static_cast<size_t>(input);+ const auto& weight_ps = get_input_partial_shape(pos);+ NODE_VALIDATION_CHECK(+ this,+ weight_ps.rank().is_dynamic() || q_shape.rank().is_dynamic() || weight_ps[0].compatible(q_shape[3]),+ "GroupQueryAttention: ",+ input_name(input),+ " must have head_size (",+ q_shape.rank().is_static() ? q_shape[3] : Dimension::dynamic(),+ ") elements, got shape ",+ weight_ps);+ NODE_VALIDATION_CHECK(this,+ get_input_element_type(pos).compatible(+ get_input_element_type(static_cast<size_t>(GroupQueryAttentionInputs::QUERY))),+ "GroupQueryAttention: ",+ input_name(input),+ " element type must match query, got ",+ get_input_element_type(pos));+ }+ }const auto past_k_shape = get_input_partial_shape(static_cast<size_t>(GroupQueryAttentionInputs::PAST_KEY));const auto& q_type = get_input_element_type(static_cast<size_t>(GroupQueryAttentionInputs::QUERY));@@ -220,6 +285,18 @@ void GroupQueryAttention::validate_and_infer_types() {const auto& sequence_len = q_shape[2];const auto& head_size = q_shape[3];+ // seqlens_k holds one length per batch entry (ORT: batch_size elements, e.g. [B] or [B, 1]).+ const auto& seqlens_ps = get_input_partial_shape(static_cast<size_t>(GroupQueryAttentionInputs::SEQLENS_K));+ if (seqlens_ps.is_static() && batch_size.is_static()) {+ NODE_VALIDATION_CHECK(this,+ static_cast<int64_t>(shape_size(seqlens_ps.to_shape())) == batch_size.get_length(),+ "GroupQueryAttention: seqlens_k must have batch_size (",+ batch_size.get_length(),+ ") elements, got shape ",+ seqlens_ps,+ ".");+ }+if (m_do_rotary) {// Partial RoPE (GPT-NeoX/Phi-style): rotary_dim = 2 * cos_cache.shape[-1] may be smaller than// head_size; only the leading rotary_dim channels are rotated (see@@ -257,6 +334,10 @@ void GroupQueryAttention::validate_and_infer_types() {m_local_window_size);// causal=0 (bidirectional) is mutually exclusive with a sliding window, matching the ONNX Runtime// precondition (gqa_attention_base.h: causal_ || local_window_size_ == -1).+ // ONNX Runtime CPU (the only provider of qk_output) rejects it with a windowed cache.+ NODE_VALIDATION_CHECK(this,+ m_qk_output == GroupQueryAttentionQKOutput::NONE || !m_sliding_window_cache,+ "GroupQueryAttention: qk_output is not supported with sliding_window_cache.");NODE_VALIDATION_CHECK(this,m_causal || m_local_window_size == -1,"GroupQueryAttention: local_window_size requires causal=1, got causal=0 and "@@ -272,15 +353,14 @@ void GroupQueryAttention::validate_and_infer_types() {// sequence_length > 1 takes the identical staging branch a dynamic sequence_length resolving to the same// runtime value would, so it is not rejected here.- // The decomposition derives a scalar past length (past_seqlen = total - current) and assumes a single- // batch entry ("Only consider batch is 1"). A statically known batch_size > 1 is rejected here; a dynamic- // batch resolving to > 1 fails at inference (seqlens_k cannot be reshaped to the single past length), so it- // never produces silently wrong results.- if (batch_size.is_static()) {+ // Any batch size is supported with per-batch seqlens_k, except the windowed cache (single-batch rolling+ // arithmetic): a statically known batch_size > 1 is rejected there; a dynamic batch resolving to > 1 fails at+ // inference (seqlens_k cannot be reshaped to the single past length), so it never produces silently wrong results.+ if (m_sliding_window_cache && 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 = ",+ "GroupQueryAttention sliding_window_cache is only supported for batch_size == 1, got "+ "batch_size = ",batch_size.get_length(),".");}@@ -332,11 +412,9 @@ void GroupQueryAttention::validate_and_infer_types() {// A zero-capacity past (absent/empty cache) cannot be written in place either, so present grows by the step.// Shared KV (statically empty key, kv_sequence_length == 0) appends nothing: present is the past as is.// A key/value of dynamic length cannot be written in place, so present grows by its own length.- const bool empty_past = output_kv_len.is_static() && output_kv_len.get_length() == 0;const auto& key_ps = get_input_partial_shape(static_cast<size_t>(GroupQueryAttentionInputs::KEY));const bool dynamic_kv_len = key_ps.rank().is_static() && key_ps[2].is_dynamic();- if (!m_sliding_window_cache && !is_shared_kv() &&- (output_kv_len.is_dynamic() || sequence_len.is_dynamic() || empty_past || dynamic_kv_len)) {+ if (!m_sliding_window_cache && !is_shared_kv() && !has_fixed_kv_capacity()) {output_kv_len += dynamic_kv_len ? key_ps[2] : sequence_len;}@@ -344,6 +422,10 @@ void GroupQueryAttention::validate_and_infer_types() {for (auto&& port : {1, 2}) {set_output_type(port, kv_cache_type, kv_shape);}+ if (m_qk_output != GroupQueryAttentionQKOutput::NONE) {+ // The last dim is the runtime total_sequence_length.+ set_output_type(3, q_type, PartialShape{batch_size, m_num_heads, sequence_len, Dimension::dynamic()});+ }}bool GroupQueryAttention::is_shared_kv() const {@@ -360,6 +442,23 @@ bool GroupQueryAttention::has_independent_kv_length() const {return !packed_qkv && key_ps.rank().is_static() && key_ps.rank().get_length() == 4 && key_ps[2].is_dynamic();}+bool GroupQueryAttention::has_fixed_kv_capacity() const {+ const auto& past_ps = get_input_partial_shape(static_cast<size_t>(GroupQueryAttentionInputs::PAST_KEY));+ const auto& query_ps = get_input_partial_shape(static_cast<size_t>(GroupQueryAttentionInputs::QUERY));+ const auto& key_ps = get_input_partial_shape(static_cast<size_t>(GroupQueryAttentionInputs::KEY));+ if (past_ps.rank().is_dynamic() || past_ps.rank().get_length() != 4 || query_ps.rank().is_dynamic() ||+ query_ps.rank().get_length() != 4) {+ return false;+ }+ const bool static_key_len = key_ps.rank().is_dynamic() || key_ps[2].is_static();+ return past_ps[2].is_static() && past_ps[2].get_length() > 0 && query_ps[2].is_static() && static_key_len;+}++bool GroupQueryAttention::has_qk_norm() const {+ const auto pos = static_cast<size_t>(GroupQueryAttentionInputs::Q_NORM_WEIGHT);+ return pos < get_input_size() && !ov::util::is_empty_constant_tensor(input_value(pos));+}+bool GroupQueryAttention::visit_attributes(AttributeVisitor& visitor) {OV_OP_SCOPE(GroupQueryAttention_visit_attributes);visitor.on_attribute("causal", m_causal);@@ -369,6 +468,8 @@ bool GroupQueryAttention::visit_attributes(AttributeVisitor& visitor) {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("qk_norm_epsilon", m_qk_norm_epsilon);+ visitor.on_attribute("qk_output", m_qk_output);visitor.on_attribute("rotary_interleaved", m_rotary_interleaved);visitor.on_attribute("scale", m_scale);visitor.on_attribute("sliding_window_cache", m_sliding_window_cache);@@ -394,7 +495,9 @@ std::shared_ptr<ov::Node> GroupQueryAttention::clone_with_new_inputs(const ov::Om_sliding_window_cache,m_smooth_softmax,m_causal,- m_softcap);+ m_softcap,+ m_qk_norm_epsilon,+ m_qk_output);}} // namespace ov::op::internaldiff --git a/src/core/tests/type_prop/group_query_attention.cpp b/src/core/tests/type_prop/group_query_attention.cppindex ddd0151e0bb..282738f8edf 100644--- a/src/core/tests/type_prop/group_query_attention.cpp+++ b/src/core/tests/type_prop/group_query_attention.cpp@@ -564,5 +564,208 @@ TEST(type_prop, group_query_attention_softcap_nan_rejected) {HasSubstr("expects softcap >= 0"));}+namespace {+// Valid base args (head_size 8) with optional inputs 7-13 empty and QK-Norm weights at 14/15.+ov::OutputVector make_gqa_args_with_qk_norm(const ov::PartialShape& q_weight_shape,+ const ov::PartialShape& k_weight_shape,+ const element::Type& weight_type = element::f32,+ bool with_k_weight = true) {+ auto args = make_valid_gqa_args();+ const auto empty = op::v0::Constant::create(element::dynamic, Shape{0}, {});+ args.resize(14, empty);+ args.push_back(std::make_shared<op::v0::Parameter>(weight_type, q_weight_shape));+ args.push_back(with_k_weight ? std::make_shared<op::v0::Parameter>(weight_type, k_weight_shape)->output(0)+ : empty->output(0));+ return args;+}++std::shared_ptr<op::internal::GroupQueryAttention> make_gqa_with_qk_norm(const ov::OutputVector& args,+ float epsilon = 1e-6f) {+ return std::make_shared<op::internal::GroupQueryAttention>(args,+ 6,+ 2,+ 1.0f,+ false,+ false,+ 0,+ op::internal::GroupQueryAttentionQuantType::NONE,+ op::internal::GroupQueryAttentionQuantType::NONE,+ -1,+ false,+ false,+ true,+ 0.0f,+ epsilon);+}+} // namespace++TEST(type_prop, group_query_attention_qk_norm_valid) {+ const auto op = make_gqa_with_qk_norm(make_gqa_args_with_qk_norm(PartialShape{8}, PartialShape{8}), 1e-5f);+ EXPECT_TRUE(op->has_qk_norm());+ EXPECT_EQ(op->get_qk_norm_epsilon(), 1e-5f);+ EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{1, 4, 48}));+}++TEST(type_prop, group_query_attention_qk_norm_absent_by_default) {+ const auto op =+ std::make_shared<op::internal::GroupQueryAttention>(make_valid_gqa_args(), 6, 2, 1.0f, false, false);+ EXPECT_FALSE(op->has_qk_norm());+ EXPECT_EQ(op->get_qk_norm_epsilon(), 1e-6f);+}++TEST(type_prop, group_query_attention_qk_norm_dynamic_weight_valid) {+ OV_ASSERT_NO_THROW(std::ignore = make_gqa_with_qk_norm(+ make_gqa_args_with_qk_norm(PartialShape::dynamic(1), PartialShape::dynamic())));+}++TEST(type_prop, group_query_attention_qk_norm_unpaired_rejected) {+ const auto args = make_gqa_args_with_qk_norm(PartialShape{8}, PartialShape{8}, element::f32, false);+ OV_EXPECT_THROW(std::ignore = make_gqa_with_qk_norm(args),+ ov::NodeValidationFailure,+ HasSubstr("q_norm_weight and k_norm_weight must be provided together"));+}++TEST(type_prop, group_query_attention_qk_norm_wrong_length_rejected) {+ OV_EXPECT_THROW(std::ignore = make_gqa_with_qk_norm(make_gqa_args_with_qk_norm(PartialShape{8}, PartialShape{4})),+ ov::NodeValidationFailure,+ HasSubstr("k_norm_weight must have head_size (8) elements"));+}++TEST(type_prop, group_query_attention_qk_norm_wrong_rank_rejected) {+ OV_EXPECT_THROW(+ std::ignore = make_gqa_with_qk_norm(make_gqa_args_with_qk_norm(PartialShape{1, 8}, PartialShape{8})),+ ov::NodeValidationFailure,+ HasSubstr("Rank of `q_norm_weight` input is not compatible"));+}++TEST(type_prop, group_query_attention_qk_norm_type_mismatch_rejected) {+ OV_EXPECT_THROW(+ std::ignore = make_gqa_with_qk_norm(make_gqa_args_with_qk_norm(PartialShape{8}, PartialShape{8}, element::f16)),+ ov::NodeValidationFailure,+ HasSubstr("q_norm_weight element type must match query"));+}++TEST(type_prop, group_query_attention_qk_norm_non_positive_epsilon_rejected) {+ const auto args = make_gqa_args_with_qk_norm(PartialShape{8}, PartialShape{8});+ OV_EXPECT_THROW(std::ignore = make_gqa_with_qk_norm(args, 0.0f),+ ov::NodeValidationFailure,+ HasSubstr("finite qk_norm_epsilon > 0"));+ OV_EXPECT_THROW(std::ignore = make_gqa_with_qk_norm(args, std::numeric_limits<float>::infinity()),+ ov::NodeValidationFailure,+ HasSubstr("finite qk_norm_epsilon > 0"));+}++TEST(type_prop, group_query_attention_non_positive_epsilon_rejected_without_qk_norm) {+ const auto args = make_valid_gqa_args();+ OV_EXPECT_THROW(std::ignore = make_gqa_with_qk_norm(args, 0.0f),+ ov::NodeValidationFailure,+ HasSubstr("finite qk_norm_epsilon > 0"));+ OV_EXPECT_THROW(std::ignore = make_gqa_with_qk_norm(args, std::numeric_limits<float>::quiet_NaN()),+ ov::NodeValidationFailure,+ HasSubstr("finite qk_norm_epsilon > 0"));+}++namespace {+std::shared_ptr<op::internal::GroupQueryAttention> make_gqa_with_qk_output(+ op::internal::GroupQueryAttentionQKOutput qk_output,+ bool sliding_window_cache = false,+ const ov::OutputVector& args = make_valid_gqa_args()) {+ return std::make_shared<op::internal::GroupQueryAttention>(args,+ 6,+ 2,+ 1.0f,+ false,+ false,+ 0,+ op::internal::GroupQueryAttentionQuantType::NONE,+ op::internal::GroupQueryAttentionQuantType::NONE,+ sliding_window_cache ? 4 : -1,+ sliding_window_cache,+ false,+ true,+ 0.0f,+ 1e-6f,+ qk_output);+}+} // namespace++TEST(type_prop, group_query_attention_qk_output_none_has_three_outputs) {+ const auto op = make_gqa_with_qk_output(op::internal::GroupQueryAttentionQKOutput::NONE);+ EXPECT_EQ(op->get_output_size(), 3);+}++TEST(type_prop, group_query_attention_qk_output_adds_scores_output) {+ for (const auto mode : {op::internal::GroupQueryAttentionQKOutput::BEFORE_SOFTMAX,+ op::internal::GroupQueryAttentionQKOutput::AFTER_SOFTMAX}) {+ const auto op = make_gqa_with_qk_output(mode);+ ASSERT_EQ(op->get_output_size(), 4);+ EXPECT_EQ(op->get_qk_output(), mode);+ EXPECT_EQ(op->get_output_element_type(3), element::f32);+ EXPECT_EQ(op->get_output_partial_shape(3), (PartialShape{1, 6, 4, Dimension::dynamic()}));+ }+}++// output_qk is laid out over total_sequence_length, so qk_output needs that input.+TEST(type_prop, group_query_attention_qk_output_requires_total_sequence_length) {+ auto args = make_valid_gqa_args();+ args[6] = op::v0::Constant::create(element::dynamic, Shape{0}, {});+ OV_EXPECT_THROW(+ std::ignore = make_gqa_with_qk_output(op::internal::GroupQueryAttentionQKOutput::BEFORE_SOFTMAX, false, args),+ ov::NodeValidationFailure,+ HasSubstr("requires total_sequence_length"));+}++TEST(type_prop, group_query_attention_qk_output_with_sliding_window_cache_rejected) {+ OV_EXPECT_THROW(+ std::ignore = make_gqa_with_qk_output(op::internal::GroupQueryAttentionQKOutput::AFTER_SOFTMAX, true),+ ov::NodeValidationFailure,+ HasSubstr("qk_output is not supported with sliding_window_cache"));+}++TEST(type_prop, group_query_attention_fixed_capacity_with_dynamic_batch) {+ // A preallocated cache keeps its capacity whatever the batch: present stays [?, 2, 5, 8].+ using op::v0::Parameter;+ auto args = make_valid_gqa_args();+ args[0] = std::make_shared<Parameter>(element::f32, PartialShape{-1, 6, 4, 8});+ args[1] = std::make_shared<Parameter>(element::f32, PartialShape{-1, 2, 4, 8});+ args[2] = std::make_shared<Parameter>(element::f32, PartialShape{-1, 2, 4, 8});+ args[3] = std::make_shared<Parameter>(element::f32, PartialShape{-1, 2, 5, 8});+ args[4] = std::make_shared<Parameter>(element::f32, PartialShape{-1, 2, 5, 8});+ const auto op = std::make_shared<op::internal::GroupQueryAttention>(args, 6, 2, 1.0f, false, false);+ EXPECT_TRUE(op->has_fixed_kv_capacity());+ EXPECT_EQ(op->get_output_partial_shape(1), (PartialShape{-1, 2, 5, 8}));+}++TEST(type_prop, group_query_attention_growing_cache_has_no_fixed_capacity) {+ using op::v0::Parameter;+ auto dynamic_past = make_valid_gqa_args();+ dynamic_past[3] = std::make_shared<Parameter>(element::f32, PartialShape{1, 2, -1, 8});+ dynamic_past[4] = std::make_shared<Parameter>(element::f32, PartialShape{1, 2, -1, 8});+ EXPECT_FALSE(std::make_shared<op::internal::GroupQueryAttention>(dynamic_past, 6, 2, 1.0f, false, false)+ ->has_fixed_kv_capacity());+ auto dynamic_step = make_valid_gqa_args();+ dynamic_step[0] = std::make_shared<Parameter>(element::f32, PartialShape{1, 6, -1, 8});+ EXPECT_FALSE(std::make_shared<op::internal::GroupQueryAttention>(dynamic_step, 6, 2, 1.0f, false, false)+ ->has_fixed_kv_capacity());+}++TEST(type_prop, group_query_attention_seqlens_k_must_match_batch) {+ // ORT: seqlens_k holds batch_size elements; a single length must not silently cover a batch of 2.+ using op::v0::Parameter;+ auto args = make_valid_gqa_args();+ args[0] = std::make_shared<Parameter>(element::f32, PartialShape{2, 6, 4, 8});+ args[1] = std::make_shared<Parameter>(element::f32, PartialShape{2, 2, 4, 8});+ args[2] = std::make_shared<Parameter>(element::f32, PartialShape{2, 2, 4, 8});+ args[3] = std::make_shared<Parameter>(element::f32, PartialShape{2, 2, 5, 8});+ args[4] = std::make_shared<Parameter>(element::f32, PartialShape{2, 2, 5, 8});+ args[5] = std::make_shared<Parameter>(element::i32, PartialShape{1, 1});+ OV_EXPECT_THROW(std::ignore = std::make_shared<op::internal::GroupQueryAttention>(args, 6, 2, 1.0f, false, false),+ ov::NodeValidationFailure,+ HasSubstr("seqlens_k must have batch_size (2) elements"));+ args[5] = std::make_shared<Parameter>(element::i32, PartialShape{2, 1});+ OV_ASSERT_NO_THROW(std::ignore =+ std::make_shared<op::internal::GroupQueryAttention>(args, 6, 2, 1.0f, false, false));+}+} // namespace testing} // namespace ov\ No newline at end of filediff --git a/src/core/tests/visitors/op/group_query_attention.cpp b/src/core/tests/visitors/op/group_query_attention.cppindex c4208466804..66894b4e850 100644--- a/src/core/tests/visitors/op/group_query_attention.cpp+++ b/src/core/tests/visitors/op/group_query_attention.cpp@@ -38,12 +38,14 @@ TEST(attributes, group_query_attention_attrs) {/*sliding_window_cache*/ false,/*smooth_softmax*/ true,/*causal*/ true,- /*softcap*/ 50.0f);+ /*softcap*/ 50.0f,+ /*qk_norm_epsilon*/ 1e-5f,+ ov::op::internal::GroupQueryAttentionQKOutput::AFTER_SOFTMAX);NodeBuilder builder(op, args);const auto g_op = ov::as_type_ptr<GroupQueryAttention>(builder.create());ASSERT_NE(g_op, nullptr);- EXPECT_EQ(builder.get_value_map_size(), 13);+ EXPECT_EQ(builder.get_value_map_size(), 15);EXPECT_EQ(g_op->get_num_heads(), op->get_num_heads());EXPECT_EQ(g_op->get_kv_num_heads(), op->get_kv_num_heads());EXPECT_EQ(g_op->get_scale(), op->get_scale());@@ -51,5 +53,8 @@ TEST(attributes, group_query_attention_attrs) {EXPECT_EQ(g_op->get_smooth_softmax(), op->get_smooth_softmax());EXPECT_EQ(g_op->get_causal(), op->get_causal());EXPECT_EQ(g_op->get_softcap(), op->get_softcap());+ EXPECT_EQ(g_op->get_qk_norm_epsilon(), op->get_qk_norm_epsilon());+ EXPECT_EQ(g_op->get_qk_output(), op->get_qk_output());+ EXPECT_EQ(g_op->get_output_size(), 4);EXPECT_EQ(g_op->get_output_partial_shape(0), op->get_output_partial_shape(0));}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.cppindex 6dcb319701d..0d64db277a3 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@@ -76,12 +76,8 @@ ov::OutputVector group_query_attention(const ov::frontend::onnx::Node& node) {const auto softcap = softcap_attr > 0.0f ? softcap_attr : 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, 14) && !common::is_input_valid(onnx_op_inputs, 15),- "GroupQueryAttention: q_norm_weight/k_norm_weight (QK-Norm) inputs are not "- "supported.");+ // QK-Norm (q_norm_weight/k_norm_weight, inputs 14/15) is forwarded as-is; the op validates the pairing.+ const auto qk_norm_epsilon = node.get_attribute_value<float>("qk_norm_epsilon", 1e-6f);// Reject spec attributes whose semantics are not implemented by the OpenVINO decomposition.FRONT_END_OP_CONVERSION_CHECK(causal == 0 || causal == 1,@@ -102,7 +98,7 @@ ov::OutputVector group_query_attention(const ov::frontend::onnx::Node& node) {local_window_size,".");// A windowed KV cache requires a real sliding window (local_window_size > 0), matching the ONNX Runtime- // precondition. batch > 1 is not handled by this decomposition (see the batch_size == 1 check below).+ // precondition. The windowed cache is single-batch (the op rejects a static batch_size > 1).// Multi-token steps (ORT's "staging" regime) are supported: the decomposition selects the staging vs.// in-place cache-write branch from the runtime past/total length, mirroring ORT's PlanWindowedKvCache,// so a static multi-token shape is not rejected here.@@ -127,9 +123,15 @@ ov::OutputVector group_query_attention(const ov::frontend::onnx::Node& node) {".");}}- // 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.");+ // qk_output: 0 = none, 1 = scores before softmax, 2 = after softmax, emitted as the 4th output `output_qk`.+ // As in ONNX Runtime, the attribute and the output must be set together.+ FRONT_END_OP_CONVERSION_CHECK(qk_output >= 0 && qk_output <= 2,+ "GroupQueryAttention: qk_output must be 0, 1 or 2, got ",+ qk_output,+ ".");+ const bool has_output_qk = node.get_outputs_size() > 3 && !node.get_output_names()[3].get().empty();+ FRONT_END_OP_CONVERSION_CHECK((qk_output != 0) == has_output_qk,+ "GroupQueryAttention: the output_qk output and qk_output != 0 must be set together.");if (0 != do_rotary) {constexpr size_t cos_cache_index = 7;@@ -275,20 +277,23 @@ ov::OutputVector group_query_attention(const ov::frontend::onnx::Node& node) {// smooth_softmax's ONNX schema default is -1, not 0, yet ORT's own CPU/CUDA kernels enable it only when// the value is exactly 1. Comparing == 1 (not != 0) keeps a graph that never set the attribute from// silently getting the smooth-softmax sink path.- return std::make_shared<internal::GroupQueryAttention>(ov_op_inputs,- num_heads,- kv_num_heads,- scale,- do_rotary,- rotary_interleaved,- kv_cache_bit_width,- k_quant_type,- v_quant_type,- local_window_size,- sliding_window_cache != 0,- smooth_softmax == 1,- causal != 0,- softcap)+ return std::make_shared<internal::GroupQueryAttention>(+ ov_op_inputs,+ num_heads,+ kv_num_heads,+ scale,+ do_rotary,+ rotary_interleaved,+ kv_cache_bit_width,+ k_quant_type,+ v_quant_type,+ local_window_size,+ sliding_window_cache != 0,+ smooth_softmax == 1,+ causal != 0,+ softcap,+ qk_norm_epsilon,+ static_cast<internal::GroupQueryAttentionQKOutput>(qk_output))->outputs();}diff --git a/src/frontends/onnx/tests/models/com.microsoft/gqa_batch_decode.prototxt b/src/frontends/onnx/tests/models/com.microsoft/gqa_batch_decode.prototxtnew file mode 100644index 00000000000..bc12d9d0920--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/gqa_batch_decode.prototxt@@ -0,0 +1,297 @@+ir_version: 10+graph {+ node {+ input: "query"+ input: ""+ input: ""+ input: "past_key"+ input: "past_value"+ input: "seqlens_k"+ input: "total_sequence_length"+ input: "cos_cache"+ input: "sin_cache"+ output: "output"+ output: "present_key"+ output: "present_value"+ name: "GroupQueryAttention_0"+ op_type: "GroupQueryAttention"+ attribute {+ name: "do_rotary"+ i: 1+ type: INT+ }+ attribute {+ name: "kv_num_heads"+ i: 1+ type: INT+ }+ attribute {+ name: "num_heads"+ i: 2+ type: INT+ }+ domain: "com.microsoft"+ }+ name: "gqa_batch_decode"+ initializer {+ dims: 8+ dims: 8+ data_type: 1+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 0.5403023+ float_data: 0.95041525+ float_data: 0.9950042+ float_data: 0.99950004+ float_data: 0.99995+ float_data: 0.999995+ float_data: 0.9999995+ float_data: 0.99999994+ float_data: -0.4161468+ float_data: 0.8065784+ float_data: 0.9800666+ float_data: 0.9980007+ float_data: 0.9998+ float_data: 0.99998+ float_data: 0.999998+ float_data: 0.9999998+ float_data: -0.9899925+ float_data: 0.5827536+ float_data: 0.9553365+ float_data: 0.99550337+ float_data: 0.99955004+ float_data: 0.999955+ float_data: 0.9999955+ float_data: 0.9999995+ float_data: -0.6536436+ float_data: 0.30113748+ float_data: 0.921061+ float_data: 0.99201065+ float_data: 0.9992001+ float_data: 0.99992+ float_data: 0.999992+ float_data: 0.9999992+ float_data: 0.28366217+ float_data: -0.010342338+ float_data: 0.87758255+ float_data: 0.987526+ float_data: 0.99875027+ float_data: 0.999875+ float_data: 0.9999875+ float_data: 0.99999875+ float_data: 0.96017027+ float_data: -0.32079637+ float_data: 0.8253356+ float_data: 0.98205394+ float_data: 0.99820054+ float_data: 0.99982+ float_data: 0.999982+ float_data: 0.9999982+ float_data: 0.75390226+ float_data: -0.5994375+ float_data: 0.7648422+ float_data: 0.9755999+ float_data: 0.997551+ float_data: 0.999755+ float_data: 0.9999755+ float_data: 0.99999756+ name: "cos_cache"+ }+ initializer {+ dims: 8+ dims: 8+ data_type: 1+ float_data: 0.0+ float_data: 0.0+ float_data: 0.0+ float_data: 0.0+ float_data: 0.0+ float_data: 0.0+ float_data: 0.0+ float_data: 0.0+ float_data: 0.841471+ float_data: 0.3109836+ float_data: 0.09983342+ float_data: 0.031617507+ float_data: 0.009999833+ float_data: 0.0031622725+ float_data: 0.0009999999+ float_data: 0.0003162278+ float_data: 0.9092974+ float_data: 0.5911271+ float_data: 0.19866933+ float_data: 0.0632034+ float_data: 0.019998666+ float_data: 0.0063245133+ float_data: 0.0019999987+ float_data: 0.0006324555+ float_data: 0.14112+ float_data: 0.8126489+ float_data: 0.29552022+ float_data: 0.09472609+ float_data: 0.0299955+ float_data: 0.009486691+ float_data: 0.0029999956+ float_data: 0.00094868324+ float_data: -0.7568025+ float_data: 0.95358074+ float_data: 0.38941833+ float_data: 0.12615408+ float_data: 0.039989334+ float_data: 0.012648774+ float_data: 0.0039999895+ float_data: 0.0012649108+ float_data: -0.9589243+ float_data: 0.99994653+ float_data: 0.47942555+ float_data: 0.1574559+ float_data: 0.049979165+ float_data: 0.01581073+ float_data: 0.0049999794+ float_data: 0.0015811382+ float_data: -0.2794155+ float_data: 0.9471482+ float_data: 0.5646425+ float_data: 0.18860029+ float_data: 0.059964005+ float_data: 0.01897253+ float_data: 0.005999964+ float_data: 0.0018973656+ float_data: 0.6569866+ float_data: 0.8004216+ float_data: 0.64421767+ float_data: 0.21955611+ float_data: 0.06994285+ float_data: 0.022134136+ float_data: 0.006999943+ float_data: 0.0022135926+ name: "sin_cache"+ }+ 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+ }+ }+ }+ output {+ name: "present_key"+ type {+ tensor_type {+ elem_type: 1+ }+ }+ }+ output {+ name: "present_value"+ type {+ tensor_type {+ elem_type: 1+ }+ }+ }+}+opset_import {+ domain: ""+ version: 21+}+opset_import {+ domain: "com.microsoft"+ version: 1+}diff --git a/src/frontends/onnx/tests/models/com.microsoft/gqa_batch_prefill_padded.prototxt b/src/frontends/onnx/tests/models/com.microsoft/gqa_batch_prefill_padded.prototxtnew file mode 100644index 00000000000..602b20b649f--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/gqa_batch_prefill_padded.prototxt@@ -0,0 +1,297 @@+ir_version: 10+graph {+ node {+ input: "query"+ input: ""+ input: ""+ input: "past_key"+ input: "past_value"+ input: "seqlens_k"+ input: "total_sequence_length"+ input: "cos_cache"+ input: "sin_cache"+ output: "output"+ output: "present_key"+ output: "present_value"+ name: "GroupQueryAttention_0"+ op_type: "GroupQueryAttention"+ attribute {+ name: "do_rotary"+ i: 1+ type: INT+ }+ attribute {+ name: "kv_num_heads"+ i: 1+ type: INT+ }+ attribute {+ name: "num_heads"+ i: 2+ type: INT+ }+ domain: "com.microsoft"+ }+ name: "gqa_batch_prefill_padded"+ initializer {+ dims: 8+ dims: 8+ data_type: 1+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 0.5403023+ float_data: 0.95041525+ float_data: 0.9950042+ float_data: 0.99950004+ float_data: 0.99995+ float_data: 0.999995+ float_data: 0.9999995+ float_data: 0.99999994+ float_data: -0.4161468+ float_data: 0.8065784+ float_data: 0.9800666+ float_data: 0.9980007+ float_data: 0.9998+ float_data: 0.99998+ float_data: 0.999998+ float_data: 0.9999998+ float_data: -0.9899925+ float_data: 0.5827536+ float_data: 0.9553365+ float_data: 0.99550337+ float_data: 0.99955004+ float_data: 0.999955+ float_data: 0.9999955+ float_data: 0.9999995+ float_data: -0.6536436+ float_data: 0.30113748+ float_data: 0.921061+ float_data: 0.99201065+ float_data: 0.9992001+ float_data: 0.99992+ float_data: 0.999992+ float_data: 0.9999992+ float_data: 0.28366217+ float_data: -0.010342338+ float_data: 0.87758255+ float_data: 0.987526+ float_data: 0.99875027+ float_data: 0.999875+ float_data: 0.9999875+ float_data: 0.99999875+ float_data: 0.96017027+ float_data: -0.32079637+ float_data: 0.8253356+ float_data: 0.98205394+ float_data: 0.99820054+ float_data: 0.99982+ float_data: 0.999982+ float_data: 0.9999982+ float_data: 0.75390226+ float_data: -0.5994375+ float_data: 0.7648422+ float_data: 0.9755999+ float_data: 0.997551+ float_data: 0.999755+ float_data: 0.9999755+ float_data: 0.99999756+ name: "cos_cache"+ }+ initializer {+ dims: 8+ dims: 8+ data_type: 1+ float_data: 0.0+ float_data: 0.0+ float_data: 0.0+ float_data: 0.0+ float_data: 0.0+ float_data: 0.0+ float_data: 0.0+ float_data: 0.0+ float_data: 0.841471+ float_data: 0.3109836+ float_data: 0.09983342+ float_data: 0.031617507+ float_data: 0.009999833+ float_data: 0.0031622725+ float_data: 0.0009999999+ float_data: 0.0003162278+ float_data: 0.9092974+ float_data: 0.5911271+ float_data: 0.19866933+ float_data: 0.0632034+ float_data: 0.019998666+ float_data: 0.0063245133+ float_data: 0.0019999987+ float_data: 0.0006324555+ float_data: 0.14112+ float_data: 0.8126489+ float_data: 0.29552022+ float_data: 0.09472609+ float_data: 0.0299955+ float_data: 0.009486691+ float_data: 0.0029999956+ float_data: 0.00094868324+ float_data: -0.7568025+ float_data: 0.95358074+ float_data: 0.38941833+ float_data: 0.12615408+ float_data: 0.039989334+ float_data: 0.012648774+ float_data: 0.0039999895+ float_data: 0.0012649108+ float_data: -0.9589243+ float_data: 0.99994653+ float_data: 0.47942555+ float_data: 0.1574559+ float_data: 0.049979165+ float_data: 0.01581073+ float_data: 0.0049999794+ float_data: 0.0015811382+ float_data: -0.2794155+ float_data: 0.9471482+ float_data: 0.5646425+ float_data: 0.18860029+ float_data: 0.059964005+ float_data: 0.01897253+ float_data: 0.005999964+ float_data: 0.0018973656+ float_data: 0.6569866+ float_data: 0.8004216+ float_data: 0.64421767+ float_data: 0.21955611+ float_data: 0.06994285+ float_data: 0.022134136+ float_data: 0.006999943+ float_data: 0.0022135926+ name: "sin_cache"+ }+ 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+ }+ }+ }+ output {+ name: "present_key"+ type {+ tensor_type {+ elem_type: 1+ }+ }+ }+ output {+ name: "present_value"+ type {+ tensor_type {+ elem_type: 1+ }+ }+ }+}+opset_import {+ domain: ""+ version: 21+}+opset_import {+ domain: "com.microsoft"+ version: 1+}diff --git a/src/frontends/onnx/tests/models/com.microsoft/gqa_batch_static_cache.prototxt b/src/frontends/onnx/tests/models/com.microsoft/gqa_batch_static_cache.prototxtnew file mode 100644index 00000000000..b704286279d--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/gqa_batch_static_cache.prototxt@@ -0,0 +1,302 @@+ir_version: 10+graph {+ node {+ input: "query"+ input: ""+ input: ""+ input: "past_key"+ input: "past_value"+ input: "seqlens_k"+ input: "total_sequence_length"+ input: "cos_cache"+ input: "sin_cache"+ output: "output"+ output: "present_key"+ output: "present_value"+ name: "GroupQueryAttention_0"+ op_type: "GroupQueryAttention"+ attribute {+ name: "do_rotary"+ i: 1+ type: INT+ }+ attribute {+ name: "kv_num_heads"+ i: 1+ type: INT+ }+ attribute {+ name: "local_window_size"+ i: 3+ type: INT+ }+ attribute {+ name: "num_heads"+ i: 2+ type: INT+ }+ domain: "com.microsoft"+ }+ name: "gqa_batch_static_cache"+ initializer {+ dims: 8+ dims: 8+ data_type: 1+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 0.5403023+ float_data: 0.95041525+ float_data: 0.9950042+ float_data: 0.99950004+ float_data: 0.99995+ float_data: 0.999995+ float_data: 0.9999995+ float_data: 0.99999994+ float_data: -0.4161468+ float_data: 0.8065784+ float_data: 0.9800666+ float_data: 0.9980007+ float_data: 0.9998+ float_data: 0.99998+ float_data: 0.999998+ float_data: 0.9999998+ float_data: -0.9899925+ float_data: 0.5827536+ float_data: 0.9553365+ float_data: 0.99550337+ float_data: 0.99955004+ float_data: 0.999955+ float_data: 0.9999955+ float_data: 0.9999995+ float_data: -0.6536436+ float_data: 0.30113748+ float_data: 0.921061+ float_data: 0.99201065+ float_data: 0.9992001+ float_data: 0.99992+ float_data: 0.999992+ float_data: 0.9999992+ float_data: 0.28366217+ float_data: -0.010342338+ float_data: 0.87758255+ float_data: 0.987526+ float_data: 0.99875027+ float_data: 0.999875+ float_data: 0.9999875+ float_data: 0.99999875+ float_data: 0.96017027+ float_data: -0.32079637+ float_data: 0.8253356+ float_data: 0.98205394+ float_data: 0.99820054+ float_data: 0.99982+ float_data: 0.999982+ float_data: 0.9999982+ float_data: 0.75390226+ float_data: -0.5994375+ float_data: 0.7648422+ float_data: 0.9755999+ float_data: 0.997551+ float_data: 0.999755+ float_data: 0.9999755+ float_data: 0.99999756+ name: "cos_cache"+ }+ initializer {+ dims: 8+ dims: 8+ data_type: 1+ float_data: 0.0+ float_data: 0.0+ float_data: 0.0+ float_data: 0.0+ float_data: 0.0+ float_data: 0.0+ float_data: 0.0+ float_data: 0.0+ float_data: 0.841471+ float_data: 0.3109836+ float_data: 0.09983342+ float_data: 0.031617507+ float_data: 0.009999833+ float_data: 0.0031622725+ float_data: 0.0009999999+ float_data: 0.0003162278+ float_data: 0.9092974+ float_data: 0.5911271+ float_data: 0.19866933+ float_data: 0.0632034+ float_data: 0.019998666+ float_data: 0.0063245133+ float_data: 0.0019999987+ float_data: 0.0006324555+ float_data: 0.14112+ float_data: 0.8126489+ float_data: 0.29552022+ float_data: 0.09472609+ float_data: 0.0299955+ float_data: 0.009486691+ float_data: 0.0029999956+ float_data: 0.00094868324+ float_data: -0.7568025+ float_data: 0.95358074+ float_data: 0.38941833+ float_data: 0.12615408+ float_data: 0.039989334+ float_data: 0.012648774+ float_data: 0.0039999895+ float_data: 0.0012649108+ float_data: -0.9589243+ float_data: 0.99994653+ float_data: 0.47942555+ float_data: 0.1574559+ float_data: 0.049979165+ float_data: 0.01581073+ float_data: 0.0049999794+ float_data: 0.0015811382+ float_data: -0.2794155+ float_data: 0.9471482+ float_data: 0.5646425+ float_data: 0.18860029+ float_data: 0.059964005+ float_data: 0.01897253+ float_data: 0.005999964+ float_data: 0.0018973656+ float_data: 0.6569866+ float_data: 0.8004216+ float_data: 0.64421767+ float_data: 0.21955611+ float_data: 0.06994285+ float_data: 0.022134136+ float_data: 0.006999943+ float_data: 0.0022135926+ name: "sin_cache"+ }+ input {+ name: "query"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim {+ dim_value: 2+ }+ dim {+ dim_value: 1+ }+ dim {+ dim_value: 64+ }+ }+ }+ }+ }+ input {+ name: "past_key"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim {+ dim_value: 2+ }+ dim {+ dim_value: 1+ }+ dim {+ dim_value: 8+ }+ dim {+ dim_value: 16+ }+ }+ }+ }+ }+ input {+ name: "past_value"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim {+ dim_value: 2+ }+ dim {+ dim_value: 1+ }+ dim {+ dim_value: 8+ }+ dim {+ dim_value: 16+ }+ }+ }+ }+ }+ input {+ name: "seqlens_k"+ type {+ tensor_type {+ elem_type: 6+ shape {+ dim {+ dim_value: 2+ }+ 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+ }+ }+ }+ output {+ name: "present_key"+ type {+ tensor_type {+ elem_type: 1+ }+ }+ }+ output {+ name: "present_value"+ type {+ tensor_type {+ elem_type: 1+ }+ }+ }+}+opset_import {+ domain: ""+ version: 21+}+opset_import {+ domain: "com.microsoft"+ version: 1+}diff --git a/src/frontends/onnx/tests/models/com.microsoft/gqa_batch_static_cache_dynamic_batch.prototxt b/src/frontends/onnx/tests/models/com.microsoft/gqa_batch_static_cache_dynamic_batch.prototxtnew file mode 100644index 00000000000..d4ab24a9a65--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/gqa_batch_static_cache_dynamic_batch.prototxt@@ -0,0 +1,302 @@+ir_version: 10+graph {+ node {+ input: "query"+ input: ""+ input: ""+ input: "past_key"+ input: "past_value"+ input: "seqlens_k"+ input: "total_sequence_length"+ input: "cos_cache"+ input: "sin_cache"+ output: "output"+ output: "present_key"+ output: "present_value"+ name: "GroupQueryAttention_0"+ op_type: "GroupQueryAttention"+ attribute {+ name: "do_rotary"+ i: 1+ type: INT+ }+ attribute {+ name: "kv_num_heads"+ i: 1+ type: INT+ }+ attribute {+ name: "local_window_size"+ i: 3+ type: INT+ }+ attribute {+ name: "num_heads"+ i: 2+ type: INT+ }+ domain: "com.microsoft"+ }+ name: "gqa_batch_static_cache_dynamic_batch"+ initializer {+ dims: 8+ dims: 8+ data_type: 1+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 1.0+ float_data: 0.5403023+ float_data: 0.95041525+ float_data: 0.9950042+ float_data: 0.99950004+ float_data: 0.99995+ float_data: 0.999995+ float_data: 0.9999995+ float_data: 0.99999994+ float_data: -0.4161468+ float_data: 0.8065784+ float_data: 0.9800666+ float_data: 0.9980007+ float_data: 0.9998+ float_data: 0.99998+ float_data: 0.999998+ float_data: 0.9999998+ float_data: -0.9899925+ float_data: 0.5827536+ float_data: 0.9553365+ float_data: 0.99550337+ float_data: 0.99955004+ float_data: 0.999955+ float_data: 0.9999955+ float_data: 0.9999995+ float_data: -0.6536436+ float_data: 0.30113748+ float_data: 0.921061+ float_data: 0.99201065+ float_data: 0.9992001+ float_data: 0.99992+ float_data: 0.999992+ float_data: 0.9999992+ float_data: 0.28366217+ float_data: -0.010342338+ float_data: 0.87758255+ float_data: 0.987526+ float_data: 0.99875027+ float_data: 0.999875+ float_data: 0.9999875+ float_data: 0.99999875+ float_data: 0.96017027+ float_data: -0.32079637+ float_data: 0.8253356+ float_data: 0.98205394+ float_data: 0.99820054+ float_data: 0.99982+ float_data: 0.999982+ float_data: 0.9999982+ float_data: 0.75390226+ float_data: -0.5994375+ float_data: 0.7648422+ float_data: 0.9755999+ float_data: 0.997551+ float_data: 0.999755+ float_data: 0.9999755+ float_data: 0.99999756+ name: "cos_cache"+ }+ initializer {+ dims: 8+ dims: 8+ data_type: 1+ float_data: 0.0+ float_data: 0.0+ float_data: 0.0+ float_data: 0.0+ float_data: 0.0+ float_data: 0.0+ float_data: 0.0+ float_data: 0.0+ float_data: 0.841471+ float_data: 0.3109836+ float_data: 0.09983342+ float_data: 0.031617507+ float_data: 0.009999833+ float_data: 0.0031622725+ float_data: 0.0009999999+ float_data: 0.0003162278+ float_data: 0.9092974+ float_data: 0.5911271+ float_data: 0.19866933+ float_data: 0.0632034+ float_data: 0.019998666+ float_data: 0.0063245133+ float_data: 0.0019999987+ float_data: 0.0006324555+ float_data: 0.14112+ float_data: 0.8126489+ float_data: 0.29552022+ float_data: 0.09472609+ float_data: 0.0299955+ float_data: 0.009486691+ float_data: 0.0029999956+ float_data: 0.00094868324+ float_data: -0.7568025+ float_data: 0.95358074+ float_data: 0.38941833+ float_data: 0.12615408+ float_data: 0.039989334+ float_data: 0.012648774+ float_data: 0.0039999895+ float_data: 0.0012649108+ float_data: -0.9589243+ float_data: 0.99994653+ float_data: 0.47942555+ float_data: 0.1574559+ float_data: 0.049979165+ float_data: 0.01581073+ float_data: 0.0049999794+ float_data: 0.0015811382+ float_data: -0.2794155+ float_data: 0.9471482+ float_data: 0.5646425+ float_data: 0.18860029+ float_data: 0.059964005+ float_data: 0.01897253+ float_data: 0.005999964+ float_data: 0.0018973656+ float_data: 0.6569866+ float_data: 0.8004216+ float_data: 0.64421767+ float_data: 0.21955611+ float_data: 0.06994285+ float_data: 0.022134136+ float_data: 0.006999943+ float_data: 0.0022135926+ name: "sin_cache"+ }+ input {+ name: "query"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim {+ dim_param: "batch_size"+ }+ dim {+ dim_value: 1+ }+ 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_value: 8+ }+ 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_value: 8+ }+ 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+ }+ }+ }+ output {+ name: "present_key"+ type {+ tensor_type {+ elem_type: 1+ }+ }+ }+ output {+ name: "present_value"+ type {+ tensor_type {+ elem_type: 1+ }+ }+ }+}+opset_import {+ domain: ""+ version: 21+}+opset_import {+ domain: "com.microsoft"+ version: 1+}diff --git a/src/frontends/onnx/tests/models/com.microsoft/gqa_qk_norm.prototxt b/src/frontends/onnx/tests/models/com.microsoft/gqa_qk_norm.prototxtindex 036389c1920..e614d309b97 100644--- a/src/frontends/onnx/tests/models/com.microsoft/gqa_qk_norm.prototxt+++ b/src/frontends/onnx/tests/models/com.microsoft/gqa_qk_norm.prototxt@@ -8,8 +8,8 @@ graph {input: "past_value"input: "seqlens_k"input: "total_sequence_length"- input: ""- input: ""+ input: "cos_cache"+ input: "sin_cache"input: ""input: ""input: ""@@ -22,46 +22,224 @@ graph {output: "present_value"name: "GroupQueryAttention_0"op_type: "GroupQueryAttention"- attribute { name: "num_heads" i: 2 type: INT }- attribute { name: "kv_num_heads" i: 1 type: INT }- attribute { name: "do_rotary" i: 0 type: INT }+ attribute {+ name: "do_rotary"+ i: 1+ 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+ }+ attribute {+ name: "qk_norm_epsilon"+ f: 1e-05+ type: FLOAT+ }domain: "com.microsoft"}- name: "GQA_QKNorm_Graph"+ name: "GroupQueryAttention_QKNorm_Graph"initializer {- dims: 8+ dims: 16data_type: 1name: "q_norm_weight"- float_data: 1.0- float_data: 1.0- float_data: 1.0- float_data: 1.0- float_data: 1.0- float_data: 1.0- float_data: 1.0- float_data: 1.0+ float_data: 0.5+ float_data: 0.6+ float_data: 0.7+ float_data: 0.8+ float_data: 0.9+ float_data: 1+ float_data: 1.1+ float_data: 1.2+ float_data: 1.3+ float_data: 1.4+ float_data: 1.5+ float_data: 1.6+ float_data: 1.7+ float_data: 1.8+ float_data: 1.9+ float_data: 2}initializer {- dims: 8+ dims: 16data_type: 1name: "k_norm_weight"- float_data: 1.0- float_data: 1.0- float_data: 1.0- float_data: 1.0- float_data: 1.0- float_data: 1.0- float_data: 1.0- float_data: 1.0+ float_data: 1.5+ float_data: 1.45+ float_data: 1.4+ float_data: 1.35+ float_data: 1.3+ float_data: 1.25+ float_data: 1.2+ float_data: 1.15+ float_data: 1.1+ float_data: 1.05+ float_data: 1+ float_data: 0.95+ float_data: 0.9+ float_data: 0.85+ float_data: 0.8+ float_data: 0.75+ }+ 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: "query" type { tensor_type { elem_type: 1 shape { dim { dim_value: 1 } dim { dim_value: 1 } dim { dim_value: 32 } } } } }- input { name: "past_key" type { tensor_type { elem_type: 1 shape { dim { dim_value: 1 } dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 8 } } } } }- input { name: "past_value" type { tensor_type { elem_type: 1 shape { dim { dim_value: 1 } dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 8 } } } } }- 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: 16 } } } } }- output { name: "present_key" type { tensor_type { elem_type: 1 shape { dim { dim_value: 1 } dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 8 } } } } }- output { name: "present_value" type { tensor_type { elem_type: 1 shape { dim { dim_value: 1 } dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 8 } } } } }+ input {+ name: "cos_cache"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "max_sequence_length" }+ dim { dim_value: 8 }+ }+ }+ }+ }+ input {+ name: "sin_cache"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "max_sequence_length" }+ dim { dim_value: 8 }+ }+ }+ }+ }+ 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}-opset_import { version: 21 }-opset_import { domain: "com.microsoft" version: 1 }diff --git a/src/frontends/onnx/tests/models/com.microsoft/gqa_qk_norm_unpaired.prototxt b/src/frontends/onnx/tests/models/com.microsoft/gqa_qk_norm_unpaired.prototxtnew file mode 100644index 00000000000..0c9a1452480--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/gqa_qk_norm_unpaired.prototxt@@ -0,0 +1,245 @@+ir_version: 10+graph {+ node {+ input: "query"+ input: ""+ input: ""+ input: "past_key"+ input: "past_value"+ input: "seqlens_k"+ input: "total_sequence_length"+ input: "cos_cache"+ input: "sin_cache"+ input: ""+ input: ""+ input: ""+ input: ""+ input: ""+ input: "q_norm_weight"+ input: ""+ output: "output"+ output: "present_key"+ output: "present_value"+ name: "GroupQueryAttention_0"+ op_type: "GroupQueryAttention"+ attribute {+ name: "do_rotary"+ i: 1+ 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+ }+ attribute {+ name: "qk_norm_epsilon"+ f: 1e-05+ type: FLOAT+ }+ domain: "com.microsoft"+ }+ name: "GroupQueryAttention_QKNorm_Graph"+ initializer {+ dims: 16+ data_type: 1+ name: "q_norm_weight"+ float_data: 0.5+ float_data: 0.6+ float_data: 0.7+ float_data: 0.8+ float_data: 0.9+ float_data: 1+ float_data: 1.1+ float_data: 1.2+ float_data: 1.3+ float_data: 1.4+ float_data: 1.5+ float_data: 1.6+ float_data: 1.7+ float_data: 1.8+ float_data: 1.9+ float_data: 2+ }+ initializer {+ dims: 16+ data_type: 1+ name: "k_norm_weight"+ float_data: 1.5+ float_data: 1.45+ float_data: 1.4+ float_data: 1.35+ float_data: 1.3+ float_data: 1.25+ float_data: 1.2+ float_data: 1.15+ float_data: 1.1+ float_data: 1.05+ float_data: 1+ float_data: 0.95+ float_data: 0.9+ float_data: 0.85+ float_data: 0.8+ float_data: 0.75+ }+ 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: "cos_cache"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "max_sequence_length" }+ dim { dim_value: 8 }+ }+ }+ }+ }+ input {+ name: "sin_cache"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "max_sequence_length" }+ dim { dim_value: 8 }+ }+ }+ }+ }+ 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_qk_output_after_softmax.prototxt b/src/frontends/onnx/tests/models/com.microsoft/gqa_qk_output_after_softmax.prototxtnew file mode 100644index 00000000000..4ed80fbe3c3--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/gqa_qk_output_after_softmax.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"+ output: "output_qk"+ name: "GroupQueryAttention_0"+ 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: 2+ type: INT+ }+ attribute {+ name: "softcap"+ f: 0.5+ type: FLOAT+ }+ domain: "com.microsoft"+ }+ name: "gqa_qk_output_after_softmax"+ initializer {+ dims: 2+ data_type: 1+ float_data: -0.5+ float_data: 0.75+ name: "head_sink"+ }+ 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+ }+ }+ }+ output {+ name: "present_key"+ type {+ tensor_type {+ elem_type: 1+ }+ }+ }+ output {+ name: "present_value"+ type {+ tensor_type {+ elem_type: 1+ }+ }+ }+ output {+ name: "output_qk"+ type {+ tensor_type {+ elem_type: 1+ }+ }+ }+}+opset_import {+ domain: ""+ version: 21+}+opset_import {+ domain: "com.microsoft"+ version: 1+}diff --git a/src/frontends/onnx/tests/models/com.microsoft/gqa_qk_output_before_softmax.prototxt b/src/frontends/onnx/tests/models/com.microsoft/gqa_qk_output_before_softmax.prototxtnew file mode 100644index 00000000000..07803f1b0b0--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/gqa_qk_output_before_softmax.prototxt@@ -0,0 +1,213 @@+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"+ output: "output_qk"+ name: "GroupQueryAttention_0"+ 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: "qk_output"+ i: 1+ type: INT+ }+ domain: "com.microsoft"+ }+ name: "gqa_qk_output_before_softmax"+ initializer {+ dims: 1+ dims: 2+ dims: 4+ dims: 4+ data_type: 1+ float_data: -0.75+ float_data: -0.5+ float_data: -0.25+ float_data: 0.0+ float_data: 0.25+ float_data: 0.5+ float_data: 0.75+ float_data: -0.75+ float_data: -0.5+ float_data: -0.25+ float_data: 0.0+ float_data: 0.25+ float_data: 0.5+ float_data: 0.75+ float_data: -0.75+ float_data: -0.5+ float_data: -0.25+ float_data: 0.0+ float_data: 0.25+ float_data: 0.5+ float_data: 0.75+ float_data: -0.75+ float_data: -0.5+ float_data: -0.25+ float_data: 0.0+ float_data: 0.25+ float_data: 0.5+ float_data: 0.75+ float_data: -0.75+ float_data: -0.5+ float_data: -0.25+ float_data: 0.0+ name: "attention_bias"+ }+ 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+ }+ }+ }+ output {+ name: "present_key"+ type {+ tensor_type {+ elem_type: 1+ }+ }+ }+ output {+ name: "present_value"+ type {+ tensor_type {+ elem_type: 1+ }+ }+ }+ output {+ name: "output_qk"+ type {+ tensor_type {+ elem_type: 1+ }+ }+ }+}+opset_import {+ domain: ""+ version: 21+}+opset_import {+ domain: "com.microsoft"+ version: 1+}diff --git a/src/frontends/onnx/tests/models/com.microsoft/gqa_qk_output_before_softmax_neg_bias.prototxt b/src/frontends/onnx/tests/models/com.microsoft/gqa_qk_output_before_softmax_neg_bias.prototxtnew file mode 100644index 00000000000..9b0ca065410--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/gqa_qk_output_before_softmax_neg_bias.prototxt@@ -0,0 +1,218 @@+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"+ output: "output_qk"+ 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: "qk_output"+ i: 1+ type: INT+ }+ domain: "com.microsoft"+ }+ name: "gqa_qk_output_before_softmax_neg_bias"+ initializer {+ dims: 1+ dims: 2+ dims: 4+ dims: 4+ data_type: 1+ float_data: -0.75+ float_data: -0.5+ float_data: -0.25+ float_data: 0.0+ float_data: 0.25+ float_data: 0.5+ float_data: 0.75+ float_data: -0.75+ float_data: -0.5+ float_data: -0.25+ float_data: 0.0+ float_data: 0.25+ float_data: 0.5+ float_data: -3e+38+ float_data: -0.75+ float_data: -0.5+ float_data: -0.25+ float_data: 0.0+ float_data: 0.25+ float_data: 0.5+ float_data: 0.75+ float_data: -0.75+ float_data: -0.5+ float_data: -0.25+ float_data: 0.0+ float_data: 0.25+ float_data: -3e+38+ float_data: 0.75+ float_data: -0.75+ float_data: -0.5+ float_data: -0.25+ float_data: 0.0+ name: "attention_bias"+ }+ 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+ }+ }+ }+ output {+ name: "present_key"+ type {+ tensor_type {+ elem_type: 1+ }+ }+ }+ output {+ name: "present_value"+ type {+ tensor_type {+ elem_type: 1+ }+ }+ }+ output {+ name: "output_qk"+ type {+ tensor_type {+ elem_type: 1+ }+ }+ }+}+opset_import {+ domain: ""+ version: 21+}+opset_import {+ domain: "com.microsoft"+ version: 1+}diff --git a/src/frontends/onnx/tests/models/com.microsoft/gqa_qk_output_static_cache.prototxt b/src/frontends/onnx/tests/models/com.microsoft/gqa_qk_output_static_cache.prototxtnew file mode 100644index 00000000000..e2a45250158--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/gqa_qk_output_static_cache.prototxt@@ -0,0 +1,164 @@+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"+ output: "output_qk"+ name: "GroupQueryAttention_0"+ 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_static_cache"+ 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: 8+ }+ 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: 8+ }+ 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+ }+ }+ }+ output {+ name: "present_key"+ type {+ tensor_type {+ elem_type: 1+ }+ }+ }+ output {+ name: "present_value"+ type {+ tensor_type {+ elem_type: 1+ }+ }+ }+ output {+ name: "output_qk"+ type {+ tensor_type {+ elem_type: 1+ }+ }+ }+}+opset_import {+ domain: ""+ version: 21+}+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.cppindex 7bd49ed8576..d7451ae5ac1 100644--- a/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp+++ b/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp@@ -2,6 +2,7 @@// SPDX-License-Identifier: Apache-2.0//+#include <cmath>#include <vector>// clang-format off@@ -3435,12 +3436,10 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_past_0_input_1_rotary) {test_case.run_with_tolerance_as_fp();}-// Regression test for the fully-masked query row. With a 2-token query but only 1 valid position-// (seqlens_k = 0), the causal mask fully masks the second query row. The attention mask must use the-// element type's finite lowest() (not -inf) so that row's softmax stays finite instead of 0/0 = NaN.-// The expected values below are finite; if the mask ever regresses to -inf this row becomes NaN and-// the comparison fails.-OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_fully_masked_row_is_finite) {+// Right-padded first prompt (sequence_length == total_sequence_length = 2, seqlens_k = 0): as in ONNX Runtime the+// prompt starts at position 0 and the padded query row 1 only sees the one valid key, so no row is fully masked.+// Expected values: ORT CPU.+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_right_padded_first_prompt) {const auto model = convert_model("com.microsoft/gqa_rotary.onnx");std::vector<float> query = {@@ -3461,7 +3460,7 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_fully_masked_row_is_finite) {-0.891500f, -0.015300f};std::vector<float> past_key = {};std::vector<float> past_value = {};- std::vector<int> seqlens_k = {0}; // only 1 valid position => query row 1 is fully masked+ std::vector<int> seqlens_k = {0}; // total 1 of a 2-token first prompt: query row 1 is paddingstd::vector<int> total_sequence_length = {2};std::vector<float> cos_cache = {0.809800f,0.337700f,@@ -3497,14 +3496,14 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_fully_masked_row_is_finite) {0.937100f};std::vector<float> expected_output = {- 0.032050f, -0.594800f, -0.075450f, -0.069000f, 0.013850f, 0.065450f, -0.437150f, -0.060400f,- -0.345600f, 0.605800f, -0.586000f, 0.494350f, -0.097450f, 0.009950f, -0.543900f, -0.109250f,- 0.032050f, -0.594800f, -0.075450f, -0.069000f, 0.013850f, 0.065450f, -0.437150f, -0.060400f,- -0.345600f, 0.605800f, -0.586000f, 0.494350f, -0.097450f, 0.009950f, -0.543900f, -0.109250f,- 0.240200f, -0.713700f, -0.166600f, 0.373700f, 0.280100f, 0.286900f, -0.590400f, 0.382300f,- -0.067200f, 0.662300f, -0.138200f, 0.839800f, 0.207600f, 0.373800f, -0.196300f, -0.203200f,- 0.240200f, -0.713700f, -0.166600f, 0.373700f, 0.280100f, 0.286900f, -0.590400f, 0.382300f,- -0.067200f, 0.662300f, -0.138200f, 0.839800f, 0.207600f, 0.373800f, -0.196300f, -0.203200f};+ 0.240200f, -0.713700f, -0.166600f, 0.373700f, 0.280100f, 0.286900f, -0.590400f, 0.382300f,+ -0.067200f, 0.662300f, -0.138200f, 0.839800f, 0.207600f, 0.373800f, -0.196300f, -0.203200f,+ 0.240200f, -0.713700f, -0.166600f, 0.373700f, 0.280100f, 0.286900f, -0.590400f, 0.382300f,+ -0.067200f, 0.662300f, -0.138200f, 0.839800f, 0.207600f, 0.373800f, -0.196300f, -0.203200f,+ 0.240200f, -0.713700f, -0.166600f, 0.373700f, 0.280100f, 0.286900f, -0.590400f, 0.382300f,+ -0.067200f, 0.662300f, -0.138200f, 0.839800f, 0.207600f, 0.373800f, -0.196300f, -0.203200f,+ 0.240200f, -0.713700f, -0.166600f, 0.373700f, 0.280100f, 0.286900f, -0.590400f, 0.382300f,+ -0.067200f, 0.662300f, -0.138200f, 0.839800f, 0.207600f, 0.373800f, -0.196300f, -0.203200f};auto test_case = ov::test::TestCase(model, s_device);test_case.add_input<float>(Shape{1, 2, 64}, query);@@ -5561,15 +5560,112 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_f8e4m3fnkv_present_type_is_f8e4m3)EXPECT_EQ(model->outputs()[2].get_element_type(), element::f8e4m3);}-OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_qk_norm_unsupported_throws) {- // q_norm_weight/k_norm_weight (QK-Norm) inputs are not implemented and must be rejected.+static std::vector<float> gqa_sink_query();++// RoPE caches for gqa_qk_norm (head_size 16, base 10000): cos/sin of position * inv_freq, [rows, 8].+static std::vector<float> gqa_qk_norm_rope_cache(size_t rows, bool is_sin) {+ std::vector<float> cache;+ for (size_t pos = 0; pos < rows; ++pos) {+ for (size_t i = 0; i < 8; ++i) {+ const float angle = static_cast<float>(pos) / std::pow(10000.0f, static_cast<float>(2 * i) / 16.0f);+ cache.push_back(is_sin ? std::sin(angle) : std::cos(angle));+ }+ }+ return cache;+}++// QK-Norm (q_norm_weight/k_norm_weight, qk_norm_epsilon = 1e-5) with packed QKV and RoPE: the new Q/K heads are+// RMS-normalized before RoPE. Expected values: ORT GQA on the same inputs with Q/K pre-normalized (ORT CPU has no+// QK-Norm kernel; this matches the CUDA semantics).+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_qk_norm_prefill) {+ const auto model = convert_model("com.microsoft/gqa_qk_norm.onnx");++ 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{4, 8}, gqa_qk_norm_rope_cache(4, false));+ test_case.add_input<float>(Shape{4, 8}, gqa_qk_norm_rope_cache(4, true));+ test_case.add_expected_output<float>(+ Shape{1, 4, 32},+ {+ -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.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.204647f, -0.064037f, 0.294030f, 0.750198f,+ -0.175318f, -0.048703f, -0.573363f, 1.317654f, 0.312172f, -1.404098f, 0.909337f, 0.566280f, 0.364273f,+ 0.346892f, 0.030539f, -0.671584f, -0.153659f, -0.148707f, 0.317910f, 0.735134f, -0.266219f, -0.693562f,+ -0.588130f, 0.961974f, 0.648947f, -1.405899f, 0.877516f, 0.387456f, 0.123936f, -0.006459f, 0.375071f,+ -0.779010f, -1.155333f, 0.250027f, 0.893889f, -0.118486f, -0.838760f, 0.491369f, -0.023320f, 0.067260f,+ -0.979102f, -1.114991f, -0.079658f, 0.405205f, 1.170673f, 0.051460f, -0.308740f, 0.538963f, -0.754140f,+ 0.001410f, 0.736677f, 0.142586f, -0.775254f, -0.790615f, -0.230226f, -0.128570f, 0.023670f, -1.213541f,+ 0.192464f, 0.152344f, 0.493062f, -0.455727f, 0.392945f, -0.044632f, -1.249879f, 0.233084f, 1.068248f,+ -0.391639f, -1.160778f, -0.117471f, 0.034006f, -0.602607f, -1.016575f, -0.816298f, -0.423137f, 0.200362f,+ 1.031485f, -0.377530f, 0.046297f, 0.882835f, -0.840033f, 0.161139f, 0.737706f, 0.077764f, -0.713160f,+ 0.284474f, -0.214861f, 0.395778f, -0.684357f, -1.021520f, 0.130751f, 0.459669f, 0.888890f, 0.130982f,+ -0.153601f, 0.334657f,+ });+ test_case.add_expected_output<float>(+ Shape{1, 1, 4, 16},+ {+ 2.077571f, -1.879617f, 1.704428f, 0.941264f, 1.296135f, -0.889845f, -0.726965f, 0.356442f,+ -1.316610f, 0.853328f, -0.728800f, 0.788628f, -1.527661f, 1.044347f, 0.491763f, -0.466484f,+ -0.245946f, 2.148291f, -1.667101f, 1.956976f, 1.842385f, 1.207076f, -1.813506f, 1.023705f,+ -0.387978f, 0.723597f, -1.977550f, -0.319341f, 0.063797f, 0.315899f, -0.101428f, 0.163809f,+ -1.214118f, -1.504665f, -0.712130f, -2.127227f, -0.729039f, -1.448440f, 1.444658f, 0.588938f,+ 1.021935f, -1.092042f, 0.706862f, -0.177798f, -1.273036f, -0.123885f, 1.208566f, 1.077567f,+ 0.687034f, -0.865623f, -0.957480f, -3.774457f, 0.724519f, -0.274241f, 1.706604f, 0.425226f,+ -0.514190f, -1.311056f, 1.215784f, 0.721253f, -0.338950f, 0.315340f, 0.462329f, -0.410953f,+ });+ test_case.run_with_tolerance_as_fp();+}++// Decode: only the new key is normalized; the past rows of present_key are passed through unchanged.+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_qk_norm_decode) {+ const auto model = convert_model("com.microsoft/gqa_qk_norm.onnx");++ const auto data = gqa_sink_query();+ auto test_case = ov::test::TestCase(model, s_device);+ test_case.add_input<float>(Shape{1, 1, 64}, std::vector<float>(data.begin() + 192, data.end()));+ test_case.add_input<float>(Shape{1, 1, 4, 16}, std::vector<float>(data.begin(), data.begin() + 64));+ test_case.add_input<float>(Shape{1, 1, 4, 16}, std::vector<float>(data.begin() + 64, data.begin() + 128));+ test_case.add_input<int>(Shape{1, 1}, {4});+ test_case.add_input<int>(Shape{}, {5});+ test_case.add_input<float>(Shape{5, 8}, gqa_qk_norm_rope_cache(5, false));+ test_case.add_input<float>(Shape{5, 8}, gqa_qk_norm_rope_cache(5, true));+ test_case.add_expected_output<float>(+ Shape{1, 1, 32},+ {+ 0.180732f, 0.166091f, -1.092899f, 0.433461f, -0.785875f, -1.266359f, -1.627180f, 0.987866f,+ 0.516814f, -0.151132f, 0.443130f, 0.060590f, 0.132206f, 1.483993f, -0.027208f, 0.096251f,+ 0.273264f, 0.286686f, -0.201092f, 0.969175f, -0.080065f, -0.571854f, -0.650118f, 0.181871f,+ 0.819878f, -0.665653f, 1.252989f, 0.003249f, -0.021254f, 1.981680f, -0.379394f, -0.118771f,+ });+ test_case.add_expected_output<float>(+ Shape{1, 1, 5, 16},+ {+ -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.803882f, -0.414984f, -1.074072f, -3.795374f, 0.727872f, -0.275237f, 1.706141f, 0.425356f,+ 0.300301f, -1.515243f, 1.114122f, 0.601554f, -0.331688f, 0.314471f, 0.464035f, -0.410819f,+ });+ test_case.run_with_tolerance_as_fp();+}++OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_qk_norm_unpaired_throws) {+ // ORT requires q_norm_weight and k_norm_weight together.try {- convert_model("com.microsoft/gqa_qk_norm.onnx");- FAIL() << "ONNX Importer did not reject unsupported QK-Norm inputs for GroupQueryAttention";- } catch (const ::ov::frontend::OpConversionFailure& e) {- EXPECT_THAT(e.what(), testing::HasSubstr("QK-Norm"));+ convert_model("com.microsoft/gqa_qk_norm_unpaired.onnx");+ FAIL() << "ONNX Importer did not reject q_norm_weight without k_norm_weight for GroupQueryAttention";} catch (const std::exception& e) {- EXPECT_THAT(e.what(), testing::HasSubstr("QK-Norm"));+ EXPECT_THAT(e.what(), testing::HasSubstr("q_norm_weight and k_norm_weight must be provided together"));} catch (...) {FAIL() << "Unexpected exception type thrown";}@@ -6281,12 +6377,11 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_sliding_window_bf16) {test_case.run_with_tolerance_as_fp(0.05f);}-// 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) {+// qk_output != 0 without the output_qk output (or vice versa) is rejected, as in ONNX Runtime.+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_qk_output_without_output_throws) {try {convert_model("com.microsoft/gqa_qk_output.onnx");- FAIL() << "ONNX Importer did not reject unsupported qk_output for GroupQueryAttention";+ FAIL() << "ONNX Importer did not reject qk_output without output_qk for GroupQueryAttention";} catch (const std::exception& e) {EXPECT_THAT(e.what(), testing::HasSubstr("qk_output"));} catch (...) {@@ -6441,20 +6536,349 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_head_sink) {test_case.run_with_tolerance_as_fp();}-// The decomposition handles a single batch entry (one scalar past length). A dynamic batch cannot be rejected at-// conversion, so a batch_size > 1 request must fail at inference instead of returning silently wrong results.-OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_dynamic_batch_greater_than_one_throws) {+static std::vector<float> gqa_sink_query_causal_output();++// Two batches with per-batch seqlens_k (dynamic batch). Identical batches give the single-batch result twice.+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_dynamic_batch_two) {const auto model = convert_model("com.microsoft/gqa_absent_past.onnx");- const std::vector<float> one_batch = gqa_sink_query();+ const auto one_batch = gqa_sink_query();std::vector<float> query = one_batch;query.insert(query.end(), one_batch.begin(), one_batch.end());+ const auto one_batch_output = gqa_sink_query_causal_output();+ std::vector<float> expected_output = one_batch_output;+ expected_output.insert(expected_output.end(), one_batch_output.begin(), one_batch_output.end());auto test_case = ov::test::TestCase(model, s_device);test_case.add_input<float>(Shape{2, 4, 64}, query);test_case.add_input<int>(Shape{2, 1}, {3, 3});test_case.add_input<int>(Shape{}, {4});- test_case.add_expected_output<float>(Shape{2, 4, 32}, std::vector<float>(2 * 4 * 32, 0.0f));- EXPECT_ANY_THROW(test_case.run());+ test_case.add_expected_output<float>(Shape{2, 4, 32}, expected_output);+ test_case.run_with_tolerance_as_fp();+}++// Batch 0 is gqa_sink_query(), batch 1 the same values reversed, so the two batches differ.+static std::vector<float> gqa_batch_query() {+ const auto one_batch = gqa_sink_query();+ std::vector<float> query = one_batch;+ query.insert(query.end(), one_batch.rbegin(), one_batch.rend());+ return query;+}++// Rows [begin, end) of each batch's 256-value block of gqa_batch_query().+static std::vector<float> gqa_batch_slice(size_t begin, size_t end) {+ const auto query = gqa_batch_query();+ std::vector<float> out;+ for (size_t b = 0; b < 2; ++b)+ out.insert(out.end(), query.begin() + b * 256 + begin, query.begin() + b * 256 + end);+ return out;+}++// Batched first prompt with right padding (packed QKV + RoPE): batch 1 has 2 valid tokens of 4 (seqlens_k = [3, 1]),+// so its keys beyond total are masked. Expected values: ORT CPU.+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_batch_prefill_padded) {+ const auto model = convert_model("com.microsoft/gqa_batch_prefill_padded.onnx");++ auto test_case = ov::test::TestCase(model, s_device);+ test_case.add_input<float>(Shape{2, 4, 64}, gqa_batch_query());+ test_case.add_input<float>(Shape{2, 1, 0, 16}, {});+ test_case.add_input<float>(Shape{2, 1, 0, 16}, {});+ test_case.add_input<int>(Shape{2, 1}, {3, 1});+ test_case.add_input<int>(Shape{}, {4});+ test_case.add_expected_output<float>(+ Shape{2, 4, 32},+ {+ -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.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.204225f, -0.064736f, 0.294227f, 0.750073f,+ -0.176069f, -0.054030f, -0.573485f, 1.314715f, 0.314954f, -1.404113f, 0.909074f, 0.564803f, 0.362288f,+ 0.343973f, 0.033385f, -0.672472f, -0.171401f, -0.119244f, 0.309601f, 0.740376f, -0.234588f, -0.469172f,+ -0.582992f, 1.085739f, 0.531761f, -1.405272f, 0.888589f, 0.449681f, 0.207565f, 0.116495f, 0.255185f,+ -0.741630f, -0.963257f, 0.173465f, 0.783527f, 0.045106f, -0.729164f, 0.263220f, -0.131603f, 0.238185f,+ -0.666511f, -1.170753f, 0.103757f, 0.401518f, 0.969658f, 0.039795f, -0.177121f, 0.286171f, -0.716121f,+ 0.012358f, 0.693261f, 0.198694f, -0.704885f, -0.598752f, -0.257329f, 0.067952f, -0.017410f, -1.229852f,+ 0.261428f, 0.223759f, 0.529122f, -0.315954f, 0.293409f, -0.078312f, -1.044812f, 0.183356f, 0.966553f,+ -0.269185f, -1.078582f, -0.198356f, -0.093013f, -0.360055f, -0.865445f, -0.734332f, -0.292378f, 0.253248f,+ 0.864749f, -0.293848f, 0.122062f, 0.777257f, -0.835625f, 0.173636f, 0.741337f, 0.060219f, -0.723884f,+ 0.354747f, -0.222320f, 0.429784f, -0.757146f, -0.963333f, 0.108504f, 0.485644f, 0.906676f, 0.175392f,+ -0.181552f, 0.398569f, 0.684437f, -0.461686f, -0.793446f, -1.375511f, -0.957919f, -0.645995f, 0.016349f,+ -0.872725f, -2.272386f, 0.228863f, -0.473675f, -0.378941f, 0.006219f, -2.043329f, -1.449158f, 0.058498f,+ 0.684437f, -0.461686f, -0.793446f, -1.375511f, -0.957919f, -0.645995f, 0.016349f, -0.872725f, -2.272386f,+ 0.228863f, -0.473675f, -0.378941f, 0.006219f, -2.043329f, -1.449158f, 0.058498f, 0.620419f, -0.452307f,+ -0.760900f, -1.308849f, -0.829499f, -0.578200f, 0.009832f, -0.841186f, -2.154895f, 0.268786f, -0.402615f,+ -0.401477f, 0.001834f, -1.910300f, -1.383642f, 0.061785f, 0.104048f, -0.376651f, -0.498385f, -0.771148f,+ 0.206352f, -0.031360f, -0.042735f, -0.586789f, -1.207202f, 0.590811f, 0.170564f, -0.583257f, -0.033540f,+ -0.837272f, -0.855183f, 0.088297f, -0.135093f, -0.341614f, -0.376809f, -0.522129f, 0.686072f, 0.221891f,+ -0.067079f, -0.468974f, -0.768308f, 0.739946f, 0.436013f, -0.667442f, -0.049922f, -0.340334f, -0.610444f,+ 0.100575f, -0.378639f, -0.305931f, -0.252994f, -0.268523f, 1.174629f, 0.479807f, -0.091872f, -0.348988f,+ -0.321331f, 0.891828f, 0.706352f, -0.753178f, -0.066606f, 0.165757f, -0.361198f, 0.113079f, -0.127944f,+ -0.342662f, -0.380444f, -0.529574f, 0.671730f, 0.214319f, -0.066351f, -0.472496f, -0.781430f, 0.735487f,+ 0.428077f, -0.664925f, -0.049433f, -0.355191f, -0.617761f, 0.100208f, 0.462462f, -0.429164f, -0.680597f,+ -1.144367f, -0.512634f, -0.410923f, -0.006248f, -0.763367f, -1.864998f, 0.367293f, -0.227280f, -0.457083f,+ -0.008987f, -1.582063f, -1.221987f, 0.069895f,+ });+ test_case.add_expected_output<float>(+ Shape{2, 1, 4, 16},+ {+ 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.120719f, 1.093262f,+ -0.841684f, 1.073608f, 1.046789f, 0.713062f, -1.116338f, 0.657559f, -0.191325f, 0.372258f, -1.421710f,+ -0.262488f, 0.047709f, 0.273473f, -0.093098f, 0.161231f, -0.956899f, -1.036736f, -0.554785f, -1.571382f,+ -0.550972f, -1.155909f, 1.200208f, 0.510669f, 0.611458f, -0.749636f, 0.736869f, -0.144763f, -1.406201f,+ -0.141981f, 1.506152f, 1.433396f, 0.479323f, -0.630619f, -0.870133f, -3.053144f, 0.605754f, -0.238113f,+ 1.534955f, 0.399442f, -0.476915f, -0.986289f, 1.363366f, 0.937437f, -0.414548f, 0.401616f, 0.621688f,+ -0.591831f, 1.495406f, -0.035300f, 0.015189f, -0.135356f, -0.468090f, -0.978691f, -0.708250f, 0.215226f,+ 0.653427f, -0.860494f, -0.308033f, -1.636424f, 0.056690f, 3.032897f, -1.583204f, -0.579369f, 1.209471f,+ 0.407535f, -1.406518f, -1.090109f, -0.272355f, 0.032906f, -1.325438f, 0.986445f, -0.622889f, -0.228535f,+ 0.051199f, -1.109059f, 1.406024f, -1.893424f, -0.007237f, -0.233262f, -1.274623f, 1.347539f, 1.420289f,+ 0.263154f, 0.074666f, 0.063762f, 0.002874f, 0.414386f, -0.451801f, -1.540746f, -1.332893f, -1.052466f,+ 0.210307f, -1.462336f, 0.102859f, 0.108326f, 0.924257f, -0.965693f, -0.569067f, -0.141891f, 0.038841f,+ -1.497145f, -1.239937f, 1.088125f, 2.457880f, -0.761932f, -0.684229f, 0.026444f, -0.230458f, 0.129313f,+ 1.657835f, 0.262536f,+ });+ test_case.add_expected_output<float>(+ Shape{2, 1, 4, 16},+ {+ -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.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, -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.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, 0.684437f, -0.461686f, -0.793446f, -1.375511f, -0.957919f, -0.645995f, 0.016349f, -0.872725f,+ -2.272386f, 0.228863f, -0.473675f, -0.378941f, 0.006219f, -2.043329f, -1.449158f, 0.058498f, -0.549630f,+ -0.280879f, -0.166065f, -0.090469f, 1.517640f, 0.660887f, -0.109279f, -0.264747f, -0.007512f, 0.998463f,+ 0.896154f, -0.813372f, -0.078320f, 0.521079f, -0.186204f, 0.121858f, -0.097781f, -0.789053f, 2.909682f,+ -0.018879f, -0.027737f, 1.944939f, -0.789237f, 1.017935f, -0.163320f, -0.366611f, -0.418189f, 0.004950f,+ 1.158923f, -0.039303f, 0.310293f, 0.436726f, 0.678687f, -1.119538f, -0.908491f, 0.120748f, 0.406092f,+ -0.926639f, -1.632419f, 0.676705f, -1.122348f, -0.500984f, 2.005177f, -1.070939f, 0.219196f, 1.341610f,+ 0.961409f, -0.841560f,+ });+ test_case.run_with_tolerance_as_fp();+}++// Batched decode on a growing cache: batch 0 has 4 past rows, batch 1 has 2, so the new key lands at a different+// row (and RoPE position) per batch. ORT leaves present rows beyond a batch's total uninitialized, so only the+// attention output is compared.+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_batch_decode) {+ const auto model = convert_model("com.microsoft/gqa_batch_decode.onnx");++ auto test_case = ov::test::TestCase(model, s_device);+ test_case.add_input<float>(Shape{2, 1, 64}, gqa_batch_slice(192, 256));+ test_case.add_input<float>(Shape{2, 1, 4, 16}, gqa_batch_slice(0, 64));+ test_case.add_input<float>(Shape{2, 1, 4, 16}, gqa_batch_slice(64, 128));+ test_case.add_input<int>(Shape{2, 1}, {4, 2});+ test_case.add_input<int>(Shape{}, {5});+ test_case.add_expected_output<float>(+ Shape{2, 1, 32},+ {+ 0.176497f, 0.161230f, -1.075928f, 0.409903f, -0.800631f, -1.267084f, -1.639485f, 1.012060f,+ 0.473925f, -0.109233f, 0.382190f, 0.075848f, 0.121989f, 1.403060f, 0.016952f, 0.126485f,+ 0.257404f, 0.259461f, -0.154608f, 0.963659f, -0.086425f, -0.607048f, -0.630661f, 0.186691f,+ 0.834736f, -0.709746f, 1.247476f, 0.012993f, -0.031949f, 1.867099f, -0.324260f, -0.159897f,+ 1.281354f, 0.702141f, -0.383030f, -0.499280f, 0.049238f, 0.150824f, -0.470997f, 0.149589f,+ -0.188584f, 0.731173f, -0.358463f, -0.862522f, -1.101834f, 0.296172f, -0.530359f, 0.030393f,+ 1.281471f, 0.176691f, -0.560869f, 0.634239f, 0.056155f, -0.477965f, -0.757145f, -0.768361f,+ -0.901344f, 0.483304f, -0.047305f, -1.216693f, -0.882895f, 0.955613f, 0.041793f, -1.049077f,+ });+ test_case.run_with_tolerance_as_fp();+}++// Batched decode on a preallocated static buffer (capacity 8, local_window_size 3): each batch's new key is written+// in place at its own row and the window is applied per batch.+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_batch_static_cache) {+ const auto model = convert_model("com.microsoft/gqa_batch_static_cache.onnx");++ // Zero-initialized capacity-8 buffers holding [4, 2] valid past rows (rows beyond total are unspecified in ORT).+ auto past_key = gqa_batch_slice(0, 128), past_value = gqa_batch_slice(128, 256);+ for (auto* past : {&past_key, &past_value}) {+ std::fill(past->begin() + 4 * 16, past->begin() + 128, 0.0f);+ std::fill(past->begin() + 128 + 2 * 16, past->end(), 0.0f);+ }+ auto test_case = ov::test::TestCase(model, s_device);+ test_case.add_input<float>(Shape{2, 1, 64}, gqa_batch_slice(192, 256));+ test_case.add_input<float>(Shape{2, 1, 8, 16}, past_key);+ test_case.add_input<float>(Shape{2, 1, 8, 16}, past_value);+ test_case.add_input<int>(Shape{2, 1}, {4, 2});+ test_case.add_input<int>(Shape{}, {5});+ test_case.add_expected_output<float>(+ Shape{2, 1, 32},+ {+ 0.414526f, -0.433350f, 0.279494f, -0.611678f, -0.957887f, -0.856399f, -0.170699f, 0.570335f,+ -0.361204f, 0.588092f, 0.126809f, 0.382532f, -0.567969f, 0.055696f, 1.005675f, 1.398716f,+ -0.767085f, -0.165474f, 0.765775f, -0.965882f, -1.168630f, -0.412102f, 0.492835f, -0.594868f,+ -0.798208f, -0.428286f, -0.295116f, 0.072938f, 0.423881f, -0.412985f, 0.478563f, 1.363478f,+ 0.009636f, -0.069890f, -0.083617f, 0.007201f, -0.071903f, -0.776515f, -0.582491f, 0.347511f,+ 0.331062f, -0.898135f, 0.446455f, 0.371435f, 0.844189f, -0.290696f, 0.807988f, -0.300425f,+ -0.480749f, 0.369244f, -0.309064f, -0.082685f, 0.087527f, 0.130781f, -1.091197f, 0.755863f,+ 0.391654f, -0.716847f, -0.565373f, -0.107579f, 0.747363f, 0.134815f, 0.217088f, -0.205244f,+ });+ test_case.add_expected_output<float>(+ Shape{2, 1, 8, 16},+ {+ -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.660289f, -0.292631f, -1.001896f, -3.081257f, 0.609869f, -0.239382f, 1.534332f, 0.399629f,+ 0.145658f, -1.133496f, 1.269686f, 0.840435f, -0.408469f, 0.400861f, 0.623222f, -0.591705f, 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, 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, 1.390027f, 0.884178f, 0.285846f, -0.398245f, 0.695815f, -0.134350f, 1.176417f,+ -0.763100f, 0.921146f, -1.086352f, -0.817775f, -1.102470f, 0.001170f, 0.507649f, -0.054978f, 0.450232f,+ -0.592210f, 0.617080f, 0.403857f, -0.432531f, 1.222434f, 1.559615f, -0.062291f, 0.404500f, 0.398880f,+ 1.536813f, -0.234292f, 0.593047f, -2.950616f, -0.428368f, -1.169002f, -0.541828f, 2.567613f, -1.154758f,+ -0.634533f, -0.140984f, 0.036535f, -1.496729f, -1.238279f, 1.088208f, 0.550263f, -0.423837f, -0.623999f,+ 0.030917f, -0.230835f, 0.134047f, 1.659074f, 0.262192f, 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, 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, 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,+ });+ test_case.add_expected_output<float>(+ Shape{2, 1, 8, 16},+ {+ 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.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, 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, 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.905910f, 0.782059f, -0.423865f, -0.159969f, 0.176214f, 0.839928f, -1.408027f,+ 1.046772f, 0.541818f, -0.605575f, -1.455318f, -0.373598f, 0.717340f, 0.346120f, -0.248725f, -0.093429f,+ 0.161023f, -0.091982f, 0.271217f, 0.037239f, -0.296302f, -1.330579f, 0.013813f, -0.001792f, 0.657610f,+ -1.116430f, 0.713923f, 1.047214f, 1.064772f, -0.979413f, 1.154819f, -0.226219f, 0.678687f, -1.119538f,+ -0.908491f, 0.120748f, 0.406092f, -0.926639f, -1.632419f, 0.676705f, -1.122348f, -0.500984f, 2.005177f,+ -1.070939f, 0.219196f, 1.341610f, 0.961409f, -0.841560f, 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, 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, 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,+ });+ test_case.run_with_tolerance_as_fp();+}++// Same preallocated cache with a dynamic batch dimension: the fixed capacity (8) is still written in place, so present+// keeps the capacity the op infers.+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_batch_static_cache_dynamic_batch) {+ const auto model = convert_model("com.microsoft/gqa_batch_static_cache_dynamic_batch.onnx");+ EXPECT_EQ(model->output("present_key").get_partial_shape(), (PartialShape{Dimension::dynamic(), 1, 8, 16}));++ auto past_key = gqa_batch_slice(0, 128), past_value = gqa_batch_slice(128, 256);+ for (auto* past : {&past_key, &past_value}) {+ std::fill(past->begin() + 4 * 16, past->begin() + 128, 0.0f);+ std::fill(past->begin() + 128 + 2 * 16, past->end(), 0.0f);+ }+ auto test_case = ov::test::TestCase(model, s_device);+ test_case.add_input<float>(Shape{2, 1, 64}, gqa_batch_slice(192, 256));+ test_case.add_input<float>(Shape{2, 1, 8, 16}, past_key);+ test_case.add_input<float>(Shape{2, 1, 8, 16}, past_value);+ test_case.add_input<int>(Shape{2, 1}, {4, 2});+ test_case.add_input<int>(Shape{}, {5});+ test_case.add_expected_output<float>(+ Shape{2, 1, 32},+ {+ 0.414526f, -0.433350f, 0.279494f, -0.611678f, -0.957887f, -0.856399f, -0.170699f, 0.570335f,+ -0.361204f, 0.588092f, 0.126809f, 0.382532f, -0.567969f, 0.055696f, 1.005675f, 1.398716f,+ -0.767085f, -0.165474f, 0.765775f, -0.965882f, -1.168630f, -0.412102f, 0.492835f, -0.594868f,+ -0.798208f, -0.428286f, -0.295116f, 0.072938f, 0.423881f, -0.412985f, 0.478563f, 1.363478f,+ 0.009636f, -0.069890f, -0.083617f, 0.007201f, -0.071903f, -0.776515f, -0.582491f, 0.347511f,+ 0.331062f, -0.898135f, 0.446455f, 0.371435f, 0.844189f, -0.290696f, 0.807988f, -0.300425f,+ -0.480749f, 0.369244f, -0.309064f, -0.082685f, 0.087527f, 0.130781f, -1.091197f, 0.755863f,+ 0.391654f, -0.716847f, -0.565373f, -0.107579f, 0.747363f, 0.134815f, 0.217088f, -0.205244f,+ });+ test_case.add_expected_output<float>(+ Shape{2, 1, 8, 16},+ {+ -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.660289f, -0.292631f, -1.001896f, -3.081257f, 0.609869f, -0.239382f, 1.534332f, 0.399629f,+ 0.145658f, -1.133496f, 1.269686f, 0.840435f, -0.408469f, 0.400861f, 0.623222f, -0.591705f, 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, 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, 1.390027f, 0.884178f, 0.285846f, -0.398245f, 0.695815f, -0.134350f, 1.176417f,+ -0.763100f, 0.921146f, -1.086352f, -0.817775f, -1.102470f, 0.001170f, 0.507649f, -0.054978f, 0.450232f,+ -0.592210f, 0.617080f, 0.403857f, -0.432531f, 1.222434f, 1.559615f, -0.062291f, 0.404500f, 0.398880f,+ 1.536813f, -0.234292f, 0.593047f, -2.950616f, -0.428368f, -1.169002f, -0.541828f, 2.567613f, -1.154758f,+ -0.634533f, -0.140984f, 0.036535f, -1.496729f, -1.238279f, 1.088208f, 0.550263f, -0.423837f, -0.623999f,+ 0.030917f, -0.230835f, 0.134047f, 1.659074f, 0.262192f, 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, 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, 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,+ });+ test_case.add_expected_output<float>(+ Shape{2, 1, 8, 16},+ {+ 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.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, 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, 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.905910f, 0.782059f, -0.423865f, -0.159969f, 0.176214f, 0.839928f, -1.408027f,+ 1.046772f, 0.541818f, -0.605575f, -1.455318f, -0.373598f, 0.717340f, 0.346120f, -0.248725f, -0.093429f,+ 0.161023f, -0.091982f, 0.271217f, 0.037239f, -0.296302f, -1.330579f, 0.013813f, -0.001792f, 0.657610f,+ -1.116430f, 0.713923f, 1.047214f, 1.064772f, -0.979413f, 1.154819f, -0.226219f, 0.678687f, -1.119538f,+ -0.908491f, 0.120748f, 0.406092f, -0.926639f, -1.632419f, 0.676705f, -1.122348f, -0.500984f, 2.005177f,+ -1.070939f, 0.219196f, 1.341610f, 0.961409f, -0.841560f, 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, 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, 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,+ });+ test_case.run_with_tolerance_as_fp();}// Plain causal GQA attention of gqa_sink_query() over an empty cache (no softcap/sink). Reference: ORT CPU EP.@@ -6597,6 +7021,289 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_softcap) {test_case.run_with_tolerance_as_fp();}+// qk_output = 1: scaled logits + attention_bias before softmax; causal and window (2) masked positions read 0.+// Expected values: ONNX Runtime CPU.+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_qk_output_before_softmax) {+ const auto model = convert_model("com.microsoft/gqa_qk_output_before_softmax.onnx");++ 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},+ {+ -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.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.209262f, -0.056373f, 0.291868f, 0.751561f,+ -0.167090f, 0.009668f, -0.572026f, 1.349849f, 0.281688f, -1.403935f, 0.912217f, 0.582467f, 0.386028f,+ 0.378876f, -0.000647f, -0.661860f, -0.254206f, 0.018261f, 0.270818f, 0.764839f, -0.086963f, 0.578093f,+ -0.559009f, 1.663371f, -0.015170f, -1.402347f, 0.940265f, 0.740097f, 0.597879f, 0.690346f, -0.304343f,+ -0.567167f, -1.416333f, 0.230501f, 1.145967f, -0.453098f, -1.218103f, -0.320617f, 0.150658f, -0.935129f,+ -0.916507f, -1.014253f, -0.483485f, 0.068703f, 1.084775f, -0.605271f, 0.106915f, 0.805040f, -0.972802f,+ 0.069830f, 0.877801f, -0.060684f, -0.934965f, -0.701049f, -0.102885f, -0.439952f, -0.258276f, -1.146274f,+ -0.039783f, 0.104749f, 0.667449f, -0.544451f, 0.333271f, 0.231408f, -1.204600f, 0.259450f, 1.150519f,+ -0.589508f, -1.373893f, -0.203722f, -0.016349f, -0.760299f, -1.309891f, -0.334629f, -0.682209f, 0.214474f,+ 0.959448f, -0.404476f, 0.167558f, 1.342210f, -1.356797f, 0.288369f, 1.209645f, -0.643833f, -1.398856f,+ -0.147246f, 0.082061f, -0.914944f, -1.360180f, -0.473603f, -0.732597f, 0.170204f, 1.084317f, -0.467966f,+ 0.101650f, 1.337812f,+ });+ test_case.add_expected_output<float>(+ Shape{1, 1, 4, 16},+ {+ 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.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.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,+ -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,+ });+ test_case.add_expected_output<float>(+ Shape{1, 1, 4, 16},+ {+ -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.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,+ -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.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,+ });+ test_case.add_expected_output<float>(+ Shape{1, 2, 4, 4},+ {+ -2.074594f, 0.000000f, 0.000000f, 0.000000f, 0.510045f, 0.448357f, 0.000000f, 0.000000f,+ 0.000000f, -1.152285f, 0.039756f, 0.000000f, 0.000000f, 0.000000f, 0.218147f, -0.774342f,+ -1.164054f, 0.000000f, 0.000000f, 0.000000f, 0.891725f, -0.030046f, 0.000000f, 0.000000f,+ 0.000000f, 0.624511f, 0.664187f, 0.000000f, 0.000000f, 0.000000f, 0.347677f, -1.017994f,+ });+ test_case.run_with_tolerance_as_fp();+}++// qk_output = 1 with an attention_bias holding -3e38 on one visible and one out-of-window key: the visible one is+// reported as logit + bias, the out-of-window one as 0, as in ORT (masked positions come from the bias-free mask).+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_qk_output_before_softmax_neg_bias) {+ const auto model = convert_model("com.microsoft/gqa_qk_output_before_softmax_neg_bias.onnx");++ 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},+ {+ -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.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.209262f, -0.056373f, 0.291868f, 0.751561f,+ -0.167090f, 0.009668f, -0.572026f, 1.349849f, 0.281688f, -1.403935f, 0.912217f, 0.582467f, 0.386028f,+ 0.378876f, -0.000647f, -0.661860f, -0.254206f, 0.018261f, 0.270818f, 0.764839f, -0.086963f, 0.578093f,+ -0.559009f, 1.663371f, -0.015170f, -1.402347f, 0.940265f, 0.740097f, 0.597879f, 0.690346f, -0.304343f,+ -0.567167f, -1.416333f, 0.230501f, 1.145967f, -0.453098f, -1.218103f, -0.320617f, 0.150658f, -0.935129f,+ -0.916507f, -1.014253f, -0.483485f, 0.068703f, 1.084775f, -0.605271f, 0.106915f, 0.805040f, -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, -1.204600f, 0.259450f, 1.150519f,+ -0.589508f, -1.373893f, -0.203722f, -0.016349f, -0.760299f, -1.309891f, -0.334629f, -0.682209f, 0.214474f,+ 0.959448f, -0.404476f, 0.167558f, 1.342210f, -1.356797f, 0.288369f, 1.209645f, -0.643833f, -1.398856f,+ -0.147246f, 0.082061f, -0.914944f, -1.360180f, -0.473603f, -0.732597f, 0.170204f, 1.084317f, -0.467966f,+ 0.101650f, 1.337812f,+ });+ test_case.add_expected_output<float>(+ Shape{1, 1, 4, 16},+ {+ 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.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.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,+ -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,+ });+ test_case.add_expected_output<float>(+ Shape{1, 1, 4, 16},+ {+ -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.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,+ -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.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,+ });+ test_case.add_expected_output<float>(+ Shape{1, 2, 4, 4},+ {+ -2.074594f, 0.000000f, 0.000000f, 0.000000f, 0.510045f, 0.448357f, 0.000000f, 0.000000f,+ 0.000000f, -1.152285f, 0.039756f, 0.000000f, 0.000000f, 0.000000f, 0.218147f, -0.774342f,+ -1.164054f, 0.000000f, 0.000000f, 0.000000f, 0.891725f, -0.030046f, 0.000000f, 0.000000f,+ 0.000000f, 0.624511f, -3e+38f, 0.000000f, 0.000000f, 0.000000f, 0.347677f, -1.017994f,+ });+ test_case.run_with_tolerance_as_fp();+}++// qk_output = 2: probabilities after softcap and head_sink renormalization (sink column not emitted).+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_qk_output_after_softmax) {+ const auto model = convert_model("com.microsoft/gqa_qk_output_after_softmax.onnx");++ 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},+ {+ -0.159478f, 0.062391f, 0.120731f, 0.392842f, 0.013566f, 0.695231f, -0.270914f, 1.057394f, -0.219357f,+ -0.701785f, 0.491310f, 0.483408f, 0.450799f, 0.568207f, -0.369181f, -0.216743f, -0.072252f, 0.028266f,+ 0.054697f, 0.177978f, 0.006146f, 0.314976f, -0.122738f, 0.479054f, -0.099380f, -0.317945f, 0.222589f,+ 0.219009f, 0.204235f, 0.257427f, -0.167258f, -0.098196f, -0.174354f, -0.027666f, 0.224546f, 0.593224f,+ -0.113400f, 0.134085f, -0.446367f, 1.129927f, 0.155175f, -1.102283f, 0.722688f, 0.492542f, 0.350326f,+ 0.366877f, -0.068090f, -0.498747f, -0.105900f, -0.050938f, 0.169338f, 0.418610f, -0.114531f, -0.141426f,+ -0.324585f, 0.677011f, 0.234877f, -0.788792f, 0.505011f, 0.286362f, 0.162042f, 0.132289f, 0.078097f,+ -0.396133f, -0.692266f, 0.110394f, 0.580308f, 0.121418f, -0.530093f, 0.159004f, -0.160985f, 0.314506f,+ -0.415873f, -0.982554f, 0.180885f, 0.342207f, 0.710706f, 0.059665f, -0.109749f, 0.114737f, -0.465036f,+ 0.033284f, 0.426486f, 0.098667f, -0.421382f, -0.211440f, -0.136247f, 0.080105f, -0.114512f, -0.728426f,+ 0.136441f, 0.166442f, 0.388081f, -0.124545f, 0.095733f, 0.007842f, -0.623679f, 0.103972f, 0.659629f,+ 0.006331f, -0.734335f, -0.072149f, -0.259656f, 0.209979f, -0.558327f, -0.631471f, 0.019062f, 0.355666f,+ 0.592014f, -0.009176f, 0.084373f, 0.438321f, -0.472317f, 0.089116f, 0.469275f, 0.064900f, -0.485942f,+ 0.114330f, -0.202309f, 0.315352f, -0.433908f, -0.569111f, 0.092302f, 0.322165f, 0.506522f, 0.099116f,+ -0.036655f, 0.256701f,+ });+ test_case.add_expected_output<float>(+ Shape{1, 1, 4, 16},+ {+ 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.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.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,+ -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,+ });+ test_case.add_expected_output<float>(+ Shape{1, 1, 4, 16},+ {+ -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.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,+ -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.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,+ });+ test_case.add_expected_output<float>(+ Shape{1, 2, 4, 4},+ {+ 0.501244f, 0.000000f, 0.000000f, 0.000000f, 0.449307f, 0.336084f, 0.000000f, 0.000000f,+ 0.308301f, 0.189777f, 0.317082f, 0.000000f, 0.208664f, 0.162241f, 0.338649f, 0.163298f,+ 0.227089f, 0.000000f, 0.000000f, 0.000000f, 0.237766f, 0.323785f, 0.000000f, 0.000000f,+ 0.116741f, 0.260192f, 0.221997f, 0.000000f, 0.237749f, 0.097726f, 0.237058f, 0.096443f,+ });+ test_case.run_with_tolerance_as_fp();+}++namespace {+// Preallocated cache (capacity 8) decode with seqlens_k = 4: output_qk has total_sequence_length columns (ORT), while+// seqlens_k alone drives the attention and the cache update.+void run_gqa_qk_output_static_cache(int total, const std::vector<float>& expected_qk) {+ const auto model = convert_model("com.microsoft/gqa_qk_output_static_cache.onnx");++ // Zero-initialized buffer holding 4 past rows; rows beyond total are unspecified in ORT.+ const auto data = gqa_sink_query();+ std::vector<float> past_key(data.begin(), data.begin() + 64), past_value(data.begin() + 128, data.begin() + 192);+ past_key.resize(128, 0.0f);+ past_value.resize(128, 0.0f);+ auto test_case = ov::test::TestCase(model, s_device);+ test_case.add_input<float>(Shape{1, 1, 64}, std::vector<float>(data.begin() + 192, data.end()));+ test_case.add_input<float>(Shape{1, 1, 8, 16}, past_key);+ test_case.add_input<float>(Shape{1, 1, 8, 16}, past_value);+ test_case.add_input<int>(Shape{1, 1}, {4});+ test_case.add_input<int>(Shape{}, {total});+ test_case.add_expected_output<float>(+ Shape{1, 1, 32},+ {+ 0.094738f, -0.258927f, -0.917125f, 0.443725f, -0.960666f, -0.096329f, 0.024586f, -0.527302f,+ 0.470633f, -0.572888f, 0.219602f, 0.154630f, -0.891648f, -0.760925f, 0.519642f, 0.463938f,+ 0.020994f, -0.306558f, 0.323556f, -0.373009f, -0.879975f, 0.287862f, 0.804064f, -0.127611f,+ -0.207956f, -0.208519f, 0.427498f, 0.897348f, -0.206569f, -0.275854f, 0.160090f, 0.182464f,+ });+ test_case.add_expected_output<float>(+ Shape{1, 1, 8, 16},+ {+ -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.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.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, 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,+ });+ test_case.add_expected_output<float>(+ Shape{1, 1, 8, 16},+ {+ 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.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, 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, 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,+ });+ test_case.add_expected_output<float>(Shape{1, 2, 1, static_cast<size_t>(total)}, expected_qk);+ test_case.run_with_tolerance_as_fp();+}+} // namespace++OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_qk_output_static_cache) {+ run_gqa_qk_output_static_cache(5,+ {-0.290551f,+ 1.084145f,+ -0.004623f,+ -2.390336f,+ -0.274342f,+ 1.730582f,+ -0.621596f,+ 0.607299f,+ 0.223935f,+ -1.017994f});+}++// total_sequence_length (4) below seqlens_k + 1 (5): output_qk keeps 4 columns, the attention still sees 5 keys.+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_qk_output_static_cache_total_below_seqlens) {+ run_gqa_qk_output_static_cache(+ 4,+ {-0.290551f, 1.084145f, -0.004623f, -2.390336f, 1.730582f, -0.621596f, 0.607299f, 0.223935f});+}+// softcap in f16: the capped chain runs in reduced precision, incl. the finite-lowest() mask clamp.OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_softcap_fp16) {ov::frontend::FrontEnd::Ptr front_end;diff --git a/src/frontends/onnx/tests/runtime/ie/unit_test.manifest b/src/frontends/onnx/tests/runtime/ie/unit_test.manifestindex 8a1e0e8faa6..1430ebfed85 100644--- a/src/frontends/onnx/tests/runtime/ie/unit_test.manifest+++ b/src/frontends/onnx/tests/runtime/ie/unit_test.manifest@@ -414,3 +414,7 @@ IE_CPU.onnx_model_dft_inverse_length_provided_onesidedIE_GPU.onnx_model_max_unpool_2d_opset9IE_GPU.onnx_model_max_unpool_2d_opset22IE_GPU.onnx_model_max_unpool++# GPU: a fully static model cannot produce the runtime-sized (total_sequence_length) GQA output_qk+IE_GPU.onnx_model_gqa_qk_output_static_cache+IE_GPU.onnx_model_gqa_qk_output_static_cache_total_below_seqlensdiff --git a/src/plugins/intel_gpu/src/graph/impls/cpu/shape_of.cpp b/src/plugins/intel_gpu/src/graph/impls/cpu/shape_of.cppindex 26680dd50af..f6855fa2104 100644--- a/src/plugins/intel_gpu/src/graph/impls/cpu/shape_of.cpp+++ b/src/plugins/intel_gpu/src/graph/impls/cpu/shape_of.cpp@@ -99,6 +99,8 @@ attach_shape_of_impl::attach_shape_of_impl() {data_types::i8,data_types::i32,data_types::i64,+ data_types::f8e4m3,+ data_types::f8e5m2,};implementation_map<shape_of>::add(impl_types::cpu, shape_types::static_shape, shape_of_impl::create, types, formats);diff --git a/src/plugins/intel_gpu/src/plugin/transformations/group_query_attention_decomposition.cpp b/src/plugins/intel_gpu/src/plugin/transformations/group_query_attention_decomposition.cppindex 589928ba05c..77d66b23254 100644--- a/src/plugins/intel_gpu/src/plugin/transformations/group_query_attention_decomposition.cpp+++ b/src/plugins/intel_gpu/src/plugin/transformations/group_query_attention_decomposition.cpp@@ -12,6 +12,7 @@#include "openvino/op/convert.hpp"#include "openvino/op/group_query_attention.hpp"#include "openvino/op/shape_of.hpp"+#include "ov_ops/rms.hpp"namespace {@@ -42,6 +43,10 @@ std::vector<uint64_t> compute_kv_group_sizes(const ov::PartialShape& data_shape,namespace ov::intel_gpu {+ov::Output<ov::Node> GroupQueryAttentionDecomposition::make_qk_norm(const ov::Output<ov::Node>& input, const ov::Output<ov::Node>& weight, float epsilon) {+ return register_new_node<ov::op::internal::RMS>(input, weight, epsilon, input.get_element_type());+}+std::optional<GroupQueryAttentionDecomposition::CompressedKV> GroupQueryAttentionDecomposition::prepare_compressed_kv(const std::shared_ptr<ov::op::internal::GroupQueryAttention>& node,const ov::Output<ov::Node>& key,diff --git a/src/plugins/intel_gpu/src/plugin/transformations/group_query_attention_decomposition.hpp b/src/plugins/intel_gpu/src/plugin/transformations/group_query_attention_decomposition.hppindex d7b1b5f9a39..04698137a8f 100644--- a/src/plugins/intel_gpu/src/plugin/transformations/group_query_attention_decomposition.hpp+++ b/src/plugins/intel_gpu/src/plugin/transformations/group_query_attention_decomposition.hpp@@ -36,6 +36,8 @@ protected:bool sliding_window_cache,float scale,bool has_sink) override;+ // RMSFusion runs before this pass on GPU, so QK-Norm is emitted as the fused RMS op directly.+ ov::Output<ov::Node> make_qk_norm(const ov::Output<ov::Node>& input, const ov::Output<ov::Node>& weight, float epsilon) override;std::optional<CompressedKV> prepare_compressed_kv(const std::shared_ptr<ov::op::internal::GroupQueryAttention>& node,const ov::Output<ov::Node>& key,diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/shape_of_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/shape_of_gpu_test.cppindex b5df8693d98..0cde5f262b9 100644--- a/src/plugins/intel_gpu/tests/unit/test_cases/shape_of_gpu_test.cpp+++ b/src/plugins/intel_gpu/tests/unit/test_cases/shape_of_gpu_test.cpp@@ -69,11 +69,11 @@ TEST(shape_of_gpu, bfyx_i64) {}}-void shape_of_cpu_impl_bfyx_i64(bool disable_usm = false);-void shape_of_cpu_impl_bfyx_i64(bool disable_usm) {+void shape_of_cpu_impl_bfyx_i64(bool disable_usm = false, data_types input_type = data_types::f32);+void shape_of_cpu_impl_bfyx_i64(bool disable_usm, data_types input_type) {auto engine = create_test_engine(engine_types::ocl, runtime_types::ocl, !disable_usm);- auto input = engine->allocate_memory({data_types::f32, format::bfyx, tensor{1, 2, 3, 3}});+ auto input = engine->allocate_memory({input_type, format::bfyx, tensor{1, 2, 3, 3}});topology topology;topology.add(input_layout("input", input->get_layout()));@@ -106,6 +106,15 @@ TEST(shape_of_cpu_impl, bfyx_i64_disable_usm) {shape_of_cpu_impl_bfyx_i64(true);}+// ShapeOf only reads dims, so f8 inputs (e.g. f8 KV caches) are accepted.+TEST(shape_of_cpu_impl, bfyx_f8e4m3_input) {+ shape_of_cpu_impl_bfyx_i64(false, data_types::f8e4m3);+}++TEST(shape_of_cpu_impl, bfyx_f8e5m2_input) {+ shape_of_cpu_impl_bfyx_i64(false, data_types::f8e5m2);+}+TEST(shape_of_gpu, yxfb) {auto& engine = get_test_engine();