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: causal attention support + partial rotary embedding, and KV-cache safety fixes (#37653)
Ankit Maheshkar618daa8eb0a3
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 62bdfd66434..b917d46e4cb 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@@ -38,14 +38,18 @@ private:const ov::Output<ov::Node>& capacity_scalar,int64_t local_window_size);- // Additive float attention mask for SDPA: causal mask, plus an optional sliding-window band- // (local_window_size >= 0) masking keys older than the window, optionally fused with an external bias.- // Masked positions use the compute type's finite lowest() so a fully-masked row cannot softmax to NaN.+ // Additive float attention mask for SDPA. When causal is true: causal mask, plus an optional sliding-window+ // band (local_window_size >= 1) masking keys older than the window. When causal is false (bidirectional):+ // no query-relative masking; only the unused cache tail beyond total_sequence_length (past + current) is+ // masked (local_window_size is always -1 in this case, enforced upstream). Either way the result is+ // optionally fused with an external bias. Masked positions use the compute type's finite lowest() so a+ // fully-masked row cannot softmax to NaN.std::shared_ptr<ov::Node> make_attention_mask(const ov::Output<ov::Node>& curr_seqlen_scalar,const ov::Output<ov::Node>& kv_len_scalar,const ov::Output<ov::Node>& kv_len_1d,const ov::Output<ov::Node>& past_seqlen,const ov::element::Type& compute_type,+ bool causal,int64_t local_window_size,const ov::Output<ov::Node>& external_bias,const ov::Output<ov::Node>& bias_col_offset);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 51b7427bc47..571b91164e4 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@@ -28,6 +28,7 @@#include "openvino/op/greater_eq.hpp"#include "openvino/op/logical_or.hpp"#include "openvino/op/maximum.hpp"+#include "openvino/op/minimum.hpp"#include "openvino/op/multiply.hpp"#include "openvino/op/pad.hpp"#include "openvino/op/power.hpp"@@ -89,6 +90,7 @@ ov::OutputVector ov::pass::GroupQueryAttentionDecomposition::decompose(const auto rotary_interleaved = node->get_rotary_interleaved();const auto local_window_size = node->get_local_window_size();const auto smooth_softmax = node->get_smooth_softmax();+ const auto causal = node->get_causal();// TODO: add softcap supportconst auto has_input = [&](const GQAInputs input_pos) {@@ -273,9 +275,24 @@ ov::OutputVector ov::pass::GroupQueryAttentionDecomposition::decompose(} 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.+ // past_seqlen is a runtime value (derived from seqlens_k) and cannot be bounded at trace time, so a+ // caller that overruns the declared cache capacity would otherwise scatter past the end of the C+ // buffer. C and curr_seqlen are both statically known here (is_static_input), so clamp past_seqlen to+ // the largest value that keeps the whole write in bounds. Measured what an unclamped ScatterUpdate+ // actually does on an overrun (PR #37653 review, sgbihu): CPU throws cleanly ("indices value that+ // points to non-existing output tensor element"), but GPU hits an unhandled SEH access violation+ // (0xc0000005) - a process crash, not a graceful error. The clamp trades a caller's mis-sized+ // seqlens_k for a silently-truncated write instead of a device-dependent crash. ORT enforces the+ // same bound with an explicit runtime check (group_query_attention.cc:336-345); OV has no+ // graph-level assert primitive to replicate that hard-stop, so clamping is the safe substitute.+ const int64_t capacity = past_key.get_partial_shape()[2].get_length();+ const int64_t curr_len = K.get_partial_shape()[2].get_length();+ const auto max_past_seqlen =+ register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{1}, {capacity - curr_len}));+ const auto clamped_past_seqlen = register_new_node<v1::Minimum>(past_seqlen, max_past_seqlen);std::shared_ptr<ov::Node> scatter_idx =register_new_node<v4::Range>(zero_without_shape, curr_seqlen_scalar, one_without_shape, ov::element::i64);- scatter_idx = register_new_node<v1::Add>(scatter_idx, past_seqlen);+ scatter_idx = register_new_node<v1::Add>(scatter_idx, clamped_past_seqlen);const auto scatter_axis = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{1}, {2}));K = register_new_node<v3::ScatterUpdate>(past_key, scatter_idx, K, scatter_axis);V = register_new_node<v3::ScatterUpdate>(past_value, scatter_idx, V, scatter_axis);@@ -330,6 +347,7 @@ ov::OutputVector ov::pass::GroupQueryAttentionDecomposition::decompose(concat_kv_len,mask_past_seqlen,T,+ causal,local_window_size,external_bias,bias_col_offset);@@ -414,38 +432,55 @@ std::shared_ptr<ov::Node> ov::pass::GroupQueryAttentionDecomposition::make_attenconst ov::Output<ov::Node>& kv_len_1d,const ov::Output<ov::Node>& past_seqlen,const ov::element::Type& compute_type,+ bool causal,int64_t local_window_size,const ov::Output<ov::Node>& external_bias,const ov::Output<ov::Node>& bias_col_offset) {const bool has_bias = external_bias.get_node_shared_ptr() != nullptr;// A window is active for local_window_size >= 1; -1 disables it and 0 is rejected upstream (FE + op).+ // A window is only ever paired with causal=1 (enforced upstream by the FE and the op), so it is only+ // considered on the causal branch below.const bool has_window = local_window_size >= 1;const auto zero = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{1}, {0}));const auto one = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{1}, {1}));const auto two = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{1}, {2}));- // Key positions [1, kv_len] and absolute query positions [curr, 1]. Coordinates are cache-relative- // (past_seqlen is the resident past length), which matches the distance-only ONNX Runtime rule.+ // Key positions [1, kv_len]. Coordinates are cache-relative (past_seqlen is the resident past length),+ // which matches the distance-only ONNX Runtime rule.const auto zero_scalar = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{}, {0}));const auto one_scalar = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{}, {1}));std::shared_ptr<ov::Node> hori_range =register_new_node<v4::Range>(zero_scalar, kv_len_scalar, one_scalar, ov::element::i64);hori_range = register_new_node<v0::Unsqueeze>(hori_range, zero);- std::shared_ptr<ov::Node> vert_range =- register_new_node<v4::Range>(zero_scalar, curr_seqlen_scalar, one_scalar, ov::element::i64);- vert_range = register_new_node<v0::Unsqueeze>(vert_range, one);- vert_range = register_new_node<v1::Add>(vert_range, past_seqlen);-- // Causal mask (future keys: k > q), OR-ed with the optional sliding-window band (keys older than the- // window: (q - k) >= local_window_size). This is applied unconditionally; an external attention_bias- // is added on top of it, matching ONNX Runtime (the bias does not replace the causal/window mask).- std::shared_ptr<ov::Node> masked = register_new_node<v1::Greater>(hori_range, vert_range);- if (has_window) {- const auto distance = register_new_node<v1::Subtract>(vert_range, hori_range);- const auto window = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{}, {local_window_size}));- const auto too_old = register_new_node<v1::GreaterEqual>(distance, window);- masked = register_new_node<v1::LogicalOr>(masked, too_old);++ std::shared_ptr<ov::Node> masked;+ if (causal) {+ // Absolute query positions [curr, 1]. Causal mask (future keys: k > q), OR-ed with the optional+ // sliding-window band (keys older than the window: (q - k) >= local_window_size). This is applied+ // unconditionally; an external attention_bias is added on top of it, matching ONNX Runtime (the bias+ // does not replace the causal/window mask).+ std::shared_ptr<ov::Node> vert_range =+ register_new_node<v4::Range>(zero_scalar, curr_seqlen_scalar, one_scalar, ov::element::i64);+ vert_range = register_new_node<v0::Unsqueeze>(vert_range, one);+ vert_range = register_new_node<v1::Add>(vert_range, past_seqlen);++ masked = register_new_node<v1::Greater>(hori_range, vert_range);+ if (has_window) {+ const auto distance = register_new_node<v1::Subtract>(vert_range, hori_range);+ const auto window =+ register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{}, {local_window_size}));+ const auto too_old = register_new_node<v1::GreaterEqual>(distance, window);+ masked = register_new_node<v1::LogicalOr>(masked, too_old);+ }+ } else {+ // Bidirectional attention: every query attends to all valid keys. Only the unused cache tail beyond+ // total_sequence_length (past + current) is masked, matching ONNX Runtime's visible_length ==+ // total_seqlen for causal=0. The mask does not depend on the query row, so it broadcasts as [1, kv_len]+ // instead of materializing a full [curr, kv_len] tensor.+ const auto past_scalar = register_new_node<v0::Squeeze>(past_seqlen);+ const auto total_scalar = register_new_node<v1::Add>(past_scalar, curr_seqlen_scalar);+ masked = register_new_node<v1::GreaterEqual>(hori_range, total_scalar);}const auto typed_zero = register_new_node(v0::Constant::create(compute_type, ov::Shape{}, {0}));@@ -513,28 +548,52 @@ std::shared_ptr<ov::Node> ov::pass::GroupQueryAttentionDecomposition::rotaryEmbebool interleaved) {auto two = v0::Constant::create(ov::element::i64, ov::Shape{1}, {2});+ // rotary_dim (2 * cos.shape[-1]) may be smaller than head_size for GPT-NeoX/Phi-style partial RoPE:+ // only the leading rotary_dim channels are rotated below; the trailing channels pass through+ // unchanged. The op-level validate_and_infer_types() already bounds rotary_dim <= head_size.+ const auto& cos_partial_shape = cos.get_partial_shape();+ const auto half_head_size_val =+ static_cast<int64_t>(cos_partial_shape[cos_partial_shape.rank().get_length() - 1].get_length());+ const auto rotary_dim_val = 2 * half_head_size_val;+ const auto& input_partial_shape = input.get_partial_shape();+ const auto head_size_val =+ static_cast<int64_t>(input_partial_shape[input_partial_shape.rank().get_length() - 1].get_length());+ const bool is_partial_rotary = rotary_dim_val < head_size_val;++ ov::Output<ov::Node> rotary_input = input;+ if (is_partial_rotary) {+ // Slice out only the leading rotary_dim channels to feed the RoPE math below; the trailing+ // pass-through channels are never materialized as a separate tensor - re-attaching them later is a+ // ScatterUpdate into the original `input`, not a Concat (avoids holding a live pass_through copy).+ const auto slice_start = v0::Constant::create(ov::element::i64, ov::Shape{1}, {0});+ const auto slice_stop = v0::Constant::create(ov::element::i64, ov::Shape{1}, {rotary_dim_val});+ const auto slice_step = v0::Constant::create(ov::element::i64, ov::Shape{1}, {1});+ const auto slice_axis = v0::Constant::create(ov::element::i64, ov::Shape{1}, {-1});+ rotary_input = register_new_node<v8::Slice>(input, slice_start, slice_stop, slice_step, slice_axis);+ }+// Unsqueeze cos/sin to 4D [1, 1, seqlen, head_size/2] to match RoPE fusion patternauto unsqueeze_axes = 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);// For interleaved mode, deinterleave first so the core RoPE formula is identical- ov::Output<ov::Node> rope_input = input;+ ov::Output<ov::Node> rope_input = rotary_input;std::shared_ptr<v3::ShapeOf> input_shape;std::shared_ptr<ov::Node> dim_bns, half_head_size;std::shared_ptr<v0::Constant> perm_5d;if (interleaved) {- input_shape = register_new_node<v3::ShapeOf>(input);+ input_shape = register_new_node<v3::ShapeOf>(rotary_input);dim_bns = get_dimensions(input_shape, {0, 1, 2});half_head_size = get_dimensions(cos.get_node_shared_ptr(), {-1});perm_5d = v0::Constant::create(ov::element::i64, ov::Shape{5}, {0, 1, 2, 4, 3});- // Deinterleave: [bs,nh,seq,head_size]- // -> reshape [bs,nh,seq,head_size/2,2]- // -> transpose [bs,nh,seq,2,head_size/2]- // -> reshape [bs,nh,seq,head_size] (now [first_half, second_half])+ // Deinterleave: [bs,nh,seq,rotary_dim]+ // -> reshape [bs,nh,seq,rotary_dim/2,2]+ // -> transpose [bs,nh,seq,2,rotary_dim/2]+ // -> reshape [bs,nh,seq,rotary_dim] (now [first_half, second_half])auto deinterleave_5d = register_new_node<v0::Concat>(ov::NodeVector{dim_bns, half_head_size, two}, 0);- auto reshaped_5d = register_new_node<v1::Reshape>(input, deinterleave_5d, false);+ auto reshaped_5d = register_new_node<v1::Reshape>(rotary_input, deinterleave_5d, false);auto transposed_5d = register_new_node<v1::Transpose>(reshaped_5d, perm_5d);rope_input = register_new_node<v1::Reshape>(transposed_5d, input_shape, false);}@@ -542,9 +601,6 @@ std::shared_ptr<ov::Node> ov::pass::GroupQueryAttentionDecomposition::rotaryEmbe// Core RoPE formula (matches RoPEFusionGPTOSS pattern for both modes)// first_ = first_half * cos - second_half * sin// second_ = second_half * cos + first_half * sin- const auto& cos_partial_shape = cos.get_partial_shape();- const auto half_head_size_val =- static_cast<int64_t>(cos_partial_shape[cos_partial_shape.rank().get_length() - 1].get_length());const auto split_axis = v0::Constant::create(ov::element::i64, ov::Shape{}, {-1});const auto split_lengths =v0::Constant::create(ov::element::i64, ov::Shape{2}, {half_head_size_val, half_head_size_val});@@ -562,16 +618,27 @@ std::shared_ptr<ov::Node> ov::pass::GroupQueryAttentionDecomposition::rotaryEmbe// For interleaved mode, re-interleave the resultif (interleaved) {- // Re-interleave: [bs,nh,seq,head_size]- // -> reshape [bs,nh,seq,2,head_size/2]- // -> transpose [bs,nh,seq,head_size/2,2]- // -> reshape [bs,nh,seq,head_size]+ // Re-interleave: [bs,nh,seq,rotary_dim]+ // -> reshape [bs,nh,seq,2,rotary_dim/2]+ // -> transpose [bs,nh,seq,rotary_dim/2,2]+ // -> reshape [bs,nh,seq,rotary_dim]auto reinterleave_5d = register_new_node<v0::Concat>(ov::NodeVector{dim_bns, two, half_head_size}, 0);auto result_5d = register_new_node<v1::Reshape>(output, reinterleave_5d, false);auto result_transposed = register_new_node<v1::Transpose>(result_5d, perm_5d);output = register_new_node<v1::Reshape>(result_transposed, input_shape, false);}+ if (is_partial_rotary) {+ // Scatter the rotated channels back into `input` at [0, rotary_dim); channels beyond rotary_dim+ // are left untouched since they were never sliced out.+ const auto zero_s = v0::Constant::create(ov::element::i64, ov::Shape{}, {0});+ const auto one_s = v0::Constant::create(ov::element::i64, ov::Shape{}, {1});+ const auto rotary_dim_scalar = v0::Constant::create(ov::element::i64, ov::Shape{}, {rotary_dim_val});+ const auto scatter_indices = register_new_node<v4::Range>(zero_s, rotary_dim_scalar, one_s, ov::element::i64);+ const auto scatter_axis = v0::Constant::create(ov::element::i64, ov::Shape{1}, {-1});+ output = register_new_node<v3::ScatterUpdate>(input, scatter_indices, output, scatter_axis);+ }+return output.get_node_shared_ptr();}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 7133165791b..8eb316956cd 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@@ -14,10 +14,13 @@#include "common_test_utils/test_assertions.hpp"#include "openvino/core/except.hpp"#include "openvino/core/model.hpp"+#include "openvino/op/add.hpp"#include "openvino/op/broadcast.hpp"#include "openvino/op/constant.hpp"+#include "openvino/op/greater.hpp"#include "openvino/op/greater_eq.hpp"#include "openvino/op/group_query_attention.hpp"+#include "openvino/op/minimum.hpp"#include "openvino/op/parameter.hpp"#include "openvino/op/reshape.hpp"#include "openvino/op/result.hpp"@@ -48,12 +51,14 @@ struct GqaParams {std::string name;bool do_rotary = false;bool rotary_interleaved = false;+ int64_t rotary_dim = HEAD_SIZE;int64_t kv_cache_bit_width = 0;element::Type kv_type = element::f32;int64_t local_window_size = -1;bool sliding_window_cache = false;bool smooth_softmax = false;bool head_sink = false;+ bool causal = true;bool attention_bias = false;Dimension bias_kv_len = Dimension::dynamic();Dimension past_len = Dimension::dynamic();@@ -63,9 +68,10 @@ struct GqaParams {bool expects_scatter_update = false;explicit GqaParams(std::string n) : name(std::move(n)) {}- GqaParams& rotary(bool interleaved = false) {+ GqaParams& rotary(bool interleaved = false, int64_t dim = HEAD_SIZE) {do_rotary = true;rotary_interleaved = interleaved;+ rotary_dim = dim;return *this;}GqaParams& quant(int64_t bits, element::Type t) {@@ -94,6 +100,10 @@ struct GqaParams {expected_sdpa_inputs = 6;return *this;}+ GqaParams& bidirectional() {+ causal = false;+ return *this;+ }// kv_len lets a case declare the bias narrower than the buffer it will be added against (e.g. a// static preallocated cache wider than total_sequence_length), reproducing a kv_len/bias-width mismatch.GqaParams& bias(const Dimension& kv_len = Dimension::dynamic()) {@@ -137,8 +147,8 @@ std::shared_ptr<Model> make_gqa_model(const GqaParams& p) {add(element::i32, PartialShape{1}); // 5: seqlens_kadd(element::i32, PartialShape{}); // 6: total_sequence_lengthif (p.do_rotary) {- add(f32, PartialShape{1, HEAD_SIZE / 2}); // 7: cos_cache- add(f32, PartialShape{1, HEAD_SIZE / 2}); // 8: sin_cache+ add(f32, PartialShape{1, p.rotary_dim / 2}); // 7: cos_cache+ add(f32, PartialShape{1, p.rotary_dim / 2}); // 8: sin_cache}if (p.attention_bias) {pad_to(10);@@ -165,7 +175,8 @@ std::shared_ptr<Model> make_gqa_model(const GqaParams& p) {quant,p.local_window_size,p.sliding_window_cache,- p.smooth_softmax);+ p.smooth_softmax,+ p.causal);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)));@@ -178,7 +189,8 @@ std::shared_ptr<GroupQueryAttention> make_gqa_op(const Dimension& batch,const Dimension& seq,const Dimension& past,int64_t local_window_size,- bool sliding_window_cache) {+ bool sliding_window_cache,+ bool causal = true) {const auto f32 = element::f32;auto q = std::make_shared<op::v0::Parameter>(f32, PartialShape{batch, NUM_HEADS, seq, HEAD_SIZE});auto k = std::make_shared<op::v0::Parameter>(f32, PartialShape{batch, KV_NUM_HEADS, seq, HEAD_SIZE});@@ -199,7 +211,8 @@ std::shared_ptr<GroupQueryAttention> make_gqa_op(const Dimension& batch,op::internal::GroupQueryAttentionQuantType::NONE,local_window_size,sliding_window_cache,- /*smooth_softmax*/ false);+ /*smooth_softmax*/ false,+ causal);}} // namespace@@ -224,8 +237,20 @@ TEST_P(GroupQueryAttentionDecompositionTest, decomposes_to_sdpa) {}}- // The windowed rolling cache assembles the present buffer with ScatterUpdate; other paths do not.- EXPECT_EQ(count_ops_of_type<op::v3::ScatterUpdate>(model) > 0u, p.expects_scatter_update);+ // The windowed rolling / static-cache paths assemble the present buffer with a ScatterUpdate along the+ // sequence axis (2); other cache paths do not. (Partial rotary also emits an unrelated ScatterUpdate to+ // re-attach pass-through channels along the last (channel) axis - filter cache writes by scatter axis.)+ bool has_cache_scatter_update = false;+ for (const auto& op : model->get_ordered_ops()) {+ if (auto su = as_type_ptr<op::v3::ScatterUpdate>(op)) {+ auto axis_const = as_type_ptr<op::v0::Constant>(su->get_input_node_shared_ptr(3));+ if (axis_const && axis_const->cast_vector<int64_t>() == std::vector<int64_t>{2}) {+ has_cache_scatter_update = true;+ break;+ }+ }+ }+ EXPECT_EQ(has_cache_scatter_update, p.expects_scatter_update);}INSTANTIATE_TEST_SUITE_P(GroupQueryAttentionDecomposition,@@ -234,6 +259,9 @@ INSTANTIATE_TEST_SUITE_P(GroupQueryAttentionDecomposition,GqaParams{"prefill"}.shape(4, Dimension::dynamic()),GqaParams{"rotary"}.rotary(),GqaParams{"rotary_interleaved"}.rotary(/*interleaved*/ true),+ GqaParams{"partial_rotary"}.rotary(/*interleaved*/ false, HEAD_SIZE / 2),+ GqaParams{"partial_rotary_interleaved"}.rotary(/*interleaved*/ true,+ HEAD_SIZE / 2),GqaParams{"static_past_scatter"}.shape(1, 8),GqaParams{"static_past_scatter_bias"}.shape(1, 8).bias(5),GqaParams{"sliding_window"}.window(2),@@ -244,7 +272,8 @@ INSTANTIATE_TEST_SUITE_P(GroupQueryAttentionDecomposition,GqaParams{"i8_per_tensor"}.quant(8, element::i8),GqaParams{"i4_per_tensor"}.quant(4, element::u8),GqaParams{"f8e4m3_per_tensor"}.quant(8, element::f8e4m3),- GqaParams{"windowed_cache"}.windowed_roll(3, 4)),+ GqaParams{"windowed_cache"}.windowed_roll(3, 4),+ GqaParams{"bidirectional"}.bidirectional()),[](const testing::TestParamInfo<GqaParams>& i) {return i.param.name;});@@ -294,6 +323,19 @@ TEST(GroupQueryAttentionOpValidation, allows_dynamic_batch) {EXPECT_NO_THROW(make_gqa_op(Dimension::dynamic(), 1, 8, /*window*/ -1, /*swc*/ false));}+TEST(GroupQueryAttentionOpValidation, rejects_local_window_size_with_causal_false) {+ // causal=0 (bidirectional) is mutually exclusive with a sliding window, matching ONNX Runtime+ // (gqa_attention_base.h: causal_ || local_window_size_ == -1).+ OV_EXPECT_THROW(make_gqa_op(1, 1, 8, /*window*/ 2, /*swc*/ false, /*causal*/ false),+ ov::NodeValidationFailure,+ testing::HasSubstr("local_window_size requires causal=1"));+}++TEST(GroupQueryAttentionOpValidation, allows_bidirectional_without_window) {+ // causal=0 with the window disabled (the only combination the FE ever produces) must construct cleanly.+ EXPECT_NO_THROW(make_gqa_op(1, 4, 8, /*window*/ -1, /*swc*/ false, /*causal*/ false));+}+// --- Decomposed constant values -------------------------------------------------------------------// The structural TEST_P above checks topology only; a wrong window boundary or a wrong sink value would// still pass it. These assert the actual constants the decomposition emits for those two features.@@ -330,6 +372,38 @@ TEST(GroupQueryAttentionValues, sliding_window_boundary_uses_window_size_constanEXPECT_EQ(window_const->cast_vector<int64_t>(), std::vector<int64_t>{W});}+TEST(GroupQueryAttentionValues, static_cache_scatter_index_clamped_to_capacity) {+ // capacity (past_len) = 8, curr_seqlen = 1 -> max valid past_seqlen = capacity - curr_seqlen = 7. A+ // caller-supplied seqlens_k implying a larger past_seqlen must not push the ScatterUpdate write past+ // the end of the static full-length cache buffer (G10: unguarded static-cache overflow).+ auto model = make_gqa_model(GqaParams{"static_scatter"}.shape(1, 8));+ decompose(model);++ std::shared_ptr<op::v3::ScatterUpdate> cache_scatter;+ for (const auto& op : model->get_ordered_ops()) {+ if (auto su = as_type_ptr<op::v3::ScatterUpdate>(op)) {+ if (ov::is_type<op::v0::Parameter>(su->get_input_node_shared_ptr(0))) {+ cache_scatter = su;+ break;+ }+ }+ }+ ASSERT_NE(cache_scatter, nullptr) << "static full-length cache ScatterUpdate not found";++ // indices = Range(0, S) + Minimum(past_seqlen, capacity - S)+ auto add = as_type_ptr<op::v1::Add>(cache_scatter->get_input_node_shared_ptr(1));+ ASSERT_NE(add, nullptr);+ std::shared_ptr<op::v1::Minimum> clamp;+ for (size_t i = 0; i < add->get_input_size(); ++i)+ if (auto m = as_type_ptr<op::v1::Minimum>(add->get_input_node_shared_ptr(i)))+ clamp = m;+ ASSERT_NE(clamp, nullptr) << "past_seqlen feeding the static-cache scatter index is not clamped";++ auto cap_const = as_type_ptr<op::v0::Constant>(clamp->get_input_node_shared_ptr(1));+ ASSERT_NE(cap_const, nullptr) << "clamp bound is not a constant";+ EXPECT_EQ(cap_const->cast_vector<int64_t>(), std::vector<int64_t>{7});+}+TEST(GroupQueryAttentionValues, smooth_softmax_sink_is_zero) {auto model = make_gqa_model(GqaParams{"smooth"}.sink_smooth());decompose(model);@@ -363,3 +437,14 @@ TEST(GroupQueryAttentionValues, head_sink_reshapes_input_to_per_head_sink) {ASSERT_NE(shape_const, nullptr);EXPECT_EQ(shape_const->cast_vector<int64_t>(), (std::vector<int64_t>{1, -1, 1, 1}));}++TEST(GroupQueryAttentionValues, bidirectional_mask_has_no_causal_comparison) {+ auto model = make_gqa_model(GqaParams{"bidir"}.bidirectional());+ decompose(model);++ // causal=0 must not emit the query-relative Greater(hori, vert) causal comparison; only the single+ // GreaterEqual against the total-length (past + current) threshold remains, and it does not depend+ // on the query row.+ EXPECT_EQ(count_ops_of_type<op::v1::Greater>(model), 0u);+ EXPECT_EQ(count_ops_of_type<op::v1::GreaterEqual>(model), 1u);+}diff --git a/src/core/dev_api/openvino/op/group_query_attention.hpp b/src/core/dev_api/openvino/op/group_query_attention.hppindex b1ae5f8c446..8524705b7b7 100644--- a/src/core/dev_api/openvino/op/group_query_attention.hpp+++ b/src/core/dev_api/openvino/op/group_query_attention.hpp@@ -75,7 +75,8 @@ public:GroupQueryAttentionQuantType v_quant_type = GroupQueryAttentionQuantType::NONE,int64_t local_window_size = -1,bool sliding_window_cache = false,- bool smooth_softmax = false);+ bool smooth_softmax = false,+ bool causal = true);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;@@ -123,6 +124,12 @@ public:bool is_kv_quantized() const {return m_kv_cache_bit_width != 0 && m_k_quant_type != GroupQueryAttentionQuantType::NONE;}+ // When true (the ONNX Runtime default), each query only attends to keys at or before its own position+ // (plus the optional sliding window). When false, attention is bidirectional: every query attends to all+ // valid keys up to total_sequence_length (only the unused cache tail beyond it is masked).+ bool get_causal() const {+ return m_causal;+ }private:int64_t m_num_heads = 0;@@ -136,6 +143,7 @@ private:int64_t m_local_window_size = -1;bool m_sliding_window_cache = false;bool m_smooth_softmax = false;+ bool m_causal = true;};} // namespace ov::op::internaldiff --git a/src/core/src/op/group_query_attention.cpp b/src/core/src/op/group_query_attention.cppindex c02bedca9d6..10914b08d46 100644--- a/src/core/src/op/group_query_attention.cpp+++ b/src/core/src/op/group_query_attention.cpp@@ -49,7 +49,8 @@ GroupQueryAttention::GroupQueryAttention(const OutputVector& args,GroupQueryAttentionQuantType v_quant_type,int64_t local_window_size,bool sliding_window_cache,- bool smooth_softmax)+ bool smooth_softmax,+ bool causal): Op(args),m_num_heads(num_heads),m_kv_num_heads(kv_num_heads),@@ -61,7 +62,8 @@ GroupQueryAttention::GroupQueryAttention(const OutputVector& args,m_v_quant_type(v_quant_type),m_local_window_size(local_window_size),m_sliding_window_cache(sliding_window_cache),- m_smooth_softmax(smooth_softmax) {+ m_smooth_softmax(smooth_softmax),+ m_causal(causal) {constructor_validate_and_infer_types();}@@ -196,6 +198,30 @@ void GroupQueryAttention::validate_and_infer_types() {const auto& sequence_len = q_shape[2];const auto& head_size = q_shape[3];+ 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+ // GroupQueryAttentionDecomposition::rotaryEmbedding). Bound-check it here so an invalid model+ // fails with a diagnostic instead of a raw shape-inference crash inside the decomposition.+ const auto cos_shape = get_input_partial_shape(static_cast<size_t>(GroupQueryAttentionInputs::COS_CACHE));+ const auto& cos_last_dim = cos_shape[1];+ if (head_size.is_static()) {+ NODE_VALIDATION_CHECK(this,+ cos_last_dim.is_static(),+ "GroupQueryAttention: cos_cache last dimension must be statically known when "+ "head_size is static, got cos_cache shape ",+ cos_shape);+ const auto rotary_dim = 2 * cos_last_dim.get_length();+ NODE_VALIDATION_CHECK(this,+ rotary_dim <= head_size.get_length(),+ "GroupQueryAttention: rotary_dim (2 * cos_cache.shape[-1] = ",+ rotary_dim,+ ") must not exceed head_size (",+ head_size.get_length(),+ ")");+ }+ }+// The op is reachable directly from a loaded IR, so mirror the ONNX frontend's sliding-window// preconditions here as well: local_window_size must be -1 (disabled) or >= 1, and a windowed cache// (sliding_window_cache) requires a real window (>= 1). This keeps the op and the frontend in agreement.@@ -207,6 +233,13 @@ void GroupQueryAttention::validate_and_infer_types() {!m_sliding_window_cache || m_local_window_size >= 1,"GroupQueryAttention: sliding_window_cache requires local_window_size >= 1, got ",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).+ NODE_VALIDATION_CHECK(this,+ m_causal || m_local_window_size == -1,+ "GroupQueryAttention: local_window_size requires causal=1, got causal=0 and "+ "local_window_size=",+ m_local_window_size);// Windowed cache: single-token decode (sequence_length == 1) always fits inside the window and is handled// by the in-place Gather + ScatterUpdate assembly. Any other step (a multi-token prefill/staging chunk,// whether or not it actually crosses a window eviction at runtime) is handled by the staging branch, which@@ -287,6 +320,7 @@ void GroupQueryAttention::validate_and_infer_types() {bool GroupQueryAttention::visit_attributes(AttributeVisitor& visitor) {OV_OP_SCOPE(GroupQueryAttention_visit_attributes);+ visitor.on_attribute("causal", m_causal);visitor.on_attribute("do_rotary", m_do_rotary);visitor.on_attribute("k_quant_type", m_k_quant_type);visitor.on_attribute("kv_cache_bit_width", m_kv_cache_bit_width);@@ -315,7 +349,8 @@ std::shared_ptr<ov::Node> GroupQueryAttention::clone_with_new_inputs(const ov::Om_v_quant_type,m_local_window_size,m_sliding_window_cache,- m_smooth_softmax);+ m_smooth_softmax,+ m_causal);}} // 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 9c14f380e71..afc3ba9a204 100644--- a/src/core/tests/type_prop/group_query_attention.cpp+++ b/src/core/tests/type_prop/group_query_attention.cpp@@ -173,6 +173,43 @@ TEST(type_prop, group_query_attention_rotary_inputs_static_shapes) {EXPECT_EQ(op->get_output_partial_shape(2), (PartialShape{1, 2, 5, 8}));}+TEST(type_prop, group_query_attention_partial_rotary_dim_accepted) {+ // head_size == 8; cos_cache last dim == 2 -> rotary_dim == 4 < head_size (GPT-NeoX/Phi-style partial RoPE).+ auto args = make_valid_gqa_args();+ const auto cos_cache = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{16, 2});+ const auto sin_cache = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{16, 2});+ args.push_back(cos_cache);+ args.push_back(sin_cache);++ const auto op = std::make_shared<op::internal::GroupQueryAttention>(args, 6, 2, 1.0f, true, false);+ EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{1, 4, 48}));+}++TEST(type_prop, group_query_attention_rotary_dim_exceeds_head_size) {+ // head_size == 8; cos_cache last dim == 8 -> rotary_dim == 16 > head_size.+ auto args = make_valid_gqa_args();+ const auto cos_cache = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{16, 8});+ const auto sin_cache = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{16, 8});+ args.push_back(cos_cache);+ args.push_back(sin_cache);++ OV_EXPECT_THROW(std::ignore = std::make_shared<op::internal::GroupQueryAttention>(args, 6, 2, 1.0f, true, false),+ ov::NodeValidationFailure,+ HasSubstr("must not exceed head_size"));+}++TEST(type_prop, group_query_attention_rotary_dim_dynamic_cos_with_static_head_size) {+ auto args = make_valid_gqa_args();+ const auto cos_cache = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{16, -1});+ const auto sin_cache = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{16, -1});+ args.push_back(cos_cache);+ args.push_back(sin_cache);++ OV_EXPECT_THROW(std::ignore = std::make_shared<op::internal::GroupQueryAttention>(args, 6, 2, 1.0f, true, false),+ ov::NodeValidationFailure,+ HasSubstr("must be statically known"));+}+TEST(type_prop, group_query_attention_quant_type_enum_names) {EXPECT_EQ(as_string(op::internal::GroupQueryAttentionQuantType::NONE), "NONE");EXPECT_EQ(as_string(op::internal::GroupQueryAttentionQuantType::PER_TENSOR), "PER_TENSOR");@@ -255,5 +292,53 @@ TEST(type_prop, group_query_attention_quantized_kv_requires_quantized_cache_typeHasSubstr("quantized KV cache element type"));}+// ---------- causal ----------++TEST(type_prop, group_query_attention_causal_defaults_true) {+ const auto args = make_valid_gqa_args();+ const auto op = std::make_shared<op::internal::GroupQueryAttention>(args, 6, 2, 1.0f, false, false);+ EXPECT_TRUE(op->get_causal());+}++TEST(type_prop, group_query_attention_bidirectional_without_window_is_valid) {+ const auto args = make_valid_gqa_args();+ const auto op =+ std::make_shared<op::internal::GroupQueryAttention>(args,+ 6,+ 2,+ 1.0f,+ false,+ false,+ /*kv_cache_bit_width*/ 0,+ op::internal::GroupQueryAttentionQuantType::NONE,+ op::internal::GroupQueryAttentionQuantType::NONE,+ /*local_window_size*/ -1,+ /*sliding_window_cache*/ false,+ /*smooth_softmax*/ false,+ /*causal*/ false);+ EXPECT_FALSE(op->get_causal());+ EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{1, 4, 48}));+}++TEST(type_prop, group_query_attention_causal_false_rejects_window) {+ const auto args = make_valid_gqa_args();+ OV_EXPECT_THROW(std::ignore = std::make_shared<op::internal::GroupQueryAttention>(+ args,+ 6,+ 2,+ 1.0f,+ false,+ false,+ /*kv_cache_bit_width*/ 0,+ op::internal::GroupQueryAttentionQuantType::NONE,+ op::internal::GroupQueryAttentionQuantType::NONE,+ /*local_window_size*/ 2,+ /*sliding_window_cache*/ false,+ /*smooth_softmax*/ false,+ /*causal*/ false),+ ov::NodeValidationFailure,+ HasSubstr("local_window_size requires causal=1"));+}+} // namespace testing} // namespace ov\ No newline at end of filediff --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 cdf55e30718..79d59aa2044 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@@ -47,6 +47,7 @@ ov::OutputVector group_query_attention(const ov::frontend::onnx::Node& node) {const auto scale = node.get_attribute_value<float>("scale", 0.0f);const auto do_rotary = node.get_attribute_value<int64_t>("do_rotary", 0);const auto rotary_interleaved = node.get_attribute_value<int64_t>("rotary_interleaved", 0);+ const auto causal = node.get_attribute_value<int64_t>("causal", 1);// Quantized KV cache attributes (com.microsoft spec). Default to the unquantized (float KV) behavior.const auto kv_cache_bit_width = node.get_attribute_value<int64_t>("kv_cache_bit_width", 0);const auto parse_quant_type = [&](const std::string& quant_type_name) {@@ -80,6 +81,17 @@ ov::OutputVector group_query_attention(const ov::frontend::onnx::Node& node) {"supported.");// Reject spec attributes whose semantics are not implemented by the OpenVINO decomposition.+ FRONT_END_OP_CONVERSION_CHECK(causal == 0 || causal == 1,+ "GroupQueryAttention: causal must be 0 or 1, got ",+ causal,+ ".");+ // causal == 0 selects bidirectional attention (no query-relative masking, only the buffer tail beyond+ // total_sequence_length is masked); ONNX Runtime does not allow combining that with a sliding window.+ FRONT_END_OP_CONVERSION_CHECK(causal == 1 || local_window_size == -1,+ "GroupQueryAttention: local_window_size requires causal=1, got causal=0 and "+ "local_window_size=",+ local_window_size,+ ".");// local_window_size == -1 disables the window; a value >= 1 selects a sliding window. A window of// size 0 is an empty attention (every query masks all keys) and is not a valid ONNX Runtime config.FRONT_END_OP_CONVERSION_CHECK(local_window_size == -1 || local_window_size >= 1,@@ -173,6 +185,18 @@ ov::OutputVector group_query_attention(const ov::frontend::onnx::Node& node) {FRONT_END_OP_CONVERSION_CHECK(!ov::op::util::is_null(K), "GroupQueryAttention: Expecting K not null.");FRONT_END_OP_CONVERSION_CHECK(!ov::op::util::is_null(V), "GroupQueryAttention: Expecting V not null.");+ // "Shared KV" (kv_sequence_length == 0): ORT treats this as the past buffer already holding the+ // complete KV, with nothing new appended and K/V skipping RoPE (helper.h). The reshape below sizes+ // K/V using Q's sequence dim (current_seqlen_size_node), so a genuinely empty K/V cannot even be+ // reshaped to it; reject cleanly here instead of failing inside the Reshape with an unrelated+ // element-count-mismatch error.+ const auto& k_ps = K.get_partial_shape();+ FRONT_END_OP_CONVERSION_CHECK(+ !(k_ps.rank().is_static() && k_ps.rank().get_length() == 3 && k_ps[1].is_static() &&+ k_ps[1].get_length() == 0),+ "GroupQueryAttention: kv_sequence_length == 0 (shared KV / past buffer already complete) is not "+ "supported.");+auto num_heads_node = v0::Constant::create(ov::element::i64, ov::Shape{1}, {num_heads});auto head_size_node = std::make_shared<v1::Divide>(hidden_size_node, num_heads_node);auto q_shape = std::make_shared<v0::Concat>(@@ -210,6 +234,9 @@ 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,@@ -221,7 +248,8 @@ ov::OutputVector group_query_attention(const ov::frontend::onnx::Node& node) {v_quant_type,local_window_size,sliding_window_cache != 0,- smooth_softmax != 0)+ smooth_softmax == 1,+ causal != 0)->outputs();}diff --git a/src/frontends/onnx/tests/models/com.microsoft/gqa_absent_past.prototxt b/src/frontends/onnx/tests/models/com.microsoft/gqa_absent_past.prototxtnew file mode 100644index 00000000000..bdb940725ef--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/gqa_absent_past.prototxt@@ -0,0 +1,137 @@+ir_version: 10+graph {+ node {+ input: "query"+ input: ""+ input: ""+ input: ""+ input: ""+ input: "seqlens_k"+ input: "total_sequence_length"+ output: "output"+ output: "present_key"+ output: "present_value"+ name: "GroupQueryAttention_0"+ op_type: "GroupQueryAttention"+ attribute {+ name: "do_rotary"+ i: 0+ type: INT+ }+ attribute {+ name: "kv_num_heads"+ i: 1+ type: INT+ }+ attribute {+ name: "local_window_size"+ i: -1+ type: INT+ }+ attribute {+ name: "num_heads"+ i: 2+ type: INT+ }+ attribute {+ name: "rotary_interleaved"+ i: 0+ type: INT+ }+ attribute {+ name: "smooth_softmax"+ i: 0+ type: INT+ }+ attribute {+ name: "softcap"+ f: 0+ type: FLOAT+ }+ domain: "com.microsoft"+ }+ name: "GroupQueryAttention_Graph"+ input {+ name: "query"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_param: "sequence_length" }+ dim { dim_value: 64 }+ }+ }+ }+ }+ input {+ name: "seqlens_k"+ type {+ tensor_type {+ elem_type: 6+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 1 }+ }+ }+ }+ }+ input {+ name: "total_sequence_length"+ type{+ tensor_type {+ elem_type: 6+ shape {+ }+ }+ }+ }+ output {+ name: "output"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_param: "sequence_length" }+ dim { dim_value: 32 }+ }+ }+ }+ }+ output {+ name: "present_key"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 1 }+ dim { dim_param: "total_sequence_length" }+ dim { dim_value: 16 }+ }+ }+ }+ }+ output {+ name: "present_value"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 1 }+ dim { dim_param: "total_sequence_length" }+ dim { dim_value: 16 }+ }+ }+ }+ }+}+opset_import {+ version: 11+}+opset_import {+ domain: "com.microsoft"+ version: 1+}diff --git a/src/frontends/onnx/tests/models/com.microsoft/gqa_causal_bidirectional.prototxt b/src/frontends/onnx/tests/models/com.microsoft/gqa_causal_bidirectional.prototxtnew file mode 100644index 00000000000..2fdfd5c4d80--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/gqa_causal_bidirectional.prototxt@@ -0,0 +1,170 @@+ir_version: 10+graph {+ node {+ input: "query"+ input: ""+ input: ""+ input: "past_key"+ input: "past_value"+ input: "seqlens_k"+ input: "total_sequence_length"+ output: "output"+ output: "present_key"+ output: "present_value"+ name: "GroupQueryAttention_0"+ op_type: "GroupQueryAttention"+ attribute {+ name: "causal"+ i: 0+ type: INT+ }+ attribute {+ name: "do_rotary"+ i: 0+ type: INT+ }+ attribute {+ name: "kv_num_heads"+ i: 1+ type: INT+ }+ attribute {+ name: "local_window_size"+ i: -1+ type: INT+ }+ attribute {+ name: "num_heads"+ i: 2+ type: INT+ }+ attribute {+ name: "rotary_interleaved"+ i: 0+ type: INT+ }+ attribute {+ name: "smooth_softmax"+ i: 0+ type: INT+ }+ attribute {+ name: "softcap"+ f: 0+ type: FLOAT+ }+ domain: "com.microsoft"+ }+ name: "GroupQueryAttention_Graph"+ input {+ name: "query"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_param: "sequence_length" }+ dim { dim_value: 64 }+ }+ }+ }+ }+ input {+ name: "past_key"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 1 }+ dim { dim_param: "past_sequence_length" }+ dim { dim_value: 16 }+ }+ }+ }+ }+ input {+ name: "past_value"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 1 }+ dim { dim_param: "past_sequence_length" }+ dim { dim_value: 16 }+ }+ }+ }+ }+ input {+ name: "seqlens_k"+ type {+ tensor_type {+ elem_type: 6+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 1 }+ }+ }+ }+ }+ input {+ name: "total_sequence_length"+ type{+ tensor_type {+ elem_type: 6+ shape {+ }+ }+ }+ }+ 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_causal_window_conflict.prototxt b/src/frontends/onnx/tests/models/com.microsoft/gqa_causal_window_conflict.prototxtnew file mode 100644index 00000000000..242b10ba689--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/gqa_causal_window_conflict.prototxt@@ -0,0 +1,170 @@+ir_version: 10+graph {+ node {+ input: "query"+ input: ""+ input: ""+ input: "past_key"+ input: "past_value"+ input: "seqlens_k"+ input: "total_sequence_length"+ output: "output"+ output: "present_key"+ output: "present_value"+ name: "GroupQueryAttention_0"+ op_type: "GroupQueryAttention"+ attribute {+ name: "causal"+ i: 0+ type: INT+ }+ attribute {+ name: "do_rotary"+ i: 0+ type: INT+ }+ attribute {+ name: "kv_num_heads"+ i: 1+ type: INT+ }+ attribute {+ name: "local_window_size"+ i: 2+ type: INT+ }+ attribute {+ name: "num_heads"+ i: 2+ type: INT+ }+ attribute {+ name: "rotary_interleaved"+ i: 0+ type: INT+ }+ attribute {+ name: "smooth_softmax"+ i: 0+ type: INT+ }+ attribute {+ name: "softcap"+ f: 0+ type: FLOAT+ }+ domain: "com.microsoft"+ }+ name: "GroupQueryAttention_Graph"+ input {+ name: "query"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_param: "sequence_length" }+ dim { dim_value: 64 }+ }+ }+ }+ }+ input {+ name: "past_key"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 1 }+ dim { dim_param: "past_sequence_length" }+ dim { dim_value: 16 }+ }+ }+ }+ }+ input {+ name: "past_value"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 1 }+ dim { dim_param: "past_sequence_length" }+ dim { dim_value: 16 }+ }+ }+ }+ }+ input {+ name: "seqlens_k"+ type {+ tensor_type {+ elem_type: 6+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 1 }+ }+ }+ }+ }+ input {+ name: "total_sequence_length"+ type{+ tensor_type {+ elem_type: 6+ shape {+ }+ }+ }+ }+ output {+ name: "output"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_param: "sequence_length" }+ dim { dim_value: 32 }+ }+ }+ }+ }+ output {+ name: "present_key"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 1 }+ dim { dim_param: "total_sequence_length" }+ dim { dim_value: 16 }+ }+ }+ }+ }+ output {+ name: "present_value"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 1 }+ dim { dim_param: "total_sequence_length" }+ dim { dim_value: 16 }+ }+ }+ }+ }+}+opset_import {+ version: 11+}+opset_import {+ domain: "com.microsoft"+ version: 1+}diff --git a/src/frontends/onnx/tests/models/com.microsoft/gqa_partial_rotary.prototxt b/src/frontends/onnx/tests/models/com.microsoft/gqa_partial_rotary.prototxtnew file mode 100644index 00000000000..6023eb999ef--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/gqa_partial_rotary.prototxt@@ -0,0 +1,191 @@+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: -1+ type: INT+ }+ attribute {+ name: "num_heads"+ i: 2+ type: INT+ }+ attribute {+ name: "rotary_interleaved"+ i: 0+ type: INT+ }+ attribute {+ name: "smooth_softmax"+ i: 0+ type: INT+ }+ attribute {+ name: "softcap"+ f: 0+ type: FLOAT+ }+ domain: "com.microsoft"+ }+ name: "GroupQueryAttention_Graph"+ input {+ name: "query"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_param: "sequence_length" }+ dim { dim_value: 128 }+ }+ }+ }+ }+ 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: 32 }+ }+ }+ }+ }+ 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: 32 }+ }+ }+ }+ }+ 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: 64 }+ }+ }+ }+ }+ 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: 32 }+ }+ }+ }+ }+ 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: 32 }+ }+ }+ }+ }+}+opset_import {+ version: 11+}+opset_import {+ domain: "com.microsoft"+ version: 1+}diff --git a/src/frontends/onnx/tests/models/com.microsoft/gqa_shared_kv.prototxt b/src/frontends/onnx/tests/models/com.microsoft/gqa_shared_kv.prototxtnew file mode 100644index 00000000000..4b4ab974dc2--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/gqa_shared_kv.prototxt@@ -0,0 +1,191 @@+ir_version: 10+graph {+ node {+ input: "query"+ input: "key"+ input: "value"+ input: "past_key"+ input: "past_value"+ input: "seqlens_k"+ input: "total_sequence_length"+ output: "output"+ output: "present_key"+ output: "present_value"+ name: "GroupQueryAttention_0"+ op_type: "GroupQueryAttention"+ attribute {+ name: "do_rotary"+ i: 0+ type: INT+ }+ attribute {+ name: "kv_num_heads"+ i: 1+ type: INT+ }+ attribute {+ name: "local_window_size"+ i: -1+ type: INT+ }+ attribute {+ name: "num_heads"+ i: 2+ type: INT+ }+ attribute {+ name: "rotary_interleaved"+ i: 0+ type: INT+ }+ attribute {+ name: "smooth_softmax"+ i: 0+ type: INT+ }+ attribute {+ name: "softcap"+ f: 0+ type: FLOAT+ }+ domain: "com.microsoft"+ }+ name: "GroupQueryAttention_Graph"+ input {+ name: "query"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_param: "sequence_length" }+ dim { dim_value: 32 }+ }+ }+ }+ }+ input {+ name: "key"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 0 }+ dim { dim_value: 16 }+ }+ }+ }+ }+ input {+ name: "value"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 0 }+ dim { dim_value: 16 }+ }+ }+ }+ }+ input {+ name: "past_key"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 1 }+ dim { dim_param: "past_sequence_length" }+ dim { dim_value: 16 }+ }+ }+ }+ }+ input {+ name: "past_value"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 1 }+ dim { dim_param: "past_sequence_length" }+ dim { dim_value: 16 }+ }+ }+ }+ }+ input {+ name: "seqlens_k"+ type {+ tensor_type {+ elem_type: 6+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 1 }+ }+ }+ }+ }+ input {+ name: "total_sequence_length"+ type{+ tensor_type {+ elem_type: 6+ shape {+ }+ }+ }+ }+ output {+ name: "output"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_param: "sequence_length" }+ dim { dim_value: 32 }+ }+ }+ }+ }+ output {+ name: "present_key"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 1 }+ dim { dim_param: "total_sequence_length" }+ dim { dim_value: 16 }+ }+ }+ }+ }+ output {+ name: "present_value"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 1 }+ dim { dim_param: "total_sequence_length" }+ dim { dim_value: 16 }+ }+ }+ }+ }+}+opset_import {+ version: 11+}+opset_import {+ domain: "com.microsoft"+ version: 1+}diff --git a/src/frontends/onnx/tests/models/com.microsoft/gqa_smooth_softmax_sentinel.prototxt b/src/frontends/onnx/tests/models/com.microsoft/gqa_smooth_softmax_sentinel.prototxtnew file mode 100644index 00000000000..f898d7f9d3a--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/gqa_smooth_softmax_sentinel.prototxt@@ -0,0 +1,165 @@+ir_version: 10+graph {+ node {+ input: "query"+ input: ""+ input: ""+ input: "past_key"+ input: "past_value"+ input: "seqlens_k"+ input: "total_sequence_length"+ output: "output"+ output: "present_key"+ output: "present_value"+ name: "GroupQueryAttention_0"+ op_type: "GroupQueryAttention"+ attribute {+ name: "do_rotary"+ i: 0+ type: INT+ }+ attribute {+ name: "kv_num_heads"+ i: 1+ type: INT+ }+ attribute {+ name: "local_window_size"+ i: -1+ type: INT+ }+ attribute {+ name: "num_heads"+ i: 2+ type: INT+ }+ attribute {+ name: "rotary_interleaved"+ i: 0+ type: INT+ }+ attribute {+ name: "smooth_softmax"+ i: -1+ type: INT+ }+ attribute {+ name: "softcap"+ f: 0+ type: FLOAT+ }+ domain: "com.microsoft"+ }+ name: "GroupQueryAttention_Graph"+ input {+ name: "query"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_param: "sequence_length" }+ dim { dim_value: 64 }+ }+ }+ }+ }+ input {+ name: "past_key"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 1 }+ dim { dim_param: "past_sequence_length" }+ dim { dim_value: 16 }+ }+ }+ }+ }+ input {+ name: "past_value"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 1 }+ dim { dim_param: "past_sequence_length" }+ dim { dim_value: 16 }+ }+ }+ }+ }+ input {+ name: "seqlens_k"+ type {+ tensor_type {+ elem_type: 6+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 1 }+ }+ }+ }+ }+ input {+ name: "total_sequence_length"+ type{+ tensor_type {+ elem_type: 6+ shape {+ }+ }+ }+ }+ output {+ name: "output"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_param: "sequence_length" }+ dim { dim_value: 32 }+ }+ }+ }+ }+ output {+ name: "present_key"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 1 }+ dim { dim_param: "total_sequence_length" }+ dim { dim_value: 16 }+ }+ }+ }+ }+ output {+ name: "present_value"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 1 }+ dim { dim_param: "total_sequence_length" }+ dim { dim_value: 16 }+ }+ }+ }+ }+}+opset_import {+ version: 11+}+opset_import {+ domain: "com.microsoft"+ version: 1+}diff --git a/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp b/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cppindex e169631eb02..accf738b543 100644--- a/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp+++ b/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp@@ -5467,6 +5467,171 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_sliding_window_equals_causal_when_test_case.run_with_tolerance_as_fp();}+// causal=0 (bidirectional): every query attends to all valid keys, not just k <= q. Output matches+// ONNX Runtime (MLAS CPU, causal=0) run against the same query/cache split.+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_causal_bidirectional) {+ const auto model = convert_model("com.microsoft/gqa_causal_bidirectional.onnx");++ std::vector<float> expected_output = {+ 0.835323f, 0.141426f, -0.716575f, 0.183820f, 0.110312f, -0.472860f, -0.283830f, 1.274872f, -0.368640f,+ -0.920300f, 0.384538f, 0.151699f, -0.114322f, 0.627885f, 0.386892f, 0.460673f, 0.775386f, 0.170116f,+ -0.647210f, 0.477085f, -0.209098f, 0.088937f, 0.219232f, 0.918672f, -0.165271f, -1.380370f, -0.805253f,+ 0.599758f, -0.238036f, 0.647694f, 0.236465f, -0.114835f, 0.522801f, -0.384009f, 0.249278f, 0.194326f,+ 0.192918f, -0.384589f, 0.091830f, 0.538561f, -0.539031f, -0.736515f, 0.056842f, 0.358661f, -0.196808f,+ 0.026687f, 0.202320f, 0.776961f, 0.529779f, -0.415570f, 0.008920f, 0.234566f, 0.171438f, -0.424543f,+ 0.274885f, 0.576314f, -0.324155f, -1.069859f, -0.148582f, 0.270502f, -0.189003f, 0.390507f, 0.221920f,+ 0.513277f, 0.758482f, 0.069074f, -0.587188f, 0.344906f, -0.045838f, -0.179893f, 0.072326f, 0.988206f,+ -0.242467f, -1.202527f, -0.321804f, 0.393656f, -0.188665f, 0.627272f, 0.285900f, 0.154855f, 0.310463f,+ -0.662996f, 1.135608f, 0.216411f, 0.200450f, -0.164241f, 0.215993f, -0.032357f, -0.850289f, -0.333808f,+ -0.158269f, 0.683606f, -0.282794f, -0.761042f, 0.034373f, 1.155105f, 0.413673f, -0.342667f, 1.253691f,+ 0.238900f, 0.083796f, 0.106136f, -0.160001f, 0.078662f, -1.166455f, 0.136124f, -0.026595f, 0.961300f,+ -0.311426f, -1.282412f, 0.015627f, 1.365237f, 0.573372f, -0.273704f, -0.057114f, 0.317745f, 0.048871f,+ -0.221081f, 0.281314f, 0.590687f, -0.321818f, -1.107932f, -0.402041f, 0.431164f, -0.219438f, 0.346153f,+ 0.198345f, 0.369227f};++ std::vector<float> expected_present_key = {+ -1.651076f, 0.535429f, -2.064415f, -0.662159f, -1.204220f, 1.461976f, 1.766161f, -0.329414f,+ 0.840733f, -0.179986f, 0.568062f, -0.752837f, -1.708339f, -1.803099f, 0.383122f, 2.247595f,+ 2.259947f, 0.869039f, -0.342117f, -0.471927f, -0.864490f, 0.374370f, 0.391546f, -1.443122f,+ 0.486335f, -0.569472f, 1.426721f, 0.156844f, 1.717730f, -0.458127f, -0.287984f, 0.299808f,+ -0.929324f, 0.411797f, 1.860056f, -1.497274f, 0.476338f, 1.112291f, -0.696591f, 0.582970f,+ -1.070892f, -0.812209f, -0.817080f, 0.192308f, -0.090981f, 0.954115f, -0.940279f, -0.131276f,+ -1.040131f, 0.022778f, 0.682829f, -0.740296f, -0.049672f, 0.718557f, -0.126909f, -0.519137f,+ 0.973093f, 0.097020f, 0.396565f, 1.171393f, 1.145316f, -0.347204f, -0.525430f, 0.284309f};++ std::vector<float> expected_present_value = {+ 0.269412f, -0.524605f, 1.912019f, 0.237302f, 0.101434f, 0.252578f, -0.132377f, -0.309476f,+ -1.434963f, 0.501624f, -0.094775f, 1.193086f, -0.368818f, -1.906370f, -0.099611f, 1.699537f,+ 1.055948f, 0.565883f, -1.233524f, 0.182901f, 0.022245f, -0.429069f, -0.648105f, 1.747577f,+ -0.390386f, -0.845923f, 0.637113f, 0.130623f, -0.075814f, 0.781302f, 0.488625f, 0.362190f,+ 0.961076f, 0.560777f, -1.324641f, 0.665204f, -0.478418f, 0.385387f, 0.300680f, 1.219319f,+ 0.116560f, -1.853806f, -1.369860f, 0.731154f, -0.258316f, 1.137979f, 0.273439f, -0.749066f,+ -0.132788f, -1.899861f, 1.275362f, 0.019361f, 0.736378f, -1.172917f, 1.288204f, -0.588263f,+ -0.107667f, -1.401425f, -0.166950f, -0.229804f, -0.185361f, 0.438505f, 0.060346f, 0.975783f};++ auto test_case = ov::test::TestCase(model, s_device);+ test_case.add_input<float>(Shape{1, 4, 64}, gqa_sliding_window_query());+ test_case.add_input<float>(Shape{1, 1, 0, 16}, {});+ test_case.add_input<float>(Shape{1, 1, 0, 16}, {});+ test_case.add_input<int>(Shape{1, 1}, {3});+ test_case.add_input<int>(Shape{}, {4});+ test_case.add_expected_output<float>(Shape{1, 4, 32}, expected_output);+ test_case.add_expected_output<float>(Shape{1, 1, 4, 16}, expected_present_key);+ test_case.add_expected_output<float>(Shape{1, 1, 4, 16}, expected_present_value);+ test_case.run_with_tolerance_as_fp();+}++// Partial RoPE (GPT-NeoX/Phi-style): rotary_dim (2 * cos_cache.shape[-1] = 16) is smaller than+// head_size (32). Only the leading 16 channels of Q/K are rotated; the trailing 16 pass through+// unchanged. Single decode token (seqlens_k=0, total_sequence_length=1) makes "output"/"present_value"+// insensitive to the rotation (softmax over one key is always 1.0), so present_key is what actually+// exercises the fix: its first half is the RoPE-rotated K, its second half is K's untouched tail.+// Expected values from real ONNX Runtime 1.30.0 CPUExecutionProvider (same native MLAS core).+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_partial_rotary) {+ const auto model = convert_model("com.microsoft/gqa_partial_rotary.onnx");++ std::vector<float> query = {+ 0.304700f, -1.040000f, 0.750500f, 0.940600f, -1.951000f, -1.302200f, 0.127800f, -0.316200f, -0.016800f,+ -0.853000f, 0.879400f, 0.777800f, 0.066000f, 1.127200f, 0.467500f, -0.859300f, 0.368800f, -0.958900f,+ 0.878500f, -0.049900f, -0.184900f, -0.680900f, 1.222500f, -0.154500f, -0.428300f, -0.352100f, 0.532300f,+ 0.365400f, 0.412700f, 0.430800f, 2.141600f, -0.406400f, -0.512200f, -0.813800f, 0.616000f, 1.129000f,+ -0.113900f, -0.840200f, -0.824500f, 0.650600f, 0.743300f, 0.543200f, -0.665500f, 0.232200f, 0.116700f,+ 0.218700f, 0.871400f, 0.223600f, 0.678900f, 0.067600f, 0.289100f, 0.631300f, -1.457200f, -0.319700f,+ -0.470400f, -0.638900f, -0.275100f, 1.494900f, -0.865800f, 0.968300f, -1.682900f, -0.334900f, 0.162800f,+ 0.586200f, 0.711200f, 0.793300f, -0.348700f, -0.462400f, 0.858000f, -0.191300f, -1.275700f, -1.133300f,+ -0.919500f, 0.497200f, 0.142400f, 0.690500f, -0.427300f, 0.158500f, 0.625600f, -0.309300f, 0.456800f,+ -0.661900f, -0.363100f, -0.381700f, -1.195800f, 0.487000f, -0.469400f, 0.012500f, 0.480700f, 0.446500f,+ 0.665400f, -0.098500f, -0.423300f, -0.079700f, -1.687300f, -1.447100f, -1.322700f, -0.997200f, 0.399800f,+ -0.905500f, -0.378200f, 1.299200f, -0.356300f, 0.737500f, -0.933600f, -0.205400f, -0.950000f, -0.339000f,+ 0.840300f, -1.727300f, 0.434400f, 0.237700f, -0.594100f, -1.446100f, 0.072100f, -0.529500f, 0.232700f,+ 0.021900f, 1.601800f, -0.239400f, -1.023500f, 0.179300f, 0.220000f, 1.359200f, 0.835100f, 0.356900f,+ 1.463300f, -1.188800f,+ };+ std::vector<float> cos_cache =+ {-0.658800f, 0.850200f, 0.162100f, -0.306300f, 0.181800f, -0.954400f, 0.917100f, -0.035400f};+ std::vector<float> sin_cache =+ {0.565500f, -0.834500f, -0.026700f, -0.018600f, 0.875700f, 0.143500f, -0.053000f, -0.466000f};++ std::vector<float> expected_output = {+ -1.322700f, -0.997200f, 0.399800f, -0.905500f, -0.378200f, 1.299200f, -0.356300f, 0.737500f,+ -0.933600f, -0.205400f, -0.950000f, -0.339000f, 0.840300f, -1.727300f, 0.434400f, 0.237700f,+ -0.594100f, -1.446100f, 0.072100f, -0.529500f, 0.232700f, 0.021900f, 1.601800f, -0.239400f,+ -1.023500f, 0.179300f, 0.220000f, 1.359200f, 0.835100f, 0.356900f, 1.463300f, -1.188800f,+ -1.322700f, -0.997200f, 0.399800f, -0.905500f, -0.378200f, 1.299200f, -0.356300f, 0.737500f,+ -0.933600f, -0.205400f, -0.950000f, -0.339000f, 0.840300f, -1.727300f, 0.434400f, 0.237700f,+ -0.594100f, -1.446100f, 0.072100f, -0.529500f, 0.232700f, 0.021900f, 1.601800f, -0.239400f,+ -1.023500f, 0.179300f, 0.220000f, 1.359200f, 0.835100f, 0.356900f, 1.463300f, -1.188800f,+ };++ std::vector<float> expected_present_key = {+ 0.051439f, 1.089377f, -0.052722f, 0.154476f, 0.530171f, 0.159832f, -1.136788f, -0.104015f,+ 1.007950f, -0.239289f, 0.032393f, -0.202900f, 0.673667f, -0.178724f, 0.641350f, 0.539067f,+ 0.456800f, -0.661900f, -0.363100f, -0.381700f, -1.195800f, 0.487000f, -0.469400f, 0.012500f,+ 0.480700f, 0.446500f, 0.665400f, -0.098500f, -0.423300f, -0.079700f, -1.687300f, -1.447100f,+ };++ std::vector<float> expected_present_value = {+ -1.322700f, -0.997200f, 0.399800f, -0.905500f, -0.378200f, 1.299200f, -0.356300f, 0.737500f,+ -0.933600f, -0.205400f, -0.950000f, -0.339000f, 0.840300f, -1.727300f, 0.434400f, 0.237700f,+ -0.594100f, -1.446100f, 0.072100f, -0.529500f, 0.232700f, 0.021900f, 1.601800f, -0.239400f,+ -1.023500f, 0.179300f, 0.220000f, 1.359200f, 0.835100f, 0.356900f, 1.463300f, -1.188800f,+ };++ auto test_case = ov::test::TestCase(model, s_device);+ test_case.add_input<float>(Shape{1, 1, 128}, query);+ test_case.add_input<float>(Shape{1, 1, 0, 32}, {});+ test_case.add_input<float>(Shape{1, 1, 0, 32}, {});+ test_case.add_input<int>(Shape{1, 1}, {0});+ test_case.add_input<int>(Shape{}, {1});+ test_case.add_input<float>(Shape{1, 8}, cos_cache);+ test_case.add_input<float>(Shape{1, 8}, sin_cache);+ test_case.add_expected_output<float>(Shape{1, 1, 64}, expected_output);+ test_case.add_expected_output<float>(Shape{1, 1, 1, 32}, expected_present_key);+ test_case.add_expected_output<float>(Shape{1, 1, 1, 32}, expected_present_value);+ test_case.run_with_tolerance_as_fp();+}++// ONNX Runtime rejects local_window_size >= 1 together with causal=0 (gqa_attention_base.h:101); the FE+// must mirror that precondition rather than silently combining a sliding window with bidirectional attention.+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_causal_window_conflict_throws) {+ try {+ convert_model("com.microsoft/gqa_causal_window_conflict.onnx");+ FAIL() << "ONNX Importer did not reject local_window_size with causal=0 for GroupQueryAttention";+ } catch (const std::exception& e) {+ EXPECT_THAT(e.what(), testing::HasSubstr("causal"));+ } catch (...) {+ FAIL() << "Unexpected exception type thrown";+ }+}++// "Shared KV" (kv_sequence_length == 0): the past buffer already holds the complete KV and nothing new is+// appended (ORT helper.h). The FE reshapes K/V using Q's sequence dim, so a genuinely empty K/V cannot be+// reshaped to it; this must fail with a named diagnostic rather than an unrelated Reshape element-count error.+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_shared_kv_unsupported_throws) {+ try {+ convert_model("com.microsoft/gqa_shared_kv.onnx");+ FAIL() << "ONNX Importer did not reject kv_sequence_length == 0 (shared KV) for GroupQueryAttention";+ } catch (const std::exception& e) {+ EXPECT_THAT(e.what(), testing::HasSubstr("kv_sequence_length"));+ } catch (...) {+ FAIL() << "Unexpected exception type thrown";+ }+}++// past_key/past_value are optional per spec and ORT (helper.h:283-293: both-absent means no past cache), but+// the FE and internal op currently hard-require them. Lock in today's clean reject (not a crash/silent-wrong+// result) so a future relaxation of this requirement is a deliberate change, not an accidental regression.+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_absent_past_unsupported_throws) {+ try {+ convert_model("com.microsoft/gqa_absent_past.onnx");+ FAIL() << "ONNX Importer did not reject absent past_key/past_value for GroupQueryAttention";+ } catch (const std::exception& e) {+ EXPECT_THAT(e.what(), testing::HasSubstr("past_key"));+ } catch (...) {+ FAIL() << "Unexpected exception type thrown";+ }+}+// External attention_bias (input 10) combined with a sliding window: the window band must be added on// top of the caller-supplied bias. Exercises the additive-band branch of make_attention_mask. Output// matches ONNX Runtime (MLAS CPU).@@ -5682,6 +5847,42 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_smooth_softmax) {test_case.run_with_tolerance_as_fp();}+// ONNX Runtime's GroupQueryAttention schema declares smooth_softmax's default as -1 (contrib_defs/bert_defs.cc),+// but both its CPU and CUDA kernels only enable the sink path on an exact 1 (gqa_attention_base.h,+// GetAttrOrDefault<int64_t>("smooth_softmax", 0) == 1) - -1 is treated identically to absent/0, i.e. disabled.+// A graph that never set the attribute explicitly can still end up with -1 baked in (e.g. schema-default+// materialization during export), so this must decompose the same as the plain (non-sink) path, not the+// sink path onnx_model_gqa_smooth_softmax exercises above.+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_smooth_softmax_negative_one_is_disabled) {+ const auto model = convert_model("com.microsoft/gqa_smooth_softmax_sentinel.onnx");++ std::vector<float> expected_output = {+ -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.223169f, -0.033279f, 0.285355f, 0.755670f,+ -0.142297f, 0.185552f, -0.567998f, 1.446860f, 0.189834f, -1.403443f, 0.920896f, 0.631242f, 0.451579f,+ 0.475252f, -0.094618f, -0.632560f, -0.174186f, -0.114620f, 0.308297f, 0.741198f, -0.229624f, -0.433955f,+ -0.582185f, 1.105163f, 0.513368f, -1.405174f, 0.890326f, 0.459447f, 0.220691f, 0.135793f, 0.236369f,+ -0.735763f, -0.916030f, 0.169364f, 0.744224f, 0.098714f, -0.674760f, 0.340823f, -0.161425f, 0.371981f,+ -0.647726f, -1.187438f, 0.167276f, 0.441306f, 0.963017f, 0.117072f, -0.215601f, 0.233242f, -0.800164f,+ 0.042054f, 0.744694f, 0.123655f, -0.759933f, -0.533470f, -0.209123f, -0.030549f, -0.139180f, -1.204685f,+ 0.176414f, 0.214857f, 0.606022f, -0.331558f, 0.254124f, 0.029913f, -0.939657f, 0.172058f, 0.883547f,+ -0.156979f, -0.967515f, -0.053405f, -0.159229f, -0.084546f, -0.818667f, -0.761607f, -0.160362f, 0.333833f,+ 0.840787f, -0.138559f, 0.052502f, 0.667249f, -0.849203f, 0.177679f, 0.743201f, 0.060907f, -0.718495f,+ 0.379690f, -0.213628f, 0.432319f, -0.764489f, -0.983679f, 0.111276f, 0.487376f, 0.924402f, 0.181732f,+ -0.199088f, 0.391633f};++ auto test_case = ov::test::TestCase(model, s_device);+ test_case.add_input<float>(Shape{1, 4, 64}, gqa_sink_query());+ test_case.add_input<float>(Shape{1, 1, 0, 16}, {});+ test_case.add_input<float>(Shape{1, 1, 0, 16}, {});+ test_case.add_input<int>(Shape{1, 1}, {3});+ test_case.add_input<int>(Shape{}, {4});+ test_case.add_expected_output<float>(Shape{1, 4, 32}, expected_output);+ test_case.run_with_tolerance_as_fp();+}+// head_sink provides a per-head logit added to the softmax denominator (via SDPA's sink input).OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_head_sink) {const auto model = convert_model("com.microsoft/gqa_head_sink.onnx");