Skip to content

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

[Op][SDPA] Extend SDPA op with sink input (#31786)

Katarzyna Mitrusae833b4e5ee6
diff --git a/docs/articles_en/documentation/openvino-ir-format/operation-sets/operation-specs/sequence/scaled-dot-product-attention.rst b/docs/articles_en/documentation/openvino-ir-format/operation-sets/operation-specs/sequence/scaled-dot-product-attention.rst
index 9f2e272bf57..7ca9459846a 100644
--- a/docs/articles_en/documentation/openvino-ir-format/operation-sets/operation-specs/sequence/scaled-dot-product-attention.rst
+++ b/docs/articles_en/documentation/openvino-ir-format/operation-sets/operation-specs/sequence/scaled-dot-product-attention.rst
@@ -20,7 +20,7 @@ omitting training-related parameter.
.. code-block:: py
:force:
- def ScaledDotProductAttention(query, key, value, attn_mask=None, scale=None, *, causal):
+ def ScaledDotProductAttention(query, key, value, attn_mask=None, scale=None, sink=None, *, causal):
L, S = Gather(ShapeOf(query), -2), Gather(ShapeOf(key), -2)
if scale is None:
scale = 1.0 / Sqrt(ConvertLike(Gather(ShapeOf(query), -1), query))
@@ -33,9 +33,13 @@ omitting training-related parameter.
else:
attn_bias += attn_mask
attn_weight = MatMul(query, Transpose(key, [-2, -1])) * scale
- attn_weight += attn_bias
- attn_weight = Softmax(attn_weight, axis=-1)
- return MatMul(attn_weight, value)
+ attn_weight += attn_bias
+ if sink is not None:
+ attn_weight = numpy.concatenate([attn_weight, sink], axis=-1)
+ attn_weight = Softmax(attn_weight, axis=-1)
+ if sink is not None:
+ attn_weight = attn_weight[..., :-1]
+ return MatMul(attn_weight, value)
**Attributes**
@@ -64,6 +68,11 @@ omitting training-related parameter.
* **5**: ``scale`` a scalar or single element 1D tensor of type *T*, an alternative scale factor instead of 1/sqrt(query.shape[-1]) used by default in the pseudo-code above. **Optional.**
+* **6**: ``sink`` a tensor of type *T* and shape ``[N, ..., 1]`` numpy-broadcastable to the batch dimensions and with the same rank as ``query``. The last dimension is expected to be equal 1 for concatenation. **Optional.**
+
+.. note::
+
+ The sink input is available since 2025.4 OpenVINO release.
**Outputs**
@@ -268,3 +277,60 @@ Other batch dimensions ``...`` are optional.
</port>
</output>
</layer>
+
+
+*Example 6: With sink input*
+
+.. code-block:: xml
+ :force:
+
+ <layer id="286" name="aten::scaled_dot_product_attention_0" type="ScaledDotProductAttention" version="opset13">
+ <data causal="false" />
+ <input>
+ <!-- Multiple batch dimensions: N1 = 1, N2 = 2, N3 = 3-->
+ <port id="0" precision="FP32"> <!-- query -->
+ <dim>1</dim> <!-- N1 -->
+ <dim>2</dim> <!-- N2 -->
+ <dim>3</dim> <!-- N3 -->
+ <dim>-1</dim> <!-- L -->
+ <dim>80</dim> <!-- E -->
+ </port>
+ <port id="1" precision="FP32"> <!-- key -->
+ <dim>1</dim> <!-- N1 -->
+ <dim>2</dim> <!-- N2 -->
+ <dim>3</dim> <!-- N3 -->
+ <dim>-1</dim> <!-- S -->
+ <dim>80</dim> <!-- E -->
+ </port>
+ <port id="2" precision="FP32"> <!-- value -->
+ <dim>1</dim> <!-- N1 -->
+ <dim>2</dim> <!-- N2 -->
+ <dim>3</dim> <!-- N3 -->
+ <dim>-1</dim> <!-- S -->
+ <dim>80</dim> <!-- Ev -->
+ </port>
+ <port id="3" precision="FP32"> <!-- attention_mask -->
+ <dim>1</dim> <!-- N1 -->
+ <dim>2</dim> <!-- N2 -->
+ <dim>3</dim> <!-- N3 -->
+ <dim>-1</dim> <!-- L -->
+ <dim>-1</dim> <!-- S -->
+ </port>
+ <port id="4" precision="FP32"> <!-- sink -->
+ <dim>1</dim> <!-- N1 -->
+ <dim>2</dim> <!-- N2 -->
+ <dim>3</dim> <!-- N3 -->
+ <dim>1</dim> <!-- 1 -->
+ <dim>1</dim> <!-- 1 for concatenation -->
+ </port>
+ </input>
+ <output>
+ <port id="5" precision="FP32">
+ <dim>1</dim> <!-- N1 -->
+ <dim>2</dim> <!-- N2 -->
+ <dim>3</dim> <!-- N3 -->
+ <dim>-1</dim> <!-- L -->
+ <dim>80</dim> <!-- Ev -->
+ </port>
+ </output>
+ </layer>
\ No newline at end of file
diff --git a/src/core/include/openvino/op/scaled_dot_product_attention.hpp b/src/core/include/openvino/op/scaled_dot_product_attention.hpp
index 8f81f161f5a..42ec8d5879a 100644
--- a/src/core/include/openvino/op/scaled_dot_product_attention.hpp
+++ b/src/core/include/openvino/op/scaled_dot_product_attention.hpp
@@ -24,6 +24,14 @@ public:
ScaledDotProductAttention(const OutputVector& inputs, bool causal);
+ ScaledDotProductAttention(const Output<Node>& query,
+ const Output<Node>& key,
+ const Output<Node>& value,
+ const Output<Node>& attn_mask,
+ const Output<Node>& scale,
+ const Output<Node>& sink,
+ bool causal);
+
ScaledDotProductAttention(const Output<Node>& query,
const Output<Node>& key,
const Output<Node>& value,
diff --git a/src/core/reference/include/openvino/reference/scaled_dot_product_attention.hpp b/src/core/reference/include/openvino/reference/scaled_dot_product_attention.hpp
index 203b19f064a..5ca3f633569 100644
--- a/src/core/reference/include/openvino/reference/scaled_dot_product_attention.hpp
+++ b/src/core/reference/include/openvino/reference/scaled_dot_product_attention.hpp
@@ -7,8 +7,10 @@
#include "openvino/core/shape.hpp"
#include "openvino/reference/add.hpp"
+#include "openvino/reference/concat.hpp"
#include "openvino/reference/matmul.hpp"
#include "openvino/reference/multiply.hpp"
+#include "openvino/reference/slice.hpp"
#include "openvino/reference/softmax.hpp"
namespace ov::reference {
namespace helpers {
@@ -41,6 +43,17 @@ std::vector<T> create_attention_mask_from_ov_boolean(const char* mask_bool, cons
return mask_data;
}
+
+void slice_last_dimension(const char* input, char* output, const Shape& input_shape, size_t element_size) {
+ std::vector<int64_t> start_indices(input_shape.size(), 0);
+ std::vector<int64_t> steps(input_shape.size(), 1);
+ Shape output_shape = input_shape;
+ output_shape.back() -= 1;
+ std::vector<int64_t> axes(input_shape.size());
+ std::iota(axes.begin(), axes.end(), 0);
+ ov::reference::slice(input, input_shape, output, output_shape, element_size, start_indices, steps, axes);
+}
+
} // namespace helpers
} // namespace ov::reference
@@ -52,12 +65,14 @@ void scaled_dot_product_attention(const T* query,
const T* value,
const TMask* mask,
const T* scale,
+ const T* sink,
T* output,
bool is_causal,
const Shape& query_shape,
const Shape& key_shape,
const Shape& value_shape,
const Shape& mask_shape,
+ const Shape& sink_shape,
const Shape& output_shape) {
static_assert(std::is_same_v<T, TMask> || std::is_same_v<TMask, char>,
"T and TMask must be either the same type, or the TMask must be char(ov::element::boolean)");
@@ -109,10 +124,52 @@ void scaled_dot_product_attention(const T* query,
ov::op::AutoBroadcastType::NUMPY);
}
+ auto gk_softmax_shape = qk_shape;
+ if (sink) {
+ OPENVINO_ASSERT(qk_shape.size() == sink_shape.size());
+ auto* sink_data_ptr = sink;
+ const auto broadcast_axes_size = qk_shape.size() - 1;
+ auto target_sink_shape = Shape(qk_shape.begin(), qk_shape.begin() + broadcast_axes_size);
+ std::vector<T> broadcasted_sink_data;
+ if (shape_size(target_sink_shape) != shape_size(sink_shape) && broadcast_axes_size > 0) {
+ std::vector<size_t> broadcast_axes(broadcast_axes_size);
+ std::iota(broadcast_axes.begin(), broadcast_axes.end(), 0);
+ broadcasted_sink_data.resize(shape_size(target_sink_shape));
+ broadcast(reinterpret_cast<const char*>(sink_data_ptr),
+ reinterpret_cast<char*>(broadcasted_sink_data.data()),
+ Shape(sink_shape.begin(), sink_shape.begin() + broadcast_axes_size),
+ target_sink_shape,
+ broadcast_axes,
+ sizeof(T));
+ sink_data_ptr = broadcasted_sink_data.data();
+ }
+ target_sink_shape.push_back(1);
+ gk_softmax_shape[gk_softmax_shape.size() - 1] += target_sink_shape.back();
+ std::vector<T> qk_data_with_sink(shape_size(gk_softmax_shape), 0);
+ ov::reference::concat(
+ {reinterpret_cast<const char*>(qk_data.data()), reinterpret_cast<const char*>(sink_data_ptr)},
+ reinterpret_cast<char*>(qk_data_with_sink.data()),
+ {qk_shape, target_sink_shape},
+ gk_softmax_shape,
+ qk_shape.size() - 1,
+ sizeof(T));
+ qk_data = qk_data_with_sink;
+ }
std::vector<T> qk_data_softmax(qk_data.size(), 0);
- ov::reference::softmax<T>(qk_data.data(), qk_data_softmax.data(), qk_shape, ov::AxisSet{qk_shape.size() - 1});
+ ov::reference::softmax<T>(qk_data.data(),
+ qk_data_softmax.data(),
+ gk_softmax_shape,
+ ov::AxisSet{gk_softmax_shape.size() - 1});
+
+ if (sink) {
+ std::vector<T> qk_data_sliced(qk_data.size(), 0);
+ ov::reference::helpers::slice_last_dimension(reinterpret_cast<const char*>(qk_data_softmax.data()),
+ reinterpret_cast<char*>(qk_data_sliced.data()),
+ gk_softmax_shape,
+ sizeof(T));
+ qk_data_softmax = qk_data_sliced;
+ }
ov::reference::matmul<T>(qk_data_softmax.data(), value, output, qk_shape, value_shape, output_shape, false, false);
}
-
} // namespace reference
} // namespace ov
\ No newline at end of file
diff --git a/src/core/shape_inference/include/scaled_dot_product_attention_shape_inference.hpp b/src/core/shape_inference/include/scaled_dot_product_attention_shape_inference.hpp
index 3827a8898a6..cdeca759c65 100644
--- a/src/core/shape_inference/include/scaled_dot_product_attention_shape_inference.hpp
+++ b/src/core/shape_inference/include/scaled_dot_product_attention_shape_inference.hpp
@@ -18,7 +18,8 @@ std::vector<TRShape> shape_infer(const ScaledDotProductAttention* op,
const auto& inputs_count = input_shapes.size();
const auto& has_attention_mask_input = inputs_count >= 4;
const auto& has_scale_input = inputs_count == 5;
- NODE_VALIDATION_CHECK(op, inputs_count == 3 || has_attention_mask_input || has_scale_input);
+ const auto& has_sink_input = inputs_count == 6;
+ NODE_VALIDATION_CHECK(op, inputs_count == 3 || has_attention_mask_input || has_scale_input || has_sink_input);
DimType e_dim{};
DimType l_dim{};
DimType s_dim{};
@@ -104,6 +105,27 @@ std::vector<TRShape> shape_infer(const ScaledDotProductAttention* op,
}
}
+ if (has_sink_input) {
+ const auto& sink_shape = input_shapes[5];
+ const auto& sink_rank = sink_shape.rank();
+ const auto& query_shape = input_shapes[0];
+ const auto& query_rank = query_shape.rank();
+ if (sink_rank.is_static() && query_rank.is_static()) {
+ const bool sink_rank_correctness = sink_rank.get_length() == query_rank.get_length();
+ NODE_SHAPE_INFER_CHECK(op,
+ input_shapes,
+ sink_rank_correctness,
+ "The rank of sink input shape must be equal to the query input rank.");
+ auto sink_broadcast_dims = TRShape(std::vector<DimType>(sink_shape.begin(), sink_shape.end() - 1));
+ const bool sink_shape_correctness =
+ TRShape::broadcast_merge_into(sink_broadcast_dims,
+ TRShape(std::vector<DimType>(query_shape.begin(), query_shape.end() - 1)),
+ AutoBroadcastType::NUMPY) &&
+ sink_shape[sink_rank.get_length() - 1].compatible(1);
+ NODE_SHAPE_INFER_CHECK(op, input_shapes, sink_shape_correctness, "Sink input has not compatible shape.");
+ }
+ }
+
if (n_dims.rank().is_static()) {
n_dims.push_back(l_dim);
n_dims.push_back(ev_dim);
diff --git a/src/core/src/op/scaled_dot_product_attention.cpp b/src/core/src/op/scaled_dot_product_attention.cpp
index d265594191d..3e418128c76 100644
--- a/src/core/src/op/scaled_dot_product_attention.cpp
+++ b/src/core/src/op/scaled_dot_product_attention.cpp
@@ -24,6 +24,15 @@ op::v13::ScaledDotProductAttention::ScaledDotProductAttention(const Output<Node>
bool causal)
: ScaledDotProductAttention({query, key, value, attn_mask, scale}, causal) {}
+op::v13::ScaledDotProductAttention::ScaledDotProductAttention(const Output<Node>& query,
+ const Output<Node>& key,
+ const Output<Node>& value,
+ const Output<Node>& attn_mask,
+ const Output<Node>& scale,
+ const Output<Node>& sink,
+ bool causal)
+ : ScaledDotProductAttention({query, key, value, attn_mask, scale, sink}, causal) {}
+
op::v13::ScaledDotProductAttention::ScaledDotProductAttention(const Output<Node>& query,
const Output<Node>& key,
const Output<Node>& value,
diff --git a/src/core/tests/type_prop/scaled_dot_product_attention.cpp b/src/core/tests/type_prop/scaled_dot_product_attention.cpp
index a81911f51e1..677e42c3fef 100644
--- a/src/core/tests/type_prop/scaled_dot_product_attention.cpp
+++ b/src/core/tests/type_prop/scaled_dot_product_attention.cpp
@@ -248,6 +248,22 @@ TEST(type_prop, scaled_dot_product_attention_infer_5_dynamic_attn_partial) {
EXPECT_EQ(op->get_output_partial_shape(0), (dynamic));
}
+TEST(type_prop, scaled_dot_product_attention_infer_6_dynamic) {
+ const auto dynamic = PartialShape::dynamic();
+ const auto query = std::make_shared<op::v0::Parameter>(element::f32, dynamic);
+ const auto key = std::make_shared<op::v0::Parameter>(element::f32, dynamic);
+ const auto value = std::make_shared<op::v0::Parameter>(element::f32, dynamic);
+ const auto attention_mask = std::make_shared<op::v0::Parameter>(element::f32, dynamic);
+ const auto scale = std::make_shared<op::v0::Parameter>(element::f32, dynamic);
+ const auto sink = std::make_shared<op::v0::Parameter>(element::f32, dynamic);
+ auto causal = false;
+
+ const auto op =
+ std::make_shared<op::v13::ScaledDotProductAttention>(query, key, value, attention_mask, scale, sink, causal);
+ EXPECT_EQ(op->get_output_element_type(0), element::f32);
+ EXPECT_EQ(op->get_output_partial_shape(0), (dynamic));
+}
+
TEST(type_prop, scaled_dot_product_attention_mixed_shape_infer_4_inputs) {
const auto query = std::make_shared<op::v0::Parameter>(element::dynamic, PartialShape{{1, 4}, 4, {2, 5}, 4});
const auto key = std::make_shared<op::v0::Parameter>(element::f64, PartialShape{{2, 8}, {1, 4}, 5, 4});
@@ -421,3 +437,103 @@ TEST(type_prop, scaled_dot_product_unsuported_attention_type) {
AssertFailure,
testing::HasSubstr("The element type of attention_mask must be either floating-point or boolean."));
}
+
+TEST(type_prop, scaled_dot_product_attention_sink_input_correct_shape) {
+ const auto query = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{2, 3, 4});
+ const auto key = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{2, 5, 4});
+ const auto value = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{2, 5, 6});
+ const auto attention_mask = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{3, 5});
+ const auto scale = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{});
+ const auto sink = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{2, 3, 1});
+ auto causal = false;
+
+ const auto op =
+ std::make_shared<op::v13::ScaledDotProductAttention>(query, key, value, attention_mask, scale, sink, causal);
+ EXPECT_EQ(op->get_output_element_type(0), element::f32);
+ EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{2, 3, 6}));
+}
+
+TEST(type_prop, scaled_dot_product_attention_sink_input_correct_dynamic_shape_4d) {
+ const auto query = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{2, -1, -1, 4});
+ const auto key = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{-1, -1, -1, -1});
+ const auto value = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{-1, -1, -1, -1});
+ const auto attention_mask = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{-1, -1});
+ const auto scale = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{});
+ const auto sink = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{-1, -1, 3, -1});
+ auto causal = true;
+
+ const auto op =
+ std::make_shared<op::v13::ScaledDotProductAttention>(query, key, value, attention_mask, scale, sink, causal);
+ EXPECT_EQ(op->get_output_element_type(0), element::f32);
+ EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{2, -1, -1, -1}));
+}
+
+TEST(type_prop, scaled_dot_product_attention_sink_input_correct_shape_4d_causal_true) {
+ const auto query = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{2, 4, 3, 4});
+ const auto key = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{2, 4, 5, 4});
+ const auto value = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{2, 4, 5, 6});
+ const auto attention_mask = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{});
+ const auto scale = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{});
+ const auto sink = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{2, 4, 3, 1});
+ auto causal = true;
+
+ const auto op =
+ std::make_shared<op::v13::ScaledDotProductAttention>(query, key, value, attention_mask, scale, sink, causal);
+ EXPECT_EQ(op->get_output_element_type(0), element::f32);
+ EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{2, 4, 3, 6}));
+}
+
+TEST(type_prop, scaled_dot_product_attention_sink_input_broadcast_shape) {
+ const auto query = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{2, 3, 4});
+ const auto key = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{2, 5, 4});
+ const auto value = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{2, 5, 6});
+ const auto attention_mask = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{3, 5});
+ const auto scale = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{});
+ const auto sink = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{1, 3, 1});
+ auto causal = false;
+
+ const auto op =
+ std::make_shared<op::v13::ScaledDotProductAttention>(query, key, value, attention_mask, scale, sink, causal);
+ EXPECT_EQ(op->get_output_element_type(0), element::f32);
+ EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{2, 3, 6}));
+}
+
+TEST(type_prop, scaled_dot_product_attention_sink_input_wrong_rank) {
+ const auto query = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{2, 3, 4});
+ const auto key = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{2, 5, 4});
+ const auto value = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{2, 5, 6});
+ const auto attention_mask = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{3, 5});
+ const auto scale = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{});
+ const auto sink = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{2, 3, 4, 1});
+ auto causal = false;
+
+ OV_EXPECT_THROW(auto op = std::make_shared<op::v13::ScaledDotProductAttention>(query,
+ key,
+ value,
+ attention_mask,
+ scale,
+ sink,
+ causal),
+ AssertFailure,
+ testing::HasSubstr("The rank of sink input shape must be equal to the query input rank."));
+}
+
+TEST(type_prop, scaled_dot_product_attention_sink_input_wrong_last_dim) {
+ const auto query = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{2, 3, 4});
+ const auto key = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{2, 5, 4});
+ const auto value = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{2, 5, 6});
+ const auto attention_mask = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{3, 5});
+ const auto scale = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{});
+ const auto sink = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{2, 3, 2});
+ auto causal = false;
+
+ OV_EXPECT_THROW(auto op = std::make_shared<op::v13::ScaledDotProductAttention>(query,
+ key,
+ value,
+ attention_mask,
+ scale,
+ sink,
+ causal),
+ AssertFailure,
+ testing::HasSubstr("Sink input has not compatible shape."));
+}
diff --git a/src/plugins/intel_cpu/tests/unit/shape_inference_test/scaled_dot_product_attention_shape_inference_test.cpp b/src/plugins/intel_cpu/tests/unit/shape_inference_test/scaled_dot_product_attention_shape_inference_test.cpp
index 6d2ead9a479..cfadf1d0196 100644
--- a/src/plugins/intel_cpu/tests/unit/shape_inference_test/scaled_dot_product_attention_shape_inference_test.cpp
+++ b/src/plugins/intel_cpu/tests/unit/shape_inference_test/scaled_dot_product_attention_shape_inference_test.cpp
@@ -102,3 +102,58 @@ TEST_F(ScaledDotProductAttentionV13StaticShapeInferenceTest, attention_S_broadca
EXPECT_EQ(output_shapes.size(), 1);
EXPECT_EQ(output_shapes.front(), StaticShape({2, 8, 16, 48}));
}
+
+TEST_F(ScaledDotProductAttentionV13StaticShapeInferenceTest, sink_input_correct_shape_casual_true) {
+ const auto query = std::make_shared<opset13::Parameter>(element::f32, PartialShape::dynamic());
+ const auto key = std::make_shared<opset13::Parameter>(element::f32, PartialShape::dynamic());
+ const auto value = std::make_shared<opset13::Parameter>(element::f32, PartialShape::dynamic());
+ const auto attention_mask = std::make_shared<opset13::Parameter>(element::f32, PartialShape::dynamic());
+ const auto scale = std::make_shared<opset13::Parameter>(element::f32, PartialShape::dynamic());
+ auto causal = true;
+
+ op = make_op(query, key, value, attention_mask, scale, causal);
+ input_shapes = StaticShapeVector{{2, 3, 4}, {2, 5, 4}, {2, 5, 6}, {}, {}, {2, 3, 1}};
+ output_shapes = shape_inference(op.get(), input_shapes);
+ EXPECT_EQ(output_shapes.size(), 1);
+ EXPECT_EQ(output_shapes.front(), StaticShape({2, 3, 6}));
+}
+
+TEST_F(ScaledDotProductAttentionV13StaticShapeInferenceTest, sink_input_correct_shape) {
+ op = make_op();
+ input_shapes = StaticShapeVector{{2, 3, 4}, {2, 5, 4}, {2, 5, 6}, {1, 3, 5}, {}, {2, 3, 1}};
+ output_shapes = shape_inference(op.get(), input_shapes);
+ EXPECT_EQ(output_shapes.size(), 1);
+ EXPECT_EQ(output_shapes.front(), StaticShape({2, 3, 6}));
+}
+
+TEST_F(ScaledDotProductAttentionV13StaticShapeInferenceTest, sink_input_broadcast_shape) {
+ op = make_op();
+ input_shapes = StaticShapeVector{{2, 3, 4}, {2, 5, 4}, {2, 5, 6}, {1, 3, 5}, {}, {1, 3, 1}};
+ output_shapes = shape_inference(op.get(), input_shapes);
+ EXPECT_EQ(output_shapes.size(), 1);
+ EXPECT_EQ(output_shapes.front(), StaticShape({2, 3, 6}));
+}
+
+TEST_F(ScaledDotProductAttentionV13StaticShapeInferenceTest, sink_input_wrong_rank) {
+ op = make_op();
+ input_shapes = StaticShapeVector{{2, 3, 4}, {2, 5, 4}, {2, 5, 6}, {1, 3, 5}, {}, {2, 3}};
+ OV_EXPECT_THROW(shape_inference(op.get(), input_shapes),
+ ov::AssertFailure,
+ testing::HasSubstr("The rank of sink input shape must be equal to the query input rank."));
+}
+
+TEST_F(ScaledDotProductAttentionV13StaticShapeInferenceTest, sink_input_wrong_last_dim) {
+ op = make_op();
+ input_shapes = StaticShapeVector{{2, 3, 4}, {2, 5, 4}, {2, 5, 6}, {1, 3, 5}, {}, {2, 3, 2}};
+ OV_EXPECT_THROW(shape_inference(op.get(), input_shapes),
+ ov::AssertFailure,
+ testing::HasSubstr("Sink input has not compatible shape."));
+}
+
+TEST_F(ScaledDotProductAttentionV13StaticShapeInferenceTest, sink_input_wrong_first_dim) {
+ op = make_op();
+ input_shapes = StaticShapeVector{{2, 3, 4}, {2, 5, 4}, {2, 5, 6}, {1, 3, 5}, {}, {4, 3, 1}};
+ OV_EXPECT_THROW(shape_inference(op.get(), input_shapes),
+ ov::AssertFailure,
+ testing::HasSubstr("Sink input has not compatible shape."));
+}
diff --git a/src/plugins/template/backend/ops/scaled_dot_product_attention.cpp b/src/plugins/template/backend/ops/scaled_dot_product_attention.cpp
index d5ee992260b..4d870217681 100644
--- a/src/plugins/template/backend/ops/scaled_dot_product_attention.cpp
+++ b/src/plugins/template/backend/ops/scaled_dot_product_attention.cpp
@@ -15,9 +15,11 @@ bool evaluate(const std::shared_ptr<ov::op::v13::ScaledDotProductAttention>& op,
const ov::TensorVector& inputs) {
using T = typename ov::element_type_traits<ET>::value_type;
using TMask = typename ov::element_type_traits<ETMask>::value_type;
- const TMask* mask = inputs.size() == 4 ? inputs[3].data<const TMask>() : nullptr;
- const T* scale = inputs.size() == 5 ? inputs[4].data<const T>() : nullptr;
- auto mask_shape = inputs.size() == 4 ? inputs[3].get_shape() : ov::Shape{};
+ const TMask* mask = inputs.size() >= 4 ? inputs[3].data<const TMask>() : nullptr;
+ const T* scale = inputs.size() >= 5 ? inputs[4].data<const T>() : nullptr;
+ auto mask_shape = inputs.size() >= 4 ? inputs[3].get_shape() : ov::Shape{};
+ const T* sink = inputs.size() >= 6 ? inputs[5].data<const T>() : nullptr;
+ auto sink_shape = inputs.size() >= 6 ? inputs[5].get_shape() : ov::Shape{};
// Hack below is needed to support dynamic shapes in the reference implementation...
const auto input_shapes = ov::util::get_tensors_partial_shapes(inputs);
@@ -31,12 +33,14 @@ bool evaluate(const std::shared_ptr<ov::op::v13::ScaledDotProductAttention>& op,
inputs[2].data<const T>(),
mask,
scale,
+ sink,
outputs[0].data<T>(),
op->get_causal(),
inputs[0].get_shape(),
inputs[1].get_shape(),
inputs[2].get_shape(),
mask_shape,
+ sink_shape,
outputs[0].get_shape());
return true;
diff --git a/src/plugins/template/tests/functional/op_reference/scaled_dot_product_attention.cpp b/src/plugins/template/tests/functional/op_reference/scaled_dot_product_attention.cpp
index ddace1f2820..f958c5d8434 100644
--- a/src/plugins/template/tests/functional/op_reference/scaled_dot_product_attention.cpp
+++ b/src/plugins/template/tests/functional/op_reference/scaled_dot_product_attention.cpp
@@ -7,6 +7,7 @@
#include <gtest/gtest.h>
#include "base_reference_test.hpp"
+#include "openvino/op/constant.hpp"
#include "openvino/op/parameter.hpp"
using namespace reference_tests;
@@ -27,6 +28,9 @@ struct SDPAParams {
reference_tests::Tensor vData;
reference_tests::Tensor attentionMaskData;
reference_tests::Tensor expectedOutputData;
+ std::vector<float> scaleValue;
+ PartialShape sinkShape;
+ reference_tests::Tensor sinkData;
};
template <typename T, typename TMask>
@@ -41,7 +45,10 @@ SDPAParams PrepareTestCaseParams(const PartialShape& qShape,
const std::vector<T>& vData,
const std::vector<TMask>& attentionMaskData,
const std::vector<T>& expectedOutputData,
- const std::string& description) {
+ const std::string& description,
+ const std::vector<float>& scaleValue = {},
+ const PartialShape& sinkShape = {0},
+ const std::vector<T>& sinkData = {}) {
SDPAParams ret;
const auto elementType = element::from<T>();
@@ -58,6 +65,11 @@ SDPAParams PrepareTestCaseParams(const PartialShape& qShape,
ret.attentionMaskData =
reference_tests::Tensor(element::from<TMask>(), attentionMaskShape.to_shape(), attentionMaskData);
ret.expectedOutputData = reference_tests::Tensor(elementType, outputShape.to_shape(), expectedOutputData);
+ ret.scaleValue = scaleValue;
+ ret.sinkShape = sinkShape;
+ if (!sinkData.empty()) {
+ ret.sinkData = reference_tests::Tensor(elementType, sinkShape.to_shape(), sinkData);
+ }
return ret;
}
@@ -70,6 +82,9 @@ public:
if (params.attentionMaskShape.size() != 0) {
inputData.push_back(params.attentionMaskData.data);
}
+ if (shape_size(params.sinkShape.get_shape()) != 0) {
+ inputData.push_back(params.sinkData.data);
+ }
refOutData = {params.expectedOutputData.data};
}
@@ -83,8 +98,13 @@ public:
result << "_attentionMaskShape=" << param.attentionMaskShape;
result << "_outputShape=" << param.outputShape;
result << "_isCausal=" << param.isCausal;
+ if (!param.scaleValue.empty()) {
+ result << "_scale=" << param.scaleValue[0];
+ }
+ if (param.sinkData.data) {
+ result << "_sinkShape=" << param.sinkShape;
+ }
result << "_=" << param.testcaseName;
-
return result.str();
}
@@ -103,6 +123,25 @@ private:
params.attentionMaskShape);
inputs.push_back(attentionMask);
paramsVec.push_back(attentionMask);
+ } else {
+ const auto attentionMask = std::make_shared<ov::op::v0::Constant>(params.qData.data.get_element_type(),
+ ov::Shape{},
+ std::vector<float>{0});
+ inputs.push_back(attentionMask);
+ }
+
+ if (!params.scaleValue.empty()) {
+ const auto scale = std::make_shared<ov::op::v0::Constant>(params.qData.data.get_element_type(),
+ ov::Shape{},
+ params.scaleValue[0]);
+ inputs.push_back(scale);
+ }
+
+ if (shape_size(params.sinkShape.get_shape()) != 0) {
+ const auto sink =
+ std::make_shared<op::v0::Parameter>(params.sinkData.data.get_element_type(), params.sinkShape);
+ inputs.push_back(sink);
+ paramsVec.push_back(sink);
}
const auto op = std::make_shared<op::v13::ScaledDotProductAttention>(inputs, params.isCausal);
@@ -172,4 +211,246 @@ INSTANTIATE_TEST_SUITE_P(smoke_SDPA_With_Hardcoded_Refs,
ReferenceSDPATest,
testing::ValuesIn(generateCombinedParams()),
ReferenceSDPATest::getTestCaseName);
+
+template <element::Type_t ET>
+std::vector<SDPAParams> generateParamsWithSink() {
+ using T = typename element_type_traits<ET>::value_type;
+ std::vector<SDPAParams> params;
+
+ PartialShape q_shape{2, 3, 4, 5};
+ PartialShape k_shape{2, 1, 4, 5};
+ PartialShape v_shape{2, 1, 4, 5};
+ PartialShape output_shape{2, 3, 4, 5};
+
+ std::vector<T> q_data = {
+ -1.1258398294448853, -1.152360200881958, -0.2505785822868347, -0.4338788092136383, 0.8487103581428528,
+ 0.946298360824585, -0.843676745891571, -0.6135830879211426, 0.03159274160861969, -0.4926769733428955,
+ -1.5311843156814575, -1.2341350317001343, 1.8197252750396729, -0.5515286922454834, -0.5692480802536011,
+ -1.881689190864563, -0.049727022647857666, -1.0449786186218262, -0.9565008282661438, 0.03353185951709747,
+ 0.6920091509819031, -0.31601276993751526, -2.1152193546295166, 0.32227492332458496, -1.2633347511291504,
+ 0.2484147548675537, 0.4396958351135254, 0.11241118609905243, 0.6407923698425293, 0.441156268119812,
+ 0.9199714064598083, 1.1108161211013794, 1.2898740768432617, -1.4781739711761475, 2.567232847213745,
+ 0.7100865840911865, 1.6458669900894165, -1.3601689338684082, 0.34456542134284973, 0.5198677182197571,
+ 0.34998318552970886, 0.30813392996788025, 0.11984150856733322, 1.237657904624939, 1.1167771816253662,
+ -0.10230965167284012, 0.7924439907073975, -0.28966769576072693, 0.05250748619437218, 0.5228604674339294,
+ -0.4731197953224182, 0.3355507552623749, -1.6293259859085083, -0.54974365234375, -0.47983425855636597,
+ -2.6133224964141846, -1.6964744329452515, -0.22824178636074066, 0.2799549996852875, -0.7015236020088196,
+ -0.2472781538963318, -1.3526537418365479, -1.6959311962127686, 0.5666506290435791, 0.7935083508491516,
+ 2.3022053241729736, -1.4688938856124878, -1.586688756942749, -0.6730899214744568, 0.8728312253952026,
+ -0.4996815323829651, -1.0669803619384766, 1.114939570426941, -0.14067143201828003, 0.8057535886764526,
+ 1.0366867780685425, -0.6036701202392578, -1.2787652015686035, 0.0929502323269844, -0.6660997271537781,
+ 0.5988394618034363, -1.5550950765609741, -0.3413603901863098, 1.85300612449646, 0.750189483165741,
+ 1.0553574562072754, 0.17784371972084045, -0.23033547401428223, -0.3917543888092041, 0.5432947278022766,
+ -0.09334823489189148, 0.6870502233505249, -0.8383153676986694, 0.0008918217499740422, 0.8418940901756287,
+ 0.6080471873283386, -0.7300198674201965, 1.3750379085540771, 0.659631073474884, 0.4765571057796478,
+ -0.5854975581169128, -0.1733967512845993, 0.18347793817520142, 1.3893661499023438, 1.586334228515625,
+ -0.3951575458049774, -0.4462171792984009, 0.7440207004547119, 1.5209795236587524, 3.4105026721954346,
+ -0.4000341594219208, 1.0394619703292847, 0.3581531047821045, -0.24600094556808472, 2.302516460418701,
+ -1.0163074731826782, 0.18036697804927826, 0.10833186656236649, -0.7548232674598694, 0.24431852996349335};
+ std::vector<T> k_data = {
+ 1.1403506994247437, -0.08988206833600998, 0.7297962307929993, -1.8453190326690674, -0.025019939988851547,
+ -1.1427778005599976, 0.03758539631962776, 2.6962764263153076, 1.235763669013977, 0.5428298115730286,
+ -1.6115024089813232, -0.47944778203964233, -0.14335104823112488, -0.3172946274280548, -0.06614404916763306,
+ 1.5735383033752441, 0.7814299464225769, -1.0786579847335815, -0.720909833908081, 1.4707926511764526,
+ 1.3693809509277344, 2.6570231914520264, 0.9851194024085999, 0.37718191742897034, 1.101234793663025,
+ 0.5255303382873535, -0.8293668627738953, -1.4072566032409668, 1.6268466711044312, 0.1722732037305832,
+ -0.3583550751209259, -1.5615617036819458, -0.3546432852745056, 1.0810725688934326, 0.13147805631160736,
+ 0.2756350040435791, 0.6667810678482056, -0.9943896532058716, -1.189363956451416, -1.1959494352340698};
+
+ std::vector<T> v_data = {
+ -0.5596300959587097, 0.5334718227386475, 0.40688660740852356, 0.3945865333080292, 0.1715109646320343,
+ 0.392026424407959, 0.5945261120796204, 0.6622740626335144, -1.2063024044036865, 0.6074396967887878,
+ -1.2536547183990479, 0.9868361353874207, -0.494655042886734, -1.2830430269241333, -0.6537995934486389,
+ 0.531403660774231, 1.2350903749465942, -1.1070388555526733, -1.7173612117767334, 1.534561038017273,
+ 0.876044750213623, -0.28708741068840027, 1.0216400623321533, -0.07439491897821426, -1.0922236442565918,
+ -0.547156810760498, 1.1710889339447021, 0.0974961370229721, 0.9633745551109314, 0.8403232097625732,
+ 1.7198240756988525, -0.9609553813934326, -0.6375024914741516, 0.07472498714923859, 0.5599694848060608,
+ -0.003206211142241955, -1.6034189462661743, 0.058098483830690384, -0.6302464604377747, 0.7466416358947754};
+
+ std::vector<T> out_data_t_no_sink_scale_default = {
+ -0.5596300959587097, 0.5334718227386475, 0.40688660740852356, 0.3945865333080292, 0.1715109646320343,
+ -0.4044354557991028, 0.5434284210205078, 0.4485347867012024, 0.1335161179304123, 0.24260151386260986,
+ -0.04295007884502411, 0.6755574941635132, 0.38903844356536865, -1.0970888137817383, 0.29717087745666504,
+ -0.9095513820648193, 0.9409497976303101, -0.3887394964694977, -1.161990761756897, -0.28604379296302795,
+ -0.5596300959587097, 0.5334718227386475, 0.40688660740852356, 0.3945865333080292, 0.1715109646320343,
+ 0.11010648310184479, 0.5764393210411072, 0.5866177678108215, -0.7320530414581299, 0.478299617767334,
+ -0.3641112446784973, 0.5661339163780212, 0.4304530918598175, -0.04928196594119072, 0.24057039618492126,
+ 0.3524087071418762, 1.1537384986877441, -0.918759286403656, -1.5207775831222534, 1.2959774732589722,
+ -0.5596300959587097, 0.5334718227386475, 0.40688660740852356, 0.3945865333080292, 0.1715109646320343,
+ -0.06002488732337952, 0.5655243992805481, 0.5409611463546753, -0.44585585594177246, 0.4003669321537018,
+ -0.9681406021118164, 0.8334401845932007, -0.17134259641170502, -0.7821053862571716, -0.3480212390422821,
+ -0.8686208128929138, 0.8932577967643738, -0.2254813015460968, -1.2397266626358032, -0.35004693269729614,
+ 0.876044750213623, -0.28708741068840027, 1.0216400623321533, -0.07439491897821426, -1.0922236442565918,
+ -0.4266248047351837, 1.0475949048995972, 0.1757626086473465, 0.8754850625991821, 0.6766543388366699,
+ 1.1049975156784058, -0.40238574147224426, -0.21055714786052704, 0.23690593242645264, 0.3474586308002472,
+ 0.1369362473487854, -0.13229122757911682, -0.01725679822266102, 0.27280086278915405, 0.662578821182251,
+ 0.876044750213623, -0.28708741068840027, 1.0216400623321533, -0.07439491897821426, -1.0922236442565918,
+ 0.4569539725780487, 0.14230245351791382, 0.7495070099830627, 0.2311975359916687, -0.5231457352638245,
+ 0.5743083953857422, 0.05502946674823761, 0.4440821409225464, 0.2777979075908661, -0.1986960619688034,
+ 0.8122739791870117, -0.27402305603027344, 0.1377803087234497, 0.1898355633020401, 0.07055333256721497,
+ 0.876044750213623, -0.28708741068840027, 1.0216400623321533, -0.07439491897821426, -1.0922236442565918,
+ 0.3447447121143341, 0.2572692036628723, 0.6766449213027954, 0.31301823258399963, -0.37077826261520386,
+ 0.8486983776092529, -0.24997326731681824, 0.8985856771469116, -0.017985841259360313, -0.9216011762619019,
+ 0.5427770614624023, -0.7654033899307251, 0.11973342299461365, -0.11444665491580963, 0.2868369519710541};
+
+ params.push_back(PrepareTestCaseParams<T, char>(q_shape,
+ k_shape,
+ v_shape,
+ Shape{1},
+ output_shape,
+ true,
+ q_data,
+ k_data,
+ v_data,
+ {0},
+ out_data_t_no_sink_scale_default,
+ "with_no_sink"));
+
+ PartialShape sink_shape{2, 3, 4, 1};
+ std::vector<T> sink_data = {1.989909291267395, 1.989909291267395, 1.989909291267395, 1.989909291267395,
+ 0.7182523012161255, 0.7182523012161255, 0.7182523012161255, 0.7182523012161255,
+ -0.4966665208339691, -0.4966665208339691, -0.4966665208339691, -0.4966665208339691,
+ 1.3100289106369019, 1.3100289106369019, 1.3100289106369019, 1.3100289106369019,
+ 0.39555686712265015, 0.39555686712265015, 0.39555686712265015, 0.39555686712265015,
+ 0.08947940915822983, 0.08947940915822983, 0.08947940915822983, 0.08947940915822983};
+
+ std::vector<T> out_data_t_with_sink_scale_one = {
+ -0.03965197131037712, 0.03779855743050575, 0.028829501941800117, 0.027957992628216743,
+ 0.012152220122516155, -0.11443307250738144, 0.11428776383399963, 0.08829117566347122,
+ 0.07568749785423279, 0.03898078203201294, 0.26677078008651733, 0.605960488319397,
+ 0.5677525401115417, -1.1716898679733276, 0.506074845790863, -1.0069886445999146,
+ 0.8096990585327148, -0.4007461667060852, -1.0468798875808716, -0.5102735757827759,
+ -0.06627094000577927, 0.06317330151796341, 0.04818318039178848, 0.046726614236831665,
+ 0.020310189574956894, 0.16821038722991943, 0.36302635073661804, 0.3897629678249359,
+ -0.6212533712387085, 0.34174299240112305, -0.48022228479385376, 0.5281412601470947,
+ 0.4162833094596863, 0.26764488220214844, 0.19879533350467682, 0.5100196599960327,
+ 1.2007501125335693, -1.071186900138855, -1.6644197702407837, 1.4861838817596436,
+ -0.11463763564825058, 0.10927923023700714, 0.0833488404750824, 0.08082922548055649,
+ 0.035133227705955505, -0.021249890327453613, 0.3913222551345825, 0.37849581241607666,
+ -0.3413900136947632, 0.285353422164917, -0.9711475372314453, 0.7777552008628845,
+ -0.3053199350833893, -0.8790218234062195, -0.4489268660545349, -1.1495906114578247,
+ 0.9593806266784668, -0.4228992164134979, -1.2732564210891724, -0.5751422047615051,
+ 0.002577104140073061, -0.0008445392595604062, 0.003005409147590399, -0.00021885121532250196,
+ -0.0032130484469234943, -0.4957696497440338, 1.068182110786438, 0.09358927607536316,
+ 0.8794413208961487, 0.7625315189361572, 0.8379843235015869, -0.426442950963974,
+ -0.282054603099823, 0.0756443440914154, 0.28236064314842224, -0.15671619772911072,
+ 0.26120778918266296, 0.013841899111866951, 0.43579405546188354, 0.6869266033172607,
+ 0.0653177946805954, -0.021405203267931938, 0.07617336511611938, -0.0055468762293457985,
+ -0.08143606781959534, 0.6066479086875916, -0.09200847148895264, 0.7866788506507874,
+ 0.047215692698955536, -0.739319384098053, 0.5055353045463562, 0.012736570090055466,
+ 0.597989022731781, 0.1530308723449707, -0.45584386587142944, 0.8580659031867981,
+ -0.31098097562789917, 0.0922587513923645, 0.1278807520866394, -0.01665644720196724,
+ 0.6572203636169434, -0.21537677943706512, 0.766447901725769, -0.0558120533823967,
+ -0.8194006681442261, 0.5205270051956177, 0.05960403382778168, 0.7777613997459412,
+ 0.16860418021678925, -0.6122713088989258, 0.8689383268356323, -0.2839549481868744,
+ 1.01072096824646, -0.0722401961684227, -1.0794318914413452, 0.31849390268325806,
+ -0.7553979158401489, 0.06754793971776962, -0.21245919167995453, 0.2665559947490692};
+
+ params.push_back(PrepareTestCaseParams<T, char>(q_shape,
+ k_shape,
+ v_shape,
+ Shape{},
+ output_shape,
+ true,
+ q_data,
+ k_data,
+ v_data,
+ {0},
+ out_data_t_with_sink_scale_one,
+ "with_sink_scale_1.0",
+ {1.0f}, // scaleValue
+ sink_shape,
+ sink_data));
+
+ std::vector<T> out_data_t_with_sink_scale_custom = {
+ -0.06069273129105568, 0.05785582587122917, 0.04412746801972389, 0.04279350861907005,
+ 0.018600624054670334, -0.0470183789730072, 0.10387451946735382, 0.09196290373802185,
+ -0.023563656955957413, 0.05878644064068794, -0.12936662137508392, 0.3176364004611969,
+ 0.11998864263296127, -0.4186060428619385, 0.06529749184846878, -0.1961163580417633,
+ 0.3280660808086395, -0.094425730407238, -0.38547027111053467, 0.03979203850030899,
+ -0.1531520038843155, 0.14599336683750153, 0.11135123670101166, 0.10798511654138565,
+ 0.04693680629134178, 0.003588348627090454, 0.28682994842529297, 0.2813684642314911,
+ -0.2812879681587219, 0.217011958360672, -0.24685132503509521, 0.4304933249950409,
+ 0.24815379083156586, -0.25411680340766907, 0.13267168402671814, 0.02236872911453247,
+ 0.6783848404884338, -0.36514297127723694, -0.8167968392372131, 0.5701109170913696,
+ -0.2974308431148529, 0.28352829813957214, 0.21625110507011414, 0.2097138911485672,
+ 0.09115423262119293, -0.05503465235233307, 0.42477408051490784, 0.40427881479263306,
+ -0.3187658190727234, 0.29664403200149536, -0.6076429486274719, 0.6167400479316711,
+ -0.0010090619325637817, -0.5514510273933411, -0.1371295005083084, -0.5157628655433655,
+ 0.7448815107345581, -0.07199841737747192, -0.9987921118736267, -0.055561356246471405,
+ 0.08635417371988297, -0.028299007564783096, 0.10070591419935226, -0.007333314977586269,
+ -0.10766353458166122, -0.07884395867586136, 0.34500038623809814, 0.1447703242301941,
+ 0.3017638027667999, 0.1491926610469818, 0.37593814730644226, -0.08060011267662048,
+ -0.0032004714012145996, 0.1259659081697464, 0.0957479178905487, 0.19390913844108582,
+ -0.1818716675043106, 0.01571568101644516, 0.0961075946688652, 0.28955501317977905,
+ 0.26782938838005066, -0.0877700001001358, 0.3123416304588318, -0.0227444376796484,
+ -0.33392083644866943, 0.1913018524646759, 0.1910492181777954, 0.41129082441329956,
+ 0.2183394581079483, -0.1980481892824173, 0.4324178695678711, 0.018276840448379517,
+ 0.2048681378364563, 0.2158849984407425, -0.020930297672748566, 0.48571550846099854,
+ -0.2236638218164444, 0.10307496786117554, 0.11739172041416168, 0.11604028195142746,
+ 0.4704568088054657, -0.15417274832725525, 0.5486449599266052, -0.039951834827661514,
+ -0.5865499973297119, 0.18774694204330444, 0.2726062536239624, 0.46677061915397644,
+ 0.2929643988609314, -0.1807970106601715, 0.6146572828292847, -0.1194060891866684,
+ 0.4525294303894043, 0.10505322366952896, -0.3701184093952179, 0.40908947587013245,
+ -0.4417523741722107, 0.09781522303819656, -0.006620079278945923, 0.20164912939071655};
+
+ params.push_back(PrepareTestCaseParams<T, char>(q_shape,
+ k_shape,
+ v_shape,
+ Shape{},
+ output_shape,
+ true,
+ q_data,
+ k_data,
+ v_data,
+ {0},
+ out_data_t_with_sink_scale_custom,
+ "with_sink_scale_custom",
+ {0.2f}, // scaleValue
+ sink_shape,
+ sink_data));
+
+ std::vector<T> sink_data_to_broadcast = {1.989909291267395,
+ 0.7182523012161255,
+ -0.4966665208339691,
+ 1.3100289106369019,
+ 0.39555686712265015,
+ 0.08947940915822983};
+
+ PartialShape sink_shape_to_broadcast_4D{2, 3, 1, 1};
+ params.push_back(PrepareTestCaseParams<T, char>(q_shape,
+ k_shape,
+ v_shape,
+ Shape{},
+ output_shape,
+ true,
+ q_data,
+ k_data,
+ v_data,
+ {0},
+ out_data_t_with_sink_scale_custom,
+ "with_sink_broadcast",
+ {0.2f}, // scaleValue
+ sink_shape_to_broadcast_4D,
+ sink_data_to_broadcast));
+
+ return params;
+}
+
+std::vector<SDPAParams> generateCombinedParamsWithSink() {
+ const std::vector<std::vector<SDPAParams>> generatedParams{generateParamsWithSink<element::Type_t::f32>(),
+ generateParamsWithSink<element::Type_t::f16>(),
+ generateParamsWithSink<element::Type_t::f64>()};
+ std::vector<SDPAParams> combinedParams;
+
+ for (const auto& params : generatedParams) {
+ combinedParams.insert(combinedParams.end(), params.begin(), params.end());
+ }
+ return combinedParams;
+}
+
+INSTANTIATE_TEST_SUITE_P(smoke_SDPA_With_Sink,
+ ReferenceSDPATest,
+ testing::ValuesIn(generateCombinedParamsWithSink()),
+ ReferenceSDPATest::getTestCaseName);
} // namespace