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] support new inputs in GroupQueryAttention (#32708)
Yaru Du251976936f06
diff --git a/src/common/transformations/src/transformations/op_conversions/group_query_attention_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/group_query_attention_decomposition.cppindex 987643418d2..a47d4a6eaec 100644--- a/src/common/transformations/src/transformations/op_conversions/group_query_attention_decomposition.cpp+++ b/src/common/transformations/src/transformations/op_conversions/group_query_attention_decomposition.cpp@@ -103,7 +103,11 @@ ov::OutputVector ov::pass::GroupQueryAttentionDecomposition::decompose(if (do_rotary) {ov::Output<ov::Node> position_ids =register_new_node<v4::Range>(zero_without_shape, curr_seqlen_scalar, one_without_shape, ov::element::i64);- position_ids = register_new_node<v1::Add>(position_ids, past_seqlen);+ if (node->get_input_size() > 8) {+ position_ids = node->input_value(8).get_node_shared_ptr();+ } else {+ position_ids = register_new_node<v1::Add>(position_ids, past_seqlen);+ }const auto cos = register_new_node<v8::Gather>(cos_cache, position_ids, zero);const auto sin = register_new_node<v8::Gather>(sin_cache, position_ids, zero);@@ -157,34 +161,46 @@ ov::OutputVector ov::pass::GroupQueryAttentionDecomposition::decompose(// Make attention maskstd::shared_ptr<ov::Node> mask;+ if (node->get_input_size() > 9) {+ auto original_mask = node->input_value(9).get_node_shared_ptr();+ // Extract mask [num_heads, curr_seqlen, concat_kv_len] from 4D mask [1, num_heads, curr_seqlen, max_kv_len]+ auto axes_to_squeeze = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{1}, {0}));+ auto mask_squeezed = register_new_node<v0::Squeeze>(original_mask, axes_to_squeeze);+ mask = register_new_node<v8::Slice>(mask_squeezed, zero, concat_kv_len, one, two);+ } else {+ std::shared_ptr<ov::Node> hori_range =+ register_new_node<v4::Range>(zero_without_shape, concat_kv_len_scalar, one_without_shape, ov::element::i64);+ hori_range = register_new_node<v0::Unsqueeze>(hori_range, zero);- std::shared_ptr<ov::Node> hori_range =- register_new_node<v4::Range>(zero_without_shape, concat_kv_len_scalar, one_without_shape, ov::element::i64);- hori_range = register_new_node<v0::Unsqueeze>(hori_range, zero);-- std::shared_ptr<ov::Node> vert_range =- register_new_node<v4::Range>(zero_without_shape, curr_seqlen_scalar, one_without_shape, ov::element::i64);- vert_range = register_new_node<v0::Unsqueeze>(vert_range, one);- const auto past_k_node_len = get_dimensions(past_key.get_node_shared_ptr(), {2});- vert_range = register_new_node<v1::Add>(vert_range, past_k_node_len);-- const auto triu = register_new_node<v1::Greater>(hori_range, vert_range);- const auto typed_zero = register_new_node(v0::Constant::create(T, ov::Shape{}, {0}));- // cf. make_attention_mask@src\plugins\intel_gpu\tests\common\subgraphs_builders.hpp- std::shared_ptr<ov::Node> minus_inf = nullptr;- if (T == ov::element::f32)- minus_inf = register_new_node(v0::Constant::create(T, ov::Shape{}, {-std::numeric_limits<float>::infinity()}));- else if (T == ov::element::f16)- minus_inf =- register_new_node(v0::Constant::create(T, ov::Shape{}, {std::numeric_limits<ov::float16>::lowest()}));- mask = register_new_node<v1::Select>(triu, minus_inf, typed_zero);+ std::shared_ptr<ov::Node> vert_range =+ register_new_node<v4::Range>(zero_without_shape, curr_seqlen_scalar, one_without_shape, ov::element::i64);+ vert_range = register_new_node<v0::Unsqueeze>(vert_range, one);+ if (is_static_input) {+ const auto past_k_node_len = get_dimensions(past_key.get_node_shared_ptr(), {2});+ vert_range = register_new_node<v1::Add>(vert_range, past_k_node_len);+ } else {+ vert_range = register_new_node<v1::Add>(vert_range, past_seqlen);+ }- if (is_static_input) {- const auto padding_len = register_new_node<v1::Subtract>(concat_kv_len, seqlens_1d);- const auto padding_mask_vert_shape = register_new_node<v0::Concat>(ov::NodeVector{current_seqlen, one}, 0);- const auto padding_mask_vert = register_new_node<v3::Broadcast>(padding_len, padding_mask_vert_shape);- const auto padding_mask = register_new_node<v1::GreaterEqual>(hori_range, padding_mask_vert);- mask = register_new_node<v1::Select>(padding_mask, mask, minus_inf);+ const auto triu = register_new_node<v1::Greater>(hori_range, vert_range);+ const auto typed_zero = register_new_node(v0::Constant::create(T, ov::Shape{}, {0}));+ // cf. make_attention_mask@src\plugins\intel_gpu\tests\common\subgraphs_builders.hpp+ std::shared_ptr<ov::Node> minus_inf = nullptr;+ if (T == ov::element::f32)+ minus_inf =+ register_new_node(v0::Constant::create(T, ov::Shape{}, {-std::numeric_limits<float>::infinity()}));+ else if (T == ov::element::f16)+ minus_inf =+ register_new_node(v0::Constant::create(T, ov::Shape{}, {std::numeric_limits<ov::float16>::lowest()}));+ mask = register_new_node<v1::Select>(triu, minus_inf, typed_zero);++ if (is_static_input) {+ const auto padding_len = register_new_node<v1::Subtract>(concat_kv_len, seqlens_1d);+ const auto padding_mask_vert_shape = register_new_node<v0::Concat>(ov::NodeVector{current_seqlen, one}, 0);+ const auto padding_mask_vert = register_new_node<v3::Broadcast>(padding_len, padding_mask_vert_shape);+ const auto padding_mask = register_new_node<v1::GreaterEqual>(hori_range, padding_mask_vert);+ mask = register_new_node<v1::Select>(padding_mask, mask, minus_inf);+ }}std::shared_ptr<ov::Node> qga_output;diff --git a/src/frontends/onnx/frontend/src/op/com.microsoft/group_query_attention.cpp b/src/frontends/onnx/frontend/src/op/com.microsoft/group_query_attention.cppindex acde3b80109..8a48dfa7cb4 100644--- a/src/frontends/onnx/frontend/src/op/com.microsoft/group_query_attention.cpp+++ b/src/frontends/onnx/frontend/src/op/com.microsoft/group_query_attention.cpp@@ -8,6 +8,7 @@#include "core/null_node.hpp"#include "core/operator_set.hpp"+#include "exceptions.hpp"#include "openvino/op/concat.hpp"#include "openvino/op/divide.hpp"#include "openvino/op/gather.hpp"@@ -39,6 +40,7 @@ ov::OutputVector group_query_attention(const ov::frontend::onnx::Node& node) {const auto do_rotary = node.get_attribute_value<int64_t>("do_rotary", 0);const auto rotary_interleaved = node.get_attribute_value<int64_t>("rotary_interleaved", 0);+ CHECK_VALID_NODE(node, onnx_op_inputs.size() >= 9, "Expected at least 9 inputs, but got: ", onnx_op_inputs.size());// In ONNX, the format of input QKV is [B, S, N*H] and of past_kv is [B, N, S, H]// In OV, we always use [B, N, S, H]auto perm = v0::Constant::create(ov::element::i64, ov::Shape{4}, {0, 2, 1, 3});@@ -89,7 +91,7 @@ ov::OutputVector group_query_attention(const ov::frontend::onnx::Node& node) {ov_op_inputs.push_back(V);}- for (int i = 3; i < 9; ++i) {+ for (std::size_t i = 3; i < onnx_op_inputs.size(); ++i) {// skip total_sequence_lengthif (i == 6)continue;diff --git a/src/frontends/onnx/tests/models/com.microsoft/gqa_rotary_posid.prototxt b/src/frontends/onnx/tests/models/com.microsoft/gqa_rotary_posid.prototxtnew file mode 100644index 00000000000..74e1267f982--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/gqa_rotary_posid.prototxt@@ -0,0 +1,194 @@+ir_version: 10+graph {+ node {+ input: "query"+ input: ""+ input: ""+ input: "past_key"+ input: "past_value"+ input: "seqlens_k"+ input: ""+ input: "cos_cache"+ input: "sin_cache"+ input: "position_ids"+ output: "output"+ output: "present_key"+ output: "present_value"+ name: "GroupQueryAttention_0"+ op_type: "GroupQueryAttention"+ attribute {+ name: "do_rotary"+ i: 1+ type: INT+ }+ attribute {+ name: "kv_num_heads"+ i: 1+ type: INT+ }+ attribute {+ name: "local_window_size"+ i: -1+ type: INT+ }+ attribute {+ name: "num_heads"+ i: 2+ type: INT+ }+ attribute {+ name: "rotary_interleaved"+ i: 0+ type: INT+ }+ attribute {+ name: "smooth_softmax"+ i: 0+ type: INT+ }+ attribute {+ name: "softcap"+ f: 0+ type: FLOAT+ }+ domain: "com.microsoft"+ }+ name: "GroupQueryAttention_Graph"+ input {+ name: "query"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_param: "sequence_length" }+ dim { dim_value: 64 }+ }+ }+ }+ }+ input {+ name: "past_key"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 1 }+ dim { dim_param: "past_sequence_length" }+ dim { dim_value: 16 }+ }+ }+ }+ }+ input {+ name: "past_value"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 1 }+ dim { dim_param: "past_sequence_length" }+ dim { dim_value: 16 }+ }+ }+ }+ }+ input {+ name: "seqlens_k"+ type {+ tensor_type {+ elem_type: 6+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 1 }+ }+ }+ }+ }+ input {+ name: "cos_cache"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "max_sequence_length" }+ dim { dim_value: 8 }+ }+ }+ }+ }+ input {+ name: "sin_cache"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "max_sequence_length" }+ dim { dim_value: 8 }+ }+ }+ }+ }+ input {+ name: "position_ids"+ type {+ tensor_type {+ elem_type: 7+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_param: "sequence_length" }+ }+ }+ }+ }+ output {+ name: "output"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_param: "sequence_length" }+ dim { dim_value: 32 }+ }+ }+ }+ }+ output {+ name: "present_key"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 1 }+ dim { dim_param: "total_sequence_length" }+ dim { dim_value: 16 }+ }+ }+ }+ }+ output {+ name: "present_value"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 1 }+ dim { dim_param: "total_sequence_length" }+ dim { dim_value: 16 }+ }+ }+ }+ }+}+opset_import {+ version: 11+}+opset_import {+ domain: "com.microsoft"+ version: 1+}diff --git a/src/frontends/onnx/tests/models/com.microsoft/gqa_rotary_posid_bias.prototxt b/src/frontends/onnx/tests/models/com.microsoft/gqa_rotary_posid_bias.prototxtnew file mode 100644index 00000000000..314c3bbe5fa--- /dev/null+++ b/src/frontends/onnx/tests/models/com.microsoft/gqa_rotary_posid_bias.prototxt@@ -0,0 +1,209 @@+ir_version: 10+graph {+ node {+ input: "query"+ input: ""+ input: ""+ input: "past_key"+ input: "past_value"+ input: "seqlens_k"+ input: ""+ input: "cos_cache"+ input: "sin_cache"+ input: "position_ids"+ input: "attention_bias"+ output: "output"+ output: "present_key"+ output: "present_value"+ name: "GroupQueryAttention_0"+ op_type: "GroupQueryAttention"+ attribute {+ name: "do_rotary"+ i: 1+ type: INT+ }+ attribute {+ name: "kv_num_heads"+ i: 1+ type: INT+ }+ attribute {+ name: "local_window_size"+ i: -1+ type: INT+ }+ attribute {+ name: "num_heads"+ i: 2+ type: INT+ }+ attribute {+ name: "rotary_interleaved"+ i: 0+ type: INT+ }+ attribute {+ name: "smooth_softmax"+ i: 0+ type: INT+ }+ attribute {+ name: "softcap"+ f: 0+ type: FLOAT+ }+ domain: "com.microsoft"+ }+ name: "GroupQueryAttention_Graph"+ input {+ name: "query"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_param: "sequence_length" }+ dim { dim_value: 64 }+ }+ }+ }+ }+ input {+ name: "past_key"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 1 }+ dim { dim_param: "past_sequence_length" }+ dim { dim_value: 16 }+ }+ }+ }+ }+ input {+ name: "past_value"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 1 }+ dim { dim_param: "past_sequence_length" }+ dim { dim_value: 16 }+ }+ }+ }+ }+ input {+ name: "seqlens_k"+ type {+ tensor_type {+ elem_type: 6+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 1 }+ }+ }+ }+ }+ input {+ name: "cos_cache"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "max_sequence_length" }+ dim { dim_value: 8 }+ }+ }+ }+ }+ input {+ name: "sin_cache"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "max_sequence_length" }+ dim { dim_value: 8 }+ }+ }+ }+ }+ input {+ name: "position_ids"+ type {+ tensor_type {+ elem_type: 7+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_param: "sequence_length" }+ }+ }+ }+ }+ input {+ name: "attention_bias"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 1 }+ dim { dim_param: "sequence_length" }+ dim { dim_param: "total_sequence_length" }+ }+ }+ }+ }+ output {+ name: "output"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_param: "sequence_length" }+ dim { dim_value: 32 }+ }+ }+ }+ }+ output {+ name: "present_key"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 1 }+ dim { dim_param: "total_sequence_length" }+ dim { dim_value: 16 }+ }+ }+ }+ }+ output {+ name: "present_value"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim { dim_param: "batch_size" }+ dim { dim_value: 1 }+ dim { dim_param: "total_sequence_length" }+ dim { dim_value: 16 }+ }+ }+ }+ }+}+opset_import {+ version: 11+}+opset_import {+ domain: "com.microsoft"+ version: 1+}diff --git a/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp b/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cppindex 53528cd06ed..6bb8c8d2e25 100644--- a/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp+++ b/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp@@ -2046,6 +2046,186 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_past_0_input_1_rotary) {test_case.run_with_tolerance_as_fp();}+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_past_0_input_1_rotary_posid) {+ const auto model = convert_model("com.microsoft/gqa_rotary_posid.onnx");++ std::vector<float> query = {+ -1.1258f, -1.1524f, -0.2506f, -0.4339f, 0.8487f, 0.6920f, -0.3160f, -2.1152f, 0.3223f, -1.2633f, 0.3500f,+ 0.3081f, 0.1198f, 1.2377f, 1.1168f, -0.2473f, -1.3527f, -1.6959f, 0.5667f, 0.7935f, 0.5988f, -1.5551f,+ -0.3414f, 1.8530f, 0.7502f, -0.5855f, -0.1734f, 0.1835f, 1.3894f, 1.5863f, 0.9463f, -0.8437f, 1.6459f,+ -1.3602f, 0.3446f, 0.5199f, -2.6133f, -1.6965f, -0.2282f, 0.2800f, 0.2469f, 0.0769f, 0.3380f, 0.4544f,+ 0.4569f, -0.8654f, 0.7813f, -0.9268f, -0.2188f, -2.4351f, -0.0729f, -0.0340f, 0.9625f, 0.3492f, -0.9215f,+ -0.0562f, -0.6227f, -0.4637f, 1.9218f, -0.4025f, 0.1239f, 1.1648f, 0.9234f, 1.3873f,+ };+ std::vector<float> past_key = {};+ std::vector<float> past_value = {};+ std::vector<int> seqlens_k = {0};+ std::vector<float> cos_cache = {+ 0.8437f,+ -0.7849f,+ -0.7829f,+ 0.4581f,+ -0.9870f,+ 0.6273f,+ -0.9483f,+ -0.9962f,+ };+ std::vector<float> sin_cache = {+ 0.5368f,+ 0.6196f,+ -0.6222f,+ 0.8889f,+ 0.1605f,+ -0.7788f,+ 0.3174f,+ -0.0872f,+ };+ std::vector<int64_t> position_ids = {0};++ std::vector<float> expected_output = {-0.2188f, -2.4351f, -0.0729f, -0.034f, 0.9625f, 0.3492f, -0.9215f, -0.0562f,+ -0.6227f, -0.4637f, 1.9218f, -0.4025f, 0.1239f, 1.1648f, 0.9234f, 1.3873f,+ -0.2188f, -2.4351f, -0.0729f, -0.034f, 0.9625f, 0.3492f, -0.9215f, -0.0562f,+ -0.6227f, -0.4637f, 1.9218f, -0.4025f, 0.1239f, 1.1648f, 0.9234f, 1.3873f};++ std::vector<float> expected_present_key = {1.2561098f,+ 1.0199738f,+ -0.05948371f,+ -0.16574995f,+ 2.5059946f,+ -1.738188f,+ -0.03158256f,+ -0.35975295f,+ 1.0918287f,+ -0.90313876f,+ -0.4790303f,+ 0.67029977f,+ -0.87039495f,+ 0.7783688f,+ -0.81333745f,+ 0.89886224f};++ std::vector<float> expected_present_value = {-0.2188f,+ -2.4351f,+ -0.0729f,+ -0.034f,+ 0.9625f,+ 0.3492f,+ -0.9215f,+ -0.0562f,+ -0.6227f,+ -0.4637f,+ 1.9218f,+ -0.4025f,+ 0.1239f,+ 1.1648f,+ 0.9234f,+ 1.3873f};++ auto test_case = ov::test::TestCase(model, s_device);+ test_case.add_input<float>(Shape{1, 1, 64}, query);+ test_case.add_input<float>(Shape{1, 1, 0, 16}, past_key);+ test_case.add_input<float>(Shape{1, 1, 0, 16}, past_value);+ test_case.add_input<int>(Shape{1, 1}, seqlens_k);+ test_case.add_input<float>(Shape{1, 8}, cos_cache);+ test_case.add_input<float>(Shape{1, 8}, sin_cache);+ test_case.add_input<int64_t>(Shape{1, 1}, position_ids);+ test_case.add_expected_output<float>(Shape{1, 1, 32}, expected_output);+ test_case.add_expected_output<float>(Shape{1, 1, 1, 16}, expected_present_key);+ test_case.add_expected_output<float>(Shape{1, 1, 1, 16}, expected_present_value);+ test_case.run_with_tolerance_as_fp();+}++OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_past_0_input_1_rotary_posid_bias) {+ const auto model = convert_model("com.microsoft/gqa_rotary_posid_bias.onnx");++ std::vector<float> query = {+ -1.1258f, -1.1524f, -0.2506f, -0.4339f, 0.8487f, 0.6920f, -0.3160f, -2.1152f, 0.3223f, -1.2633f, 0.3500f,+ 0.3081f, 0.1198f, 1.2377f, 1.1168f, -0.2473f, -1.3527f, -1.6959f, 0.5667f, 0.7935f, 0.5988f, -1.5551f,+ -0.3414f, 1.8530f, 0.7502f, -0.5855f, -0.1734f, 0.1835f, 1.3894f, 1.5863f, 0.9463f, -0.8437f, 1.6459f,+ -1.3602f, 0.3446f, 0.5199f, -2.6133f, -1.6965f, -0.2282f, 0.2800f, 0.2469f, 0.0769f, 0.3380f, 0.4544f,+ 0.4569f, -0.8654f, 0.7813f, -0.9268f, -0.2188f, -2.4351f, -0.0729f, -0.0340f, 0.9625f, 0.3492f, -0.9215f,+ -0.0562f, -0.6227f, -0.4637f, 1.9218f, -0.4025f, 0.1239f, 1.1648f, 0.9234f, 1.3873f,+ };+ std::vector<float> past_key = {};+ std::vector<float> past_value = {};+ std::vector<int> seqlens_k = {0};+ std::vector<float> cos_cache = {+ 0.8437f,+ -0.7849f,+ -0.7829f,+ 0.4581f,+ -0.9870f,+ 0.6273f,+ -0.9483f,+ -0.9962f,+ };+ std::vector<float> sin_cache = {+ 0.5368f,+ 0.6196f,+ -0.6222f,+ 0.8889f,+ 0.1605f,+ -0.7788f,+ 0.3174f,+ -0.0872f,+ };+ std::vector<int64_t> position_ids = {0};+ std::vector<float> attention_bias = {2.f};++ std::vector<float> expected_output = {-0.2188f, -2.4351f, -0.0729f, -0.034f, 0.9625f, 0.3492f, -0.9215f, -0.0562f,+ -0.6227f, -0.4637f, 1.9218f, -0.4025f, 0.1239f, 1.1648f, 0.9234f, 1.3873f,+ -0.2188f, -2.4351f, -0.0729f, -0.034f, 0.9625f, 0.3492f, -0.9215f, -0.0562f,+ -0.6227f, -0.4637f, 1.9218f, -0.4025f, 0.1239f, 1.1648f, 0.9234f, 1.3873f};++ std::vector<float> expected_present_key = {1.2561098f,+ 1.0199738f,+ -0.05948371f,+ -0.16574995f,+ 2.5059946f,+ -1.738188f,+ -0.03158256f,+ -0.35975295f,+ 1.0918287f,+ -0.90313876f,+ -0.4790303f,+ 0.67029977f,+ -0.87039495f,+ 0.7783688f,+ -0.81333745f,+ 0.89886224f};++ std::vector<float> expected_present_value = {-0.2188f,+ -2.4351f,+ -0.0729f,+ -0.034f,+ 0.9625f,+ 0.3492f,+ -0.9215f,+ -0.0562f,+ -0.6227f,+ -0.4637f,+ 1.9218f,+ -0.4025f,+ 0.1239f,+ 1.1648f,+ 0.9234f,+ 1.3873f};++ auto test_case = ov::test::TestCase(model, s_device);+ test_case.add_input<float>(Shape{1, 1, 64}, query);+ test_case.add_input<float>(Shape{1, 1, 0, 16}, past_key);+ test_case.add_input<float>(Shape{1, 1, 0, 16}, past_value);+ test_case.add_input<int>(Shape{1, 1}, seqlens_k);+ test_case.add_input<float>(Shape{1, 8}, cos_cache);+ test_case.add_input<float>(Shape{1, 8}, sin_cache);+ test_case.add_input<int64_t>(Shape{1, 1}, position_ids);+ test_case.add_input<float>(Shape{1, 1, 1, 1}, attention_bias);+ test_case.add_expected_output<float>(Shape{1, 1, 32}, expected_output);+ test_case.add_expected_output<float>(Shape{1, 1, 1, 16}, expected_present_key);+ test_case.add_expected_output<float>(Shape{1, 1, 1, 16}, expected_present_value);+ test_case.run_with_tolerance_as_fp();+}+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_past_0_input_1_rotary_interleaved) {const auto model = convert_model("com.microsoft/gqa_rotary_interleaved.onnx");@@ -2248,6 +2428,242 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_past_1_input_1_rotary) {test_case.run_with_tolerance_as_fp();}+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_past_1_input_1_rotary_posid) {+ const auto model = convert_model("com.microsoft/gqa_rotary_posid.onnx");++ std::vector<float> query = {+ -1.1258f, -1.1524f, -0.2506f, -0.4339f, 0.8487f, 0.6920f, -0.3160f, -2.1152f, 0.3223f, -1.2633f, 0.3500f,+ 0.3081f, 0.1198f, 1.2377f, 1.1168f, -0.2473f, -1.3527f, -1.6959f, 0.5667f, 0.7935f, 0.5988f, -1.5551f,+ -0.3414f, 1.8530f, 0.7502f, -0.5855f, -0.1734f, 0.1835f, 1.3894f, 1.5863f, 0.9463f, -0.8437f, 1.6459f,+ -1.3602f, 0.3446f, 0.5199f, -2.6133f, -1.6965f, -0.2282f, 0.2800f, 0.2469f, 0.0769f, 0.3380f, 0.4544f,+ 0.4569f, -0.8654f, 0.7813f, -0.9268f, -0.2188f, -2.4351f, -0.0729f, -0.0340f, 0.9625f, 0.3492f, -0.9215f,+ -0.0562f, -0.6227f, -0.4637f, 1.9218f, -0.4025f, 0.1239f, 1.1648f, 0.9234f, 1.3873f,+ };+ std::vector<float> past_key = {+ -0.6136f,+ 0.0316f,+ -0.4927f,+ 0.2484f,+ 0.4397f,+ 0.1124f,+ 0.6408f,+ 0.4412f,+ -0.1023f,+ 0.7924f,+ -0.2897f,+ 0.0525f,+ 0.5229f,+ 2.3022f,+ -1.4689f,+ -1.5867f,+ };+ std::vector<float> past_value = {+ -0.5692f,+ 0.9200f,+ 1.1108f,+ 1.2899f,+ -1.4782f,+ 2.5672f,+ -0.4731f,+ 0.3356f,+ -1.6293f,+ -0.5497f,+ -0.4798f,+ -0.4997f,+ -1.0670f,+ 1.1149f,+ -0.1407f,+ 0.8058f,+ };+ std::vector<int> seqlens_k = {1};+ std::vector<float> cos_cache = {+ 0.8437f,+ -0.7849f,+ -0.7829f,+ 0.4581f,+ -0.9870f,+ 0.6273f,+ -0.9483f,+ -0.9962f,+ -0.9635f,+ -0.8046f,+ 0.4139f,+ 0.9863f,+ 0.4117f,+ 0.9874f,+ -0.9743f,+ 0.9494f,+ };+ std::vector<float> sin_cache = {+ 0.5368f,+ 0.6196f,+ -0.6222f,+ 0.8889f,+ 0.1605f,+ -0.7788f,+ 0.3174f,+ -0.0872f,+ 0.2677f,+ -0.5938f,+ -0.9103f,+ -0.1650f,+ -0.9113f,+ -0.1583f,+ 0.2253f,+ 0.3140f,+ };+ std::vector<int64_t> position_ids = {1};++ std::vector<float> expected_output = {+ -0.5393495f, 0.6341805f, 1.0099611f, 1.1771175f, -1.2702779f, 2.3782496f, -0.5112990f, 0.3022227f,+ -1.5435482f, -0.5423737f, -0.2752087f, -0.4914196f, -0.9655478f, 1.1191508f, -0.0500498f, 0.8553377f,+ -0.4935675f, 0.1958148f, 0.8553030f, 1.0041413f, -0.9513844f, 2.0884532f, -0.5698854f, 0.2510314f,+ -1.4120293f, -0.5311372f, 0.0385759f, -0.4787198f, -0.8099489f, 1.1256707f, 0.0889818f, 0.9313145f};++ std::vector<float> expected_present_key = {+ -0.6136f, 0.0316f, -0.4927f, 0.2484f, 0.4397f, 0.1124f, 0.6408f, 0.4412f,+ -0.1023f, 0.7924f, -0.2897f, 0.0525f, 0.5229f, 2.3022f, -1.4689f, -1.5867f,+ -1.6519198f, 1.1400802f, 0.45031136f, 0.5877534f, -0.65952265f, -1.8121169f, 0.04630837f, 0.5568472f,+ 0.20271924f, 0.7458131f, -0.17379119f, 0.3623912f, 2.5696063f, -0.58594f, -0.8126341f, -0.7919839f};++ std::vector<float> expected_present_value = {+ -0.5692f, 0.9200f, 1.1108f, 1.2899f, -1.4782f, 2.5672f, -0.4731f, 0.3356f, -1.6293f, -0.5497f, -0.4798f,+ -0.4997f, -1.0670f, 1.1149f, -0.1407f, 0.8058f, -0.2188f, -2.4351f, -0.0729f, -0.034f, 0.9625f, 0.3492f,+ -0.9215f, -0.0562f, -0.6227f, -0.4637f, 1.9218f, -0.4025f, 0.1239f, 1.1648f, 0.9234f, 1.3873f};++ auto test_case = ov::test::TestCase(model, s_device);+ test_case.add_input<float>(Shape{1, 1, 64}, query);+ test_case.add_input<float>(Shape{1, 1, 1, 16}, past_key);+ test_case.add_input<float>(Shape{1, 1, 1, 16}, past_value);+ test_case.add_input<int>(Shape{1, 1}, seqlens_k);+ test_case.add_input<float>(Shape{2, 8}, cos_cache);+ test_case.add_input<float>(Shape{2, 8}, sin_cache);+ test_case.add_input<int64_t>(Shape{1, 1}, position_ids);+ test_case.add_expected_output<float>(Shape{1, 1, 32}, expected_output);+ test_case.add_expected_output<float>(Shape{1, 1, 2, 16}, expected_present_key);+ test_case.add_expected_output<float>(Shape{1, 1, 2, 16}, expected_present_value);+ test_case.run_with_tolerance_as_fp();+}++OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_past_1_input_1_rotary_posid_bias) {+ const auto model = convert_model("com.microsoft/gqa_rotary_posid_bias.onnx");++ std::vector<float> query = {+ -1.1258f, -1.1524f, -0.2506f, -0.4339f, 0.8487f, 0.6920f, -0.3160f, -2.1152f, 0.3223f, -1.2633f, 0.3500f,+ 0.3081f, 0.1198f, 1.2377f, 1.1168f, -0.2473f, -1.3527f, -1.6959f, 0.5667f, 0.7935f, 0.5988f, -1.5551f,+ -0.3414f, 1.8530f, 0.7502f, -0.5855f, -0.1734f, 0.1835f, 1.3894f, 1.5863f, 0.9463f, -0.8437f, 1.6459f,+ -1.3602f, 0.3446f, 0.5199f, -2.6133f, -1.6965f, -0.2282f, 0.2800f, 0.2469f, 0.0769f, 0.3380f, 0.4544f,+ 0.4569f, -0.8654f, 0.7813f, -0.9268f, -0.2188f, -2.4351f, -0.0729f, -0.0340f, 0.9625f, 0.3492f, -0.9215f,+ -0.0562f, -0.6227f, -0.4637f, 1.9218f, -0.4025f, 0.1239f, 1.1648f, 0.9234f, 1.3873f,+ };+ std::vector<float> past_key = {+ -0.6136f,+ 0.0316f,+ -0.4927f,+ 0.2484f,+ 0.4397f,+ 0.1124f,+ 0.6408f,+ 0.4412f,+ -0.1023f,+ 0.7924f,+ -0.2897f,+ 0.0525f,+ 0.5229f,+ 2.3022f,+ -1.4689f,+ -1.5867f,+ };+ std::vector<float> past_value = {+ -0.5692f,+ 0.9200f,+ 1.1108f,+ 1.2899f,+ -1.4782f,+ 2.5672f,+ -0.4731f,+ 0.3356f,+ -1.6293f,+ -0.5497f,+ -0.4798f,+ -0.4997f,+ -1.0670f,+ 1.1149f,+ -0.1407f,+ 0.8058f,+ };+ std::vector<int> seqlens_k = {1};+ std::vector<float> cos_cache = {+ 0.8437f,+ -0.7849f,+ -0.7829f,+ 0.4581f,+ -0.9870f,+ 0.6273f,+ -0.9483f,+ -0.9962f,+ -0.9635f,+ -0.8046f,+ 0.4139f,+ 0.9863f,+ 0.4117f,+ 0.9874f,+ -0.9743f,+ 0.9494f,+ };+ std::vector<float> sin_cache = {+ 0.5368f,+ 0.6196f,+ -0.6222f,+ 0.8889f,+ 0.1605f,+ -0.7788f,+ 0.3174f,+ -0.0872f,+ 0.2677f,+ -0.5938f,+ -0.9103f,+ -0.1650f,+ -0.9113f,+ -0.1583f,+ 0.2253f,+ 0.3140f,+ };+ std::vector<int64_t> position_ids = {1};+ std::vector<float> attention_bias = {0.5f, 1.5f};++ std::vector<float> expected_output = {+ -0.4984190f, 0.2422683f, 0.8716921f, 1.0224715f, -0.9851774f, 2.1191630f, -0.5636769f, 0.2564562f,+ -1.4259663f, -0.5323280f, 0.0053242f, -0.4800655f, -0.8264377f, 1.1249797f, 0.0742486f, 0.9232633f,+ -0.4192308f, -0.5159631f, 0.6041833f, 0.7232785f, -0.4335947f, 1.6179089f, -0.6650125f, 0.1679118f,+ -1.1984810f, -0.5128924f, 0.5480707f, -0.4580989f, -0.5573018f, 1.1362569f, 0.3147285f, 1.0546785f};++ std::vector<float> expected_present_key = {+ -0.6136f, 0.0316f, -0.4927f, 0.2484f, 0.4397f, 0.1124f, 0.6408f, 0.4412f,+ -0.1023f, 0.7924f, -0.2897f, 0.0525f, 0.5229f, 2.3022f, -1.4689f, -1.5867f,+ -1.6519198f, 1.1400802f, 0.45031136f, 0.5877534f, -0.65952265f, -1.8121169f, 0.04630837f, 0.5568472f,+ 0.20271924f, 0.7458131f, -0.17379119f, 0.3623912f, 2.5696063f, -0.58594f, -0.8126341f, -0.7919839f};++ std::vector<float> expected_present_value = {+ -0.5692f, 0.9200f, 1.1108f, 1.2899f, -1.4782f, 2.5672f, -0.4731f, 0.3356f, -1.6293f, -0.5497f, -0.4798f,+ -0.4997f, -1.0670f, 1.1149f, -0.1407f, 0.8058f, -0.2188f, -2.4351f, -0.0729f, -0.034f, 0.9625f, 0.3492f,+ -0.9215f, -0.0562f, -0.6227f, -0.4637f, 1.9218f, -0.4025f, 0.1239f, 1.1648f, 0.9234f, 1.3873f};++ auto test_case = ov::test::TestCase(model, s_device);+ test_case.add_input<float>(Shape{1, 1, 64}, query);+ test_case.add_input<float>(Shape{1, 1, 1, 16}, past_key);+ test_case.add_input<float>(Shape{1, 1, 1, 16}, past_value);+ test_case.add_input<int>(Shape{1, 1}, seqlens_k);+ test_case.add_input<float>(Shape{2, 8}, cos_cache);+ test_case.add_input<float>(Shape{2, 8}, sin_cache);+ test_case.add_input<int64_t>(Shape{1, 1}, position_ids);+ test_case.add_input<float>(Shape{1, 1, 1, 2}, attention_bias);+ test_case.add_expected_output<float>(Shape{1, 1, 32}, expected_output);+ test_case.add_expected_output<float>(Shape{1, 1, 2, 16}, expected_present_key);+ test_case.add_expected_output<float>(Shape{1, 1, 2, 16}, expected_present_value);+ test_case.run_with_tolerance_as_fp();+}+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_gqa_past_1_input_1_rotary_interleaved) {const auto model = convert_model("com.microsoft/gqa_rotary_interleaved.onnx");