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] Add support for com.microsoft.MultiHeadAttention. (#36138)
Nikolay Proshunin81d8f2e3dfa6
diff --git a/src/frontends/onnx/docs/supported_ops.md b/src/frontends/onnx/docs/supported_ops.mdindex 0243dafeb6f..7ebd331a0c7 100644--- a/src/frontends/onnx/docs/supported_ops.md+++ b/src/frontends/onnx/docs/supported_ops.md@@ -263,7 +263,7 @@ OpenVINO provides support for operations of Default Opset (empty in table below)|com.microsoft |MaxpoolWithMask | |1 | ||com.microsoft |MoE | |1 | ||com.microsoft |MulInteger | |1 | |-|com.microsoft |MultiHeadAttention | |1 | |+|com.microsoft |MultiHeadAttention |1 |1 | ||com.microsoft |MurmurHash3 | |1 | ||com.microsoft |NGramRepeatBlock | |1 | ||com.microsoft |NhwcConv | |1 | |diff --git a/src/frontends/onnx/frontend/src/op/attention.cpp b/src/frontends/onnx/frontend/src/op/attention.cppindex db75a444f1b..28b858766af 100644--- a/src/frontends/onnx/frontend/src/op/attention.cpp+++ b/src/frontends/onnx/frontend/src/op/attention.cpp@@ -10,27 +10,15 @@#include "openvino/op/add.hpp"#include "openvino/op/concat.hpp"#include "openvino/op/constant.hpp"-#include "openvino/op/convert.hpp"#include "openvino/op/divide.hpp"-#include "openvino/op/greater_eq.hpp"-#include "openvino/op/matmul.hpp"-#include "openvino/op/multiply.hpp"-#include "openvino/op/range.hpp"#include "openvino/op/reshape.hpp"-#include "openvino/op/scaled_dot_product_attention.hpp"-#include "openvino/op/select.hpp"#include "openvino/op/shape_of.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"#include "openvino/op/tile.hpp"#include "openvino/op/transpose.hpp"-#include "openvino/op/unsqueeze.hpp"#include "utils/common.hpp"using namespace ov::op;+using namespace ov::frontend::onnx::attention;namespace ov {namespace frontend {@@ -39,8 +27,6 @@ namespace ai_onnx {namespace detail {namespace {-using ov::frontend::onnx::attention::get_dimensions;-// Reshape 3D input (batch, seq, num_heads * head_size) to 4D (batch, num_heads, seq, head_size)// Uses direct reshape matching the ONNX Attention spec (no transpose):// the hidden dimension is split as [num_heads, seq, head_size] in row-major order.@@ -77,161 +63,6 @@ ov::Output<ov::Node> repeat_kv(const ov::Output<ov::Node>& input, int64_t n_rep)return std::make_shared<v0::Tile>(input, repeats);}-// Convert boolean mask to float additive mask: true -> 0.0, false -> -10000.0-ov::Output<ov::Node> convert_boolean_mask(const ov::Output<ov::Node>& mask, const ov::element::Type& type) {- auto zero = v0::Constant::create(type, ov::Shape{}, {0.0f});- auto neg_large = v0::Constant::create(type, ov::Shape{}, {-10000.0f});- return std::make_shared<v1::Select>(mask, zero, neg_large);-}--// Build additive causal mask of shape (seq_q, seq_kv): 0 for allowed, -10000 for masked.-// When use_offset=true, accounts for KV cache offset so that query position i attends to-// key positions j where j <= i + (seq_kv - seq_q). Use this for KV cache scenarios.-// When use_offset=false, builds a simple lower-triangular mask matching np.tril(k=0),-// where query position i attends to key positions j where j <= i.-ov::Output<ov::Node> build_causal_mask(const ov::Output<ov::Node>& Q, const ov::Output<ov::Node>& K, bool use_offset) {- auto q_shape = std::make_shared<v3::ShapeOf>(Q);- auto k_shape = std::make_shared<v3::ShapeOf>(K);- // Q is 4D: (B, heads, seq_q, head_size), K is 4D: (B, heads, seq_kv, head_size)- auto seq_q = get_dimensions(q_shape, {2});- auto seq_kv = get_dimensions(k_shape, {2});-- auto zero = v0::Constant::create(ov::element::i64, ov::Shape{}, {0});- auto one = v0::Constant::create(ov::element::i64, ov::Shape{}, {1});-- auto seq_q_scalar = std::make_shared<v0::Squeeze>(seq_q, zero);- auto seq_kv_scalar = std::make_shared<v0::Squeeze>(seq_kv, zero);-- // Column indices: [0, 1, ..., seq_kv-1]- auto col_indices = std::make_shared<v4::Range>(zero, seq_kv_scalar, one, ov::element::i64);-- std::shared_ptr<ov::Node> row_indices;- if (use_offset) {- // Row indices adjusted for KV cache offset: [offset, offset+1, ..., offset+seq_q-1]- auto offset = std::make_shared<v1::Subtract>(seq_kv_scalar, seq_q_scalar);- auto end = std::make_shared<v1::Add>(offset, seq_q_scalar);- row_indices = std::make_shared<v4::Range>(offset, end, one, ov::element::i64);- } else {- // Row indices without offset: [0, 1, ..., seq_q-1] (matches np.tril(k=0))- row_indices = std::make_shared<v4::Range>(zero, seq_q_scalar, one, ov::element::i64);- }-- // Unsqueeze rows to (seq_q, 1) for broadcasting with (seq_kv,)- auto axis = v0::Constant::create(ov::element::i64, ov::Shape{1}, {1});- auto rows_2d = std::make_shared<v0::Unsqueeze>(row_indices, axis);-- // Lower-triangular: position (i, j) allowed when adjusted_row[i] >= col[j]- auto is_allowed = std::make_shared<v1::GreaterEqual>(rows_2d, col_indices);-- // Convert boolean to additive float mask: true -> 0.0, false -> -10000.0- return convert_boolean_mask(is_allowed, Q.get_element_type());-}--// Build SDPA-based attention (primary fast path)-ov::Output<ov::Node> build_sdpa(const ov::Output<ov::Node>& Q,- const ov::Output<ov::Node>& K,- const ov::Output<ov::Node>& V,- bool has_mask,- const ov::Output<ov::Node>& attn_mask,- float scale_attr,- bool is_causal) {- ov::OutputVector inputs{Q, K, V};- if (has_mask) {- inputs.push_back(attn_mask);- }- if (scale_attr != 0.0f) {- if (!has_mask) {- // SDPA interprets inputs positionally (index 3 = mask, index 4 = scale),- // so a zero mask placeholder is needed when only scale is provided- inputs.push_back(v0::Constant::create(Q.get_element_type(), ov::Shape{}, {0.0f}));- }- inputs.push_back(v0::Constant::create(Q.get_element_type(), ov::Shape{}, {scale_attr}));- }- return std::make_shared<v13::ScaledDotProductAttention>(inputs, is_causal)->output(0);-}--// Build manual attention decomposition (for softcap or qk_matmul_output)-// Returns {Y, qk_matmul_output_or_null}-ov::OutputVector build_manual_attention(const ov::Output<ov::Node>& Q,- const ov::Output<ov::Node>& K,- const ov::Output<ov::Node>& V,- bool has_mask,- const ov::Output<ov::Node>& attn_mask,- float scale_attr,- float softcap,- bool is_causal,- int64_t qk_matmul_output_mode,- bool needs_qk_output) {- // 1. Q @ K^T- auto qk = std::make_shared<v0::MatMul>(Q, K, false, true);-- // 2. Apply scale- std::shared_ptr<ov::Node> scaled_qk;- if (scale_attr != 0.0f) {- auto scale_node = v0::Constant::create(Q.get_element_type(), ov::Shape{}, {scale_attr});- scaled_qk = std::make_shared<v1::Multiply>(qk, scale_node);- } else {- // Default scale: 1/sqrt(head_size). Q is always 4D here: (B, heads, seq, head_size)- auto q_shape = std::make_shared<v3::ShapeOf>(Q);- auto head_size = get_dimensions(q_shape, {3});- auto head_size_f = std::make_shared<v0::Convert>(head_size, Q.get_element_type());- auto sqrt_head = std::make_shared<v0::Sqrt>(head_size_f);- scaled_qk = std::make_shared<v1::Divide>(qk, sqrt_head);- }-- // 3. Apply attention mask and causal mask- std::shared_ptr<ov::Node> masked = scaled_qk;- if (has_mask) {- masked = std::make_shared<v1::Add>(scaled_qk, attn_mask);- }- if (is_causal) {- auto causal_mask = build_causal_mask(Q, K, false);- masked = std::make_shared<v1::Add>(masked, causal_mask);- }-- // Capture qk_matmul_output at mode 0 (raw QK) or mode 1 (after mask)- ov::Output<ov::Node> qk_debug_output;- if (needs_qk_output && qk_matmul_output_mode == 0) {- qk_debug_output = scaled_qk->output(0);- } else if (needs_qk_output && qk_matmul_output_mode == 1) {- qk_debug_output = masked->output(0);- }-- // 4. Apply softcap: softcap * tanh(scores / softcap)- std::shared_ptr<ov::Node> capped = masked;- if (softcap > 0.0f) {- auto cap = v0::Constant::create(Q.get_element_type(), ov::Shape{}, {softcap});- auto divided = std::make_shared<v1::Divide>(masked, cap);- auto tanh_out = std::make_shared<v0::Tanh>(divided);- capped = std::make_shared<v1::Multiply>(tanh_out, cap);- }-- // Capture at mode 2 (after softcap)- if (needs_qk_output && qk_matmul_output_mode == 2) {- qk_debug_output = capped->output(0);- }-- // 5. Softmax- auto softmax_out = std::make_shared<v8::Softmax>(capped, -1);-- // Capture at mode 3 (after softmax)- if (needs_qk_output && qk_matmul_output_mode == 3) {- qk_debug_output = softmax_out->output(0);- }-- // 6. softmax @ V- auto output = std::make_shared<v0::MatMul>(softmax_out, V);-- ov::OutputVector results;- results.push_back(output->output(0));- if (needs_qk_output && qk_debug_output.get_node()) {- results.push_back(qk_debug_output);- } else {- results.push_back(ov::Output<ov::Node>{});- }- return results;-}-} // namespace} // namespace detail@@ -365,7 +196,7 @@ ov::OutputVector attention(const ov::frontend::onnx::Node& node) {if (attn_mask.get_element_type() == ov::element::boolean) {// For manual path, convert boolean to float; for SDPA path, SDPA handles boolean nativelyif (softcap > 0.0f || needs_qk_output) {- attn_mask = detail::convert_boolean_mask(attn_mask, Q.get_element_type());+ attn_mask = convert_boolean_mask(attn_mask, Q.get_element_type());}}}@@ -375,7 +206,7 @@ ov::OutputVector attention(const ov::frontend::onnx::Node& node) {// which doesn't match the ONNX spec's np.tril(k=0) for non-square attention matrices// (seq_q != seq_kv). For KV cache scenarios, use offset to account for past sequence.if (is_causal) {- auto causal_mask = detail::build_causal_mask(Q, K, has_past_key);+ auto causal_mask = build_causal_mask(Q, K, has_past_key);if (has_attn_mask) {attn_mask = std::make_shared<v1::Add>(attn_mask, causal_mask);} else {@@ -391,23 +222,23 @@ ov::OutputVector attention(const ov::frontend::onnx::Node& node) {if (softcap > 0.0f || needs_qk_output) {// Manual decomposition path (softcap or debug output)- auto results = detail::build_manual_attention(Q,- K,- V,- has_attn_mask,- attn_mask,- scale_attr,- softcap,- is_causal,- qk_matmul_output_mode,- needs_qk_output);+ auto results = build_manual_attention(Q,+ K,+ V,+ has_attn_mask,+ attn_mask,+ scale_attr,+ softcap,+ is_causal,+ qk_matmul_output_mode,+ needs_qk_output);Y = results[0];if (needs_qk_output && results.size() > 1 && results[1].get_node()) {qk_debug_output = results[1];}} else {// SDPA path (primary fast path)- Y = detail::build_sdpa(Q, K, V, has_attn_mask, attn_mask, scale_attr, is_causal);+ Y = build_sdpa(Q, K, V, has_attn_mask, attn_mask, scale_attr, is_causal);}// Reshape output back to 3D if Q was 3Ddiff --git a/src/frontends/onnx/frontend/src/op/com.microsoft/multi_head_attention.cpp b/src/frontends/onnx/frontend/src/op/com.microsoft/multi_head_attention.cppnew file mode 100644index 00000000000..ee4dcf9c24e--- /dev/null+++ b/src/frontends/onnx/frontend/src/op/com.microsoft/multi_head_attention.cpp@@ -0,0 +1,463 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include <tuple>++#include "core/null_node.hpp"+#include "core/operator_set.hpp"+#include "exceptions.hpp"+#include "openvino/frontend/exception.hpp"+#include "openvino/op/add.hpp"+#include "openvino/op/broadcast.hpp"+#include "openvino/op/concat.hpp"+#include "openvino/op/constant.hpp"+#include "openvino/op/convert.hpp"+#include "openvino/op/gather_elements.hpp"+#include "openvino/op/greater.hpp"+#include "openvino/op/multiply.hpp"+#include "openvino/op/range.hpp"+#include "openvino/op/reshape.hpp"+#include "openvino/op/scatter_update.hpp"+#include "openvino/op/shape_of.hpp"+#include "openvino/op/slice.hpp"+#include "openvino/op/squeeze.hpp"+#include "openvino/op/transpose.hpp"+#include "openvino/op/unsqueeze.hpp"+#include "openvino/op/variadic_split.hpp"+#include "utils/attention.hpp"+#include "utils/common.hpp"+#include "utils/split.hpp"++using namespace ov::op;+using namespace ov::frontend::onnx::attention;++namespace ov {+namespace frontend {+namespace onnx {+namespace com_microsoft {+namespace detail {+namespace {++// Reshape 3D input (batch, seq, num_heads * head_size) to 4D (batch, num_heads, seq, head_size)+ov::Output<ov::Node> reshape_3d_to_4d(const ov::Output<ov::Node>& input, int64_t num_heads) {+ // Reshape to (batch, seq, num_heads, head_size)+ auto reshape_pattern = v0::Constant::create<int64_t>(ov::element::i64, ov::Shape{4}, {0, 0, num_heads, -1});+ auto reshaped = std::make_shared<v1::Reshape>(input, reshape_pattern, true);+ // Transpose to (batch, num_heads, seq, head_size)+ auto perm = v0::Constant::create(ov::element::i64, ov::Shape{4}, {0, 2, 1, 3});+ return std::make_shared<v1::Transpose>(reshaped, perm);+}++// Reshape 4D output (batch, num_heads, seq, head_size) back to 3D (batch, seq, num_heads * head_size)+ov::Output<ov::Node> reshape_4d_to_3d(const ov::Output<ov::Node>& output) {+ // Transpose from (batch, num_heads, seq, head_size) to (batch, seq, num_heads, head_size)+ auto perm = v0::Constant::create(ov::element::i64, ov::Shape{4}, {0, 2, 1, 3});+ auto transposed = std::make_shared<v1::Transpose>(output, perm);+ // Reshape to (batch, seq, num_heads * head_size)+ auto reshape_pattern = v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, -1});+ return std::make_shared<v1::Reshape>(transposed, reshape_pattern, true);+}++// Split bias into Q, K, V parts and reshape each to (1, num_heads, 1, head_size) for broadcasting.+OutputVector split_bias(const Output<ov::Node>& bias,+ const Output<ov::Node>& Q,+ const Output<ov::Node>& K,+ const Output<ov::Node>& V,+ int64_t num_heads) {+ auto Q_shape = std::make_shared<v3::ShapeOf>(Q);+ auto K_shape = std::make_shared<v3::ShapeOf>(K);+ auto V_shape = std::make_shared<v3::ShapeOf>(V);+ auto Q_head_depth = get_dimensions(Q_shape, {3});+ auto K_head_depth = get_dimensions(K_shape, {3});+ auto V_head_depth = get_dimensions(V_shape, {3});+ auto num_heads_node = ov::op::v0::Constant::create(ov::element::i64, Shape{1}, {num_heads});+ auto Q_hidden_dim = std::make_shared<v1::Multiply>(Q_head_depth, num_heads_node);+ auto K_hidden_dim = std::make_shared<v1::Multiply>(K_head_depth, num_heads_node);+ auto V_hidden_dim = std::make_shared<v1::Multiply>(V_head_depth, num_heads_node);++ auto axis_node = v0::Constant::create(ov::element::i64, Shape{}, {0});+ auto split_lengths_node = std::make_shared<v0::Concat>(ov::NodeVector{Q_hidden_dim, K_hidden_dim, V_hidden_dim}, 0);+ auto variadic_split = std::make_shared<v1::VariadicSplit>(bias, axis_node, split_lengths_node);++ auto outputs = variadic_split->outputs();+ auto reshape_pattern = v0::Constant::create<int64_t>(ov::element::i64, ov::Shape{4}, {1, num_heads, 1, -1});+ outputs[0] = std::make_shared<v1::Reshape>(outputs[0], reshape_pattern, false);+ outputs[1] = std::make_shared<v1::Reshape>(outputs[1], reshape_pattern, false);+ outputs[2] = std::make_shared<v1::Reshape>(outputs[2], reshape_pattern, false);+ return outputs;+}++// Build 4D attention mask from key_padding_mask input, which can have rank 1, 2 or 3.+ov::Output<ov::Node> build_mask(const ov::Output<ov::Node>& key_padding_mask,+ const ov::Output<ov::Node>& Q,+ const ov::Output<ov::Node>& K,+ float mask_filter_value) {+ auto q_shape = std::make_shared<v3::ShapeOf>(Q);+ auto k_shape = std::make_shared<v3::ShapeOf>(K);+ // Q is 4D: (B, heads, seq_q, head_size), K is 4D: (B, heads, seq_kv, head_size)+ auto seq_q = get_dimensions(q_shape, {2});+ auto seq_kv = get_dimensions(k_shape, {2});+ auto batch = get_dimensions(q_shape, {0});++ auto zero = v0::Constant::create(ov::element::i64, ov::Shape{}, {0});+ auto zero_1d = v0::Constant::create(ov::element::i64, ov::Shape{1}, {0});+ auto one = v0::Constant::create(ov::element::i64, ov::Shape{}, {1});+ auto one_1d = v0::Constant::create(ov::element::i64, ov::Shape{1}, {1});++ auto seq_q_scalar = std::make_shared<v0::Squeeze>(seq_q, zero);+ auto seq_kv_scalar = std::make_shared<v0::Squeeze>(seq_kv, zero);++ auto key_padding_rank = key_padding_mask.get_partial_shape().rank();+ FRONT_END_GENERAL_CHECK(key_padding_rank.is_static(), "'key_padding_mask' rank must be static");+ ov::Output<ov::Node> output_mask_3d;+ if (key_padding_rank.get_length() == 1) {+ // Column indices: [0, 1, ..., seq_kv-1]+ auto col_indices = std::make_shared<v4::Range>(zero, seq_kv_scalar, one, ov::element::i64);++ // Take only first B elements, in case of packed 3*B+2 mask, still only first B needed+ auto sliced = std::make_shared<v8::Slice>(key_padding_mask, zero_1d, batch, one_1d, zero_1d);+ // Unsqueeze mask to (B, 1)+ auto converted = std::make_shared<v0::Convert>(sliced, ov::element::i64);+ auto batch_indices = std::make_shared<v0::Unsqueeze>(converted, one_1d);++ auto is_allowed = std::make_shared<v1::Greater>(batch_indices, col_indices);++ auto mask_3d = std::make_shared<v0::Unsqueeze>(is_allowed, one_1d); // (B, 1, seq_kv)++ auto broadcast_shape = std::make_shared<v0::Concat>(ov::NodeVector{batch, seq_q, seq_kv}, 0);+ output_mask_3d = std::make_shared<v1::Broadcast>(mask_3d, broadcast_shape);+ } else if (key_padding_rank.get_length() == 2) {+ auto mask_3d = std::make_shared<v0::Unsqueeze>(key_padding_mask, one_1d); // (B, 1, seq_kv)+ auto converted = std::make_shared<v0::Convert>(mask_3d, ov::element::boolean);+ auto broadcast_shape = std::make_shared<v0::Concat>(ov::NodeVector{batch, seq_q, seq_kv}, 0);+ output_mask_3d = std::make_shared<v1::Broadcast>(converted, broadcast_shape);+ } else {+ FRONT_END_GENERAL_CHECK(key_padding_rank.get_length() == 3,+ "Expected 'key_padding_mask' to have a rank of 1, 2 or 3, got: ",+ key_padding_rank.get_length());+ output_mask_3d = std::make_shared<v0::Convert>(key_padding_mask, ov::element::boolean);+ }+ // Convert boolean to additive float mask: true -> 0.0, false -> -10000.0+ auto output_mask_4d = std::make_shared<v0::Unsqueeze>(output_mask_3d, one_1d); // (B, 1, seq_q, seq_kv)+ return convert_boolean_mask(output_mask_4d, Q.get_element_type(), mask_filter_value);+}++// Handle different input formats for Q, K, V: separate vs packed. Returns {Q, K, V} in (batch, num_heads, seq_len,+// head_size) and is_regular_QKV flag.+std::tuple<ov::OutputVector, bool> prepare_qkv(const ov::frontend::onnx::Node& node,+ const ov::OutputVector& inputs,+ int64_t num_heads) {+ ov::Output<ov::Node> Q, K, V;+ bool is_packed_QKV = !common::is_input_valid(node, 1) && !common::is_input_valid(node, 2);+ bool is_packed_KV = !common::is_input_valid(node, 2) && !is_packed_QKV;+ bool is_cross_attn = false;++ if (is_packed_QKV) {+ // Packed QKV: split input 0 into Q, K, V+ // In this case input[0] should have shape (batch_size, kv_sequence_length, num_heads, 3, head_size)+ auto split = ov::op::util::make_split(inputs[0], 3, 3);+ auto reshape_pattern = v0::Constant::create(ov::element::i64, ov::Shape{4}, {0, 0, 0, -1});+ auto reshaped_Q = std::make_shared<v1::Reshape>(split[0], reshape_pattern, true);+ auto reshaped_K = std::make_shared<v1::Reshape>(split[1], reshape_pattern, true);+ auto reshaped_V = std::make_shared<v1::Reshape>(split[2], reshape_pattern, true);+ auto perm = v0::Constant::create(ov::element::i64, ov::Shape{4}, {0, 2, 1, 3});+ Q = std::make_shared<v1::Transpose>(reshaped_Q, perm);+ K = std::make_shared<v1::Transpose>(reshaped_K, perm);+ V = std::make_shared<v1::Transpose>(reshaped_V, perm);+ } else if (is_packed_KV) {+ // Packed KV: input 1 is K/V concatenated; split into K and V+ // Q should be 3D in this case+ Q = reshape_3d_to_4d(inputs[0], num_heads);+ // In this case input[1] should have shape (batch_size, kv_sequence_length, num_heads, 2, head_size)+ auto split = ov::op::util::make_split(inputs[1], 2, 3);+ auto reshape_pattern = v0::Constant::create(ov::element::i64, ov::Shape{4}, {0, 0, 0, -1});+ auto reshaped_K = std::make_shared<v1::Reshape>(split[0], reshape_pattern, true);+ auto reshaped_V = std::make_shared<v1::Reshape>(split[1], reshape_pattern, true);+ auto perm = v0::Constant::create(ov::element::i64, ov::Shape{4}, {0, 2, 1, 3});+ K = std::make_shared<v1::Transpose>(reshaped_K, perm);+ V = std::make_shared<v1::Transpose>(reshaped_V, perm);+ } else {+ Q = reshape_3d_to_4d(inputs[0], num_heads);++ K = inputs[1];+ V = inputs[2];+ // Check if this is cross-attention: K and V are 4D in this case+ auto k_rank = K.get_partial_shape().rank();+ auto v_rank = V.get_partial_shape().rank();+ if (k_rank.is_static() && v_rank.is_static()) {+ bool kv_is_3d = (k_rank.get_length() == 3) && (v_rank.get_length() == 3);+ is_cross_attn = (k_rank.get_length() == 4) && (v_rank.get_length() == 4);+ CHECK_VALID_NODE(node,+ kv_is_3d || is_cross_attn,+ "KV input rank must be 3 or 4, got: ",+ k_rank.get_length(),+ v_rank.get_length());+ }+ if (!is_cross_attn) {+ // For self-attention, reshape K and V to 4D+ K = reshape_3d_to_4d(K, num_heads);+ V = reshape_3d_to_4d(V, num_heads);+ }+ }+ bool is_regular_QKV = !(is_packed_QKV || is_packed_KV || is_cross_attn);+ return {{Q, K, V}, is_regular_QKV};+}++// Apply beam search cache indirection to reorder cached K/V by beam indices.+ov::OutputVector apply_cache_indirection(const ov::Output<ov::Node>& cache_K,+ const ov::Output<ov::Node>& cache_V,+ const ov::Output<ov::Node>& indirection_input,+ const ov::Output<ov::Node>& past_seq_len_1d) {+ auto zero_1d = v0::Constant::create(ov::element::i64, ov::Shape{1}, {0});+ auto one_1d = v0::Constant::create(ov::element::i64, ov::Shape{1}, {1});+ auto axis_2 = v0::Constant::create(ov::element::i64, ov::Shape{1}, {2});++ ov::Output<ov::Node> cache_indirection =+ std::make_shared<v8::Slice>(indirection_input, zero_1d, past_seq_len_1d, one_1d, axis_2);+ auto indirection_shape = std::make_shared<v3::ShapeOf>(cache_indirection);+ auto cache_shape = std::make_shared<v3::ShapeOf>(cache_K);+ auto num_beams = get_dimensions(indirection_shape, {1});+ auto indirection_batch = get_dimensions(indirection_shape, {0});+ auto cache_num_heads = get_dimensions(cache_shape, {1});+ auto cache_head_size = get_dimensions(cache_shape, {3});+ auto reshape_pattern = std::make_shared<v0::Concat>(+ ov::OutputVector{indirection_batch, num_beams, cache_num_heads, past_seq_len_1d, cache_head_size},+ 0);+ ov::Output<ov::Node> cache_K_out = std::make_shared<v1::Reshape>(cache_K, reshape_pattern, false);+ ov::Output<ov::Node> cache_V_out = std::make_shared<v1::Reshape>(cache_V, reshape_pattern, false);++ auto indirection_reshape_pattern =+ std::make_shared<v0::Concat>(ov::OutputVector{indirection_batch, num_beams, one_1d, past_seq_len_1d, one_1d},+ 0);+ cache_indirection = std::make_shared<v1::Reshape>(cache_indirection, indirection_reshape_pattern, false);+ cache_indirection = std::make_shared<v1::Broadcast>(cache_indirection, reshape_pattern);++ // Gather with indirection: (B * beam_num, seq_kv)+ cache_K_out = std::make_shared<v6::GatherElements>(cache_K_out, cache_indirection, 1);+ cache_V_out = std::make_shared<v6::GatherElements>(cache_V_out, cache_indirection, 1);++ cache_K_out = std::make_shared<v1::Reshape>(cache_K_out, cache_shape, false);+ cache_V_out = std::make_shared<v1::Reshape>(cache_V_out, cache_shape, false);+ return {cache_K_out, cache_V_out};+}++// Handle KV cache: buffer sharing, cache indirection, and concatenation with current K/V.+// Modifies K, V by prepending cached values. Returns {present_key, present_value}.+ov::OutputVector apply_kv_cache(const ov::Output<ov::Node>& K,+ const ov::Output<ov::Node>& V,+ const ov::OutputVector& inputs,+ bool has_buffer_sharing,+ bool has_cache_indirection) {+ ov::Output<ov::Node> present_key, present_value;+ ov::Output<ov::Node> cache_K = inputs[6];+ ov::Output<ov::Node> cache_V = inputs[7];+ if (has_buffer_sharing) {+ auto past_seq_len_converted = std::make_shared<v0::Convert>(inputs[8], ov::element::i64);+ auto new_shape = v0::Constant::create(ov::element::i64, ov::Shape{1}, {1});+ auto past_seq_len_1d = std::make_shared<v1::Reshape>(past_seq_len_converted, new_shape, false);++ auto k_shape = std::make_shared<v3::ShapeOf>(K);+ auto seq_kv = get_dimensions(k_shape, {2});++ // First, update the present values+ auto start = std::make_shared<v0::Squeeze>(past_seq_len_1d);+ auto end = std::make_shared<v0::Squeeze>(std::make_shared<v1::Add>(past_seq_len_1d, seq_kv));+ auto step = v0::Constant::create(ov::element::i64, ov::Shape{}, {1});+ auto axis_2 = v0::Constant::create(ov::element::i64, ov::Shape{1}, {2});+ auto indices = std::make_shared<v4::Range>(start, end, step, ov::element::i64);+ present_key = std::make_shared<v3::ScatterUpdate>(cache_K, indices, K, axis_2);+ present_value = std::make_shared<v3::ScatterUpdate>(cache_V, indices, V, axis_2);++ // Then slice the past values+ auto zero_1d = v0::Constant::create(ov::element::i64, ov::Shape{1}, {0});+ auto one_1d = v0::Constant::create(ov::element::i64, ov::Shape{1}, {1});+ cache_K = std::make_shared<v8::Slice>(cache_K, zero_1d, past_seq_len_1d, one_1d, axis_2);+ cache_V = std::make_shared<v8::Slice>(cache_V, zero_1d, past_seq_len_1d, one_1d, axis_2);+ if (has_cache_indirection) {+ auto kv_cache_with_indirection = apply_cache_indirection(cache_K, cache_V, inputs[9], past_seq_len_1d);+ cache_K = kv_cache_with_indirection[0];+ cache_V = kv_cache_with_indirection[1];+ }+ }++ auto K_out = std::make_shared<v0::Concat>(ov::OutputVector{cache_K, K}, 2);+ auto V_out = std::make_shared<v0::Concat>(ov::OutputVector{cache_V, V}, 2);+ // If buffer sharing is disabled, present_key and present_value are K and V after concatenation+ if (!has_buffer_sharing) {+ present_key = K_out;+ present_value = V_out;+ }+ return {K_out, V_out, present_key, present_value};+}++} // namespace+} // namespace detail++namespace opset_1 {+ov::OutputVector multi_head_attention(const ov::frontend::onnx::Node& node) {+ auto inputs = node.get_ov_inputs();+ const auto num_inputs = inputs.size();+ CHECK_VALID_NODE(node, num_inputs >= 1, "MultiHeadAttention expects at least 1 input, got: ", num_inputs);++ // Attributes+ int64_t num_heads = node.get_attribute_value<int64_t>("num_heads");+ float mask_filter_value = node.get_attribute_value<float>("mask_filter_value", -10000.0f);+ bool unidirectional = static_cast<bool>(node.get_attribute_value<int64_t>("unidirectional", 0));+ float scale_attr = node.get_attribute_value<float>("scale", 0);++ // Required inputs+ CHECK_VALID_NODE(node, num_heads > 0, "num_heads attribute should be > 0");+ auto [qkv, is_regular_QKV] = detail::prepare_qkv(node, inputs, num_heads);+ auto Q = qkv[0], K = qkv[1], V = qkv[2];++ // Optional inputs+ bool has_bias = common::is_input_valid(node, 3);+ bool has_key_padding_mask = common::is_input_valid(node, 4);+ bool has_attention_bias = common::is_input_valid(node, 5);+ bool has_past_key = common::is_input_valid(node, 6);+ bool has_past_value = common::is_input_valid(node, 7);+ bool has_buffer_sharing = common::is_input_valid(node, 8);+ bool has_cache_indirection = common::is_input_valid(node, 9);++ CHECK_VALID_NODE(node,+ !has_cache_indirection || has_buffer_sharing,+ "cache_indirection is only supported in buffer_sharing mode");++ CHECK_VALID_NODE(node,+ !has_buffer_sharing || has_past_key,+ "buffer_sharing is supported when past key/value are present");++ CHECK_VALID_NODE(node,+ has_past_key == has_past_value,+ "past_key and past_value must be both present or both absent");+ CHECK_VALID_NODE(node,+ !has_past_key || is_regular_QKV,+ "past_key and past_value are only supported in unpacked 3D case");++ if (has_bias) {+ auto bias_splits = detail::split_bias(inputs[3], Q, K, V, num_heads);+ Q = std::make_shared<v1::Add>(Q, bias_splits[0]);+ K = std::make_shared<v1::Add>(K, bias_splits[1]);+ V = std::make_shared<v1::Add>(V, bias_splits[2]);+ }++ // Handle KV cache+ ov::Output<ov::Node> present_key = K;+ ov::Output<ov::Node> present_value = V;+ if (has_past_key) {+ auto kv_cache_result = detail::apply_kv_cache(K, V, inputs, has_buffer_sharing, has_cache_indirection);+ K = kv_cache_result[0];+ V = kv_cache_result[1];+ present_key = kv_cache_result[2];+ present_value = kv_cache_result[3];+ }++ // Prepare attention mask+ ov::Output<ov::Node> attn_mask;+ if (has_key_padding_mask) {+ attn_mask = inputs[4];+ auto attn_rank = attn_mask.get_partial_shape().rank();+ CHECK_VALID_NODE(node, attn_rank.is_static(), "Attention rank must be static, got rank: ", attn_rank);++ attn_mask = detail::build_mask(attn_mask, Q, K, mask_filter_value);+ }++ // Build an explicit unidirectional mask instead of relying on SDPA's internal is_causal flag.+ // SDPA's internal mask uses offset-based semantics (ncausal = kv_len - q_len + m + 1)+ // which doesn't match the ONNX spec's np.tril(k=0) for non-square attention matrices+ // (seq_q != seq_kv). For KV cache scenarios, use offset to account for past sequence.+ if (unidirectional) {+ auto unidirectional_mask = build_causal_mask(Q, K, has_past_key);+ if (has_key_padding_mask) {+ attn_mask = std::make_shared<v1::Add>(attn_mask, unidirectional_mask);+ } else {+ attn_mask = unidirectional_mask;+ }+ has_key_padding_mask = true;+ }++ if (has_attention_bias) {+ auto attention_bias = inputs[5];+ auto bias_rank = attention_bias.get_partial_shape().rank();+ CHECK_VALID_NODE(node,+ bias_rank.is_static() && bias_rank.get_length() == 4,+ "attention_bias must have rank 4, got: ",+ bias_rank);+ if (has_key_padding_mask) {+ attn_mask = std::make_shared<v1::Add>(attn_mask, attention_bias);+ } else {+ attn_mask = attention_bias;+ }+ has_key_padding_mask = true;+ }++ // Choose execution path+ ov::Output<ov::Node> Y;+ ov::Output<ov::Node> qk_debug_output;++ // Determine number of requested outputs+ size_t num_outputs = node.get_outputs_size();+ const auto& output_names = node.get_output_names();+ bool needs_qk_output = output_names.size() > 3 && !output_names[3].get().empty();++ if (needs_qk_output) {+ // Manual decomposition path (softcap or debug output)+ auto results = build_manual_attention(Q,+ K,+ V,+ has_key_padding_mask,+ attn_mask,+ scale_attr,+ 0.0f /*softcap*/,+ false,+ 0,+ true);+ Y = results[0];+ qk_debug_output = results[1];+ } else {+ // SDPA path (primary fast path)+ Y = build_sdpa(Q, K, V, has_key_padding_mask, attn_mask, scale_attr, false);+ }++ Y = detail::reshape_4d_to_3d(Y);++ // Build output vector.+ // Output names from the ONNX graph determine which outputs are actually requested.+ // Empty names indicate unused optional outputs — push NullNode for those to avoid+ // creating shared input/output parameters that confuse port resolution.+ ov::OutputVector results;+ results.push_back(Y);++ if (num_outputs > 1) {+ if (!output_names[1].get().empty()) {+ results.push_back(present_key);+ } else {+ results.push_back(std::make_shared<NullNode>()->output(0));+ }+ }+ if (num_outputs > 2) {+ if (!output_names[2].get().empty()) {+ results.push_back(present_value);+ } else {+ results.push_back(std::make_shared<NullNode>()->output(0));+ }+ }+ if (num_outputs > 3) {+ if (qk_debug_output.get_node() && !output_names[3].get().empty()) {+ results.push_back(qk_debug_output);+ } else {+ results.push_back(std::make_shared<NullNode>()->output(0));+ }+ }++ return results;+}++ONNX_OP("MultiHeadAttention", OPSET_SINCE(1), com_microsoft::opset_1::multi_head_attention, MICROSOFT_DOMAIN);+} // namespace opset_1++} // namespace com_microsoft+} // namespace onnx+} // namespace frontend+} // namespace ovdiff --git a/src/frontends/onnx/frontend/src/utils/attention.cpp b/src/frontends/onnx/frontend/src/utils/attention.cppindex 4164c1f7714..419d964d58b 100644--- a/src/frontends/onnx/frontend/src/utils/attention.cpp+++ b/src/frontends/onnx/frontend/src/utils/attention.cpp@@ -4,8 +4,24 @@#include "utils/attention.hpp"+#include "openvino/op/add.hpp"#include "openvino/op/constant.hpp"+#include "openvino/op/convert.hpp"+#include "openvino/op/divide.hpp"#include "openvino/op/gather.hpp"+#include "openvino/op/greater_eq.hpp"+#include "openvino/op/matmul.hpp"+#include "openvino/op/multiply.hpp"+#include "openvino/op/range.hpp"+#include "openvino/op/scaled_dot_product_attention.hpp"+#include "openvino/op/select.hpp"+#include "openvino/op/shape_of.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"+#include "openvino/op/unsqueeze.hpp"using namespace ov::op;@@ -24,6 +40,163 @@ std::shared_ptr<ov::Node> get_dimensions(const std::shared_ptr<ov::Node>& node,return get_dimensions(std::make_shared<v3::ShapeOf>(node), dims);}+// Convert boolean mask to float additive mask: true -> 0.0, false -> -10000.0+ov::Output<ov::Node> convert_boolean_mask(const ov::Output<ov::Node>& mask,+ const ov::element::Type& type,+ float mask_filter_value) {+ auto zero = v0::Constant::create(type, ov::Shape{}, {0.0f});+ auto neg_large = v0::Constant::create(type, ov::Shape{}, {mask_filter_value});+ return std::make_shared<v1::Select>(mask, zero, neg_large);+}++// Build additive causal mask of shape (seq_q, seq_kv): 0 for allowed, -10000 for masked.+// When use_offset=true, accounts for KV cache offset so that query position i attends to+// key positions j where j <= i + (seq_kv - seq_q). Use this for KV cache scenarios.+// When use_offset=false, builds a simple lower-triangular mask matching np.tril(k=0),+// where query position i attends to key positions j where j <= i.+ov::Output<ov::Node> build_causal_mask(const ov::Output<ov::Node>& Q, const ov::Output<ov::Node>& K, bool use_offset) {+ auto q_shape = std::make_shared<v3::ShapeOf>(Q);+ auto k_shape = std::make_shared<v3::ShapeOf>(K);+ // Q is 4D: (B, heads, seq_q, head_size), K is 4D: (B, heads, seq_kv, head_size)+ auto seq_q = get_dimensions(q_shape, {2});+ auto seq_kv = get_dimensions(k_shape, {2});++ auto zero = v0::Constant::create(ov::element::i64, ov::Shape{}, {0});+ auto one = v0::Constant::create(ov::element::i64, ov::Shape{}, {1});++ auto seq_q_scalar = std::make_shared<v0::Squeeze>(seq_q, zero);+ auto seq_kv_scalar = std::make_shared<v0::Squeeze>(seq_kv, zero);++ // Column indices: [0, 1, ..., seq_kv-1]+ auto col_indices = std::make_shared<v4::Range>(zero, seq_kv_scalar, one, ov::element::i64);++ std::shared_ptr<ov::Node> row_indices;+ if (use_offset) {+ // Row indices adjusted for KV cache offset: [offset, offset+1, ..., offset+seq_q-1]+ auto offset = std::make_shared<v1::Subtract>(seq_kv_scalar, seq_q_scalar);+ auto end = std::make_shared<v1::Add>(offset, seq_q_scalar);+ row_indices = std::make_shared<v4::Range>(offset, end, one, ov::element::i64);+ } else {+ // Row indices without offset: [0, 1, ..., seq_q-1] (matches np.tril(k=0))+ row_indices = std::make_shared<v4::Range>(zero, seq_q_scalar, one, ov::element::i64);+ }++ // Unsqueeze rows to (seq_q, 1) for broadcasting with (seq_kv,)+ auto axis = v0::Constant::create(ov::element::i64, ov::Shape{1}, {1});+ auto rows_2d = std::make_shared<v0::Unsqueeze>(row_indices, axis);++ // Lower-triangular: position (i, j) allowed when adjusted_row[i] >= col[j]+ auto is_allowed = std::make_shared<v1::GreaterEqual>(rows_2d, col_indices);++ // Convert boolean to additive float mask: true -> 0.0, false -> -10000.0+ return convert_boolean_mask(is_allowed, Q.get_element_type());+}++// Build SDPA-based attention (primary fast path)+ov::Output<ov::Node> build_sdpa(const ov::Output<ov::Node>& Q,+ const ov::Output<ov::Node>& K,+ const ov::Output<ov::Node>& V,+ bool has_mask,+ const ov::Output<ov::Node>& attn_mask,+ float scale_attr,+ bool is_causal) {+ ov::OutputVector inputs{Q, K, V};+ if (has_mask) {+ inputs.push_back(attn_mask);+ }+ if (scale_attr != 0.0f) {+ if (!has_mask) {+ // SDPA interprets inputs positionally (index 3 = mask, index 4 = scale),+ // so a zero mask placeholder is needed when only scale is provided+ inputs.push_back(v0::Constant::create(Q.get_element_type(), ov::Shape{}, {0.0f}));+ }+ inputs.push_back(v0::Constant::create(Q.get_element_type(), ov::Shape{}, {scale_attr}));+ }+ return std::make_shared<v13::ScaledDotProductAttention>(inputs, is_causal)->output(0);+}++// Build manual attention decomposition (for softcap or qk_matmul_output)+// Returns {Y, qk_matmul_output_or_null}+ov::OutputVector build_manual_attention(const ov::Output<ov::Node>& Q,+ const ov::Output<ov::Node>& K,+ const ov::Output<ov::Node>& V,+ bool has_mask,+ const ov::Output<ov::Node>& attn_mask,+ float scale_attr,+ float softcap,+ bool is_causal,+ int64_t qk_matmul_output_mode,+ bool needs_qk_output) {+ // 1. Q @ K^T+ auto qk = std::make_shared<v0::MatMul>(Q, K, false, true);++ // 2. Apply scale+ std::shared_ptr<ov::Node> scaled_qk;+ if (scale_attr != 0.0f) {+ auto scale_node = v0::Constant::create(Q.get_element_type(), ov::Shape{}, {scale_attr});+ scaled_qk = std::make_shared<v1::Multiply>(qk, scale_node);+ } else {+ // Default scale: 1/sqrt(head_size). Q is always 4D here: (B, heads, seq, head_size)+ auto q_shape = std::make_shared<v3::ShapeOf>(Q);+ auto head_size = get_dimensions(q_shape, {3});+ auto head_size_f = std::make_shared<v0::Convert>(head_size, Q.get_element_type());+ auto sqrt_head = std::make_shared<v0::Sqrt>(head_size_f);+ scaled_qk = std::make_shared<v1::Divide>(qk, sqrt_head);+ }++ // 3. Apply attention mask and causal mask+ std::shared_ptr<ov::Node> masked = scaled_qk;+ if (has_mask) {+ masked = std::make_shared<v1::Add>(scaled_qk, attn_mask);+ }+ if (is_causal) {+ auto causal_mask = build_causal_mask(Q, K, false);+ masked = std::make_shared<v1::Add>(masked, causal_mask);+ }++ // Capture qk_matmul_output at mode 0 (raw QK) or mode 1 (after mask)+ ov::Output<ov::Node> qk_debug_output;+ if (needs_qk_output && qk_matmul_output_mode == 0) {+ qk_debug_output = scaled_qk->output(0);+ } else if (needs_qk_output && qk_matmul_output_mode == 1) {+ qk_debug_output = masked->output(0);+ }++ // 4. Apply softcap: softcap * tanh(scores / softcap)+ std::shared_ptr<ov::Node> capped = masked;+ if (softcap > 0.0f) {+ auto cap = v0::Constant::create(Q.get_element_type(), ov::Shape{}, {softcap});+ auto divided = std::make_shared<v1::Divide>(masked, cap);+ auto tanh_out = std::make_shared<v0::Tanh>(divided);+ capped = std::make_shared<v1::Multiply>(tanh_out, cap);+ }++ // Capture at mode 2 (after softcap)+ if (needs_qk_output && qk_matmul_output_mode == 2) {+ qk_debug_output = capped->output(0);+ }++ // 5. Softmax+ auto softmax_out = std::make_shared<v8::Softmax>(capped, -1);++ // Capture at mode 3 (after softmax)+ if (needs_qk_output && qk_matmul_output_mode == 3) {+ qk_debug_output = softmax_out->output(0);+ }++ // 6. softmax @ V+ auto output = std::make_shared<v0::MatMul>(softmax_out, V);++ ov::OutputVector results;+ results.push_back(output->output(0));+ if (needs_qk_output && qk_debug_output.get_node()) {+ results.push_back(qk_debug_output);+ } else {+ results.push_back(ov::Output<ov::Node>{});+ }+ return results;+}+} // namespace attention} // namespace onnx} // namespace frontenddiff --git a/src/frontends/onnx/frontend/src/utils/attention.hpp b/src/frontends/onnx/frontend/src/utils/attention.hppindex 32d9dca2509..42cec237130 100644--- a/src/frontends/onnx/frontend/src/utils/attention.hpp+++ b/src/frontends/onnx/frontend/src/utils/attention.hpp@@ -25,6 +25,69 @@ std::shared_ptr<ov::Node> get_dimensions(const std::shared_ptr<ov::op::v3::Shape/// \brief Convenience overload: computes ShapeOf for the given node, then extracts dimensions.std::shared_ptr<ov::Node> get_dimensions(const std::shared_ptr<ov::Node>& node, const std::vector<int>& dims);+/// \brief Convert boolean mask to float additive mask: true -> 0.0, false -> mask_filter_value.+///+/// \param mask Boolean tensor where true means "attend" and false means "mask out".+/// \param type Target floating-point element type for the output mask.+/// \param mask_filter_value Value assigned to masked (false) positions (default: -10000.0).+/// \return A Select node producing an additive float mask of the same shape as the input.+ov::Output<ov::Node> convert_boolean_mask(const ov::Output<ov::Node>& mask,+ const ov::element::Type& type,+ float mask_filter_value = -10000.0f);++/// \brief Build additive causal mask of shape (seq_q, seq_kv): 0 for allowed, -10000 for masked.+///+/// \param Q Query tensor of shape (B, heads, seq_q, head_size).+/// \param K Key tensor of shape (B, heads, seq_kv, head_size).+/// \param use_offset When true, adjusts row indices for KV cache offset so that query position i+/// attends to key positions j where j <= i + (seq_kv - seq_q). When false, builds+/// a simple lower-triangular mask (np.tril with k=0).+/// \return A float additive mask broadcastable over the attention scores.+ov::Output<ov::Node> build_causal_mask(const ov::Output<ov::Node>& Q, const ov::Output<ov::Node>& K, bool use_offset);++/// \brief Build SDPA-based attention (primary fast path).+///+/// \param Q Query tensor of shape (B, heads, seq_q, head_size).+/// \param K Key tensor of shape (B, heads, seq_kv, head_size).+/// \param V Value tensor of shape (B, heads, seq_kv, head_size).+/// \param has_mask Whether an attention mask is provided.+/// \param attn_mask Additive attention mask (used only when has_mask is true).+/// \param scale_attr Explicit scale factor; when 0.0 the SDPA op uses the default 1/sqrt(head_size).+/// \param is_causal When true, the SDPA op applies internal causal masking.+/// \return The output of ScaledDotProductAttention.+ov::Output<ov::Node> build_sdpa(const ov::Output<ov::Node>& Q,+ const ov::Output<ov::Node>& K,+ const ov::Output<ov::Node>& V,+ bool has_mask,+ const ov::Output<ov::Node>& attn_mask,+ float scale_attr,+ bool is_causal);++/// \brief Build manual attention decomposition (for softcap or qk_matmul_output).+///+/// \param Q Query tensor of shape (B, heads, seq_q, head_size).+/// \param K Key tensor of shape (B, heads, seq_kv, head_size).+/// \param V Value tensor of shape (B, heads, seq_kv, head_size).+/// \param has_mask Whether an attention mask is provided.+/// \param attn_mask Additive attention mask (used only when has_mask is true).+/// \param scale_attr Explicit scale factor; when 0.0, uses default 1/sqrt(head_size).+/// \param softcap Soft-capping value; when > 0, applies softcap * tanh(scores / softcap).+/// \param is_causal When true, adds an additive causal mask to attention scores.+/// \param qk_matmul_output_mode Selects at which stage the intermediate QK tensor is captured:+/// 0 = after scale, 1 = after mask, 2 = after softcap, 3 = after softmax.+/// \param needs_qk_output When true, the intermediate QK tensor is returned as the second output.+/// \return A two-element OutputVector: {attention_output, qk_intermediate_or_empty}.+ov::OutputVector build_manual_attention(const ov::Output<ov::Node>& Q,+ const ov::Output<ov::Node>& K,+ const ov::Output<ov::Node>& V,+ bool has_mask,+ const ov::Output<ov::Node>& attn_mask,+ float scale_attr,+ float softcap,+ bool is_causal,+ int64_t qk_matmul_output_mode,+ bool needs_qk_output);+} // namespace attention} // namespace onnx} // namespace frontenddiff --git a/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_01_packed_qkv.prototxt b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_01_packed_qkv.prototxtnew file mode 100644index 00000000000..03dc890e890--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_01_packed_qkv.prototxt@@ -0,0 +1,38 @@+ir_version: 10+producer_name: "OpenVINO ONNX Frontend"+graph {+ node {+ input: "query"+ output: "output"+ name: "MultiHeadAttention_01_packed_qkv"+ op_type: "MultiHeadAttention"+ attribute {+ name: "num_heads"+ i: 2+ type: INT+ }+ domain: "com.microsoft"+ }+ name: "multi_head_attention_01_packed_qkv"+ input {+ name: "query"+ type { tensor_type { elem_type: 1+ shape {+ dim { dim_value: 1 }+ dim { dim_value: 4 }+ dim { dim_value: 2 }+ dim { dim_value: 3 }+ dim { dim_value: 3 }+ } } }+ }+ output {+ name: "output"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+}+opset_import { version: 11 }+opset_import {+ domain: "com.microsoft"+ version: 1+}\ No newline at end of filediff --git a/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_02_query_packed_kv.prototxt b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_02_query_packed_kv.prototxtnew file mode 100644index 00000000000..cef02b86f74--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_02_query_packed_kv.prototxt@@ -0,0 +1,44 @@+ir_version: 10+producer_name: "OpenVINO ONNX Frontend"+graph {+ node {+ input: "query"+ input: "key"+ output: "output"+ name: "MultiHeadAttention_02_query_packed_kv"+ op_type: "MultiHeadAttention"+ attribute {+ name: "num_heads"+ i: 2+ type: INT+ }+ domain: "com.microsoft"+ }+ name: "multi_head_attention_02_query_packed_kv"+ input {+ name: "query"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ input {+ name: "key"+ type { tensor_type { elem_type: 1+ shape {+ dim { dim_value: 1 }+ dim { dim_value: 4 }+ dim { dim_value: 2 }+ dim { dim_value: 2 }+ dim { dim_value: 3 }+ } } }+ }+ output {+ name: "output"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+}+opset_import { version: 11 }+opset_import {+ domain: "com.microsoft"+ version: 1+}\ No newline at end of filediff --git a/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_03_qkv_regular.prototxt b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_03_qkv_regular.prototxtnew file mode 100644index 00000000000..b40fcf7b458--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_03_qkv_regular.prototxt@@ -0,0 +1,44 @@+ir_version: 10+producer_name: "OpenVINO ONNX Frontend"+graph {+ node {+ input: "query"+ input: "key"+ input: "value"+ output: "output"+ name: "MultiHeadAttention_03_qkv_regular"+ op_type: "MultiHeadAttention"+ attribute {+ name: "num_heads"+ i: 2+ type: INT+ }+ domain: "com.microsoft"+ }+ name: "multi_head_attention_03_qkv_regular"+ input {+ name: "query"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ input {+ name: "key"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ input {+ name: "value"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ output {+ name: "output"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+}+opset_import { version: 11 }+opset_import {+ domain: "com.microsoft"+ version: 1+}\ No newline at end of filediff --git a/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_04_cross_attn.prototxt b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_04_cross_attn.prototxtnew file mode 100644index 00000000000..b661d40017b--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_04_cross_attn.prototxt@@ -0,0 +1,44 @@+ir_version: 10+producer_name: "OpenVINO ONNX Frontend"+graph {+ node {+ input: "query"+ input: "key"+ input: "value"+ output: "output"+ name: "MultiHeadAttention_04_cross_attn"+ op_type: "MultiHeadAttention"+ attribute {+ name: "num_heads"+ i: 2+ type: INT+ }+ domain: "com.microsoft"+ }+ name: "multi_head_attention_04_cross_attn"+ input {+ name: "query"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ input {+ name: "key"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 2 } dim { dim_value: 4 } dim { dim_value: 3 } } } }+ }+ input {+ name: "value"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 2 } dim { dim_value: 4 } dim { dim_value: 3 } } } }+ }+ output {+ name: "output"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+}+opset_import { version: 11 }+opset_import {+ domain: "com.microsoft"+ version: 1+}\ No newline at end of filediff --git a/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_05_qkv_with_bias.prototxt b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_05_qkv_with_bias.prototxtnew file mode 100644index 00000000000..1e20555c436--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_05_qkv_with_bias.prototxt@@ -0,0 +1,50 @@+ir_version: 10+producer_name: "OpenVINO ONNX Frontend"+graph {+ node {+ input: "query"+ input: "key"+ input: "value"+ input: "bias"+ output: "output"+ name: "MultiHeadAttention_05_qkv_with_bias"+ op_type: "MultiHeadAttention"+ attribute {+ name: "num_heads"+ i: 2+ type: INT+ }+ domain: "com.microsoft"+ }+ name: "multi_head_attention_05_qkv_with_bias"+ input {+ name: "query"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ input {+ name: "key"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ input {+ name: "value"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ input {+ name: "bias"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 18 } } } }+ }+ output {+ name: "output"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+}+opset_import { version: 11 }+opset_import {+ domain: "com.microsoft"+ version: 1+}\ No newline at end of filediff --git a/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_06_mask_batch.prototxt b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_06_mask_batch.prototxtnew file mode 100644index 00000000000..19cc57a0bec--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_06_mask_batch.prototxt@@ -0,0 +1,51 @@+ir_version: 10+producer_name: "OpenVINO ONNX Frontend"+graph {+ node {+ input: "query"+ input: "key"+ input: "value"+ input: ""+ input: "key_padding_mask"+ output: "output"+ name: "MultiHeadAttention_06_mask_batch"+ op_type: "MultiHeadAttention"+ attribute {+ name: "num_heads"+ i: 2+ type: INT+ }+ domain: "com.microsoft"+ }+ name: "multi_head_attention_06_mask_batch"+ input {+ name: "query"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 2 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ input {+ name: "key"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 2 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ input {+ name: "value"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 2 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ input {+ name: "key_padding_mask"+ type { tensor_type { elem_type: 6+ shape { dim { dim_value: 2 } } } }+ }+ output {+ name: "output"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 2 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+}+opset_import { version: 11 }+opset_import {+ domain: "com.microsoft"+ version: 1+}\ No newline at end of filediff --git a/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_07_mask_packed_metadata.prototxt b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_07_mask_packed_metadata.prototxtnew file mode 100644index 00000000000..1b69769a516--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_07_mask_packed_metadata.prototxt@@ -0,0 +1,51 @@+ir_version: 10+producer_name: "OpenVINO ONNX Frontend"+graph {+ node {+ input: "query"+ input: "key"+ input: "value"+ input: ""+ input: "key_padding_mask"+ output: "output"+ name: "MultiHeadAttention_07_mask_packed_metadata"+ op_type: "MultiHeadAttention"+ attribute {+ name: "num_heads"+ i: 2+ type: INT+ }+ domain: "com.microsoft"+ }+ name: "multi_head_attention_07_mask_packed_metadata"+ input {+ name: "query"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ input {+ name: "key"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ input {+ name: "value"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ input {+ name: "key_padding_mask"+ type { tensor_type { elem_type: 6+ shape { dim { dim_value: 5 } } } }+ }+ output {+ name: "output"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+}+opset_import { version: 11 }+opset_import {+ domain: "com.microsoft"+ version: 1+}\ No newline at end of filediff --git a/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_08_mask_2D.prototxt b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_08_mask_2D.prototxtnew file mode 100644index 00000000000..ec508c06974--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_08_mask_2D.prototxt@@ -0,0 +1,51 @@+ir_version: 10+producer_name: "OpenVINO ONNX Frontend"+graph {+ node {+ input: "query"+ input: "key"+ input: "value"+ input: ""+ input: "key_padding_mask"+ output: "output"+ name: "MultiHeadAttention_08_mask_2D"+ op_type: "MultiHeadAttention"+ attribute {+ name: "num_heads"+ i: 2+ type: INT+ }+ domain: "com.microsoft"+ }+ name: "multi_head_attention_08_mask_2D"+ input {+ name: "query"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 2 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ input {+ name: "key"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 2 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ input {+ name: "value"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 2 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ input {+ name: "key_padding_mask"+ type { tensor_type { elem_type: 6+ shape { dim { dim_value: 2 } dim { dim_value: 4 } } } }+ }+ output {+ name: "output"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 2 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+}+opset_import { version: 11 }+opset_import {+ domain: "com.microsoft"+ version: 1+}\ No newline at end of filediff --git a/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_09_mask_3D.prototxt b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_09_mask_3D.prototxtnew file mode 100644index 00000000000..3c2eb311efd--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_09_mask_3D.prototxt@@ -0,0 +1,51 @@+ir_version: 10+producer_name: "OpenVINO ONNX Frontend"+graph {+ node {+ input: "query"+ input: "key"+ input: "value"+ input: ""+ input: "key_padding_mask"+ output: "output"+ name: "MultiHeadAttention_09_mask_3D"+ op_type: "MultiHeadAttention"+ attribute {+ name: "num_heads"+ i: 2+ type: INT+ }+ domain: "com.microsoft"+ }+ name: "multi_head_attention_09_mask_3D"+ input {+ name: "query"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 2 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ input {+ name: "key"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 2 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ input {+ name: "value"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 2 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ input {+ name: "key_padding_mask"+ type { tensor_type { elem_type: 6+ shape { dim { dim_value: 2 } dim { dim_value: 4 } dim { dim_value: 4 } } } }+ }+ output {+ name: "output"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 2 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+}+opset_import { version: 11 }+opset_import {+ domain: "com.microsoft"+ version: 1+}\ No newline at end of filediff --git a/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_10_attention_bias.prototxt b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_10_attention_bias.prototxtnew file mode 100644index 00000000000..39b2b3a6f54--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_10_attention_bias.prototxt@@ -0,0 +1,52 @@+ir_version: 10+producer_name: "OpenVINO ONNX Frontend"+graph {+ node {+ input: "query"+ input: "key"+ input: "value"+ input: ""+ input: ""+ input: "attention_bias"+ output: "output"+ name: "MultiHeadAttention_10_attention_bias"+ op_type: "MultiHeadAttention"+ attribute {+ name: "num_heads"+ i: 2+ type: INT+ }+ domain: "com.microsoft"+ }+ name: "multi_head_attention_10_attention_bias"+ input {+ name: "query"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 2 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ input {+ name: "key"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 2 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ input {+ name: "value"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 2 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ input {+ name: "attention_bias"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 2 } dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 4 } } } }+ }+ output {+ name: "output"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 2 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+}+opset_import { version: 11 }+opset_import {+ domain: "com.microsoft"+ version: 1+}\ No newline at end of filediff --git a/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_11_custom_scale.prototxt b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_11_custom_scale.prototxtnew file mode 100644index 00000000000..3ff2890ce6c--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_11_custom_scale.prototxt@@ -0,0 +1,49 @@+ir_version: 10+producer_name: "OpenVINO ONNX Frontend"+graph {+ node {+ input: "query"+ input: "key"+ input: "value"+ output: "output"+ name: "MultiHeadAttention_11_custom_scale"+ op_type: "MultiHeadAttention"+ attribute {+ name: "num_heads"+ i: 2+ type: INT+ }+ attribute {+ name: "scale"+ f: 0.5+ type: FLOAT+ }+ domain: "com.microsoft"+ }+ name: "multi_head_attention_11_custom_scale"+ input {+ name: "query"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ input {+ name: "key"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ input {+ name: "value"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ output {+ name: "output"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+}+opset_import { version: 11 }+opset_import {+ domain: "com.microsoft"+ version: 1+}\ No newline at end of filediff --git a/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_12_unidirectional.prototxt b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_12_unidirectional.prototxtnew file mode 100644index 00000000000..d43e689e03a--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_12_unidirectional.prototxt@@ -0,0 +1,49 @@+ir_version: 10+producer_name: "OpenVINO ONNX Frontend"+graph {+ node {+ input: "query"+ input: "key"+ input: "value"+ output: "output"+ name: "MultiHeadAttention_12_unidirectional"+ op_type: "MultiHeadAttention"+ attribute {+ name: "num_heads"+ i: 2+ type: INT+ }+ attribute {+ name: "unidirectional"+ i: 1+ type: INT+ }+ domain: "com.microsoft"+ }+ name: "multi_head_attention_12_unidirectional"+ input {+ name: "query"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ input {+ name: "key"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ input {+ name: "value"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ output {+ name: "output"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+}+opset_import { version: 11 }+opset_import {+ domain: "com.microsoft"+ version: 1+}\ No newline at end of filediff --git a/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_13_mask_filter_value.prototxt b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_13_mask_filter_value.prototxtnew file mode 100644index 00000000000..b67ca3cea08--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_13_mask_filter_value.prototxt@@ -0,0 +1,56 @@+ir_version: 10+producer_name: "OpenVINO ONNX Frontend"+graph {+ node {+ input: "query"+ input: "key"+ input: "value"+ input: ""+ input: "key_padding_mask"+ output: "output"+ name: "MultiHeadAttention_13_mask_filter_value"+ op_type: "MultiHeadAttention"+ attribute {+ name: "num_heads"+ i: 2+ type: INT+ }+ attribute {+ name: "mask_filter_value"+ f: -1.0+ type: FLOAT+ }+ domain: "com.microsoft"+ }+ name: "multi_head_attention_13_mask_filter_value"+ input {+ name: "query"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ input {+ name: "key"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ input {+ name: "value"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ input {+ name: "key_padding_mask"+ type { tensor_type { elem_type: 6+ shape { dim { dim_value: 1 } } } }+ }+ output {+ name: "output"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+}+opset_import { version: 11 }+opset_import {+ domain: "com.microsoft"+ version: 1+}\ No newline at end of filediff --git a/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_14_cache_standard.prototxt b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_14_cache_standard.prototxtnew file mode 100644index 00000000000..211abbc9f5b--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_14_cache_standard.prototxt@@ -0,0 +1,71 @@+ir_version: 10+producer_name: "OpenVINO ONNX Frontend"+graph {+ node {+ input: "query"+ input: "key"+ input: "value"+ input: ""+ input: ""+ input: ""+ input: "past_key"+ input: "past_value"+ output: "output"+ output: "present_key"+ output: "present_value"+ name: "MultiHeadAttention_14_cache_standard"+ op_type: "MultiHeadAttention"+ attribute {+ name: "num_heads"+ i: 2+ type: INT+ }+ domain: "com.microsoft"+ }+ name: "multi_head_attention_14_cache_standard"+ input {+ name: "query"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 2 } dim { dim_value: 6 } } } }+ }+ input {+ name: "key"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 2 } dim { dim_value: 6 } } } }+ }+ input {+ name: "value"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 2 } dim { dim_value: 6 } } } }+ }+ input {+ name: "past_key"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 2 } dim { dim_value: 3 } dim { dim_value: 3 } } } }+ }+ input {+ name: "past_value"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 2 } dim { dim_value: 3 } dim { dim_value: 3 } } } }+ }+ output {+ name: "output"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 2 } dim { dim_value: 6 } } } }+ }+ output {+ name: "present_key"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 2 } dim { dim_value: 5 } dim { dim_value: 3 } } } }+ }+ output {+ name: "present_value"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 2 } dim { dim_value: 5 } dim { dim_value: 3 } } } }+ }+}+opset_import { version: 11 }+opset_import {+ domain: "com.microsoft"+ version: 1+}\ No newline at end of filediff --git a/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_15_cache_buffer_sharing.prototxt b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_15_cache_buffer_sharing.prototxtnew file mode 100644index 00000000000..6b057a50563--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_15_cache_buffer_sharing.prototxt@@ -0,0 +1,77 @@+ir_version: 10+producer_name: "OpenVINO ONNX Frontend"+graph {+ node {+ input: "query"+ input: "key"+ input: "value"+ input: ""+ input: ""+ input: ""+ input: "past_key"+ input: "past_value"+ input: "past_sequence_length"+ output: "output"+ output: "present_key"+ output: "present_value"+ name: "MultiHeadAttention_15_cache_buffer_sharing"+ op_type: "MultiHeadAttention"+ attribute {+ name: "num_heads"+ i: 2+ type: INT+ }+ domain: "com.microsoft"+ }+ name: "multi_head_attention_15_cache_buffer_sharing"+ input {+ name: "query"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 1 } dim { dim_value: 6 } } } }+ }+ input {+ name: "key"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 1 } dim { dim_value: 6 } } } }+ }+ input {+ name: "value"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 1 } dim { dim_value: 6 } } } }+ }+ input {+ name: "past_key"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 2 } dim { dim_value: 8 } dim { dim_value: 3 } } } }+ }+ input {+ name: "past_value"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 2 } dim { dim_value: 8 } dim { dim_value: 3 } } } }+ }+ input {+ name: "past_sequence_length"+ type { tensor_type { elem_type: 6+ shape { dim { dim_value: 1 } } } }+ }+ output {+ name: "output"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 1 } dim { dim_value: 6 } } } }+ }+ output {+ name: "present_key"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 2 } dim { dim_value: 8 } dim { dim_value: 3 } } } }+ }+ output {+ name: "present_value"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 2 } dim { dim_value: 8 } dim { dim_value: 3 } } } }+ }+}+opset_import { version: 11 }+opset_import {+ domain: "com.microsoft"+ version: 1+}\ No newline at end of filediff --git a/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_16_cache_beam_search.prototxt b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_16_cache_beam_search.prototxtnew file mode 100644index 00000000000..a5c083d8d33--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_16_cache_beam_search.prototxt@@ -0,0 +1,83 @@+ir_version: 10+producer_name: "OpenVINO ONNX Frontend"+graph {+ node {+ input: "query"+ input: "key"+ input: "value"+ input: ""+ input: ""+ input: ""+ input: "past_key"+ input: "past_value"+ input: "past_sequence_length"+ input: "cache_indirection"+ output: "output"+ output: "present_key"+ output: "present_value"+ name: "MultiHeadAttention_16_cache_beam_search"+ op_type: "MultiHeadAttention"+ attribute {+ name: "num_heads"+ i: 2+ type: INT+ }+ domain: "com.microsoft"+ }+ name: "multi_head_attention_16_cache_beam_search"+ input {+ name: "query"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 2 } dim { dim_value: 1 } dim { dim_value: 6 } } } }+ }+ input {+ name: "key"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 2 } dim { dim_value: 1 } dim { dim_value: 6 } } } }+ }+ input {+ name: "value"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 2 } dim { dim_value: 1 } dim { dim_value: 6 } } } }+ }+ input {+ name: "past_key"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 2 } dim { dim_value: 2 } dim { dim_value: 4 } dim { dim_value: 3 } } } }+ }+ input {+ name: "past_value"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 2 } dim { dim_value: 2 } dim { dim_value: 4 } dim { dim_value: 3 } } } }+ }+ input {+ name: "past_sequence_length"+ type { tensor_type { elem_type: 6+ shape { } } }+ }+ input {+ name: "cache_indirection"+ type { tensor_type { elem_type: 6+ shape { dim { dim_value: 1 } dim { dim_value: 2 } dim { dim_value: 4 } } } }+ }+ output {+ name: "output"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 2 } dim { dim_value: 1 } dim { dim_value: 6 } } } }+ }+ output {+ name: "present_key"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 2 } dim { dim_value: 2 } dim { dim_value: 4 } dim { dim_value: 3 } } } }+ }+ output {+ name: "present_value"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 2 } dim { dim_value: 2 } dim { dim_value: 4 } dim { dim_value: 3 } } } }+ }+}+opset_import { version: 11 }+opset_import {+ domain: "com.microsoft"+ version: 1+}\ No newline at end of filediff --git a/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_17_output_qk.prototxt b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_17_output_qk.prototxtnew file mode 100644index 00000000000..50578ef7f44--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_17_output_qk.prototxt@@ -0,0 +1,57 @@+ir_version: 10+producer_name: "OpenVINO ONNX Frontend"+graph {+ node {+ input: "query"+ input: "key"+ input: "value"+ input: ""+ input: ""+ input: ""+ input: ""+ input: ""+ output: "output"+ output: ""+ output: ""+ output: "qk"+ name: "MultiHeadAttention_17_output_qk"+ op_type: "MultiHeadAttention"+ attribute {+ name: "num_heads"+ i: 2+ type: INT+ }+ domain: "com.microsoft"+ }+ name: "multi_head_attention_17_output_qk"+ input {+ name: "query"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 3 } dim { dim_value: 6 } } } }+ }+ input {+ name: "key"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ input {+ name: "value"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 4 } dim { dim_value: 6 } } } }+ }+ output {+ name: "output"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 3 } dim { dim_value: 6 } } } }+ }+ output {+ name: "qk"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 2 } dim { dim_value: 3 } dim { dim_value: 4 } } } }+ }+}+opset_import { version: 11 }+opset_import {+ domain: "com.microsoft"+ version: 1+}\ No newline at end of filediff --git a/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_18_cache_unidirectional.prototxt b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_18_cache_unidirectional.prototxtnew file mode 100644index 00000000000..00750b55562--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_18_cache_unidirectional.prototxt@@ -0,0 +1,76 @@+ir_version: 10+producer_name: "OpenVINO ONNX Frontend"+graph {+ node {+ input: "query"+ input: "key"+ input: "value"+ input: ""+ input: ""+ input: ""+ input: "past_key"+ input: "past_value"+ output: "output"+ output: "present_key"+ output: "present_value"+ name: "MultiHeadAttention_18_cache_unidirectional"+ op_type: "MultiHeadAttention"+ attribute {+ name: "num_heads"+ i: 2+ type: INT+ }+ attribute {+ name: "unidirectional"+ i: 1+ type: INT+ }+ domain: "com.microsoft"+ }+ name: "multi_head_attention_18_cache_unidirectional"+ input {+ name: "query"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 2 } dim { dim_value: 6 } } } }+ }+ input {+ name: "key"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 2 } dim { dim_value: 6 } } } }+ }+ input {+ name: "value"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 2 } dim { dim_value: 6 } } } }+ }+ input {+ name: "past_key"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 2 } dim { dim_value: 3 } dim { dim_value: 3 } } } }+ }+ input {+ name: "past_value"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 2 } dim { dim_value: 3 } dim { dim_value: 3 } } } }+ }+ output {+ name: "output"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 2 } dim { dim_value: 6 } } } }+ }+ output {+ name: "present_key"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 2 } dim { dim_value: 5 } dim { dim_value: 3 } } } }+ }+ output {+ name: "present_value"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 2 } dim { dim_value: 5 } dim { dim_value: 3 } } } }+ }+}+opset_import { version: 11 }+opset_import {+ domain: "com.microsoft"+ version: 1+}\ No newline at end of filediff --git a/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_19_cache_bias.prototxt b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_19_cache_bias.prototxtnew file mode 100644index 00000000000..f664d90c904--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/multi_head_attention_19_cache_bias.prototxt@@ -0,0 +1,76 @@+ir_version: 10+producer_name: "OpenVINO ONNX Frontend"+graph {+ node {+ input: "query"+ input: "key"+ input: "value"+ input: "bias"+ input: ""+ input: ""+ input: "past_key"+ input: "past_value"+ output: "output"+ output: "present_key"+ output: "present_value"+ name: "MultiHeadAttention_19_cache_bias"+ op_type: "MultiHeadAttention"+ attribute {+ name: "num_heads"+ i: 2+ type: INT+ }+ domain: "com.microsoft"+ }+ name: "multi_head_attention_19_cache_bias"+ input {+ name: "query"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 2 } dim { dim_value: 6 } } } }+ }+ input {+ name: "key"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 2 } dim { dim_value: 6 } } } }+ }+ input {+ name: "value"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 2 } dim { dim_value: 6 } } } }+ }+ input {+ name: "bias"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 18 } } } }+ }+ input {+ name: "past_key"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 2 } dim { dim_value: 3 } dim { dim_value: 3 } } } }+ }+ input {+ name: "past_value"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 2 } dim { dim_value: 3 } dim { dim_value: 3 } } } }+ }+ output {+ name: "output"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 2 } dim { dim_value: 6 } } } }+ }+ output {+ name: "present_key"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 2 } dim { dim_value: 5 } dim { dim_value: 3 } } } }+ }+ output {+ name: "present_value"+ type { tensor_type { elem_type: 1+ shape { dim { dim_value: 1 } dim { dim_value: 2 } dim { dim_value: 5 } dim { dim_value: 3 } } } }+ }+}+opset_import { version: 11 }+opset_import {+ domain: "com.microsoft"+ version: 1+}\ No newline at end of filediff --git a/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp b/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cppindex 79e9426ae10..7917ca36009 100644--- a/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp+++ b/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp@@ -1110,6 +1110,985 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_attention_dynamic_shapes) {test_case.run_with_tolerance_as_fp(1e-6f);}+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_multi_head_attention_01_packed_qkv) {+ auto model = convert_model("com.microsoft/multi_head_attention_01_packed_qkv.onnx");+ auto test_case = test::TestCase(model, s_device);+ // QKV: (1, 4, 2, 3, 3)+ test_case.add_input<float>(+ {-0.035826f, 1.564644f, -2.619745f, 0.296120f, 0.261055f, 0.005113f, 0.791032f, -0.909387f, 1.402794f,+ -0.808494f, -0.501757f, 0.915402f, 0.257550f, -0.074446f, -1.918771f, -1.062304f, 0.473592f, -0.919424f,+ 0.821903f, 0.087047f, -0.299007f, -0.234587f, -1.415371f, -0.420645f, -1.401851f, 0.586857f, 2.190456f,+ 0.328751f, -0.529760f, 0.513267f, -0.026514f, 0.060230f, 2.463242f, 1.549934f, -0.783253f, -0.322062f,+ 0.091761f, -1.987569f, -0.219672f, -0.342715f, -0.802277f, -0.161286f, -0.990536f, -0.566298f, 0.099651f,+ 0.097078f, 0.968645f, -0.702053f, -0.192361f, 0.301547f, -0.034712f, 0.813517f, -1.230864f, 0.227460f,+ 0.357113f, 1.477894f, -0.518270f, 0.404051f, 1.886186f, 0.174578f, -0.503476f, -1.550663f, 0.068563f,+ -0.327662f, -0.392108f, -1.463515f, -1.168678f, 1.142823f, 0.751933f, 1.307143f, -1.607483f, 0.184634f});+ test_case.add_expected_output<float>(+ Shape{1, 4, 6},+ {-0.376205f, -1.164383f, 0.494832f, 1.251880f, -1.010314f, -0.134396f, -0.433258f, -0.718601f,+ 0.898995f, 0.979683f, -0.832299f, -0.209895f, -1.080272f, 0.093997f, 1.487117f, 0.203439f,+ -0.572602f, -0.311992f, -0.340959f, -1.273095f, 0.406927f, -0.541346f, 0.026989f, -0.646756f});+ test_case.run_with_tolerance_as_fp(1e-4f);+}++OPENVINO_TEST(${BACKEND_NAME}, onnx_model_multi_head_attention_02_query_packed_kv) {+ auto model = convert_model("com.microsoft/multi_head_attention_02_query_packed_kv.onnx");+ auto test_case = test::TestCase(model, s_device);+ // Q: (1, 4, 6)+ test_case.add_input<float>({-0.035826f, 1.564644f, -2.619745f, -0.808494f, -0.501757f, 0.915402f,+ 0.821903f, 0.087047f, -0.299007f, 0.328751f, -0.529760f, 0.513267f,+ 0.091761f, -1.987569f, -0.219672f, 0.097078f, 0.968645f, -0.702053f,+ 0.357113f, 1.477894f, -0.518270f, -0.327662f, -0.392108f, -1.463515f});+ // KV: (1, 4, 2, 2, 3)+ test_case.add_input<float>({0.296120f, 0.261055f, 0.005113f, 0.791032f, -0.909387f, 1.402794f, 0.257550f,+ -0.074446f, -1.918771f, -1.062304f, 0.473592f, -0.919424f, -0.234587f, -1.415371f,+ -0.420645f, -1.401851f, 0.586857f, 2.190456f, -0.026514f, 0.060230f, 2.463242f,+ 1.549934f, -0.783253f, -0.322062f, -0.342715f, -0.802277f, -0.161286f, -0.990536f,+ -0.566298f, 0.099651f, -0.192361f, 0.301547f, -0.034712f, 0.813517f, -1.230864f,+ 0.227460f, 0.404051f, 1.886186f, 0.174578f, -0.503476f, -1.550663f, 0.068563f,+ -1.168678f, 1.142823f, 0.751933f, 1.307143f, -1.607483f, 0.184634f});+ test_case.add_expected_output<float>(+ Shape{1, 4, 6},+ {-0.376205f, -1.164383f, 0.494832f, 1.251880f, -1.010314f, -0.134396f, -0.433258f, -0.718601f,+ 0.898995f, 0.979683f, -0.832299f, -0.209895f, -1.080272f, 0.093997f, 1.487117f, 0.203439f,+ -0.572602f, -0.311992f, -0.340959f, -1.273095f, 0.406927f, -0.541346f, 0.026989f, -0.646756f});+ test_case.run_with_tolerance_as_fp(1e-4f);+}++OPENVINO_TEST(${BACKEND_NAME}, onnx_model_multi_head_attention_03_qkv_regular) {+ auto model = convert_model("com.microsoft/multi_head_attention_03_qkv_regular.onnx");+ auto test_case = test::TestCase(model, s_device);+ // Q: (1, 4, 6)+ test_case.add_input<float>({-0.035826f, 1.564644f, -2.619745f, -0.808494f, -0.501757f, 0.915402f,+ 0.821903f, 0.087047f, -0.299007f, 0.328751f, -0.529760f, 0.513267f,+ 0.091761f, -1.987569f, -0.219672f, 0.097078f, 0.968645f, -0.702053f,+ 0.357113f, 1.477894f, -0.518270f, -0.327662f, -0.392108f, -1.463515f});+ // K: (1, 4, 6)+ test_case.add_input<float>({0.296120f, 0.261055f, 0.005113f, 0.257550f, -0.074446f, -1.918771f,+ -0.234587f, -1.415371f, -0.420645f, -0.026514f, 0.060230f, 2.463242f,+ -0.342715f, -0.802277f, -0.161286f, -0.192361f, 0.301547f, -0.034712f,+ 0.404051f, 1.886186f, 0.174578f, -1.168678f, 1.142823f, 0.751933f});+ // V: (1, 4, 6)+ test_case.add_input<float>({0.791032f, -0.909387f, 1.402794f, -1.062304f, 0.473592f, -0.919424f,+ -1.401851f, 0.586857f, 2.190456f, 1.549934f, -0.783253f, -0.322062f,+ -0.990536f, -0.566298f, 0.099651f, 0.813517f, -1.230864f, 0.227460f,+ -0.503476f, -1.550663f, 0.068563f, 1.307143f, -1.607483f, 0.184634f});+ test_case.add_expected_output<float>(+ Shape{1, 4, 6},+ {-0.376205f, -1.164383f, 0.494832f, 1.251880f, -1.010314f, -0.134396f, -0.433258f, -0.718601f,+ 0.898995f, 0.979683f, -0.832299f, -0.209895f, -1.080272f, 0.093997f, 1.487117f, 0.203439f,+ -0.572602f, -0.311992f, -0.340959f, -1.273095f, 0.406927f, -0.541346f, 0.026989f, -0.646756f});+ test_case.run_with_tolerance_as_fp(1e-4f);+}++OPENVINO_TEST(${BACKEND_NAME}, onnx_model_multi_head_attention_04_cross_attn) {+ auto model = convert_model("com.microsoft/multi_head_attention_04_cross_attn.onnx");+ auto test_case = test::TestCase(model, s_device);+ // Q: (1, 4, 6)+ test_case.add_input<float>({-0.035826f, 1.564644f, -2.619745f, -0.808494f, -0.501757f, 0.915402f,+ 0.821903f, 0.087047f, -0.299007f, 0.328751f, -0.529760f, 0.513267f,+ 0.091761f, -1.987569f, -0.219672f, 0.097078f, 0.968645f, -0.702053f,+ 0.357113f, 1.477894f, -0.518270f, -0.327662f, -0.392108f, -1.463515f});+ // K: (1, 2, 4, 3)+ test_case.add_input<float>({0.296120f, 0.261055f, 0.005113f, -0.234587f, -1.415371f, -0.420645f,+ -0.342715f, -0.802277f, -0.161286f, 0.404051f, 1.886186f, 0.174578f,+ 0.257550f, -0.074446f, -1.918771f, -0.026514f, 0.060230f, 2.463242f,+ -0.192361f, 0.301547f, -0.034712f, -1.168678f, 1.142823f, 0.751933f});+ // V: (1, 2, 4, 3)+ test_case.add_input<float>({0.791032f, -0.909387f, 1.402794f, -1.401851f, 0.586857f, 2.190456f,+ -0.990536f, -0.566298f, 0.099651f, -0.503476f, -1.550663f, 0.068563f,+ -1.062304f, 0.473592f, -0.919424f, 1.549934f, -0.783253f, -0.322062f,+ 0.813517f, -1.230864f, 0.227460f, 1.307143f, -1.607483f, 0.184634f});+ test_case.add_expected_output<float>(+ Shape{1, 4, 6},+ {-0.376205f, -1.164383f, 0.494832f, 1.251880f, -1.010314f, -0.134396f, -0.433258f, -0.718601f,+ 0.898995f, 0.979683f, -0.832299f, -0.209895f, -1.080272f, 0.093997f, 1.487117f, 0.203439f,+ -0.572602f, -0.311992f, -0.340959f, -1.273095f, 0.406927f, -0.541346f, 0.026989f, -0.646756f});+ test_case.run_with_tolerance_as_fp(1e-4f);+}++OPENVINO_TEST(${BACKEND_NAME}, onnx_model_multi_head_attention_05_qkv_with_bias) {+ auto model = convert_model("com.microsoft/multi_head_attention_05_qkv_with_bias.onnx");+ auto test_case = test::TestCase(model, s_device);+ // Q: (1, 4, 6)+ test_case.add_input<float>({0.500788f, -0.466532f, -0.072120f, 0.797042f, -0.196038f, -1.626126f,+ 1.667177f, -1.467366f, -0.519668f, -0.834358f, 0.883516f, -0.423264f,+ 0.414926f, -1.375037f, 0.590562f, 0.306573f, -0.956622f, 1.786636f,+ -0.292153f, 0.079714f, -0.360660f, 1.460447f, 1.037711f, 0.655908f});+ // K: (1, 4, 6)+ test_case.add_input<float>({-0.159858f, -0.520155f, 1.281123f, 1.497393f, 0.327479f, -0.099673f,+ -0.285721f, -0.526933f, 0.836597f, 0.974657f, -1.115275f, -1.066058f,+ -0.129775f, -1.613878f, -0.328692f, -0.190567f, 1.685015f, 0.405967f,+ -0.187556f, 0.874089f, 0.691861f, -1.465640f, 1.912281f, -1.244010f});+ // V: (1, 4, 6)+ test_case.add_input<float>({-1.047010f, 0.303499f, -1.294304f, 0.855919f, -1.039776f, -0.735715f,+ -0.043205f, -0.137544f, 0.279007f, 1.171143f, -0.879711f, 0.284893f,+ 0.827591f, 0.073086f, 1.101309f, 0.321106f, 1.278001f, 0.094257f,+ -0.738374f, 0.852652f, 0.877477f, -0.748606f, 0.451661f, 0.959747f});+ // Bias: (18)+ test_case.add_input<float>({-1.584188f,+ -0.921880f,+ -1.485478f,+ 0.448456f,+ 0.559887f,+ -1.520577f,+ 1.551526f,+ 0.704305f,+ 0.177998f,+ 0.591930f,+ 0.842607f,+ 1.271139f,+ -0.742549f,+ 0.999647f,+ -0.208352f,+ 0.588757f,+ -0.206641f,+ 1.173998f});+ test_case.add_expected_output<float>(+ Shape{1, 4, 6},+ {-0.230642f, 1.097652f, 0.601209f, 1.207533f, -0.727536f, 1.429972f, -0.032768f, 1.075902f,+ 0.773524f, 0.043782f, 0.222059f, 1.984603f, -0.195165f, 1.081651f, 0.599461f, 1.380906f,+ -0.736803f, 1.064204f, -0.301282f, 1.119363f, 0.574715f, 1.128514f, -0.502941f, 0.996273f});+ test_case.run_with_tolerance_as_fp(1e-4f);+}++OPENVINO_TEST(${BACKEND_NAME}, onnx_model_multi_head_attention_06_mask_batch) {+ auto model = convert_model("com.microsoft/multi_head_attention_06_mask_batch.onnx");+ auto test_case = test::TestCase(model, s_device);+ // Q: (2, 4, 6)+ test_case.add_input<float>({2.414269f, 1.493686f, -0.248355f, -0.882597f, -0.934036f, 1.496378f, 0.931530f,+ 0.121790f, 0.952951f, 0.496913f, 1.046078f, 0.006713f, 0.278629f, -1.290837f,+ 0.878857f, -0.687077f, -0.232260f, 0.194475f, 0.111104f, -1.542101f, -0.512412f,+ -0.481877f, 0.705976f, 0.388797f, 0.659943f, -0.620150f, -1.462235f, -0.275975f,+ -2.143318f, 0.096746f, -0.229285f, 0.448629f, 0.894851f, -1.235702f, -0.461685f,+ 0.368896f, 1.031920f, -1.116880f, 0.300853f, 0.169378f, -0.604415f, -2.676176f,+ -0.167914f, 1.926949f, 0.624043f, -0.714218f, -0.416713f, -0.562544f});+ // K: (2, 4, 6)+ test_case.add_input<float>({-2.033886f, -0.940820f, -1.691066f, 0.867390f, 2.073566f, -1.431837f, -0.296306f,+ -0.831233f, -0.876234f, -0.379968f, -0.967283f, -0.113957f, -0.073196f, -0.301250f,+ 0.837002f, -0.357545f, 0.992237f, 0.251948f, -1.349071f, -1.487922f, 0.697364f,+ -0.844215f, -0.678731f, -0.444069f, 0.742095f, 0.642506f, 1.343380f, -2.115452f,+ -2.063730f, 0.868498f, -0.569475f, 0.806037f, -0.563011f, -0.822407f, -0.228678f,+ -0.716711f, 0.811572f, 0.658422f, -1.091227f, -0.519456f, 0.145228f, -1.719544f,+ -0.241919f, -0.698864f, -0.268680f, 1.593978f, -0.569250f, 0.405264f});+ // V: (2, 4, 6)+ test_case.add_input<float>({0.199364f, -1.095764f, -1.328098f, 0.790207f, 0.223132f, -0.336433f, 0.276191f,+ 1.415912f, -1.880674f, -0.503161f, 0.111360f, -1.038897f, -0.183301f, -0.813844f,+ 0.288287f, 0.593714f, 0.967929f, -0.627702f, 1.973337f, -0.133892f, 1.728640f,+ 1.146520f, -0.398141f, 2.302237f, -1.639317f, 0.924433f, -0.570678f, -0.567836f,+ 0.895974f, 1.214792f, -1.006176f, -1.000671f, 0.620023f, 1.871847f, 2.304910f,+ -0.181579f, 2.192029f, 1.863850f, -0.473984f, 1.304245f, -0.562526f, 0.316287f,+ 0.637470f, 1.157756f, -0.478634f, -0.037194f, -0.792742f, 1.001240f});+ // Mask: (2)+ test_case.add_input<int>({2, 3});+ test_case.add_expected_output<float>(+ Shape{2, 4, 6},+ {0.269799f, 1.206941f, -1.834700f, -0.461953f, 0.114921f, -1.016516f, 0.260877f, 0.915272f,+ -1.770532f, 0.659943f, 0.211875f, -0.407183f, 0.249166f, 0.532398f, -1.686298f, -0.168022f,+ 0.140322f, -0.856874f, 0.233433f, 0.018039f, -1.573138f, 0.330898f, 0.183439f, -0.585897f,+ 1.095134f, 1.091988f, -0.217685f, -0.327546f, 0.935886f, 1.083994f, -0.850754f, 0.565629f,+ -0.238988f, -0.085193f, 0.970903f, 0.952430f, -0.230991f, 0.957618f, -0.358885f, 1.359290f,+ 0.007306f, 0.248131f, -0.668151f, 0.485498f, -0.163849f, 0.656470f, 0.836396f, 0.566272f});+ test_case.run_with_tolerance_as_fp(1e-4f);+}++OPENVINO_TEST(${BACKEND_NAME}, onnx_model_multi_head_attention_07_mask_packed_metadata) {+ auto model = convert_model("com.microsoft/multi_head_attention_07_mask_packed_metadata.onnx");+ auto test_case = test::TestCase(model, s_device);+ // Q: (1, 4, 6)+ test_case.add_input<float>({-0.035826f, 1.564644f, -2.619745f, -0.808494f, -0.501757f, 0.915402f,+ 0.821903f, 0.087047f, -0.299007f, 0.328751f, -0.529760f, 0.513267f,+ 0.091761f, -1.987569f, -0.219672f, 0.097078f, 0.968645f, -0.702053f,+ 0.357113f, 1.477894f, -0.518270f, -0.327662f, -0.392108f, -1.463515f});+ // K: (1, 4, 6)+ test_case.add_input<float>({0.296120f, 0.261055f, 0.005113f, 0.257550f, -0.074446f, -1.918771f,+ -0.234587f, -1.415371f, -0.420645f, -0.026514f, 0.060230f, 2.463242f,+ -0.342715f, -0.802277f, -0.161286f, -0.192361f, 0.301547f, -0.034712f,+ 0.404051f, 1.886186f, 0.174578f, -1.168678f, 1.142823f, 0.751933f});+ // V: (1, 4, 6)+ test_case.add_input<float>({0.791032f, -0.909387f, 1.402794f, -1.062304f, 0.473592f, -0.919424f,+ -1.401851f, 0.586857f, 2.190456f, 1.549934f, -0.783253f, -0.322062f,+ -0.990536f, -0.566298f, 0.099651f, 0.813517f, -1.230864f, 0.227460f,+ -0.503476f, -1.550663f, 0.068563f, 1.307143f, -1.607483f, 0.184634f});+ // Mask: (5)+ test_case.add_input<int>({2, 0, 4, 0, 4});+ test_case.add_expected_output<float>(+ Shape{1, 4, 6},+ {0.138752f, -0.464324f, 1.637087f, 1.334554f, -0.679626f, -0.371315f, -0.162276f, -0.258928f,+ 1.745213f, 0.94686f, -0.493092f, -0.459972f, -1.128629f, 0.400433f, 2.092317f, -0.664492f,+ 0.28219f, -0.828453f, 0.361562f, -0.616352f, 1.557055f, -0.997998f, 0.442652f, -0.904719f});+ test_case.run_with_tolerance_as_fp(1e-4f);+}++OPENVINO_TEST(${BACKEND_NAME}, onnx_model_multi_head_attention_08_mask_2D) {+ auto model = convert_model("com.microsoft/multi_head_attention_08_mask_2D.onnx");+ auto test_case = test::TestCase(model, s_device);+ // Q: (2, 4, 6)+ test_case.add_input<float>({1.178842f, -0.588332f, 0.411434f, -1.091373f, 1.698974f, -0.942831f, -0.912207f,+ 0.298497f, -1.012579f, -0.583918f, 0.952963f, 0.478946f, 0.189541f, -0.312117f,+ -0.081829f, -0.539691f, -2.017537f, 0.185154f, -0.149735f, -0.462661f, 1.931883f,+ 0.168544f, -0.991800f, 0.485264f, -0.225168f, 1.449681f, -1.086470f, 1.098004f,+ -1.012051f, -0.297929f, -0.177786f, 1.791980f, 0.099199f, -0.259967f, -0.235795f,+ 1.181306f, 2.159240f, -0.625949f, 0.792943f, -0.300578f, 0.392830f, 0.800928f,+ -0.393912f, 2.075703f, 0.787087f, 2.016828f, -1.149390f, 0.419710f});+ // K: (2, 4, 6)+ test_case.add_input<float>({-1.745823f, 0.832173f, -0.103363f, -0.312527f, 0.705116f, 0.052063f, -0.871936f,+ 0.426491f, -0.813450f, 0.551936f, 1.369293f, 0.153079f, -0.469306f, 0.557184f,+ 0.045078f, 1.612454f, -0.500493f, 0.599157f, 0.564862f, 1.462613f, -0.639713f,+ -0.037957f, 1.651678f, -0.647739f, -1.673202f, -0.557986f, 1.723515f, 1.312842f,+ 0.823060f, -0.167017f, -2.073166f, 0.485943f, -1.185025f, -0.656164f, 0.446398f,+ -1.283233f, -0.048684f, -0.503312f, -0.988174f, -0.270661f, 0.070413f, -0.752441f,+ -0.829736f, 1.631957f, -0.955723f, 0.525124f, 1.433940f, -0.155200f});+ // V: (2, 4, 6)+ test_case.add_input<float>({-0.744891f, -0.332752f, -0.645481f, -0.599071f, -0.372085f, 0.540749f, 1.217237f,+ 0.960120f, 1.222193f, -0.039909f, 0.884915f, -1.485115f, 0.690202f, 0.536082f,+ 0.457347f, 0.854271f, 0.290782f, 0.401909f, 1.806902f, 2.080657f, 0.582483f,+ 0.342819f, 0.536176f, -0.322169f, 0.386478f, -0.098439f, -0.387852f, 0.647060f,+ 0.562506f, 0.415310f, -1.020316f, -0.287768f, -0.360681f, -1.445551f, -0.535288f,+ -0.310522f, -0.856826f, -0.839114f, -0.901571f, -0.946835f, 0.153810f, -0.281031f,+ 0.056529f, -0.598709f, 1.605809f, 0.638936f, 0.615119f, -0.133803f});+ // Mask: (2, 4)+ test_case.add_input<int>({0, 1, 1, 0, 1, 0, 0, 1});+ test_case.add_expected_output<float>(+ Shape{2, 4, 6},+ {0.897471f, 0.702845f, 0.758140f, 0.014065f, 0.849052f, -1.371211f, 1.041358f, 0.818613f,+ 0.966953f, 0.157232f, 0.753926f, -1.069080f, 0.956361f, 0.750227f, 0.843604f, 0.737445f,+ 0.368406f, 0.155367f, 0.843860f, 0.659711f, 0.680339f, 0.662595f, 0.418140f, -0.002593f,+ 0.067145f, -0.582613f, 1.541665f, 0.644642f, 0.578168f, 0.251846f, 0.094979f, -0.540412f,+ 1.373484f, 0.642910f, 0.589380f, 0.134834f, 0.295551f, -0.236303f, 0.161558f, 0.642432f,+ 0.592481f, 0.102469f, 0.132021f, -0.484248f, 1.149662f, 0.645347f, 0.573600f, 0.299524f});+ test_case.run_with_tolerance_as_fp(1e-4f);+}++OPENVINO_TEST(${BACKEND_NAME}, onnx_model_multi_head_attention_09_mask_3D) {+ auto model = convert_model("com.microsoft/multi_head_attention_09_mask_3D.onnx");+ auto test_case = test::TestCase(model, s_device);+ // Q: (2, 4, 6)+ test_case.add_input<float>({0.171911f, 1.149517f, -1.411962f, 0.410496f, 0.409460f, -1.135476f, -0.194869f,+ -0.272008f, 1.612752f, 1.204299f, -0.403567f, 0.034698f, -1.260308f, -0.489011f,+ -0.239979f, 0.532567f, -0.630106f, -3.002482f, 1.721283f, 0.066135f, -0.008350f,+ -0.302829f, 1.189350f, -0.127051f, -0.402091f, -0.609681f, -0.429554f, 0.117646f,+ 1.824711f, 0.974382f, -0.522243f, -1.687855f, 1.724833f, 0.767940f, 0.112722f,+ -0.211808f, -1.005934f, 0.488847f, 1.578735f, -1.036853f, -0.808379f, 0.650656f,+ -0.463425f, 1.085516f, 0.471409f, -1.386118f, 0.281034f, -1.405665f});+ // K: (2, 4, 6)+ test_case.add_input<float>({-0.214302f, 1.139173f, 1.632261f, -0.048986f, 1.215915f, 0.138627f, 0.614674f,+ -0.653751f, -0.878698f, 0.016974f, -1.530056f, -0.171601f, 0.165732f, -0.055068f,+ -0.048665f, 0.089228f, 0.530092f, 1.210951f, 0.550441f, 1.109022f, 1.200449f,+ 1.100326f, 0.879118f, -0.051082f, 0.270656f, -0.104863f, 1.593474f, -0.972787f,+ 0.500993f, 0.122744f, 0.010271f, 0.791066f, -0.784976f, -0.918032f, -0.522943f,+ -0.568718f, 0.442974f, 0.194005f, -0.886002f, -0.282961f, 0.202165f, -1.997038f,+ 0.313970f, -0.069803f, 0.793222f, 2.214140f, -1.313767f, 0.849646f});+ // V: (2, 4, 6)+ test_case.add_input<float>({-0.319471f, 0.544227f, -0.710860f, 1.333414f, 0.232788f, 0.946570f, 1.471010f,+ 0.544308f, 0.281784f, 0.588671f, 0.451751f, -0.662783f, 1.277066f, 0.167604f,+ -0.170514f, -0.002224f, -1.843149f, 1.819181f, 0.879733f, 0.265978f, -1.158533f,+ -0.499476f, 0.716312f, 0.407628f, -0.241591f, -0.806894f, 0.641374f, 1.580501f,+ 0.000453f, 0.433148f, -0.658517f, -1.511967f, 1.421374f, 0.158469f, -1.537625f,+ -0.286630f, -0.208616f, -0.420988f, -0.254890f, 0.931781f, -1.423789f, 2.363608f,+ -0.061310f, 0.809641f, 0.177027f, -0.629823f, 0.016361f, -0.331419f});+ // Mask: (2, 4, 4)+ test_case.add_input<int>(+ {1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0});+ test_case.add_expected_output<float>(+ Shape{2, 4, 6},+ {0.967805f, 0.544285f, 0.002807f, 1.039917f, 0.319080f, 0.312337f, 0.118178f, 0.477229f,+ -0.529566f, 0.580508f, -0.304798f, 0.475190f, 1.152318f, 0.198490f, -0.480716f, -0.457030f,+ 0.497832f, 0.528121f, 1.201172f, 0.346924f, -0.370560f, -0.174293f, -0.361930f, 0.866541f,+ -0.143535f, 0.072346f, 0.388814f, 1.102068f, 0.003896f, 0.267655f, -0.394515f, -0.871780f,+ 0.437742f, 0.640447f, -1.466675f, 1.365169f, -0.219685f, 0.193967f, 0.507019f, -0.057731f,+ -1.111422f, -0.298914f, -0.229401f, -0.664236f, 0.310052f, 1.091398f, -1.073355f, 1.888620f});+ test_case.run_with_tolerance_as_fp(1e-4f);+}++OPENVINO_TEST(${BACKEND_NAME}, onnx_model_multi_head_attention_10_attention_bias) {+ auto model = convert_model("com.microsoft/multi_head_attention_10_attention_bias.onnx");+ auto test_case = test::TestCase(model, s_device);+ // Q: (2, 4, 6)+ test_case.add_input<float>({0.631754f, 0.669734f, 2.255635f, 0.160511f, -0.097022f, -1.058020f, -0.090150f,+ -1.516458f, -0.191944f, 1.118815f, -2.206739f, -1.692282f, 0.441020f, 0.114214f,+ 0.147258f, -0.586127f, 0.619637f, -0.292006f, -0.320732f, 0.446724f, -0.823775f,+ 0.016548f, -0.428055f, 1.232233f, -0.155777f, -1.587976f, 0.427614f, -2.071625f,+ 3.295498f, 0.220447f, 0.108732f, 1.229409f, -0.809486f, -0.359760f, -0.767645f,+ 1.447128f, -2.079479f, 0.373836f, -0.149541f, 0.878389f, 0.304425f, -0.060318f,+ 0.901337f, -1.003998f, 0.999944f, -1.844644f, -0.240135f, -0.230783f});+ // K: (2, 4, 6)+ test_case.add_input<float>({-2.088322f, -0.650248f, -0.292286f, -1.082512f, 0.916626f, 0.716934f, 0.906080f,+ 0.028912f, -0.250721f, -0.740634f, 1.105669f, -0.030639f, -0.052854f, 0.388908f,+ 0.596515f, -0.616387f, 1.060799f, 0.625264f, 0.617091f, 0.084425f, -0.082083f,+ -0.439068f, 1.467175f, 0.845821f, -0.112836f, -1.008509f, -0.249840f, 0.266454f,+ 1.701386f, -0.205294f, -1.337344f, 1.006911f, 1.298912f, 0.510521f, 0.246669f,+ -0.831456f, -0.085988f, -1.642547f, -0.497313f, -0.097910f, 0.437478f, 1.890606f,+ 1.256807f, -0.193415f, 0.835403f, 2.683102f, 0.201742f, 0.364024f});+ // V: (2, 4, 6)+ test_case.add_input<float>({1.546191f, 0.584335f, 0.849519f, 1.563010f, -1.045431f, -0.424912f, -1.397499f,+ 1.080616f, -0.135972f, 0.942940f, 0.183162f, 0.326155f, -0.508379f, -0.533352f,+ -1.639434f, -0.930212f, -0.459669f, 0.920094f, -0.182963f, -0.678488f, 0.555118f,+ -0.322072f, -1.361877f, -0.090990f, 0.777217f, 0.184627f, -1.227485f, 1.100581f,+ -0.552859f, -0.602199f, 0.434188f, 0.166850f, -0.197795f, 0.995602f, 1.554552f,+ 1.540314f, 1.007041f, 1.083889f, 0.628102f, 0.256808f, 0.160061f, 1.222113f,+ -0.138347f, -0.360813f, -0.418015f, 0.592153f, 2.731303f, -1.734940f});+ // Attention bias: (2, 4, 4)+ test_case.add_input<float>({-0.018581f, 1.473321f, 0.753584f, 1.403393f, -0.213004f, -1.000797f, 0.784008f,+ 0.083793f, -0.796462f, 0.327761f, 0.917032f, 1.953662f, -0.428677f, 1.394534f,+ 2.070687f, 1.696589f, 1.289813f, 1.208038f, -0.186171f, -0.554063f, 1.812312f,+ -1.232174f, 1.511315f, 0.932466f, -0.870709f, 1.124674f, -0.681370f, -0.101360f,+ -0.267328f, 0.771216f, -1.237868f, -0.964730f});+ test_case.add_expected_output<float>(+ Shape{2, 4, 6},+ {-0.637803f, -0.074269f, -0.436488f, 0.334656f, -0.427601f, 0.257946f, 0.253579f, -0.024499f,+ -0.112622f, -0.154810f, -0.588941f, 0.465481f, -0.378858f, -0.389806f, 0.014392f, -0.198539f,+ -0.950647f, 0.162309f, -0.499025f, -0.140439f, -0.468329f, -0.340393f, -0.697783f, 0.430090f,+ 0.734679f, 0.356473f, -0.626391f, 1.063969f, -0.446041f, -0.453523f, 0.609446f, 0.284722f,+ -0.529473f, 0.372587f, 0.299403f, 0.804409f, 0.449080f, 0.182920f, -0.203662f, 0.802314f,+ 1.797163f, 0.061460f, 0.418494f, 0.123126f, -0.432803f, 0.931614f, 0.933841f, 0.990207f});+ test_case.run_with_tolerance_as_fp(1e-4f);+}++OPENVINO_TEST(${BACKEND_NAME}, onnx_model_multi_head_attention_11_custom_scale) {+ auto model = convert_model("com.microsoft/multi_head_attention_11_custom_scale.onnx");+ auto test_case = test::TestCase(model, s_device);+ // Q: (1, 4, 6)+ test_case.add_input<float>({0.591468f, -1.255400f, -0.161877f, -0.427714f, 0.490554f, 0.471514f,+ 0.033110f, -0.230670f, -1.325633f, -0.678606f, 1.637428f, -0.039956f,+ 1.424739f, 1.477517f, 0.117651f, -0.496312f, 0.811690f, -0.378689f,+ 1.108388f, -0.708602f, 0.205968f, -0.612794f, -1.079098f, 0.016927f});+ // K: (1, 4, 6)+ test_case.add_input<float>({-0.281602f, 0.834503f, 0.493743f, 1.438564f, -0.714108f, 0.507913f,+ 0.874791f, -1.060169f, 0.991535f, 0.666758f, 0.334132f, -0.180667f,+ 0.113462f, -1.028317f, 0.204918f, -1.713102f, 0.110518f, -1.096585f,+ -0.074069f, -0.042640f, -0.195191f, -0.710781f, -0.596969f, -0.048746f});+ // V: (1, 4, 6)+ test_case.add_input<float>({0.356172f, 0.401375f, -0.413736f, -0.747005f, -0.519761f, 0.460136f,+ 0.286267f, 0.444109f, -1.543422f, -0.908271f, 0.919309f, 0.078947f,+ 0.324866f, 0.137249f, -0.360263f, 1.289033f, -0.039674f, -0.982759f,+ -0.928877f, -0.452811f, 0.098747f, 0.861644f, 1.201556f, -1.256939f});+ test_case.add_expected_output<float>(+ Shape{1, 4, 6},+ {0.091921f, 0.180198f, -0.758029f, 0.265805f, 0.432730f, -0.530781f, -0.100481f, 0.042511f,+ -0.423590f, 0.489783f, 0.395589f, -0.649330f, 0.035272f, 0.176660f, -0.549437f, 0.474474f,+ 0.394462f, -0.642841f, 0.104952f, 0.209011f, -0.824280f, 0.443754f, 0.432535f, -0.653196f});+ test_case.run_with_tolerance_as_fp(1e-4f);+}++OPENVINO_TEST(${BACKEND_NAME}, onnx_model_multi_head_attention_12_unidirectional) {+ auto model = convert_model("com.microsoft/multi_head_attention_12_unidirectional.onnx");+ auto test_case = test::TestCase(model, s_device);+ // Q: (1, 4, 6)+ test_case.add_input<float>({0.763157f, -1.736108f, -1.693602f, -0.130071f, -1.493915f, 0.536139f,+ -1.695399f, 0.213582f, 0.779525f, -0.422040f, 0.442692f, 0.904750f,+ -1.345052f, 1.181543f, -0.383095f, -1.129182f, -1.358498f, 0.181608f,+ 1.467260f, -0.488720f, 0.067600f, 0.813261f, -0.410832f, -0.859603f});+ // K: (1, 4, 6)+ test_case.add_input<float>({0.320349f, 0.455102f, -0.201270f, -1.073210f, 0.131007f, 0.279952f,+ 1.310442f, 0.439139f, 0.059728f, -0.544267f, 0.417130f, 1.576669f,+ -0.988473f, -0.611304f, 0.043102f, -0.005837f, -0.772120f, 0.306943f,+ -0.885798f, -0.185542f, 0.456907f, 0.100875f, 0.757357f, 0.318546f});+ // V: (1, 4, 6)+ test_case.add_input<float>({1.294832f, -0.045494f, 0.123401f, 1.788317f, 1.602329f, 0.723241f,+ 0.776543f, -0.425794f, -1.787336f, -1.103704f, 1.669609f, 0.591973f,+ 0.421913f, 0.106899f, 0.529449f, 0.275918f, -0.134726f, -2.559006f,+ 0.054601f, 1.336137f, 0.305235f, 0.864290f, 0.870780f, 0.777970f});+ test_case.add_expected_output<float>(+ Shape{1, 4, 6},+ {1.294832f, -0.045494f, 0.123401f, 1.788317f, 1.602329f, 0.723241f, 1.140035f, -0.159078f,+ -0.447276f, -0.093177f, 1.646100f, 0.637840f, 0.802408f, -0.035060f, 0.007217f, 0.507874f,+ 0.956543f, -0.559896f, 0.785790f, -0.095690f, -0.872420f, 0.570673f, 0.715425f, -0.572088f});+ test_case.run_with_tolerance_as_fp(1e-4f);+}++OPENVINO_TEST(${BACKEND_NAME}, onnx_model_multi_head_attention_13_mask_filter_value) {+ auto model = convert_model("com.microsoft/multi_head_attention_13_mask_filter_value.onnx");+ auto test_case = test::TestCase(model, s_device);+ // Q: (1, 4, 6)+ test_case.add_input<float>({-0.004815f, 0.315698f, -0.950926f, 1.736456f, -0.569141f, 3.417437f,+ 0.092952f, 0.949537f, -0.312971f, -0.445572f, 0.012943f, 0.145773f,+ 0.793050f, -1.220664f, 0.058867f, 0.037140f, 1.069238f, -0.331442f,+ 0.743906f, -1.078334f, 0.011862f, 2.430786f, -1.919814f, -1.248909f});+ // K: (1, 4, 6)+ test_case.add_input<float>({0.436345f, 0.443550f, 0.178174f, 0.821855f, -0.419325f, 0.530089f,+ -0.451802f, 1.333365f, 0.910245f, -0.854425f, 0.077223f, -1.458590f,+ 1.535575f, 1.271915f, -0.273165f, -0.751594f, -0.903711f, 1.265961f,+ -1.450006f, -0.389976f, 0.259376f, 0.782885f, -1.362092f, -1.661010f});+ // V: (1, 4, 6)+ test_case.add_input<float>({-0.651325f, 0.499091f, 0.394836f, -0.836832f, -1.138136f, -0.060758f,+ 0.553349f, 0.272738f, 0.074907f, -1.566197f, 2.381995f, 3.666111f,+ 0.886348f, -1.190575f, -0.703657f, -0.138615f, -1.165533f, -0.190768f,+ -0.754842f, -0.861068f, -1.140825f, 0.191213f, -0.103034f, -0.623577f});+ // Mask: (1)+ test_case.add_input<int>({2});+ test_case.add_expected_output<float>(+ Shape{1, 4, 6},+ {0.015217f, -0.075032f, -0.105048f, -0.642630f, -1.132953f, -0.090547f, 0.165671f, -0.031624f,+ -0.064637f, -0.908601f, 0.394500f, 1.384287f, -0.184221f, -0.020413f, -0.066868f, -1.102100f,+ 0.905021f, 1.945917f, -0.163094f, -0.023861f, -0.067551f, -0.046673f, -0.186338f, -0.365650f});+ test_case.run_with_tolerance_as_fp(1e-4f);+}++OPENVINO_TEST(${BACKEND_NAME}, onnx_model_multi_head_attention_14_cache_standard) {+ auto model = convert_model("com.microsoft/multi_head_attention_14_cache_standard.onnx");+ auto test_case = test::TestCase(model, s_device);+ // Q: (1, 2, 6)+ test_case.add_input<float>({0.545757f,+ -0.112433f,+ 1.860055f,+ -0.902486f,+ 0.048880f,+ -0.611522f,+ -0.133876f,+ -0.510272f,+ 0.937600f,+ 1.344088f,+ 0.173445f,+ -0.768379f});+ // K: (1, 2, 6)+ test_case.add_input<float>({0.912625f,+ -0.001525f,+ 0.701053f,+ 1.307534f,+ 0.131957f,+ -0.757927f,+ 0.012941f,+ -1.291529f,+ -0.619094f,+ -0.053724f,+ -0.629695f,+ 1.326786f});+ // V: (1, 2, 6)+ test_case.add_input<float>({1.175690f,+ -0.776358f,+ -0.897604f,+ 1.889715f,+ 0.692087f,+ 0.801224f,+ 2.171347f,+ -0.775571f,+ 1.237221f,+ 0.503803f,+ -0.494952f,+ -0.776084f});+ // past_key: (1, 2, 3, 3)+ test_case.add_input<float>({0.007796f,+ -1.399294f,+ -0.810345f,+ -0.790828f,+ -1.212683f,+ 0.933362f,+ -0.843760f,+ 0.849301f,+ -0.305789f,+ 1.279238f,+ -0.750740f,+ 0.855745f,+ -1.495647f,+ 0.042313f,+ -1.011973f,+ -1.202155f,+ -0.739261f,+ 0.526944f});+ // past_value: (1, 2, 3, 3)+ test_case.add_input<float>({0.234069f,+ 0.635683f,+ 1.871725f,+ -0.247566f,+ 0.535697f,+ -0.174310f,+ 0.880957f,+ -0.307055f,+ 0.489298f,+ -1.554317f,+ 0.724578f,+ 0.447344f,+ -0.086974f,+ 0.765638f,+ 1.224396f,+ -0.958257f,+ -0.750733f,+ -0.695065f});+ // Output: (1, 2, 6)+ test_case.add_expected_output<float>(Shape{1, 2, 6},+ {0.681416f,+ -0.190417f,+ -0.169402f,+ -0.116328f,+ 0.263488f,+ 0.470749f,+ 0.620325f,+ -0.017722f,+ 0.272212f,+ 0.675188f,+ 0.559061f,+ 0.566867f});+ // present_key: (1, 2, 5, 3)+ test_case.add_expected_output<float>(+ Shape{1, 2, 5, 3},+ {0.007796f, -1.399294f, -0.810345f, -0.790828f, -1.212683f, 0.933362f, -0.843760f, 0.849301f,+ -0.305789f, 0.912625f, -0.001525f, 0.701053f, 0.012941f, -1.291529f, -0.619094f, 1.279238f,+ -0.750740f, 0.855745f, -1.495647f, 0.042313f, -1.011973f, -1.202155f, -0.739261f, 0.526944f,+ 1.307534f, 0.131957f, -0.757927f, -0.053724f, -0.629695f, 1.326786f});+ // present_value: (1, 2, 5, 3)+ test_case.add_expected_output<float>(+ Shape{1, 2, 5, 3},+ {0.234069f, 0.635683f, 1.871725f, -0.247566f, 0.535697f, -0.174310f, 0.880957f, -0.307055f,+ 0.489298f, 1.175690f, -0.776358f, -0.897604f, 2.171347f, -0.775571f, 1.237221f, -1.554317f,+ 0.724578f, 0.447344f, -0.086974f, 0.765638f, 1.224396f, -0.958257f, -0.750733f, -0.695065f,+ 1.889715f, 0.692087f, 0.801224f, 0.503803f, -0.494952f, -0.776084f});++ test_case.run_with_tolerance_as_fp(1e-4f);+}++OPENVINO_TEST(${BACKEND_NAME}, onnx_model_multi_head_attention_15_cache_buffer_sharing) {+ auto model = convert_model("com.microsoft/multi_head_attention_15_cache_buffer_sharing.onnx");+ auto test_case = test::TestCase(model, s_device);+ // Q: (1, 1, 6)+ test_case.add_input<float>({-0.502763f, -0.268339f, -0.627002f, -0.026298f, -0.477923f, -0.959982f});+ // K: (1, 1, 6)+ test_case.add_input<float>({-1.522568f, -0.516134f, -0.797255f, 0.956753f, 0.386596f, 0.501619f});+ // V: (1, 1, 6)+ test_case.add_input<float>({-0.061915f, -0.069701f, 0.272578f, 0.507838f, -0.291678f, -1.688897f});+ // past_key: (1, 2, 8, 3)+ test_case.add_input<float>({-1.633144f, 0.574429f, 0.180382f, -2.065948f, 2.251946f, -2.474243f, -0.095624f,+ -0.475753f, -0.283201f, -0.906520f, -0.161607f, 0.439711f, 0.060502f, 1.313367f,+ -0.219802f, 0.459024f, 0.545309f, 0.562743f, -0.208949f, 0.036794f, 2.255347f,+ 0.719079f, -0.648445f, 0.094805f, -0.660082f, -0.284994f, 1.612288f, -0.163533f,+ -0.512006f, -0.556645f, -1.343872f, 0.942692f, -1.384635f, 1.417410f, 0.588609f,+ -0.012637f, -0.395745f, 1.228617f, 0.738330f, -0.893525f, -0.904549f, 0.072122f,+ 1.918728f, -0.093395f, 2.004566f, -0.474692f, 0.144446f, -0.880570f});+ // past_value: (1, 2, 8, 3)+ test_case.add_input<float>({1.624742f, 1.589109f, 0.223456f, 0.341966f, -1.576143f, 2.364328f, 0.117859f,+ 0.885522f, -0.390474f, -0.817975f, 0.185934f, -0.158277f, -1.156958f, -0.256053f,+ 0.640194f, -1.933494f, 1.459255f, 0.924655f, 0.019855f, 0.311210f, 0.732947f,+ -0.491835f, 1.382449f, 0.153854f, -0.418824f, -0.789253f, 0.140109f, 0.096971f,+ -0.637027f, -0.991046f, -0.278132f, 0.238912f, -0.166286f, 1.644490f, -0.756377f,+ 1.568445f, -0.601715f, -0.862884f, -1.157213f, 0.815486f, 2.053719f, 0.026404f,+ -0.720157f, -0.195971f, 0.281561f, -1.334606f, 0.029407f, 0.999880f});+ // past_sequence_length: (1)+ test_case.add_input<int>({3});+ // Output: (1, 1, 6)+ test_case.add_expected_output<float>(Shape{1, 1, 6},+ {0.414841f, -0.230426f, 0.985419f, -0.037767f, -0.261106f, -0.663645f});+ // present_key: (1, 2, 8, 3)+ test_case.add_expected_output<float>(+ Shape{1, 2, 8, 3},+ {-1.633144f, 0.574429f, 0.180382f, -2.065948f, 2.251946f, -2.474243f, -0.095624f, -0.475753f,+ -0.283201f, -1.522568f, -0.516134f, -0.797255f, 0.060502f, 1.313367f, -0.219802f, 0.459024f,+ 0.545309f, 0.562743f, -0.208949f, 0.036794f, 2.255347f, 0.719079f, -0.648445f, 0.094805f,+ -0.660082f, -0.284994f, 1.612288f, -0.163533f, -0.512006f, -0.556645f, -1.343872f, 0.942692f,+ -1.384635f, 0.956753f, 0.386596f, 0.501619f, -0.395745f, 1.228617f, 0.738330f, -0.893525f,+ -0.904549f, 0.072122f, 1.918728f, -0.093395f, 2.004566f, -0.474692f, 0.144446f, -0.880570f});+ // present_value: (1, 2, 8, 3)+ test_case.add_expected_output<float>(+ Shape{1, 2, 8, 3},+ {1.624742f, 1.589109f, 0.223456f, 0.341966f, -1.576143f, 2.364328f, 0.117859f, 0.885522f,+ -0.390474f, -0.061915f, -0.069701f, 0.272578f, -1.156958f, -0.256053f, 0.640194f, -1.933494f,+ 1.459255f, 0.924655f, 0.019855f, 0.311210f, 0.732947f, -0.491835f, 1.382449f, 0.153854f,+ -0.418824f, -0.789253f, 0.140109f, 0.096971f, -0.637027f, -0.991046f, -0.278132f, 0.238912f,+ -0.166286f, 0.507838f, -0.291678f, -1.688897f, -0.601715f, -0.862884f, -1.157213f, 0.815486f,+ 2.053719f, 0.026404f, -0.720157f, -0.195971f, 0.281561f, -1.334606f, 0.029407f, 0.999880f});++ test_case.run_with_tolerance_as_fp(1e-4f);+}++OPENVINO_TEST(${BACKEND_NAME}, onnx_model_multi_head_attention_16_cache_beam_search) {+ auto model = convert_model("com.microsoft/multi_head_attention_16_cache_beam_search.onnx");+ auto test_case = test::TestCase(model, s_device);+ // Q: (2, 1, 6)+ test_case.add_input<float>({0.014633f,+ 2.050712f,+ 0.219489f,+ -0.758997f,+ 0.532654f,+ 0.233358f,+ -1.221251f,+ -0.758219f,+ -1.441508f,+ 0.281829f,+ 0.176174f,+ 0.052142f});+ // K: (2, 1, 6)+ test_case.add_input<float>({-0.708303f,+ -0.651082f,+ -0.966571f,+ 2.566096f,+ 1.036422f,+ 1.169582f,+ -1.467058f,+ 0.566868f,+ 0.300726f,+ 0.163399f,+ 1.761693f,+ 1.046739f});+ // V: (2, 1, 6)+ test_case.add_input<float>({-0.261049f,+ -0.510067f,+ -0.164336f,+ 2.401257f,+ 0.038037f,+ -0.907690f,+ -1.401583f,+ 0.475986f,+ 1.020456f,+ 0.141976f,+ -0.242386f,+ -0.229653f});+ // past_key: (2, 2, 4, 3)+ test_case.add_input<float>({-1.179903f, -0.820847f, 0.147255f, -0.806921f, -0.541269f, -3.832336f, 1.263634f,+ -0.013534f, -2.544328f, -0.451034f, -1.318139f, -1.049004f, -0.600362f, -2.259691f,+ -0.968099f, -0.473152f, -0.157991f, 0.246555f, 0.184235f, -2.002737f, -0.956401f,+ 0.397505f, -1.326733f, 0.002806f, -0.753141f, -0.227997f, -0.595219f, -2.109120f,+ -0.323724f, 0.044683f, 0.587469f, -0.054632f, 1.351582f, -1.290819f, 0.657286f,+ -1.984299f, -1.012252f, -0.647734f, -0.720376f, -1.461135f, 0.683642f, -0.069769f,+ -0.746679f, -0.572421f, -0.793770f, 0.092700f, 0.198125f, -0.802795f});+ // past_value: (2, 2, 4, 3)+ test_case.add_input<float>({0.098929f, 0.397491f, 0.480757f, 0.093701f, -0.474389f, 0.398639f, 1.665058f,+ 0.975667f, 0.237879f, -1.127842f, 0.765723f, 1.999417f, 1.193337f, 0.827391f,+ 1.474067f, -1.358840f, 1.459235f, -0.447496f, -2.640829f, 0.224341f, -0.238580f,+ -0.752533f, 0.008406f, 0.354385f, -1.521480f, -1.131067f, 0.140327f, -0.246926f,+ -0.799155f, -0.498223f, 0.798299f, -0.514823f, -0.028915f, 0.419435f, 0.038079f,+ 0.910346f, -0.993182f, -1.103120f, -0.344755f, 1.704449f, -0.041656f, 0.687651f,+ -1.323473f, 1.099172f, -0.646563f, -2.083734f, 0.930031f, 0.866925f});+ // past_sequence_length: (1)+ test_case.add_input<int>({3});+ // cache_indirection: (1, 2, 4)+ test_case.add_input<int>({0, 1, 1, 0, 1, 1, 0, 0});+ // Output: (2, 1, 6)+ test_case.add_expected_output<float>(Shape{2, 1, 6},+ {0.254965f,+ -0.453316f,+ -0.097362f,+ 1.010793f,+ 0.346349f,+ 0.288128f,+ -0.197175f,+ -0.247718f,+ 0.041533f,+ -0.353823f,+ -0.274332f,+ -0.046942f});+ // present_key: (2, 2, 4, 3)+ test_case.add_expected_output<float>(+ Shape{2, 2, 4, 3},+ {-1.179903f, -0.820847f, 0.147255f, -0.806921f, -0.541269f, -3.832336f, 1.263634f, -0.013534f,+ -2.544328f, -0.708303f, -0.651082f, -0.966571f, -0.600362f, -2.259691f, -0.968099f, -0.473152f,+ -0.157991f, 0.246555f, 0.184235f, -2.002737f, -0.956401f, 2.566096f, 1.036422f, 1.169582f,+ -0.753141f, -0.227997f, -0.595219f, -2.109120f, -0.323724f, 0.044683f, 0.587469f, -0.054632f,+ 1.351582f, -1.467058f, 0.566868f, 0.300726f, -1.012252f, -0.647734f, -0.720376f, -1.461135f,+ 0.683642f, -0.069769f, -0.746679f, -0.572421f, -0.793770f, 0.163399f, 1.761693f, 1.046739f});+ // present_value: (2, 2, 4, 3)+ test_case.add_expected_output<float>(+ Shape{2, 2, 4, 3},+ {0.098929f, 0.397491f, 0.480757f, 0.093701f, -0.474389f, 0.398639f, 1.665058f, 0.975667f,+ 0.237879f, -0.261049f, -0.510067f, -0.164336f, 1.193337f, 0.827391f, 1.474067f, -1.358840f,+ 1.459235f, -0.447496f, -2.640829f, 0.224341f, -0.238580f, 2.401257f, 0.038037f, -0.907690f,+ -1.521480f, -1.131067f, 0.140327f, -0.246926f, -0.799155f, -0.498223f, 0.798299f, -0.514823f,+ -0.028915f, -1.401583f, 0.475986f, 1.020456f, -0.993182f, -1.103120f, -0.344755f, 1.704449f,+ -0.041656f, 0.687651f, -1.323473f, 1.099172f, -0.646563f, 0.141976f, -0.242386f, -0.229653f});++ test_case.run_with_tolerance_as_fp(1e-4f);+}++OPENVINO_TEST(${BACKEND_NAME}, onnx_model_multi_head_attention_17_output_qk) {+ auto model = convert_model("com.microsoft/multi_head_attention_17_output_qk.onnx");+ auto test_case = test::TestCase(model, s_device);+ // Q: (1, 4, 6)+ test_case.add_input<float>({1.051868f,+ 0.625783f,+ 0.409239f,+ -0.709610f,+ 1.814253f,+ 0.535333f,+ 0.456102f,+ -0.496785f,+ 0.645828f,+ -0.992543f,+ 0.600572f,+ -0.907871f,+ -0.360408f,+ 0.011880f,+ -0.644068f,+ 1.302161f,+ 1.409975f,+ 2.692361f});+ // K: (1, 4, 6)+ test_case.add_input<float>({-0.667510f, -1.561886f, -0.916755f, -0.400884f, 0.676683f, 0.501052f,+ -0.432432f, -0.965812f, -1.167684f, -1.032523f, 2.662656f, -0.046547f,+ 1.023166f, 0.435278f, -0.722526f, 0.134017f, -1.191387f, 0.166177f,+ 0.566148f, 0.516441f, -0.385748f, 0.223202f, -0.529323f, 0.440974f});+ // V: (1, 4, 6)+ test_case.add_input<float>({0.351677f, -0.281540f, -0.582924f, -0.987096f, -0.557608f, -0.322645f,+ 2.578884f, 0.533502f, 0.430136f, 0.620238f, -0.775554f, 0.141197f,+ 1.106112f, 0.258746f, -0.448094f, 0.824640f, -1.355070f, 0.688569f,+ 0.138647f, 0.742778f, -0.490102f, 0.700676f, 1.003421f, 0.434979f});+ test_case.add_expected_output<float>(Shape{1, 3, 6},+ {0.832044f,+ 0.429053f,+ -0.385924f,+ 0.464469f,+ -0.721851f,+ 0.106980f,+ 0.983984f,+ 0.295017f,+ -0.300954f,+ 0.363394f,+ -0.636786f,+ 0.128481f,+ 1.156259f,+ 0.276583f,+ -0.221725f,+ 0.125018f,+ -0.425868f,+ 0.077078f});+ test_case.add_expected_output<float>(+ Shape{1, 2, 3, 4},+ {-1.186285f, -0.887452f, 0.607915f, 0.439265f, -0.069627f, -0.272253f, -0.124823f, -0.142874f,+ 0.469082f, 0.517563f, 0.058757f, 0.029179f, 1.027900f, 3.197656f, -1.251474f, -0.509595f,+ 0.201727f, 1.539331f, -0.577003f, -0.542583f, 1.028321f, 1.318925f, -0.610782f, 0.422374f});+ test_case.run_with_tolerance_as_fp(1e-4f);+}++OPENVINO_TEST(${BACKEND_NAME}, onnx_model_multi_head_attention_18_cache_unidirectional) {+ auto model = convert_model("com.microsoft/multi_head_attention_18_cache_unidirectional.onnx");+ auto test_case = test::TestCase(model, s_device);+ // Q: (1, 2, 6)+ test_case.add_input<float>({1.123173f,+ 1.560471f,+ -0.982731f,+ 0.547975f,+ -0.461464f,+ -0.488095f,+ 0.823373f,+ 0.885939f,+ -0.486904f,+ -0.051340f,+ 0.378610f,+ 0.122047f});+ // K: (1, 2, 6)+ test_case.add_input<float>({-1.509428f,+ -0.268259f,+ 1.906879f,+ 0.167194f,+ -0.542977f,+ -0.340443f,+ -0.197825f,+ -1.105133f,+ -1.770980f,+ 0.047243f,+ 0.305181f,+ 0.145112f});+ // V: (1, 2, 6)+ test_case.add_input<float>({0.253975f,+ -0.832144f,+ 0.151920f,+ -0.008827f,+ 1.886953f,+ -0.562337f,+ 0.977240f,+ -1.360663f,+ -0.819639f,+ 1.336034f,+ 0.113086f,+ -0.018064f});+ // past_key: (1, 2, 3, 3)+ test_case.add_input<float>({0.579000f,+ 0.723763f,+ -1.860608f,+ -0.344961f,+ 0.228242f,+ -1.000478f,+ 0.084259f,+ -0.019806f,+ -1.482682f,+ 0.037463f,+ -0.686512f,+ -0.311796f,+ 0.093783f,+ 0.688912f,+ -0.159462f,+ -1.397634f,+ -0.137557f,+ -0.338529f});+ // past_value: (1, 2, 3, 3)+ test_case.add_input<float>({0.037679f,+ -0.045304f,+ -0.488814f,+ 1.094324f,+ 0.850733f,+ -0.892390f,+ -1.093348f,+ -0.089354f,+ 0.707041f,+ -0.529374f,+ 0.797083f,+ -1.046826f,+ 1.921977f,+ -0.794896f,+ 1.044066f,+ 1.725781f,+ -0.258335f,+ -0.714704f});+ // Output: (1, 2, 6)+ test_case.add_expected_output<float>(Shape{1, 2, 6},+ {-0.033162f,+ 0.066176f,+ -0.306049f,+ 0.529358f,+ 0.624898f,+ -0.402690f,+ 0.096545f,+ -0.080529f,+ -0.315609f,+ 0.995826f,+ 0.255064f,+ -0.181851f});+ // present_key: (1, 2, 6, 3)+ test_case.add_expected_output<float>(+ Shape{1, 2, 5, 3},+ {0.579000f, 0.723763f, -1.860608f, -0.344961f, 0.228242f, -1.000478f, 0.084259f, -0.019806f,+ -1.482682f, -1.509428f, -0.268259f, 1.906879f, -0.197825f, -1.105133f, -1.770980f, 0.037463f,+ -0.686512f, -0.311796f, 0.093783f, 0.688912f, -0.159462f, -1.397634f, -0.137557f, -0.338529f,+ 0.167194f, -0.542977f, -0.340443f, 0.047243f, 0.305181f, 0.145112f});+ // present_value: (1, 2, 6, 3)+ test_case.add_expected_output<float>(+ Shape{1, 2, 5, 3},+ {0.037679f, -0.045304f, -0.488814f, 1.094324f, 0.850733f, -0.892390f, -1.093348f, -0.089354f,+ 0.707041f, 0.253975f, -0.832144f, 0.151920f, 0.977240f, -1.360663f, -0.819639f, -0.529374f,+ 0.797083f, -1.046826f, 1.921977f, -0.794896f, 1.044066f, 1.725781f, -0.258335f, -0.714704f,+ -0.008827f, 1.886953f, -0.562337f, 1.336034f, 0.113086f, -0.018064f});++ test_case.run_with_tolerance_as_fp(1e-4f);+}++OPENVINO_TEST(${BACKEND_NAME}, onnx_model_multi_head_attention_19_cache_bias) {+ auto model = convert_model("com.microsoft/multi_head_attention_19_cache_bias.onnx");+ auto test_case = test::TestCase(model, s_device);+ // Q: (1, 2, 6)+ test_case.add_input<float>({2.279423f,+ -0.652962f,+ 0.500308f,+ 1.043512f,+ 0.386979f,+ 0.545369f,+ -0.538741f,+ -0.960648f,+ 0.931486f,+ 1.067415f,+ -0.337619f,+ 0.041636f});+ // K: (1, 2, 6)+ test_case.add_input<float>({0.680873f,+ -0.413977f,+ -0.555961f,+ -0.912894f,+ -0.909848f,+ 0.168466f,+ 0.584217f,+ -1.205842f,+ 1.238899f,+ 1.448333f,+ -0.218776f,+ 1.595606f});+ // V: (1, 2, 6)+ test_case.add_input<float>({0.502159f,+ -0.775111f,+ 0.925219f,+ 0.635485f,+ -0.137744f,+ -0.343956f,+ -2.171855f,+ -1.056835f,+ -0.492180f,+ -0.626209f,+ 1.531523f,+ 0.145174f});+ // bias: (18)+ test_case.add_input<float>({-0.981659f,+ 1.382180f,+ 0.142673f,+ 0.935466f,+ 0.081688f,+ 0.211567f,+ 0.729370f,+ 0.307383f,+ 0.737141f,+ 1.001979f,+ -0.077435f,+ -0.255901f,+ -1.147294f,+ 0.600177f,+ 1.774534f,+ 1.259823f,+ -0.078648f,+ -1.016208f});+ // past_key: (1, 2, 3, 3)+ test_case.add_input<float>({-0.369884f,+ 0.829115f,+ -0.750030f,+ 0.413610f,+ -0.101967f,+ -0.340023f,+ -0.380541f,+ 0.637319f,+ -0.576284f,+ 1.086806f,+ 0.564889f,+ 0.002937f,+ -0.785653f,+ -0.713155f,+ -0.168350f,+ -0.397433f,+ -0.467106f,+ 0.534076f});+ // past_value: (1, 2, 3, 3)+ test_case.add_input<float>({-0.056342f,+ -0.628234f,+ -1.537388f,+ 1.151579f,+ -1.671898f,+ 2.328456f,+ 1.445433f,+ -1.268296f,+ -0.570315f,+ 0.989535f,+ 0.197333f,+ -0.550965f,+ -1.947071f,+ -0.335638f,+ -1.325481f,+ -0.174132f,+ -0.659972f,+ -0.141652f});+ // Output: (1, 2, 6)+ test_case.add_expected_output<float>(Shape{1, 2, 6},+ {-1.275576f,+ -0.598931f,+ 1.451448f,+ 0.666530f,+ 1.196724f,+ -0.832774f,+ -0.215988f,+ -0.885536f,+ 0.242943f,+ 0.671371f,+ 1.141197f,+ -0.843512f});+ // present_key: (1, 2, 5, 3)+ test_case.add_expected_output<float>(+ Shape{1, 2, 5, 3},+ {-0.369884f, 0.829115f, -0.750030f, 0.413610f, -0.101967f, -0.340023f, -0.380541f, 0.637319f,+ -0.576284f, 1.410243f, -0.106594f, 0.181180f, 1.313587f, -0.898459f, 1.976040f, 1.086806f,+ 0.564889f, 0.002937f, -0.785653f, -0.713155f, -0.168350f, -0.397433f, -0.467106f, 0.534076f,+ 0.089085f, -0.987283f, -0.087435f, 2.450312f, -0.296211f, 1.339705f});+ // present_value: (1, 2, 5, 3)+ test_case.add_expected_output<float>(+ Shape{1, 2, 5, 3},+ {-0.056342f, -0.628234f, -1.537388f, 1.151579f, -1.671898f, 2.328456f, 1.445433f, -1.268296f,+ -0.570315f, -0.645135f, -0.174934f, 2.699753f, -3.319149f, -0.456658f, 1.282354f, 0.989535f,+ 0.197333f, -0.550965f, -1.947071f, -0.335638f, -1.325481f, -0.174132f, -0.659972f, -0.141652f,+ 1.895308f, -0.216392f, -1.360164f, 0.633614f, 1.452875f, -0.871034f});++ test_case.run_with_tolerance_as_fp(1e-4f);+}+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_fusedgemm_abc) {const auto model = convert_model("com.microsoft/fusedgemm.onnx");auto test_case = ov::test::TestCase(model, s_device);