Skip to content

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

[GPU] Fix GPU sdpa kernel to support sink input (#31915)

Taylor Yeonbok Lee5d101b74fea7
diff --git a/src/plugins/intel_gpu/include/intel_gpu/primitives/scaled_dot_product_attention.hpp b/src/plugins/intel_gpu/include/intel_gpu/primitives/scaled_dot_product_attention.hpp
index c95cf8bf18e..aa3592bad69 100644
--- a/src/plugins/intel_gpu/include/intel_gpu/primitives/scaled_dot_product_attention.hpp
+++ b/src/plugins/intel_gpu/include/intel_gpu/primitives/scaled_dot_product_attention.hpp
@@ -11,6 +11,18 @@ namespace cldnn {
struct scaled_dot_product_attention : public primitive_base<scaled_dot_product_attention> {
CLDNN_DECLARE_PRIMITIVE(scaled_dot_product_attention)
+ enum ScaledDotProductAttentionInputIdx {
+ QUERY = 0,
+ KEY = 1,
+ VALUE = 2,
+ ATTN_MASK = 3,
+ SCALE = 4,
+ SINK = 5,
+ KEY_SCALES = 6,
+ KEY_ZP = 7,
+ VALUE_SCALES = 8,
+ VALUE_ZP = 9
+ };
using QuantizationAttributes = ov::op::internal::DynamicQuantize::Attributes;
@@ -18,7 +30,7 @@ struct scaled_dot_product_attention : public primitive_base<scaled_dot_product_a
/// @brief Constructs scaled_dot_product_attention primitive.
/// @param id This primitive id.
- /// @param inputs Input data primitives id (query, keys, values, [attention_mask], [scale], [keys scales], [keys zp], [values scales], [values zp]).
+ /// @param inputs Input data primitives id (query, keys, values, [attention_mask], [scale], [sink], [keys scales], [keys zp], [values scales], [values zp]).
/// @param is_causal If true, assumes causal attention masking. In this case attention_mask input is ignored.
scaled_dot_product_attention(const primitive_id& id,
const std::vector<cldnn::input_info> inputs,
@@ -50,13 +62,15 @@ struct scaled_dot_product_attention : public primitive_base<scaled_dot_product_a
quantization_attributes.output_storage_type == ov::op::internal::DynamicQuantize::OutputStorageType::Planar)
data_inputs_num -= 2; // zp
}
- has_attn_mask_input = data_inputs_num > 3;
- has_scale_input = data_inputs_num > 4;
+ has_attn_mask_input = data_inputs_num > ScaledDotProductAttentionInputIdx::ATTN_MASK;
+ has_scale_input = data_inputs_num > ScaledDotProductAttentionInputIdx::SCALE;
+ has_sink_input = data_inputs_num > ScaledDotProductAttentionInputIdx::SINK;
}
bool is_causal = false;
bool has_attn_mask_input = false;
bool has_scale_input = false;
+ bool has_sink_input = false;
int64_t indirect_axis = -1;
bool is_kv_compressed = false;
@@ -75,6 +89,7 @@ struct scaled_dot_product_attention : public primitive_base<scaled_dot_product_a
seed = hash_combine(seed, is_causal);
seed = hash_combine(seed, has_attn_mask_input);
seed = hash_combine(seed, has_scale_input);
+ seed = hash_combine(seed, has_sink_input);
seed = hash_combine(seed, indirect_axis);
seed = hash_range(seed, input_q_transpose_order.begin(), input_q_transpose_order.end());
seed = hash_range(seed, input_k_transpose_order.begin(), input_k_transpose_order.end());
@@ -109,6 +124,7 @@ struct scaled_dot_product_attention : public primitive_base<scaled_dot_product_a
return is_causal == rhs_casted.is_causal &&
has_attn_mask_input == rhs_casted.has_attn_mask_input &&
has_scale_input == rhs_casted.has_scale_input &&
+ has_sink_input == rhs_casted.has_sink_input &&
indirect_axis == rhs_casted.indirect_axis &&
input_q_transpose_order == rhs_casted.input_q_transpose_order &&
input_k_transpose_order == rhs_casted.input_k_transpose_order &&
@@ -132,6 +148,7 @@ struct scaled_dot_product_attention : public primitive_base<scaled_dot_product_a
ob << is_kv_compressed;
ob << has_attn_mask_input;
ob << has_scale_input;
+ ob << has_sink_input;
ob << indirect_axis;
ob << input_q_transpose_order;
ob << input_k_transpose_order;
@@ -160,6 +177,7 @@ struct scaled_dot_product_attention : public primitive_base<scaled_dot_product_a
ib >> is_kv_compressed;
ib >> has_attn_mask_input;
ib >> has_scale_input;
+ ib >> has_sink_input;
ib >> indirect_axis;
ib >> input_q_transpose_order;
ib >> input_k_transpose_order;
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/sdpa_base.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/sdpa_base.cpp
index 68d4cbf4128..454450e695b 100644
--- a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/sdpa_base.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/sdpa_base.cpp
@@ -205,16 +205,12 @@ JitConstants SDPABase::get_jit_constants(const kernel_impl_params& params) const
if (params.is_type<scaled_dot_product_attention>()) {
const auto& desc = params.typed_desc<scaled_dot_product_attention>();
auto data_inputs_num = get_data_inputs_num(*desc);
- const size_t attn_mask_id = 3;
jit.make("IS_CAUSAL", desc->is_causal);
- if (desc->attn_mask_val.has_value()) {
- jit.make("STATIC_SCALAR_ATTN_MASK_VALUE", desc->attn_mask_val.value());
- jit.make("HAS_ATTN_MASK_INPUT", 0);
- } else {
- jit.make("HAS_ATTN_MASK_INPUT", data_inputs_num > attn_mask_id);
+ if (desc->has_sink_input) {
+ jit.make("SINK_DATA_T", to_ocl_type(params.input_layouts[5].data_type));
+ jit.make("HAS_SINK_INPUT", 1);
}
-
jit.make("IS_KV_COMPRESSED", desc->is_kv_compressed);
GPU_DEBUG_TRACE_DETAIL << "desc->is_kv_compressed = " << desc->is_kv_compressed << std::endl;
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/sdpa_gen_micro.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/sdpa_gen_micro.cpp
index 88d3bdc67e4..946de0ecdbb 100644
--- a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/sdpa_gen_micro.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/sdpa_gen_micro.cpp
@@ -12,6 +12,7 @@
#include "intel_gpu/primitives/scaled_dot_product_attention.hpp"
#include "ocl_v2/utils/jitter.hpp"
#include "scaled_dot_product_attention_inst.h"
+#include "paged_attention_inst.h"
#include "sdpa_base.hpp"
#include "../utils/kernel_generator.hpp"
// clang-format on
@@ -942,7 +943,13 @@ JitConstants SDPAMicroGenerator::get_jit_constants(const kernel_impl_params& par
jit.add(make_layout_jit_constants("OUTPUT" + to_code_string(1), params.output_layouts[1], out_offsets_map.at(1)));
}
} else {
+ const auto desc = params.typed_desc<scaled_dot_product_attention>();
jit.add(make_tensors_jit_constants(params));
+ if (desc->has_sink_input) {
+ const auto& sink_layout = params.input_layouts[ScaledDotProductAttentionInputIdx::SINK];
+ jit.make("SINK_DATA_T", to_ocl_type(sink_layout.data_type));
+ jit.make("HAS_SINK_INPUT", 1);
+ }
}
const auto& device_info = params.get_device_info();
@@ -1190,23 +1197,26 @@ Arguments SDPAMicroGenerator::get_arguments_desc(const kernel_impl_params& param
auto data_inputs_num = micro_get_input_num(params, config);
- args.push_back({ArgumentDescriptor::Types::INPUT, 1}); // K
- args.push_back({ArgumentDescriptor::Types::INPUT, 0}); // Q
- args.push_back({ArgumentDescriptor::Types::INPUT, 2}); // V
- args.push_back({ArgumentDescriptor::Types::OUTPUT, 0}); // A
+ args.push_back({ArgumentDescriptor::Types::INPUT, ScaledDotProductAttentionInputIdx::KEY}); // K
+ args.push_back({ArgumentDescriptor::Types::INPUT, ScaledDotProductAttentionInputIdx::QUERY}); // Q
+ args.push_back({ArgumentDescriptor::Types::INPUT, ScaledDotProductAttentionInputIdx::VALUE}); // V
+ args.push_back({ArgumentDescriptor::Types::OUTPUT, 0}); // A
if (config.is_paged_attention) {
- args.push_back({ArgumentDescriptor::Types::INPUT, 6}); // subsequence_begins
+ args.push_back({ArgumentDescriptor::Types::INPUT, PagedAttentionInputIdx::SUBSEQUENCE_BEGINS}); // subsequence_begins
if (!config.has_const_scale_val)
- args.push_back({ArgumentDescriptor::Types::INPUT, 9}); // scale
- args.push_back({ArgumentDescriptor::Types::INTERNAL_BUFFER, 3}); // blocked_indexes_start_and_gws_mapping
+ args.push_back({ArgumentDescriptor::Types::INPUT, PagedAttentionInputIdx::SCALE}); // scale
+ args.push_back({ArgumentDescriptor::Types::INTERNAL_BUFFER, 3}); // blocked_indexes_start_and_gws_mapping
} else {
- const uint32_t attn_mask_idx = 3;
- const uint32_t scale_idx = 4;
+ const uint32_t attn_mask_idx = ScaledDotProductAttentionInputIdx::ATTN_MASK;
if (config.input_num > attn_mask_idx && !config.has_const_attn_mask_val)
args.push_back({ArgumentDescriptor::Types::INPUT, attn_mask_idx}); // mask
+ const uint32_t scale_idx = ScaledDotProductAttentionInputIdx::SCALE;
if (config.input_num > scale_idx && !config.has_const_scale_val)
args.push_back({ArgumentDescriptor::Types::INPUT, scale_idx}); // Scale
+ const uint32_t sink_idx = ScaledDotProductAttentionInputIdx::SINK;
+ if (config.input_num > sink_idx)
+ args.push_back({ArgumentDescriptor::Types::INPUT, sink_idx}); // Sink
args.push_back({ArgumentDescriptor::Types::SCALAR, 0}); // D
args.push_back({ArgumentDescriptor::Types::SCALAR, 1}); // K
@@ -1514,6 +1524,5 @@ void SDPAMicroGenerator::init_microkernels(const kernel_impl_params& params,
throw;
}
}
-
} // namespace ov::intel_gpu::ocl
#endif
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/sdpa_gen_opt.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/sdpa_gen_opt.cpp
index adbfecc1df5..1fddcb8d752 100644
--- a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/sdpa_gen_opt.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/sdpa_gen_opt.cpp
@@ -66,7 +66,14 @@ JitConstants SDPAOptGeneratorBase::get_jit_constants_base(const kernel_impl_para
GPU_DEBUG_TRACE_DETAIL << "k_head_size = " << k_head_size << ", v_head_size = " << v_head_size << "\n";
size_t data_inputs_num = get_data_inputs_num(*desc);
- size_t scale_idx = 4;
+ size_t attn_mask_idx = ScaledDotProductAttentionInputIdx::ATTN_MASK;
+ if (desc->attn_mask_val.has_value()) {
+ jit.make("STATIC_SCALAR_ATTN_MASK_VALUE", desc->attn_mask_val.value());
+ jit.make("HAS_ATTN_MASK_INPUT", 0);
+ } else {
+ jit.make("HAS_ATTN_MASK_INPUT", data_inputs_num > attn_mask_idx);
+ }
+ size_t scale_idx = ScaledDotProductAttentionInputIdx::SCALE;
if ((data_inputs_num > scale_idx) && (!desc->scale_val.has_value())) {
jit.make("HAS_SCALE_INPUT", 1);
} else if (desc->scale_val.has_value()) {
@@ -76,7 +83,6 @@ JitConstants SDPAOptGeneratorBase::get_jit_constants_base(const kernel_impl_para
jit.make("STATIC_SCALE_VALUE_INV", std::sqrt(static_cast<float>(k_head_size)));
jit.make("STATIC_SCALE_VALUE", 1.0f / std::sqrt(static_cast<float>(k_head_size)));
}
- // jit.make("NUM_KV_HEADS", -1);
if (info.supports_immad && broadcast_axis == -1 && k_head_size >= 128) {
jit.make("LOAD_KEY_LEFTOVERS_IN_CALC_LOOP", 1);
}
@@ -106,8 +112,8 @@ Arguments SDPAOptGeneratorBase::get_arguments_desc_impl(const kernel_impl_params
size_t data_inputs_num = stage == SDPAStage::FINALIZATION ? 0 : get_data_inputs_num(*desc);
auto has_zp_input_buffers = desc->get_compression_zp_inputs_num() > 0;
- const size_t attn_mask_idx = 3;
- const size_t scale_idx = 4;
+ const size_t attn_mask_idx = ScaledDotProductAttentionInputIdx::ATTN_MASK;
+ const size_t scale_idx = ScaledDotProductAttentionInputIdx::SCALE;
for (uint32_t i = 0; i < data_inputs_num; i++) {
if (i == attn_mask_idx && desc->attn_mask_val.has_value())
continue;
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/sdpa_opt.hpp b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/sdpa_opt.hpp
index 4e8698f977b..337d27621dc 100644
--- a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/sdpa_opt.hpp
+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/sdpa_opt.hpp
@@ -39,10 +39,9 @@ struct SDPAOpt : public ImplementationManager {
ov::element::f16,
ov::element::i8,
};
-
- const auto& q_layout = node.get_input_layout(0);
- const auto& k_layout = node.get_input_layout(1);
- const auto& v_layout = node.get_input_layout(2);
+ const auto& q_layout = node.get_input_layout(ScaledDotProductAttentionInputIdx::QUERY);
+ const auto& k_layout = node.get_input_layout(ScaledDotProductAttentionInputIdx::KEY);
+ const auto& v_layout = node.get_input_layout(ScaledDotProductAttentionInputIdx::VALUE);
const auto& out_layout = node.get_output_layout(0);
if (!everyone_is(format::bfyx, q_layout.format, k_layout.format, v_layout.format, out_layout.format)) {
return false;
@@ -62,6 +61,13 @@ struct SDPAOpt : public ImplementationManager {
return false;
}
+ if (desc->has_sink_input) {
+ auto sink_layout = node.get_input_layout(ScaledDotProductAttentionInputIdx::SINK);
+ auto q_heads_num = q_layout.get_partial_shape()[1].get_length();
+ if (sink_layout.count() != static_cast<size_t>(q_heads_num))
+ OPENVINO_THROW("Currently only supporting per-head sink.Sink_layout : ", sink_layout.to_short_string(), " heads_num :", q_heads_num);
+ }
+
const bool use_asymmetric_quantization =
desc->quantization_attributes.quantization_type == ov::op::internal::DynamicQuantize::QuantizationType::Asymmetric;
const bool combine_scales_and_zp = desc->quantization_attributes.output_storage_type != ov::op::internal::DynamicQuantize::OutputStorageType::Planar;
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/sdpa_ref.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/sdpa_ref.cpp
index ffb765aea98..e058d2806de 100644
--- a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/sdpa_ref.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/sdpa_ref.cpp
@@ -31,8 +31,16 @@ protected:
auto desc = params.typed_desc<scaled_dot_product_attention>();
jit.add(make_type_jit_constants("ACCUMULATOR", get_accumulator_type(params)));
- jit.make("NUM_KV_HEADS", -1);
+ size_t data_inputs_num = get_data_inputs_num(*desc);
+ size_t attn_mask_idx = ScaledDotProductAttentionInputIdx::ATTN_MASK;
+ if (data_inputs_num > attn_mask_idx) {
+ jit.make("HAS_ATTN_MASK_INPUT", 1);
+ }
+ size_t scale_idx = ScaledDotProductAttentionInputIdx::SCALE;
+ if (data_inputs_num > scale_idx) {
+ jit.make("HAS_SCALE_INPUT", 1);
+ }
return jit;
}
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa_micro.cl b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa_micro.cl
index ec85087bc4b..452f581ff8e 100644
--- a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa_micro.cl
+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa_micro.cl
@@ -152,6 +152,9 @@ KERNEL(micro_sdpa)(OPTIONAL_SHAPE_INFO_ARG
#if WITH_SCALE
global SCALE_DATA_T *scale_ptr,
#endif
+#ifdef HAS_SINK_INPUT
+ const global SINK_DATA_T *sink_ptr,
+#endif
#if IS_PAGED_ATTENTION
const __global int* blocked_indexes_start_and_gws_mapping
#else
@@ -185,7 +188,6 @@ KERNEL(micro_sdpa)(OPTIONAL_SHAPE_INFO_ARG
#else
uint wg_j0 = get_group_id(0) * ugemm_kq_wg_tile_n;
#endif
-
/* Leading dimension for matrices */
#if IS_PAGED_ATTENTION
uint ldk = HEAD_SIZE * KV_HEADS_NUM + INPUT1_PAD_BEFORE_FEATURE_NUM + INPUT1_PAD_AFTER_FEATURE_NUM;
@@ -317,11 +319,23 @@ KERNEL(micro_sdpa)(OPTIONAL_SHAPE_INFO_ARG
float scale = native_recip(iscale);
#endif
#endif
- scale *= 1.442695f; // log2(e)
-
+ const float log2_e = 1.442695f;
+#if !defined(HAS_SINK_INPUT)
+#define LOG_2_E_MUL_SCALE 1
+ scale *= log2_e;
+#endif
#ifdef STATIC_SCALAR_ATTN_MASK_VALUE
float masked_scale = iscale * STATIC_SCALAR_ATTN_MASK_VALUE;
#endif
+#ifdef HAS_SINK_INPUT
+ const float sink_val = convert_float(sink_ptr[b0]);
+ #define MULTI_TOKENS_PER_WI ((ugemm_kq_sg_tile_n/SUBGROUP_SIZE) > 1)
+ #if MULTI_TOKENS_PER_WI
+ #define VEC_SIZE (ugemm_kq_sg_tile_n / SUBGROUP_SIZE)
+ typedef float __attribute__((ext_vector_type(VEC_SIZE))) s_sink_vec_type;
+ s_sink_vec_type sink_val_vec = sink_val;
+ #endif
+#endif
#ifdef PREFETCH_K0
/* Prefetch first K tile. */
@@ -389,7 +403,6 @@ KERNEL(micro_sdpa)(OPTIONAL_SHAPE_INFO_ARG
s_sum_tile_type S_max_tile, S_max_tile_old;
tile_fill(S_sum_tile, 0.0f);
tile_fill(S_max_tile, -INFINITY);
-
/* Wait for Q data to reach SLM */
barrier(CLK_LOCAL_MEM_FENCE);
@@ -400,7 +413,6 @@ KERNEL(micro_sdpa)(OPTIONAL_SHAPE_INFO_ARG
uint sg_i0_kq = sg_i_kq * ugemm_kq_sg_tile_m;
uint sg_j0_kq = sg_j_kq * ugemm_kq_sg_tile_n;
-
#if WITH_ATTN_MASK
/* Load mask. No remainder handling needed assuming k block size is a power of 2. */
mask_tile_type mask_tile;
@@ -454,10 +466,15 @@ KERNEL(micro_sdpa)(OPTIONAL_SHAPE_INFO_ARG
#define mask_scale_op(x) ((x) + masked_scale)
tile_elementwise(S_tile, mask_scale_op);
#elif WITH_ATTN_MASK
-#define unscale(x) ((x)*iscale)
mask_tile_type_float mask_tile_float;
tile_copy(mask_tile, mask_tile_float);
+#ifdef LOG_2_E_MUL_SCALE
+#define unscale(x) ((x)*iscale)
tile_elementwise(mask_tile_float, unscale);
+#else
+#define scale(x) ((x)* scale)
+ tile_elementwise(S_tile, scale);
+#endif // LOG_2_MUL_SCALE
tile_binary(S_tile, mask_tile_float, binary_add);
#endif
@@ -483,6 +500,23 @@ KERNEL(micro_sdpa)(OPTIONAL_SHAPE_INFO_ARG
S_max_tile, S_max_slm, ugemm_kq_wg_tile_n, sg_j0_kq, 0);
intel_work_group_barrier_arrive(CLK_LOCAL_MEM_FENCE);
+ #ifdef HAS_SINK_INPUT
+ const int cur_k = k - k0 - 1;
+ const bool is_last_m_sg = last && (sg_i_kq == cur_k / ugemm_kq_sg_tile_m);
+ if (is_last_m_sg) {
+ #if MULTI_TOKENS_PER_WI
+ #define max_sink(x) (fmax(x, sink_val_vec))
+ tile_elementwise(S_max_tile, max_sink);
+ #undef max_sink
+ #else
+ #define max_sink(x) (MAX(x, sink_val))
+ tile_elementwise_s(S_max_tile, max_sink);
+ #undef max_sink
+ #endif
+ }
+ #endif
+
+
int k_chunk = min(k - k0, ugemm_kq_wg_tile_m);
#ifdef PREFETCH_V
/* Prefetch V tile. */
@@ -535,9 +569,12 @@ KERNEL(micro_sdpa)(OPTIONAL_SHAPE_INFO_ARG
#endif
tile_vbroadcast_sub(&S_tile, S_max_tile);
-
/* Scale + exponentiate */
-#define scaled_exp(x) native_vexp2(x *scale)
+#ifdef LOG_2_E_MUL_SCALE
+#define scaled_exp(x) native_vexp2(x * scale)
+#else
+#define scaled_exp(x) native_vexp2(x * log2_e)
+#endif
tile_elementwise(S_tile, scaled_exp);
#ifdef ALT_MAX
@@ -556,6 +593,16 @@ KERNEL(micro_sdpa)(OPTIONAL_SHAPE_INFO_ARG
s_sum_tile_type S_sum_tile1;
tile_fill(S_sum_tile1, 0.0f);
tile_vreduce_add(S_tile, &S_sum_tile1);
+#ifdef HAS_SINK_INPUT
+ if (is_last_m_sg){
+ s_sum_tile_type sink_minus_max_exp;
+ tile_fill(sink_minus_max_exp, convert_float(sink_val));
+ #define binary_exp_neg(x, y) native_vexp2(((x) - (y)) * log2_e)
+ tile_binary(sink_minus_max_exp, S_max_tile, binary_exp_neg);
+ tile_binary(S_sum_tile1, sink_minus_max_exp, binary_add);
+ #undef binary_exp_neg
+ }
+#endif
/* Convert to half, VNNI format */
s_tile_type_half2 S_tile_half2;
@@ -569,7 +616,11 @@ KERNEL(micro_sdpa)(OPTIONAL_SHAPE_INFO_ARG
/* Rescale existing accumulator and sums to match new maxima */
if (!first) {
+#ifdef LOG_2_E_MUL_SCALE
#define binary_exp_sub(x, y) native_vexp2(scale *((x) - (y)))
+#else
+#define binary_exp_sub(x, y) native_vexp2(((x) - (y)) * log2_e)
+#endif
#define binary_mul(x, y) ((x) * (y))
tile_binary(S_max_tile_old, S_max_tile, binary_exp_sub);
tile_binary(S_sum_tile, S_max_tile_old, binary_mul);
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa_opt.cl b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa_opt.cl
index c443658f383..e3fc4cb53d6 100644
--- a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa_opt.cl
+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa_opt.cl
@@ -151,6 +151,9 @@ KERNEL(sdpa_opt)(
#endif
#if HAS_SCALE_INPUT
const __global SCALE_TYPE* scale,
+#endif
+#if HAS_SINK_INPUT
+ const __global SINK_DATA_T* sink_ptr,
#endif
__global OUTPUT_TYPE* output,
#if IS_KV_COMPRESSED
@@ -473,6 +476,9 @@ KERNEL(sdpa_opt)(
// Final maximum value of qk after reduction across all subgroups
qk_max[seq_idx] = sub_group_reduce_max(qk_max[seq_idx]);
+ #ifdef HAS_SINK_INPUT
+ qk_max[seq_idx] = qk_max[seq_idx] > sink_ptr[b1_idx] ? qk_max[seq_idx] : sink_ptr[b1_idx];
+ #endif
}
SOFTMAX_ACCUMULATOR_TYPE exp_sum[TARGET_SEQ_LEN_BLOCK_SIZE] = {SOFTMAX_ACCUMULATOR_VAL_ZERO};
@@ -506,6 +512,9 @@ KERNEL(sdpa_opt)(
// Find the final sum of all exp_sum[seq_idx] values in workgroup
exp_sum[seq_idx] = sub_group_reduce_add(exp_sum[seq_idx]);
+ #ifdef HAS_SINK_INPUT
+ exp_sum[seq_idx] += (native_exp(TO_SOFTMAX_ACCUMULATOR_TYPE(sink_ptr[b1_idx] - qk_max[seq_idx])));
+ #endif
}
// const SOFTMAX_ACCUMULATOR_TYPE inv_exp_sum = SOFTMAX_ACCUMULATOR_VAL_ONE / exp_sum[seq_idx];
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa_ref.cl b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa_ref.cl
index 0bb15e9065e..1a3d9736015 100644
--- a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa_ref.cl
+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa_ref.cl
@@ -138,7 +138,10 @@ KERNEL(sdpa_ref)(
const __global INPUT3_TYPE* attn_mask,
#endif
#if HAS_SCALE_INPUT
- const __global SCALE_TYPE* scale,
+ const __global half* scale,
+#endif
+#ifdef HAS_SINK_INPUT
+ global SINK_DATA_T *sink_ptr,
#endif
__global OUTPUT_TYPE* output,
#if IS_KV_COMPRESSED
@@ -239,6 +242,9 @@ KERNEL(sdpa_ref)(
tmp_buf[tmp_buf_offset] = qk_val;
qk_max = ACCUMULATOR_MAX_FUNC(qk_max, TO_ACCUMULATOR_TYPE(qk_val));
+ #ifdef HAS_SINK_INPUT
+ qk_max = ACCUMULATOR_MAX_FUNC(qk_max, TO_ACCUMULATOR_TYPE(sink_ptr[b1]));
+ #endif
}
ACCUMULATOR_TYPE exp_sum = ACCUMULATOR_VAL_ZERO;
@@ -253,6 +259,10 @@ KERNEL(sdpa_ref)(
tmp_buf[tmp_buf_offset] = TO_OUTPUT_TYPE(val);
}
+ #ifdef HAS_SINK_INPUT
+ ACCUMULATOR_TYPE val = native_exp(TO_ACCUMULATOR_TYPE(sink_ptr[b1] - qk_max));
+ exp_sum += val;
+ #endif
const ACCUMULATOR_TYPE inv_sum = ACCUMULATOR_VAL_ONE / exp_sum;
for (uint s = 0; s < SOURCE_SEQ_LEN /* seq_len */; s++) {
diff --git a/src/plugins/intel_gpu/src/graph/include/scaled_dot_product_attention_inst.h b/src/plugins/intel_gpu/src/graph/include/scaled_dot_product_attention_inst.h
index 1857b8b6da5..93e046ee6ac 100644
--- a/src/plugins/intel_gpu/src/graph/include/scaled_dot_product_attention_inst.h
+++ b/src/plugins/intel_gpu/src/graph/include/scaled_dot_product_attention_inst.h
@@ -10,6 +10,7 @@
namespace cldnn {
+using ScaledDotProductAttentionInputIdx = cldnn::scaled_dot_product_attention::ScaledDotProductAttentionInputIdx;
template <>
struct typed_program_node<scaled_dot_product_attention> : public typed_program_node_base<scaled_dot_product_attention> {
using parent = typed_program_node_base<scaled_dot_product_attention>;
diff --git a/src/plugins/intel_gpu/src/plugin/ops/scaled_dot_product_attention.cpp b/src/plugins/intel_gpu/src/plugin/ops/scaled_dot_product_attention.cpp
index c062f23cdfe..a25136bc7d4 100644
--- a/src/plugins/intel_gpu/src/plugin/ops/scaled_dot_product_attention.cpp
+++ b/src/plugins/intel_gpu/src/plugin/ops/scaled_dot_product_attention.cpp
@@ -25,8 +25,14 @@ using IndirectSDPA = ov::intel_gpu::op::IndirectSDPA;
namespace ov::intel_gpu {
-const size_t attn_mask_idx = 3;
-const size_t scale_idx = 4;
+constexpr size_t value_idx = cldnn::scaled_dot_product_attention::ScaledDotProductAttentionInputIdx::VALUE;
+constexpr size_t mask_idx = cldnn::scaled_dot_product_attention::ScaledDotProductAttentionInputIdx::ATTN_MASK;
+constexpr size_t scale_idx = cldnn::scaled_dot_product_attention::ScaledDotProductAttentionInputIdx::SCALE;
+constexpr size_t sink_idx = cldnn::scaled_dot_product_attention::ScaledDotProductAttentionInputIdx::SINK;
+constexpr size_t cnt_inputs_with_qkv = value_idx + 1;
+constexpr size_t cnt_inputs_with_mask = mask_idx + 1;
+constexpr size_t cnt_inputs_with_scale = scale_idx + 1;
+constexpr size_t cnt_inputs_with_sink = sink_idx + 1;
static std::shared_ptr<ov::op::v0::Constant> GetScalarConstInput(const std::shared_ptr<ov::op::Op>& op, size_t idx) {
std::shared_ptr<ov::op::v0::Constant> constOp = nullptr;
@@ -77,12 +83,13 @@ static void GetNewOrder(ProgramBuilder&p, const std::shared_ptr<ov::op::internal
static void CreateScaledDotProductAttentionOp(ProgramBuilder& p, const std::shared_ptr<ov::op::v13::ScaledDotProductAttention>& op) {
// if transpose fusion is disabled, this is used
- validate_inputs_count(op, {3, 4, 5});
+
+ validate_inputs_count(op, {cnt_inputs_with_qkv, cnt_inputs_with_mask, cnt_inputs_with_scale, cnt_inputs_with_sink});
auto inputs = p.GetInputInfo(op);
auto layerName = layer_type_name_ID(op);
auto scalar_scale = GetScalarConstInput(op, scale_idx);
- auto scalar_attn_mask = GetScalarConstInput(op, attn_mask_idx);
+ auto scalar_attn_mask = GetScalarConstInput(op, mask_idx);
ReshapeInput(p, op, inputs);
@@ -109,12 +116,12 @@ static void CreateScaledDotProductAttentionOp(ProgramBuilder& p, const std::shar
}
static void CreateSDPAOp(ProgramBuilder& p, const std::shared_ptr<ov::op::internal::SDPA>& op) {
- validate_inputs_count(op, {3, 4, 5});
+ validate_inputs_count(op, {cnt_inputs_with_qkv, cnt_inputs_with_mask, cnt_inputs_with_scale, cnt_inputs_with_sink});
auto inputs = p.GetInputInfo(op);
auto layerName = layer_type_name_ID(op);
auto scalar_scale = GetScalarConstInput(op, scale_idx);
- auto scalar_attn_mask = GetScalarConstInput(op, attn_mask_idx);
+ auto scalar_attn_mask = GetScalarConstInput(op, mask_idx);
ReshapeInput(p, op, inputs);
@@ -148,7 +155,7 @@ static void CreateIndirectSDPAOp(ProgramBuilder& p, const std::shared_ptr<ov::op
auto layerName = layer_type_name_ID(op);
auto scalar_scale = GetScalarConstInput(op, scale_idx);
- auto scalar_attn_mask = GetScalarConstInput(op, attn_mask_idx);
+ auto scalar_attn_mask = GetScalarConstInput(op, mask_idx);
ReshapeInput(p, op, inputs);
@@ -157,7 +164,8 @@ static void CreateIndirectSDPAOp(ProgramBuilder& p, const std::shared_ptr<ov::op
bool is_causal = op->get_causal();
const auto compression_inputs = op->get_compression_inputs_num();
- validate_inputs_count(op, {4 + compression_inputs, 5 + compression_inputs, 6 + compression_inputs});
+ validate_inputs_count(op, {cnt_inputs_with_mask + compression_inputs,
+ cnt_inputs_with_scale + compression_inputs, cnt_inputs_with_sink + compression_inputs});
int64_t indirect_axis = op->get_indirect_axis();
auto sdpa_prim = cldnn::scaled_dot_product_attention(layerName,
diff --git a/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp b/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp
index f4135b05749..d96bbbe433f 100644
--- a/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp
+++ b/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp
@@ -194,6 +194,7 @@
#include "openvino/op/transpose.hpp"
#include "openvino/util/log.hpp"
+#include "intel_gpu/primitives/scaled_dot_product_attention.hpp"
namespace {
template<typename T>
static bool disable_reduce_decomposition(const std::shared_ptr<const ov::Node> node) {
@@ -543,6 +544,12 @@ void TransformationsPipeline::apply(std::shared_ptr<ov::Model> func) {
return false;
auto sdpa = ov::as_type_ptr<const ov::op::v13::ScaledDotProductAttention>(node);
+ // TODO: sdpa_opt is not supporting sink_input for 1st token case yet
+ constexpr size_t sink_idx = cldnn::scaled_dot_product_attention::ScaledDotProductAttentionInputIdx::SINK;
+ if (sdpa->get_input_size() > sink_idx && !device_info.supports_immad) {
+ return false;
+ }
+
const auto& query_ps = sdpa->get_input_partial_shape(0);
const auto& key_ps = sdpa->get_input_partial_shape(1);
const auto& value_ps = sdpa->get_input_partial_shape(2);
diff --git a/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/scaled_dot_product_attention.cpp b/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/scaled_dot_product_attention.cpp
index 3d1c9e4d441..65162536e6b 100644
--- a/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/scaled_dot_product_attention.cpp
+++ b/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/scaled_dot_product_attention.cpp
@@ -20,14 +20,15 @@
namespace {
using ov::test::InputShape;
-typedef std::tuple<ov::element::Type, // netPrecision
- std::vector<InputShape>, // shape
- bool, // is_causal
- bool, // has_attn
- bool, // is_attn_const
- bool, // has_scale
- bool, // is_scale_const
- std::vector<std::vector<int64_t>> // input_transpose
+typedef std::tuple<ov::element::Type, // netPrecision
+ std::vector<InputShape>, // shape
+ bool, // is_causal
+ bool, // has_attn
+ bool, // is_attn_const
+ bool, // has_scale
+ bool, // is_scale_const
+ std::vector<std::vector<int64_t>>, // input_transpose
+ bool // has_sink
> ScaledAttnGPUTestParams;
class ScaledAttnLayerGPUTest : public testing::WithParamInterface<ScaledAttnGPUTestParams>,
@@ -44,11 +45,12 @@ protected:
bool is_attn_const;
bool has_scale;
bool is_scale_const;
+ bool has_sink;
};
std::string ScaledAttnLayerGPUTest::getTestCaseName(const testing::TestParamInfo<ScaledAttnGPUTestParams>& obj) {
bool transpose_enable;
- const auto& [inType, inputShapes, is_causal, has_attn, is_attn_const, has_scale, is_scale_const, input_transpose] = obj.param;
+ const auto& [inType, inputShapes, is_causal, has_attn, is_attn_const, has_scale, is_scale_const, input_transpose, has_sink] = obj.param;
transpose_enable = (input_transpose.size() != 0);
std::ostringstream result;
@@ -70,6 +72,7 @@ std::string ScaledAttnLayerGPUTest::getTestCaseName(const testing::TestParamInfo
result << "has_scale=" << has_scale << "_";
result << "is_scale_const=" << is_scale_const << "_";
result << "with_transpose" << transpose_enable << "_";
+ result << "has_sink=" << has_sink << "_";
return result.str();
}
@@ -77,13 +80,14 @@ std::string ScaledAttnLayerGPUTest::getTestCaseName(const testing::TestParamInfo
void ScaledAttnLayerGPUTest::SetUp() {
targetDevice = ov::test::utils::DEVICE_GPU;
- const auto& [inType, _inputShapes, _is_causal, _has_attn, _is_attn_const, _has_scale, _is_scale_const, input_transpose] = this->GetParam();
+ const auto& [inType, _inputShapes, _is_causal, _has_attn, _is_attn_const, _has_scale, _is_scale_const, input_transpose, _has_sink] = this->GetParam();
is_causal = _is_causal;
has_attn = _has_attn;
is_attn_const = _is_attn_const;
has_scale = _has_scale;
is_scale_const = _is_scale_const;
auto inputShapes = _inputShapes;
+ has_sink = _has_sink;
transpose_prepare(inputShapes, input_transpose);
init_input_shapes(inputShapes);
@@ -158,7 +162,14 @@ void ScaledAttnLayerGPUTest::SetUp() {
for (size_t i = 0; i < inputParams_transpose.size(); i++) {
inputs.push_back(inputParams_transpose[i]);
}
-
+ if (has_sink) {
+ size_t num_heads = inputDynamicShapes[0][1].get_length();
+ ov::test::utils::InputGenerateData data(0, 5, 100);
+ auto sink_tensor = ov::test::utils::create_and_fill_tensor(ov::element::f16, ov::Shape{1, num_heads, 1, 1}, data);
+ auto sink_const = std::make_shared<ov::op::v0::Constant>(sink_tensor);
+ sink_const->set_friendly_name("sink");
+ inputs.push_back(sink_const);
+ }
auto sdp = std::make_shared<ov::opset13::ScaledDotProductAttention>(inputs, is_causal);
sdp->set_friendly_name("sdpa");
@@ -272,7 +283,6 @@ void ScaledAttnLayerGPUTest::generate_inputs(const std::vector<ov::Shape>& targe
TEST_P(ScaledAttnLayerGPUTest, CompareWithRefs) {
run();
}
-
const std::vector<std::vector<InputShape>> dynamic_shapes_3D {
{
// q shape
@@ -303,7 +313,8 @@ const auto dynamic_shape_params_3D = testing::Combine(testing::Values(ov::elemen
testing::Values(false),
testing::Values(true, false),
testing::Values(false),
- testing::ValuesIn({disable_transpose, transpose_all_3D}));
+ testing::ValuesIn({disable_transpose, transpose_all_3D}),
+ testing::Values(false));
INSTANTIATE_TEST_SUITE_P(smoke_ScaledAttnDynamic3D_GPU,
ScaledAttnLayerGPUTest,
@@ -339,13 +350,52 @@ const auto static_shape_params_3D = testing::Combine(testing::Values(ov::element
testing::Values(true, false),
testing::Values(true, false),
testing::Values(true, false),
- testing::ValuesIn({disable_transpose, transpose_all_3D}));
+ testing::ValuesIn({disable_transpose, transpose_all_3D}),
+ testing::Values(false));
INSTANTIATE_TEST_SUITE_P(smoke_ScaledAttnStatic3D_GPU,
ScaledAttnLayerGPUTest,
static_shape_params_3D,
ScaledAttnLayerGPUTest::getTestCaseName);
+
+const std::vector<std::vector<InputShape>> static_shapes_4D{
+ // static shapes
+ {
+ // q shape
+ {ov::test::InputShape{ov::PartialShape{1, 16, 128, 80},
+ {ov::Shape{1, 16, 128, 80}}}
+ },
+ // k shape
+ {ov::test::InputShape{ov::PartialShape{1, 16, 128, 80},
+ {ov::Shape{1, 16, 128, 80}}}
+ },
+ // v shape
+ {ov::test::InputShape{ov::PartialShape{1, 16, 128, 80},
+ {ov::Shape{1, 16, 128, 80}}}
+ },
+ // attn shape: [B, 128, -128, L0+L1]
+ {ov::test::InputShape{ov::PartialShape{128, 128},
+ {ov::Shape{128, 128}}}
+ },
+ },
+};
+
+const auto static_shape_params_4D_sink = testing::Combine(testing::Values(ov::element::f16),
+ testing::ValuesIn(static_shapes_4D),
+ testing::Values(false),
+ testing::Values(true),
+ testing::Values(false),
+ testing::Values(true),
+ testing::Values(false),
+ testing::ValuesIn({disable_transpose}),
+ testing::Values(true));
+
+INSTANTIATE_TEST_SUITE_P(smoke_sink_ScaledAttnStatic4D_GPU,
+ ScaledAttnLayerGPUTest,
+ static_shape_params_4D_sink,
+ ScaledAttnLayerGPUTest::getTestCaseName);
+
const std::vector<std::vector<InputShape>> dynamic_shapes_4D {
// normal case, shapes of q,k,v are same
{
@@ -601,13 +651,146 @@ const auto dynamic_shape_params_4D = testing::Combine(testing::Values(ov::elemen
testing::Values(true, false),
testing::Values(true, false),
testing::Values(true, false),
- testing::ValuesIn({disable_transpose, transpose_value}));
+ testing::ValuesIn({disable_transpose, transpose_value}),
+ testing::Values(false));
INSTANTIATE_TEST_SUITE_P(smoke_ScaledAttnDynamic4D_GPU,
ScaledAttnLayerGPUTest,
dynamic_shape_params_4D,
ScaledAttnLayerGPUTest::getTestCaseName);
+
+const std::vector<std::vector<InputShape>> dynamic_shapes_4D_sink {
+ // normal case, shapes of q,k,v are same
+ {
+ // q shape
+ {ov::test::InputShape{ov::PartialShape{-1, 8, -1, 128},
+ {ov::Shape{1, 8, 100, 128}, ov::Shape{1, 8, 1, 128}, ov::Shape{2, 8, 10, 128}}}
+ },
+ // k shape
+ {ov::test::InputShape{ov::PartialShape{-1, 8, -1, 128},
+ {ov::Shape{1, 8, 100, 128}, ov::Shape{1, 8, 1, 128}, ov::Shape{2, 8, 10, 128}}}
+ },
+ // v shape
+ {ov::test::InputShape{ov::PartialShape{-1, 8, -1, 128},
+ {ov::Shape{1, 8, 100, 128}, ov::Shape{1, 8, 1, 128}, ov::Shape{2, 8, 10, 128}}}
+ },
+ // attn shape: [B, 1, -1, L0+L1]
+ {ov::test::InputShape{ov::PartialShape{-1, 1, -1, -1},
+ {ov::Shape{1, 1, 100, 100}, ov::Shape{1, 1, 1, 1}, ov::Shape{2, 1, 10, 10}}}
+ },
+ },
+ {
+ // q shape
+ {ov::test::InputShape{ov::PartialShape{-1, 8, -1, 64},
+ {ov::Shape{1, 8, 100, 64}, ov::Shape{1, 8, 1, 64}, ov::Shape{2, 8, 10, 64}}}
+ },
+ // k shape
+ {ov::test::InputShape{ov::PartialShape{-1, 8, -1, 64},
+ {ov::Shape{1, 8, 100, 64}, ov::Shape{1, 8, 1, 64}, ov::Shape{2, 8, 10, 64}}}
+ },
+ // v shape
+ {ov::test::InputShape{ov::PartialShape{-1, 8, -1, 64},
+ {ov::Shape{1, 8, 100, 64}, ov::Shape{1, 8, 1, 64}, ov::Shape{2, 8, 10, 64}}}
+ },
+ // attn shape: [B, 1, -1, L0+L1]
+ {ov::test::InputShape{ov::PartialShape{-1, 1, -1, -1},
+ {ov::Shape{1, 1, 100, 100}, ov::Shape{1, 1, 1, 1}, ov::Shape{2, 1, 10, 10}}}
+ },
+ },
+ {
+ // q shape
+ {ov::test::InputShape{ov::PartialShape{-1, 5, -1, 128},
+ {ov::Shape{2, 5, 100, 128}, ov::Shape{2, 5, 1, 128}, ov::Shape{2, 5, 387, 128}}}
+ },
+ // k shape
+ {ov::test::InputShape{ov::PartialShape{-1, 5, -1, 128},
+ {ov::Shape{2, 5, 100, 128}, ov::Shape{2, 5, 1, 128}, ov::Shape{2, 5, 387, 128}}}
+ },
+ // v shape
+ {ov::test::InputShape{ov::PartialShape{-1, 5, -1, 128},
+ {ov::Shape{2, 5, 100, 128}, ov::Shape{2, 5, 1, 128}, ov::Shape{2, 5, 387, 128}}}
+ },
+ // attn shape: [B, 1, -1, L0+L1]
+ {ov::test::InputShape{ov::PartialShape{-1, 1, -1, -1},
+ {ov::Shape{1, 1, 100, 100}, ov::Shape{1, 1, 1, 1}, ov::Shape{2, 1, 387, 387}}}
+ },
+ },
+ // heads number of kv is 1, attn mask: [B, H, L1, L0+L1]
+ {
+ // q shape
+ {ov::test::InputShape{ov::PartialShape{-1, 8, -1, 128},
+ {ov::Shape{1, 8, 100, 128}, ov::Shape{1, 8, 1, 128}, ov::Shape{2, 8, 10, 128}}}
+ },
+ // k shape
+ {ov::test::InputShape{ov::PartialShape{-1, 1, -1, 128},
+ {ov::Shape{1, 1, 100, 128}, ov::Shape{1, 1, 1, 128}, ov::Shape{2, 1, 10, 128}}}
+ },
+ // v shape
+ {ov::test::InputShape{ov::PartialShape{-1, 1, -1, 128},
+ {ov::Shape{1, 1, 100, 128}, ov::Shape{1, 1, 1, 128}, ov::Shape{2, 1, 10, 128}}}
+ },
+ // attn shape
+ {ov::test::InputShape{ov::PartialShape{-1, 8, -1, -1},
+ {ov::Shape{1, 8, 100, 100}, ov::Shape{1, 8, 1, 1}, ov::Shape{2, 8, 10, 10}}}
+ },
+ },
+ // 4D inputs, 2D mask
+ {
+ // q shape
+ {ov::test::InputShape{ov::PartialShape{-1, 8, -1, 64},
+ {ov::Shape{1, 8, 245, 64}, ov::Shape{1, 8, 1, 64}, ov::Shape{2, 8, 387, 64}}}
+ },
+ // k shape
+ {ov::test::InputShape{ov::PartialShape{-1, 8, -1, 64},
+ {ov::Shape{1, 8, 245, 64}, ov::Shape{1, 8, 1, 64}, ov::Shape{2, 8, 387, 64}}}
+ },
+ // v shape
+ {ov::test::InputShape{ov::PartialShape{-1, 8, -1, 64},
+ {ov::Shape{1, 8, 245, 64}, ov::Shape{1, 8, 1, 64}, ov::Shape{2, 8, 387, 64}}}
+ },
+ // attn shape: [B, 1, -1, L0+L1]
+ {ov::test::InputShape{ov::PartialShape{-1, -1},
+ {ov::Shape{245, 245}, ov::Shape{1, 1}, ov::Shape{387, 387}}}
+ },
+ },
+ {
+ // q shape
+ {ov::test::InputShape{ov::PartialShape{-1, 10, -1, 64},
+ {ov::Shape{1, 10, 77, 64}}}
+ },
+ // k shape
+ {ov::test::InputShape{ov::PartialShape{-1, 10, -1, 64},
+ {ov::Shape{1, 10, 77, 64}}}
+ },
+ // v shape
+ {ov::test::InputShape{ov::PartialShape{-1, 10, -1, 64},
+ {ov::Shape{1, 10, 77, 64}}}
+ },
+ // attn shape: [B, 1, -1, L0+L1]
+ {ov::test::InputShape{ov::PartialShape{77, 77},
+ {ov::Shape{77, 77}}}
+ },
+ }
+};
+
+
+const auto dynamic_shape_params_4D_sink = testing::Combine(testing::Values(ov::element::f16 /*, ov::element::f32 */),
+ testing::ValuesIn(dynamic_shapes_4D_sink),
+ testing::Values(false),
+ testing::Values(false),
+ testing::Values(true),
+ testing::Values(false),
+ testing::Values(true),
+ testing::ValuesIn({disable_transpose}),
+ testing::Values(true));
+
+INSTANTIATE_TEST_SUITE_P(smoke_sink_ScaledAttnDynamic4D_GPU,
+ ScaledAttnLayerGPUTest,
+ dynamic_shape_params_4D_sink,
+ ScaledAttnLayerGPUTest::getTestCaseName);
+
+
const std::vector<std::vector<InputShape>> static_shapes{
// static shapes
{
@@ -709,7 +892,8 @@ const auto static_shape_params = testing::Combine(testing::Values(ov::element::f
testing::Values(false),
testing::Values(true, false),
testing::Values(false),
- testing::ValuesIn({disable_transpose, transpose_all_4D}));
+ testing::ValuesIn({disable_transpose, transpose_all_4D}),
+ testing::Values(false));
INSTANTIATE_TEST_SUITE_P(smoke_ScaledAttnStatic_GPU,
ScaledAttnLayerGPUTest,