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
[GPU] Enable INT4 KV-cache compress (#33109)
Min, Byungil5ed7d4164fd9
diff --git a/src/common/transformations/include/transformations/common_optimizations/convert_pagedattn_inputs.hpp b/src/common/transformations/include/transformations/common_optimizations/convert_pagedattn_inputs.hppindex 8efcca8e045..9e7d945cf87 100644--- a/src/common/transformations/include/transformations/common_optimizations/convert_pagedattn_inputs.hpp+++ b/src/common/transformations/include/transformations/common_optimizations/convert_pagedattn_inputs.hpp@@ -20,6 +20,7 @@ class TRANSFORMATIONS_API ConvertPagedAttnInputs;class ConvertPagedAttnInputs : public ov::pass::MatcherPass {public:using UpdateShapeFunc = std::function<void(const ov::element::Type, const bool, const size_t, int64_t&, int64_t&)>;+ using UpdatePrecisionFunc = std::function<void(ov::element::Type&)>;struct KVCacheConfig {ov::element::Type keyCachePrecision;@@ -36,7 +37,9 @@ public:};OPENVINO_MATCHER_PASS_RTTI("ConvertPagedAttnInputs");- ConvertPagedAttnInputs(const KVCacheConfig& config, UpdateShapeFunc update_shape_func);+ ConvertPagedAttnInputs(const KVCacheConfig& config,+ UpdateShapeFunc update_shape_func,+ UpdatePrecisionFunc update_precision_func = nullptr);void setKVCacheConfig(const KVCacheConfig& config);@@ -45,6 +48,7 @@ public:private:KVCacheConfig m_config;UpdateShapeFunc m_update_shape_func;+ UpdatePrecisionFunc m_update_precision_func;};} // namespace passdiff --git a/src/common/transformations/src/transformations/common_optimizations/convert_pagedattn_inputs.cpp b/src/common/transformations/src/transformations/common_optimizations/convert_pagedattn_inputs.cppindex 2a75c1385c3..a219d0a0f8b 100644--- a/src/common/transformations/src/transformations/common_optimizations/convert_pagedattn_inputs.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/convert_pagedattn_inputs.cpp@@ -22,9 +22,12 @@ namespace v0 = ov::op::v0;namespace ov::pass {-ConvertPagedAttnInputs::ConvertPagedAttnInputs(const KVCacheConfig& config, UpdateShapeFunc func)+ConvertPagedAttnInputs::ConvertPagedAttnInputs(const KVCacheConfig& config,+ UpdateShapeFunc func,+ UpdatePrecisionFunc update_precision_func): m_config(config),- m_update_shape_func(std::move(func)) {+ m_update_shape_func(std::move(func)),+ m_update_precision_func(std::move(update_precision_func)) {MATCHER_SCOPE(ConvertPagedAttnInputs);auto Q = pattern::any_input(pattern::has_static_rank());@@ -87,6 +90,7 @@ ConvertPagedAttnInputs::ConvertPagedAttnInputs(const KVCacheConfig& config, Updareturn cache_precision == ov::element::f16 && infer_precision == ov::element::bf16 ? infer_precision: cache_precision;};+auto init_cache_shape = [&](const size_t head_nums,const size_t head_size,const size_t block_size,@@ -105,6 +109,7 @@ ConvertPagedAttnInputs::ConvertPagedAttnInputs(const KVCacheConfig& config, Upda}}size_t group_num = _head_size / _group_size;+ // Update head_size and block_size by precision and quantizing channel modem_update_shape_func(precision, bychannel, group_num, _head_size, _block_size);auto block_shape = ov::PartialShape::dynamic(4);@@ -147,6 +152,13 @@ ConvertPagedAttnInputs::ConvertPagedAttnInputs(const KVCacheConfig& config, Updastatus = false;}+ if (m_update_precision_func) {+ m_update_precision_func(key_cache_precision);+ m_update_precision_func(value_cache_precision);+ key_cache->set_element_type(key_cache_precision);+ value_cache->set_element_type(value_cache_precision);+ }+key_cache->validate_and_infer_types();value_cache->validate_and_infer_types();return status;diff --git a/src/common/transformations/tests/common_optimizations/convert_pagedattn_inputs.cpp b/src/common/transformations/tests/common_optimizations/convert_pagedattn_inputs.cppindex 964151c7241..6c614b00fb9 100644--- a/src/common/transformations/tests/common_optimizations/convert_pagedattn_inputs.cpp+++ b/src/common/transformations/tests/common_optimizations/convert_pagedattn_inputs.cpp@@ -351,6 +351,7 @@ std::vector<std::vector<ov::element::Type>> get_cache_prec() {{ov::element::f16, ov::element::f16},{ov::element::u8, ov::element::u8},{ov::element::u8, ov::element::u4},+ {ov::element::u4, ov::element::u4},};}diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/pa_kv_cache_update_ref.cl b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/pa_kv_cache_update_ref.clindex 15ffc198433..9bb27521f04 100644--- a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/pa_kv_cache_update_ref.cl+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/pa_kv_cache_update_ref.cl@@ -4,6 +4,9 @@#include "include/batch_headers/common.cl"#include "include/batch_headers/sub_group_block_read.cl"+#include "include/batch_headers/int4_utils.cl"++#define UINT4_RANGE 15inline void FUNC(quantize_and_save_per_token)(__global const INPUT0_TYPE* in_data,const uint in_data_offset,@@ -31,21 +34,38 @@ inline void FUNC(quantize_and_save_per_token)(__global const INPUT0_TYPE* in_dat// If the range of input data is zero, it is adjusted to the minimum value(0.001).#define ACCUMULATOR_TYPE floatACCUMULATOR_TYPE diff_value = max_value == min_value ? (grp_max) : (max_value - min_value);++ #if IS_INT4_COMPRESSED+ ACCUMULATOR_TYPE scale_tmp = (ACCUMULATOR_TYPE)((UINT4_RANGE) / diff_value);+ ACCUMULATOR_TYPE zp_tmp = (ACCUMULATOR_TYPE)(-min_value * scale_tmp);+ #elseACCUMULATOR_TYPE scale_tmp = (ACCUMULATOR_TYPE)((CHAR_MAX - CHAR_MIN) / diff_value);ACCUMULATOR_TYPE zp_tmp = (ACCUMULATOR_TYPE)(-min_value * scale_tmp) + CHAR_MIN;+ #endifINPUT0_TYPE scale = (INPUT1_TYPE)(scale_tmp);INPUT0_TYPE zp = (INPUT1_TYPE)(zp_tmp);+#undef ACCUMULATOR_TYPE- unroll_for (uint i = 0; i < num_groups; i++) {- OUTPUT_TYPE res = convert_char_rte(input_data[i] * scale + zp);+ #if IS_INT4_COMPRESSED+ char2 res_vec = 0;+ uint packed_offset[((K_HEAD_SIZE+V_HEAD_SIZE) / SUBGROUP_SIZE) / U4_ELEMS_PER_BYTE] = {0, };+ unroll_for (uint i = 0; i < num_groups; i+=U4_ELEMS_PER_BYTE) {+ res_vec.s0 = convert_char_rte(input_data[i] * scale + zp);+ res_vec.s1 = (i+1 < num_groups) ? convert_char_rte(input_data[i+1] * scale + zp) : 0;+ uint packed_output_offset = out_data_offset + ((i / U4_ELEMS_PER_BYTE) * SUBGROUP_SIZE + sglid) * out_data_pitch;+ out_data[packed_output_offset] = cvt_int8x2_to_uint4x2(res_vec);+ }+ #else // !IS_INT4_COMPRESSED+ unroll_for (uint i = 0; i < num_groups; i++) {+ OUTPUT_TYPE res = convert_char_rte(input_data[i] * scale + zp);- uint offset = out_data_offset + (i * SUBGROUP_SIZE + sglid) * out_data_pitch;- out_data[offset] = res;- }+ uint offset = out_data_offset + (i * SUBGROUP_SIZE + sglid) * out_data_pitch;+ out_data[offset] = res;+ }+ #endif // !IS_INT4_COMPRESSEDINPUT0_TYPE* comp_ptr = out_data + comp_offset;-if (sglid == 0) {comp_ptr[token_pos_in_block] = 1.0 / scale;comp_ptr[PAGED_ATTENTION_BLOCK_SIZE + token_pos_in_block] = zp;@@ -85,8 +105,8 @@ inline void FUNC(quantize_and_save_by_channel_block_with_requantize)(__global cofor (int j = 0; j < new_tokens_num; ++j) {INPUT0_TYPE new_token = BLOCK_READN(INPUT0_TYPE, 1, in_data, in_data_offset + j * K_HEAD_SIZE * KV_HEADS_NUM + hidden_idx);cache_data_vec_decompressed[token_pos_in_block + j] = new_token;- INPUT0_TYPE max_value = fmax(max_value, new_token);- INPUT0_TYPE min_value = fmin(min_value, new_token);+ max_value = fmax(max_value, new_token);+ min_value = fmin(min_value, new_token);}// Read a hidden dim of the previously quantized cache => decompress// TODO : current block size is 16 (same as PA block size),@@ -125,7 +145,156 @@ inline void FUNC(quantize_and_save_by_channel_block_with_requantize)(__global cocomp_ptr[0] = 1.0/scale;comp_ptr[1] = zp;}- }+ }+}++inline void FUNC(quantize_and_save_by_channel_block_with_requantize_int4)(__global const INPUT0_TYPE* in_data,+ const uint in_data_offset,+ const uint in_data_pitch,+ __global OUTPUT_TYPE* out_data,+ const uint out_data_offset,+ const uint out_data_pitch,+ const uint token_pos_in_block,+ const uint new_tokens_num,+ const uint sglid,+ const uint is_prefill_stage) {+ int head_size_offset = SUBGROUP_SIZE * get_group_id(2) * U4_ELEMS_PER_BYTE;+ int num_head_size_groups;+ if (is_prefill_stage) {+ num_head_size_groups = NUM_HEAD_SIZE_GROUPS;+ } else {+ // But INT4 work groups process U4_ELEMS_PER_BYTE partitions at a time, so multiply by U4_ELEMS_PER_BYTE+ num_head_size_groups = (NUM_HEAD_SIZE_GROUPS / NUM_K_HEAD_SIZE_PARTITIONS) * U4_ELEMS_PER_BYTE;+ if ((NUM_K_HEAD_SIZE_PARTITIONS % 2) != 0 && NUM_K_HEAD_SIZE_PARTITIONS > 1 &&+ get_group_id(2) == get_num_groups(2) - 1) {+ num_head_size_groups -= 1;+ }+ }++ int packed_head_size_offset = SUBGROUP_SIZE * (get_group_id(2));++ INPUT0_TYPE orig_scale[U4_ELEMS_PER_BYTE] = {0, };+ INPUT0_TYPE orig_zp[U4_ELEMS_PER_BYTE] = {0, };+ OUTPUT_TYPE orig_cache[ADJUSTED_PAGED_ATTENTION_BLOCK_SIZE] = {0, };++ INPUT0_TYPE scale[U4_ELEMS_PER_BYTE];+ INPUT0_TYPE zp[U4_ELEMS_PER_BYTE];+ OUTPUT_TYPE buffer[ADJUSTED_PAGED_ATTENTION_BLOCK_SIZE] = {0, };++ MAKE_VECTOR_TYPE(INPUT0_TYPE, 16) cache_data_vec_decompressed[NUM_HEAD_SIZE_GROUPS] = {0, };++ INPUT0_TYPE* prev_comp_ptr;+ for (int h_sub = 0; h_sub < num_head_size_groups; h_sub++) {+ const int hidden_idx = head_size_offset + h_sub * SUBGROUP_SIZE + sglid;++ // cache+ const uint order_in_packed = (h_sub % U4_ELEMS_PER_BYTE);+ const int packed_hidden_idx = packed_head_size_offset + (h_sub/U4_ELEMS_PER_BYTE) * SUBGROUP_SIZE + sglid;+ const uint packed_out_offset_per_wi = out_data_offset + packed_hidden_idx * out_data_pitch;++ // Read original scale and zp+ if (order_in_packed == 0) {+ INPUT0_TYPE* comp_ptr = (INPUT0_TYPE*) (&out_data[packed_out_offset_per_wi + COMP_K_OFFSET]);+ orig_scale[0] = comp_ptr[0];+ orig_zp[0] = comp_ptr[1];+ orig_scale[1] = comp_ptr[2];+ orig_zp[1] = comp_ptr[3];+ }+ INPUT0_TYPE max_value = INPUT0_VAL_MIN;+ INPUT0_TYPE min_value = INPUT0_VAL_MAX;++ // Read new input+ #define READ_SIZE 16+ #define OUT_DATA_VEC MAKE_VECTOR_TYPE(OUTPUT_TYPE, READ_SIZE)+ #define IN_DATA_VEC MAKE_VECTOR_TYPE(INPUT0_TYPE, READ_SIZE)+ #define VLOAD CAT(vload, READ_SIZE)++ for (int j = 0; j < new_tokens_num; ++j) {+ INPUT0_TYPE new_token = BLOCK_READN(INPUT0_TYPE, 1, in_data, in_data_offset + j * K_HEAD_SIZE * KV_HEADS_NUM + hidden_idx);++ cache_data_vec_decompressed[order_in_packed][token_pos_in_block + j] = new_token;++ max_value = fmax(max_value, new_token);+ min_value = fmin(min_value, new_token);+ }++ {+ // Read a hidden dim of the previously quantized cache => decompress+ // TODO : current block size is 16 (same as PA block size),+ // but when the block size becomes different, this part should be updated as well+ OUT_DATA_VEC prev_cache_data_vec;+ if (order_in_packed == 0)+ prev_cache_data_vec = VLOAD(0, out_data + packed_out_offset_per_wi);+ #undef READ_SIZE+ #undef VLOAD+ #undef DATA_VEC+ for (int j = 0; j < token_pos_in_block + new_tokens_num; ++j) {+ if (j < token_pos_in_block) {+ if (order_in_packed == 0) {+ // Generate cache_data_vec_decompressed[0~token_pos_in_block] from key-cache+ char temp = prev_cache_data_vec[j];+ MAKE_VECTOR_TYPE(char, U4_ELEMS_PER_BYTE) buff = unpack_to_char(*(uint4x2_t *)&temp);++ if (h_sub + 1 >= num_head_size_groups) {+ cache_data_vec_decompressed[0][j] = ((INPUT0_TYPE)buff.s0 - orig_zp[0]) * orig_scale[0];+ orig_cache[j] = buff.s1;+ } else {+ cache_data_vec_decompressed[0][j] = ((INPUT0_TYPE)buff.s0 - orig_zp[0]) * orig_scale[0];+ cache_data_vec_decompressed[1][j] = ((INPUT0_TYPE)buff.s1 - orig_zp[1]) * orig_scale[1];+ }+ }+ }+ max_value = fmax(max_value, cache_data_vec_decompressed[order_in_packed][j]);+ min_value = fmin(min_value, cache_data_vec_decompressed[order_in_packed][j]);+ }+ }++ // requantize and store+ {+ #define ACCUMULATOR_TYPE float+ ACCUMULATOR_TYPE range = (max_value == min_value) ? (0.001) : (max_value - min_value);+ const ACCUMULATOR_TYPE min_range = fabs(max_value * 0.1f);+ if (range <= min_range) {+ // When the range is very small, expand the range to avoid zp overflow+ range += fmax(1.0f, min_range);+ }++ ACCUMULATOR_TYPE scale_tmp = (ACCUMULATOR_TYPE)((UINT4_RANGE) / range);+ ACCUMULATOR_TYPE zp_tmp = (ACCUMULATOR_TYPE)(-min_value * scale_tmp);+ scale[order_in_packed] = (INPUT1_TYPE)(scale_tmp);+ zp[order_in_packed] = (INPUT1_TYPE)(zp_tmp);+ #undef ACCUMULATOR_TYPE++ INPUT0_TYPE* comp_ptr = (INPUT0_TYPE*) (&out_data[packed_out_offset_per_wi + COMP_K_OFFSET]);+ // [0,1] 1st scale and zp, [2,3] 2nd scale and zp. It represnets [PACKED_CACHE][Scale][ZP][Scale][ZP]+ comp_ptr[2*order_in_packed] = 1.0/scale[order_in_packed];+ comp_ptr[2*order_in_packed+1] = zp[order_in_packed];+ }++ if (order_in_packed == 0 && h_sub + 1 >= num_head_size_groups) {+ // NUM_HEAD_SIZE_GROUPS or number of processing groups of this partition is not aligned by U4_ELEMS_PER_BYTE.+ // This sub is the last and single size.+ for (uint token = 0; token < token_pos_in_block + new_tokens_num; ++token) {+ char2 res_vec = 0;+ res_vec.s0 = convert_char_rte(cache_data_vec_decompressed[0][token] * scale[0] + zp[0]);+ res_vec.s1 = orig_cache[token];+ out_data[packed_out_offset_per_wi + token] = cvt_int8x2_to_uint4x2(res_vec);+ }+ } else {+ // Process aligned size sub-group from num_head_size_groups+ for (uint token = 0; token < token_pos_in_block + new_tokens_num; ++token) {+ if (order_in_packed == (U4_ELEMS_PER_BYTE - 1)) {+ char2 res_vec;+ res_vec.s0 = buffer[token];+ res_vec.s1 = convert_char_rte(cache_data_vec_decompressed[1][token] * scale[1] + zp[1]);++ out_data[packed_out_offset_per_wi + token] = cvt_int8x2_to_uint4x2(res_vec);+ } else {+ buffer[token] = convert_char_rte(cache_data_vec_decompressed[0][token] * scale[0] + zp[0]);+ }+ }+ }+ }}inline void FUNC(quantize_and_save_by_channel_prefill)(__global const INPUT0_TYPE* in_data,@@ -137,6 +306,10 @@ inline void FUNC(quantize_and_save_by_channel_prefill)(__global const INPUT0_TYP//const uint token_start_pos_key,const uint sglid) {uint out_offset = out_data_offset;+ #if IS_INT4_COMPRESSED+ // store the rest of the pair+ OUTPUT_TYPE buffer[PAGED_ATTENTION_BLOCK_SIZE] = {0, };+ #endiffor (uint i = 0; i < NUM_HEAD_SIZE_GROUPS; i++) {uint key_in_offset_tmp = in_data_offset + i * SUBGROUP_SIZE;INPUT0_TYPE input_data[PAGED_ATTENTION_BLOCK_SIZE];@@ -150,33 +323,77 @@ inline void FUNC(quantize_and_save_by_channel_prefill)(__global const INPUT0_TYPkey_in_offset_tmp += in_data_pitch;}#define ACCUMULATOR_TYPE float- ACCUMULATOR_TYPE range = max_value - min_value;+ ACCUMULATOR_TYPE range = (max_value == min_value) ? (0.001) : (max_value - min_value);const ACCUMULATOR_TYPE min_range = fabs(max_value * 0.1f);if (range <= min_range) {// When the range is very small, expand the range to avoid zp overflowrange += fmax(1.0f, min_range);}- ACCUMULATOR_TYPE scale_tmp = (ACCUMULATOR_TYPE)((CHAR_MAX - CHAR_MIN) / range);- ACCUMULATOR_TYPE zp_tmp = (ACCUMULATOR_TYPE)(-min_value * scale_tmp) + CHAR_MIN;++ #if IS_INT4_COMPRESSED+ ACCUMULATOR_TYPE scale_tmp = (ACCUMULATOR_TYPE)((UINT4_RANGE) / range);+ ACCUMULATOR_TYPE zp_tmp = (ACCUMULATOR_TYPE)(-min_value * scale_tmp);+ #else+ ACCUMULATOR_TYPE scale_tmp = (ACCUMULATOR_TYPE)((CHAR_MAX - CHAR_MIN) / range);+ ACCUMULATOR_TYPE zp_tmp = (ACCUMULATOR_TYPE)(-min_value * scale_tmp) + CHAR_MIN;+ #endifINPUT0_TYPE scale = (INPUT1_TYPE)(scale_tmp);INPUT0_TYPE zp = (INPUT1_TYPE)(zp_tmp);#undef ACCUMULATOR_TYPE+// Quantize and save each hidden dimuint out_offset_per_wi = out_offset + sglid * ADJUSTED_PAGED_ATTENTION_BLOCK_SIZE;// store comp_dataINPUT0_TYPE* comp_ptr = (INPUT0_TYPE*) (&out_data[out_offset_per_wi + COMP_K_OFFSET]);- comp_ptr[0] = 1.0 / scale;- comp_ptr[1] = zp;++ #if IS_INT4_COMPRESSED+ const uint order_in_packed = i % U4_ELEMS_PER_BYTE;+ comp_ptr[2 * order_in_packed] = 1.0 / scale;+ comp_ptr[2 * order_in_packed + 1] = zp;+ #else+ comp_ptr[0] = 1.0 / scale;+ comp_ptr[1] = zp;+ #endif+// Store quantized key- for (uint token_num = 0; token_num < tokens_num; token_num++) {- OUTPUT_TYPE res = convert_char_rte(input_data[token_num] * scale + zp);- out_data[out_offset_per_wi] = res;- out_offset_per_wi++;- }- out_offset += ADJUSTED_PAGED_ATTENTION_BLOCK_SIZE * SUBGROUP_SIZE;+ #if IS_INT4_COMPRESSED+ for (uint token_num = 0; token_num < tokens_num; token_num++) {+ if (order_in_packed == (U4_ELEMS_PER_BYTE - 1)) {+ char2 res_vec = 0;+ res_vec.s0 = buffer[token_num];+ res_vec.s1 = convert_char_rte(input_data[token_num] * scale + zp);+ out_data[out_offset_per_wi] = cvt_int8x2_to_uint4x2(res_vec);++ out_offset_per_wi++;+ } else {+ buffer[token_num] = convert_char_rte(input_data[token_num] * scale + zp);++ if (i + 1 >= NUM_HEAD_SIZE_GROUPS) {+ char2 res_vec = 0;+ res_vec.s0 = buffer[token_num];+ res_vec.s1 = 0;++ out_data[out_offset_per_wi] = cvt_int8x2_to_uint4x2(res_vec);+ out_offset_per_wi++;+ }+ }+ }++ if (order_in_packed == (U4_ELEMS_PER_BYTE - 1)) {+ out_offset += (ADJUSTED_PAGED_ATTENTION_BLOCK_SIZE * SUBGROUP_SIZE);+ }+ #else+ for (uint token_num = 0; token_num < tokens_num; token_num++) {+ OUTPUT_TYPE res = convert_char_rte(input_data[token_num] * scale + zp);+ out_data[out_offset_per_wi] = res;++ out_offset_per_wi++;+ }+ out_offset += ADJUSTED_PAGED_ATTENTION_BLOCK_SIZE * SUBGROUP_SIZE;+ #endif}}-#endif+#endif // IS_KEY_BY_CHANNELREQD_SUB_GROUP_SIZE(SUBGROUP_SIZE)__attribute__((reqd_work_group_size(1, 1, SUBGROUP_SIZE)))@@ -202,6 +419,19 @@ KERNEL(pa_kv_cache_update)(#ifdef IS_KEY_BY_CHANNELconst int k_hidden_stride = ADJUSTED_PAGED_ATTENTION_BLOCK_SIZE;#endif++#if IS_INT4_COMPRESSED+ const uint phys_adjusted_k_head_size = PACKED_ADJUSTED_K_HEAD_SIZE;+ const uint phys_adjusted_v_head_size = PACKED_ADJUSTED_V_HEAD_SIZE;+ const uint phys_k_head_size = PACKED_K_HEAD_SIZE;+ const uint phys_v_head_size = PACKED_V_HEAD_SIZE;+#else+ const uint phys_adjusted_k_head_size = ADJUSTED_K_HEAD_SIZE;+ const uint phys_adjusted_v_head_size = ADJUSTED_V_HEAD_SIZE;+ const uint phys_k_head_size = K_HEAD_SIZE;+ const uint phys_v_head_size = V_HEAD_SIZE;+#endif+if (!is_prefill_stage) {// 2nd+ tokenconst uint seq_idx = (uint)get_global_id(0);@@ -212,17 +442,19 @@ KERNEL(pa_kv_cache_update)(const uint current_token_pos_in_block = past_seq_len % PAGED_ATTENTION_BLOCK_SIZE;const uint seq_block_idx = block_indices_begins[seq_idx] + past_seq_len / PAGED_ATTENTION_BLOCK_SIZE;const uint block_idx = block_indices[seq_block_idx];+uint key_in_offset = INPUT0_OFFSET + seq_idx * KEY_IN_STRIDE + head_idx * K_HEAD_SIZE;uint value_in_offset = INPUT1_OFFSET + seq_idx * VAL_IN_STRIDE + head_idx * V_HEAD_SIZE;#ifdef IS_KEY_BY_CHANNEL- uint block_k_base_offset = block_idx * KV_HEADS_NUM * ADJUSTED_K_HEAD_SIZE * ADJUSTED_PAGED_ATTENTION_BLOCK_SIZE + head_idx * ADJUSTED_K_HEAD_SIZE * ADJUSTED_PAGED_ATTENTION_BLOCK_SIZE;+ uint block_k_base_offset = block_idx * KV_HEADS_NUM * phys_adjusted_k_head_size * ADJUSTED_PAGED_ATTENTION_BLOCK_SIZE + head_idx * phys_adjusted_k_head_size * ADJUSTED_PAGED_ATTENTION_BLOCK_SIZE;#else // can it be shared?- uint block_k_base_offset = block_idx * KV_HEADS_NUM * ADJUSTED_K_HEAD_SIZE * PAGED_ATTENTION_BLOCK_SIZE + head_idx * ADJUSTED_K_HEAD_SIZE * PAGED_ATTENTION_BLOCK_SIZE;+ uint block_k_base_offset = block_idx * KV_HEADS_NUM * phys_adjusted_k_head_size * PAGED_ATTENTION_BLOCK_SIZE + head_idx * phys_adjusted_k_head_size * PAGED_ATTENTION_BLOCK_SIZE;#endif- uint block_v_base_offset = block_idx * KV_HEADS_NUM * ADJUSTED_V_HEAD_SIZE * PAGED_ATTENTION_BLOCK_SIZE + head_idx * ADJUSTED_V_HEAD_SIZE * PAGED_ATTENTION_BLOCK_SIZE;+ uint block_v_base_offset = block_idx * KV_HEADS_NUM * phys_adjusted_v_head_size * PAGED_ATTENTION_BLOCK_SIZE + head_idx * phys_adjusted_v_head_size * PAGED_ATTENTION_BLOCK_SIZE;uint key_out_offset = block_k_base_offset + current_token_pos_in_block;- uint value_out_offset = block_v_base_offset + current_token_pos_in_block * V_HEAD_SIZE;+ uint value_out_offset = block_v_base_offset + current_token_pos_in_block * phys_v_head_size;+#if !IS_KV_COMPRESSED#define READ_K_BLOCK_SIZE GENERATE_STAGE_K_BLOCK_SIZEfor (uint head_idx_index = 0; head_idx_index < K_HEAD_SIZE; head_idx_index += SUBGROUP_SIZE * READ_K_BLOCK_SIZE) {@@ -261,20 +493,25 @@ KERNEL(pa_kv_cache_update)(#ifdef IS_KEY_BY_CHANNEL// key by channel{- FUNC_CALL(quantize_and_save_by_channel_block_with_requantize)(key_data,- key_in_offset,- KEY_IN_STRIDE,- key_cache_data,- block_k_base_offset,- k_hidden_stride,- current_token_pos_in_block,- 1,- sglid,- 0);+ #if IS_INT4_COMPRESSED+ FUNC_CALL(quantize_and_save_by_channel_block_with_requantize_int4)(key_data,+ #else+ FUNC_CALL(quantize_and_save_by_channel_block_with_requantize)(key_data,+ #endif+ key_in_offset,+ KEY_IN_STRIDE,+ key_cache_data,+ block_k_base_offset,+ k_hidden_stride,+ current_token_pos_in_block,+ 1,+ sglid,+ 0);}+// value per tokenif (get_group_id(2) == 0) {- const uint comp_v_offset = block_v_base_offset + V_HEAD_SIZE * PAGED_ATTENTION_BLOCK_SIZE;+ const uint comp_v_offset = block_v_base_offset + phys_v_head_size * PAGED_ATTENTION_BLOCK_SIZE;INPUT0_TYPE input_data[V_HEAD_SIZE / SUBGROUP_SIZE];FUNC_CALL(quantize_and_save_per_token)(value_data, value_in_offset, value_cache_data, value_out_offset, 1, comp_v_offset,current_token_pos_in_block, sglid, V_HEAD_SIZE / SUBGROUP_SIZE, &input_data[0]);@@ -282,27 +519,25 @@ KERNEL(pa_kv_cache_update)(#else// IS_KEY_BY_CHANNEL false{- const uint comp_k_offset = block_k_base_offset + K_HEAD_SIZE * PAGED_ATTENTION_BLOCK_SIZE;+ const uint comp_k_offset = block_k_base_offset + phys_k_head_size * PAGED_ATTENTION_BLOCK_SIZE;// key processing- INPUT0_TYPE input_data[K_HEAD_SIZE / SUBGROUP_SIZE];+ INPUT0_TYPE input_k_data[K_HEAD_SIZE / SUBGROUP_SIZE];FUNC_CALL(quantize_and_save_per_token)(key_data, key_in_offset, key_cache_data, key_out_offset, PAGED_ATTENTION_BLOCK_SIZE, comp_k_offset,- current_token_pos_in_block, sglid, K_HEAD_SIZE / SUBGROUP_SIZE, &input_data[0]);- }- {- const uint comp_v_offset = block_v_base_offset + V_HEAD_SIZE * PAGED_ATTENTION_BLOCK_SIZE;- INPUT0_TYPE input_data[V_HEAD_SIZE / SUBGROUP_SIZE];+ current_token_pos_in_block, sglid, K_HEAD_SIZE / SUBGROUP_SIZE, &input_k_data[0]);++ const uint comp_v_offset = block_v_base_offset + phys_v_head_size * PAGED_ATTENTION_BLOCK_SIZE;+ INPUT0_TYPE input_v_data[V_HEAD_SIZE / SUBGROUP_SIZE];FUNC_CALL(quantize_and_save_per_token)(value_data, value_in_offset, value_cache_data, value_out_offset, 1, comp_v_offset,- current_token_pos_in_block, sglid, V_HEAD_SIZE / SUBGROUP_SIZE, &input_data[0]);+ current_token_pos_in_block, sglid, V_HEAD_SIZE / SUBGROUP_SIZE, &input_v_data[0]);}#endif#endif // IS_KV_COMPRESSED} else {-// 1st tokenconst uint block_idx = get_global_id(0);const uint head_idx = get_global_id(1);const uint sglid = get_global_id(2);-+const uint subsequence_idx = gws_seq_indexes_correspondence[block_idx];const uint subsequence_begin_idx = subsequence_begins[subsequence_idx];@@ -322,29 +557,34 @@ KERNEL(pa_kv_cache_update)(const uint block_offset = block_indices_begins[subsequence_idx] + current_block_idx;#if defined(IS_KV_COMPRESSED) && defined(IS_KEY_BY_CHANNEL)- uint block_k_base_offset = block_indices[block_offset] * KV_HEADS_NUM * ADJUSTED_K_HEAD_SIZE * ADJUSTED_PAGED_ATTENTION_BLOCK_SIZE +- head_idx * ADJUSTED_K_HEAD_SIZE * ADJUSTED_PAGED_ATTENTION_BLOCK_SIZE;- uint key_out_offset = block_k_base_offset;+ uint block_k_base_offset = block_indices[block_offset] * KV_HEADS_NUM * phys_adjusted_k_head_size * ADJUSTED_PAGED_ATTENTION_BLOCK_SIZE ++ head_idx * phys_adjusted_k_head_size * ADJUSTED_PAGED_ATTENTION_BLOCK_SIZE;+ uint key_out_offset = block_k_base_offset;#else- uint block_k_base_offset = block_indices[block_offset] * KV_HEADS_NUM * ADJUSTED_K_HEAD_SIZE * PAGED_ATTENTION_BLOCK_SIZE +- head_idx * ADJUSTED_K_HEAD_SIZE * PAGED_ATTENTION_BLOCK_SIZE;- uint key_out_offset = block_k_base_offset;- const uint comp_k_offset = block_k_base_offset + K_HEAD_SIZE * PAGED_ATTENTION_BLOCK_SIZE;- key_out_offset += token_start_pos_key;+ uint block_k_base_offset = block_indices[block_offset] * KV_HEADS_NUM * phys_adjusted_k_head_size * PAGED_ATTENTION_BLOCK_SIZE ++ head_idx * phys_adjusted_k_head_size * PAGED_ATTENTION_BLOCK_SIZE;+ uint key_out_offset = block_k_base_offset;+ const uint comp_k_offset = block_k_base_offset + phys_k_head_size * PAGED_ATTENTION_BLOCK_SIZE;+ key_out_offset += token_start_pos_key;#endif- uint block_v_base_offset = block_indices[block_offset] * KV_HEADS_NUM * ADJUSTED_V_HEAD_SIZE * PAGED_ATTENTION_BLOCK_SIZE +- head_idx * ADJUSTED_V_HEAD_SIZE * PAGED_ATTENTION_BLOCK_SIZE;- const uint comp_v_offset = block_v_base_offset + V_HEAD_SIZE * PAGED_ATTENTION_BLOCK_SIZE;+ uint block_v_base_offset = block_indices[block_offset] * KV_HEADS_NUM * phys_adjusted_v_head_size * PAGED_ATTENTION_BLOCK_SIZE ++ head_idx * phys_adjusted_v_head_size * PAGED_ATTENTION_BLOCK_SIZE;+ const uint comp_v_offset = block_v_base_offset + phys_v_head_size * PAGED_ATTENTION_BLOCK_SIZE;uint value_out_offset = block_v_base_offset;- value_out_offset += token_start_pos_val * V_HEAD_SIZE;+ value_out_offset += token_start_pos_val * phys_v_head_size;+if (tokens_num == PAGED_ATTENTION_BLOCK_SIZE) {// block is full#if defined(IS_KV_COMPRESSED) && defined(IS_KEY_BY_CHANNEL)// Key by channelif (token_start_pos_key != 0) {// mixed mode => need requantize with prev tokens+ #if IS_INT4_COMPRESSED+ FUNC_CALL(quantize_and_save_by_channel_block_with_requantize_int4)(key_data,+ #elseFUNC_CALL(quantize_and_save_by_channel_block_with_requantize)(key_data,+ #endifkey_in_offset,KEY_IN_STRIDE,key_cache_data,@@ -369,9 +609,9 @@ KERNEL(pa_kv_cache_update)(FUNC_CALL(quantize_and_save_per_token)(value_data, value_in_offset, value_cache_data, value_out_offset, 1,comp_v_offset, token_num, sglid, V_HEAD_SIZE / SUBGROUP_SIZE, &input_data[0]);value_in_offset += (KV_HEADS_NUM * V_HEAD_SIZE + INPUT1_PAD_AFTER_FEATURE_NUM + INPUT1_PAD_BEFORE_FEATURE_NUM);- value_out_offset += V_HEAD_SIZE;+ value_out_offset += phys_v_head_size;}- #else // defined(IS_KV_COMPRESSED) && defined(IS_KEY_BY_CHANNEL)+ #else // !(defined(IS_KV_COMPRESSED) && defined(IS_KEY_BY_CHANNEL))unroll_for (uint token_num = 0; token_num < PAGED_ATTENTION_BLOCK_SIZE; token_num++) {#if !IS_KV_COMPRESSED{@@ -489,30 +729,32 @@ KERNEL(pa_kv_cache_update)(#else // IS_KV_COMPRESSED{// Key per token- INPUT0_TYPE input_data[K_HEAD_SIZE / SUBGROUP_SIZE];+ INPUT0_TYPE input_k_data[K_HEAD_SIZE / SUBGROUP_SIZE];FUNC_CALL(quantize_and_save_per_token)(key_data, key_in_offset, key_cache_data, key_out_offset, PAGED_ATTENTION_BLOCK_SIZE,- comp_k_offset, token_num, sglid, K_HEAD_SIZE / SUBGROUP_SIZE, &input_data[0]);- }- {+ comp_k_offset, token_num, sglid, K_HEAD_SIZE / SUBGROUP_SIZE, &input_k_data[0]);+// Value per token- INPUT0_TYPE input_data[V_HEAD_SIZE / SUBGROUP_SIZE];+ INPUT0_TYPE input_v_data[V_HEAD_SIZE / SUBGROUP_SIZE];FUNC_CALL(quantize_and_save_per_token)(value_data, value_in_offset, value_cache_data, value_out_offset, 1,- comp_v_offset, token_num, sglid, V_HEAD_SIZE / SUBGROUP_SIZE, &input_data[0]);+ comp_v_offset, token_num, sglid, V_HEAD_SIZE / SUBGROUP_SIZE, &input_v_data[0]);}#endif // IS_KV_COMPRESSEDkey_in_offset += (KV_HEADS_NUM * K_HEAD_SIZE + INPUT0_PAD_AFTER_FEATURE_NUM + INPUT0_PAD_BEFORE_FEATURE_NUM);key_out_offset += 1;value_in_offset += (KV_HEADS_NUM * V_HEAD_SIZE + INPUT1_PAD_AFTER_FEATURE_NUM + INPUT1_PAD_BEFORE_FEATURE_NUM);- value_out_offset += V_HEAD_SIZE;+ value_out_offset += phys_v_head_size;}- #endif // defined(IS_KV_COMPRESSED) && defined(IS_KEY_BY_CHANNEL)+ #endif // !(defined(IS_KV_COMPRESSED) && defined(IS_KEY_BY_CHANNEL))} else {- // block with leftover tokens#if defined(IS_KV_COMPRESSED) && defined(IS_KEY_BY_CHANNEL)// key processing by channelif (token_start_pos_key != 0) {// mixed mode => need requantize with prev tokens+ #if IS_INT4_COMPRESSED+ FUNC_CALL(quantize_and_save_by_channel_block_with_requantize_int4)(key_data,+ #elseFUNC_CALL(quantize_and_save_by_channel_block_with_requantize)(key_data,+ #endifkey_in_offset,KEY_IN_STRIDE,key_cache_data,@@ -538,7 +780,7 @@ KERNEL(pa_kv_cache_update)(FUNC_CALL(quantize_and_save_per_token)(value_data, value_in_offset, value_cache_data, value_out_offset, 1,comp_v_offset, token_start_pos_val + token_num, sglid, V_HEAD_SIZE / SUBGROUP_SIZE, &input_data[0]);value_in_offset += (KV_HEADS_NUM * V_HEAD_SIZE + INPUT1_PAD_AFTER_FEATURE_NUM + INPUT1_PAD_BEFORE_FEATURE_NUM);- value_out_offset += V_HEAD_SIZE;+ value_out_offset += phys_v_head_size;}#else // defined(IS_KV_COMPRESSED) && defined(IS_KEY_BY_CHANNEL)for (uint token_num = 0; token_num < tokens_num; token_num++) {@@ -569,21 +811,20 @@ KERNEL(pa_kv_cache_update)(#else // IS_KV_COMPRESSED{// key processing- INPUT0_TYPE input_data[K_HEAD_SIZE / SUBGROUP_SIZE];+ INPUT0_TYPE input_k_data[K_HEAD_SIZE / SUBGROUP_SIZE];FUNC_CALL(quantize_and_save_per_token)(key_data, key_in_offset, key_cache_data, key_out_offset, PAGED_ATTENTION_BLOCK_SIZE,- comp_k_offset, token_start_pos_key + token_num, sglid, K_HEAD_SIZE / SUBGROUP_SIZE, &input_data[0]);- }- {+ comp_k_offset, token_start_pos_key + token_num, sglid, K_HEAD_SIZE / SUBGROUP_SIZE, &input_k_data[0]);+// value processing- INPUT0_TYPE input_data[V_HEAD_SIZE / SUBGROUP_SIZE];+ INPUT0_TYPE input_v_data[V_HEAD_SIZE / SUBGROUP_SIZE];FUNC_CALL(quantize_and_save_per_token)(value_data, value_in_offset, value_cache_data, value_out_offset, 1,- comp_v_offset, token_start_pos_val + token_num, sglid, V_HEAD_SIZE / SUBGROUP_SIZE, &input_data[0]);+ comp_v_offset, token_start_pos_val + token_num, sglid, V_HEAD_SIZE / SUBGROUP_SIZE, &input_v_data[0]);}#endif // IS_KV_COMPRESSEDkey_in_offset += (KV_HEADS_NUM * K_HEAD_SIZE + INPUT0_PAD_AFTER_FEATURE_NUM + INPUT0_PAD_BEFORE_FEATURE_NUM);key_out_offset += 1;value_in_offset += (KV_HEADS_NUM * V_HEAD_SIZE + INPUT1_PAD_AFTER_FEATURE_NUM + INPUT1_PAD_BEFORE_FEATURE_NUM);- value_out_offset += V_HEAD_SIZE;+ value_out_offset += phys_v_head_size;}#endif // defined(IS_KV_COMPRESSED) && defined(IS_KEY_BY_CHANNEL)}diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/paged_attention_opt.cl b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/paged_attention_opt.clindex 336b83d6475..865acb6fa3d 100644--- a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/paged_attention_opt.cl+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/paged_attention_opt.cl@@ -3,6 +3,7 @@//#include "include/batch_headers/common.cl"+#include "include/batch_headers/int4_utils.cl"#include "include/batch_headers/sub_group_block_read.cl"#include "include/batch_headers/sub_group_block_write.cl"#include "include/batch_headers/sub_group_shuffle.cl"@@ -129,6 +130,20 @@ KERNEL(pa_sdpa_opt)(#error "pa_sdpa_opt.cl: Unsupported scale factor"#endif+#if IS_INT4_COMPRESSED+ const uint phys_adjusted_k_head_size = PACKED_ADJUSTED_K_HEAD_SIZE;+ const uint phys_adjusted_v_head_size = PACKED_ADJUSTED_V_HEAD_SIZE;+ const uint phys_k_head_size = PACKED_K_HEAD_SIZE;+ const uint phys_v_head_size = PACKED_V_HEAD_SIZE;+#else+ const uint phys_adjusted_k_head_size = ADJUSTED_K_HEAD_SIZE;+ const uint phys_adjusted_v_head_size = ADJUSTED_V_HEAD_SIZE;+ const uint phys_k_head_size = K_HEAD_SIZE;+ const uint phys_v_head_size = V_HEAD_SIZE;+#endif++ const uint batch_idx = seq_idx;+#if MULTI_TOKENS_PROCESSINGconst int subsequence_idx = gws_subseq_mapping[seq_idx];const int subsequence_begin = subsequence_begins[subsequence_idx];@@ -191,6 +206,7 @@ KERNEL(pa_sdpa_opt)(barrier(CLK_LOCAL_MEM_FENCE);#else // !STORE_QUERY_TO_SLM+INPUT0_TYPE q_val[K_HEAD_SIZE / SUBGROUP_SIZE];unroll_for (uint i = 0; i < K_HEAD_SIZE / SUBGROUP_SIZE; i++) {const uint query_idx = INPUT0_OFFSET +@@ -225,15 +241,15 @@ KERNEL(pa_sdpa_opt)(#define KEY_BLOCK MAKE_VECTOR_TYPE(INPUT1_TYPE, KEY_VEC_SIZE)#if IS_KV_COMPRESSED#ifdef IS_KEY_BY_CHANNEL- const uint head_stride = ADJUSTED_K_HEAD_SIZE * ADJUSTED_PAGED_ATTENTION_BLOCK_SIZE;+ const uint head_stride = phys_adjusted_k_head_size * ADJUSTED_PAGED_ATTENTION_BLOCK_SIZE;const uint block_stride = KV_HEADS_NUM * head_stride;const uint key_block_offset = block_indice * block_stride + head_idx * head_stride;const uint hidden_stride = ADJUSTED_PAGED_ATTENTION_BLOCK_SIZE;#else- const uint block_offset = block_indice * ADJUSTED_K_HEAD_SIZE * KV_HEADS_NUM * SUBGROUP_SIZE + head_idx * ADJUSTED_K_HEAD_SIZE * SUBGROUP_SIZE;+ const uint block_offset = block_indice * phys_adjusted_k_head_size * KV_HEADS_NUM * SUBGROUP_SIZE + head_idx * phys_adjusted_k_head_size * SUBGROUP_SIZE;const uint key_block_offset = block_offset;const uint hidden_stride = SUBGROUP_SIZE;- const uint key_comp_offset = key_block_offset + K_HEAD_SIZE * PAGED_ATTENTION_BLOCK_SIZE;+ const uint key_comp_offset = key_block_offset + phys_k_head_size * PAGED_ATTENTION_BLOCK_SIZE;INPUT0_TYPE* key_comp_ptr = key_cache + key_comp_offset;INPUT0_TYPE comp_scale = key_comp_ptr[0 + sglid];INPUT0_TYPE comp_zp = key_comp_ptr[PAGED_ATTENTION_BLOCK_SIZE + sglid];@@ -242,6 +258,71 @@ KERNEL(pa_sdpa_opt)(const uint block_offset = block_indice * ADJUSTED_K_HEAD_SIZE * KV_HEADS_NUM * SUBGROUP_SIZE + head_idx * ADJUSTED_K_HEAD_SIZE * SUBGROUP_SIZE;#endif+ // Loop for qk_index+#if IS_KV_COMPRESSED && IS_INT4_COMPRESSED+ MAKE_VECTOR_TYPE(INPUT0_TYPE, KEY_VEC_SIZE) k_vals[K_HEAD_SIZE / KEY_VEC_SIZE];++ unroll_for (uint qk_idx = 0; qk_idx < (K_HEAD_SIZE / KEY_VEC_SIZE); qk_idx+=U4_ELEMS_PER_BYTE) {+ #ifdef IS_KEY_BY_CHANNEL+ INPUT0_TYPE comp_scale[U4_ELEMS_PER_BYTE] = {0, };+ INPUT0_TYPE comp_zp[U4_ELEMS_PER_BYTE] = {0, };++ uint key_comp_offset = key_block_offset + (qk_idx / U4_ELEMS_PER_BYTE) * SUBGROUP_SIZE * hidden_stride + sglid * hidden_stride + PAGED_ATTENTION_BLOCK_SIZE;+ INPUT0_TYPE* key_comp_ptr = key_cache + key_comp_offset;+ comp_scale[0] = key_comp_ptr[0];+ comp_zp[0] = key_comp_ptr[1];+ comp_scale[1] = key_comp_ptr[2];+ comp_zp[1] = key_comp_ptr[3];+ #endif++ uint init_index = key_block_offset + 0 * hidden_stride * KEY_VEC_SIZE;+ unroll_for (uint i = 0; i < KEY_VEC_SIZE; i++) {+ uint index = key_block_offset + (qk_idx/U4_ELEMS_PER_BYTE) * hidden_stride * KEY_VEC_SIZE + i * hidden_stride;++ char packed_cache = BLOCK_READN(INPUT1_TYPE, 1, key_cache, index);+ MAKE_VECTOR_TYPE(char, U4_ELEMS_PER_BYTE) buff = unpack_to_char(*(uint4x2_t *)&packed_cache);++ char key_orig = buff.s0;+ #ifdef IS_KEY_BY_CHANNEL+ INPUT0_TYPE first_scale = sub_group_shuffle(comp_scale[0], i);+ INPUT0_TYPE second_scale = sub_group_shuffle(comp_scale[1], i);+ INPUT0_TYPE first_zp = sub_group_shuffle(comp_zp[0], i);+ INPUT0_TYPE second_zp = sub_group_shuffle(comp_zp[1], i);+ k_vals[qk_idx][i] = ((INPUT0_TYPE)key_orig - first_zp) * first_scale;+ if (qk_idx + 1 < (K_HEAD_SIZE / KEY_VEC_SIZE)) {+ key_orig = buff.s1;+ k_vals[qk_idx+1][i] = ((INPUT0_TYPE)key_orig - second_zp) * second_scale;+ }+ #else+ k_vals[qk_idx][i] = ((INPUT0_TYPE)key_orig - comp_zp) * comp_scale;+ if (qk_idx + 1 < (K_HEAD_SIZE / KEY_VEC_SIZE)) {+ key_orig = buff.s1;+ k_vals[qk_idx+1][i] = ((INPUT0_TYPE)key_orig - comp_zp) * comp_scale;+ }+ #endif+ }+ }++ #if STORE_QUERY_TO_SLM+ unroll_for (uint qk_idx = 0; qk_idx < K_HEAD_SIZE / KEY_VEC_SIZE; qk_idx++) {+ unroll_for (uint q_idx = 0; q_idx < QUERIES_PER_WI; q_idx++) {+ SOFTMAX_ACCUMULATOR_TYPE q_val = slm_query[q_idx * K_HEAD_SIZE + qk_idx * KEY_VEC_SIZE + sglid];+ unroll_for (uint i = 0; i < KEY_VEC_SIZE; i++) {+ GET_VECTOR_ELEMENT(qk_acc, q_idx) = mad(sub_group_broadcast(q_val, i), TO_SOFTMAX_ACCUMULATOR_TYPE(k_vals[qk_idx][i]), GET_VECTOR_ELEMENT(qk_acc, q_idx));+ }+ }+ }+ #else+ unroll_for (uint qk_idx = 0; qk_idx < K_HEAD_SIZE / KEY_VEC_SIZE; qk_idx++) {+ unroll_for (uint q_idx = 0; q_idx < QUERIES_PER_WI; q_idx++) {+ unroll_for (uint i = 0; i < KEY_VEC_SIZE; i++) {+ qk_acc = mad(TO_SOFTMAX_ACCUMULATOR_TYPE(sub_group_broadcast(q_val[qk_idx], i)), TO_SOFTMAX_ACCUMULATOR_TYPE(k_vals[qk_idx][i]), qk_acc);+ }+ }+ }+ #endif++#else // !(IS_KV_COMPRESSED && IS_INT4_COMPRESSED)#define KEY_BLOCK_UNCOMPRESSED MAKE_VECTOR_TYPE(INPUT0_TYPE, KEY_VEC_SIZE)#ifdef DISABLE_QK_LOOP_UNROLLfor (uint qk_idx = 0; qk_idx < K_HEAD_SIZE / KEY_VEC_SIZE; qk_idx++) {@@ -250,28 +331,29 @@ KERNEL(pa_sdpa_opt)(#endif#if IS_KV_COMPRESSED- #ifdef IS_KEY_BY_CHANNEL- const uint key_comp_offset = key_block_offset + qk_idx * SUBGROUP_SIZE * hidden_stride + sglid * hidden_stride + PAGED_ATTENTION_BLOCK_SIZE;- INPUT0_TYPE* key_comp_ptr = key_cache + key_comp_offset;- INPUT0_TYPE comp_scale = key_comp_ptr[0];- INPUT0_TYPE comp_zp = key_comp_ptr[1];+ #ifdef IS_KEY_BY_CHANNEL+ const uint key_comp_offset = key_block_offset + qk_idx * SUBGROUP_SIZE * hidden_stride + sglid * hidden_stride + PAGED_ATTENTION_BLOCK_SIZE;+ INPUT0_TYPE* key_comp_ptr = key_cache + key_comp_offset;+ INPUT0_TYPE comp_scale = key_comp_ptr[0];+ INPUT0_TYPE comp_zp = key_comp_ptr[1];#endifKEY_BLOCK_UNCOMPRESSED k_vals;+ uint init_index = key_block_offset + 0 * hidden_stride * KEY_VEC_SIZE;unroll_for (uint i = 0; i < KEY_VEC_SIZE; i++) {k_vals[i] = BLOCK_READN(INPUT1_TYPE, 1, key_cache, key_block_offset + qk_idx * hidden_stride * KEY_VEC_SIZE + i * hidden_stride);- #ifdef IS_KEY_BY_CHANNEL- k_vals[i] = (k_vals[i] - _sub_group_shuffle(comp_zp, i)) * _sub_group_shuffle(comp_scale, i);+ #ifdef IS_KEY_BY_CHANNEL+ k_vals[i] = ((INPUT0_TYPE)k_vals[i] - _sub_group_shuffle(comp_zp, i)) * _sub_group_shuffle(comp_scale, i);#elsek_vals[i] = (k_vals[i] - comp_zp) * comp_scale;#endif}-#else+#else // !IS_KV_COMPRESSEDKEY_BLOCK k_vals = 0;unroll_for (uint i = 0; i < KEY_VEC_SIZE; i++) {k_vals[i] = BLOCK_READN(INPUT1_TYPE, 1, key_cache, block_offset + qk_idx * SUBGROUP_SIZE * KEY_VEC_SIZE + i * SUBGROUP_SIZE);}-#endif+#endif // !IS_KV_COMPRESSED#if XE2_QK_MULTIPLICATION#if STORE_QUERY_TO_SLM@@ -306,6 +388,7 @@ KERNEL(pa_sdpa_opt)(}#endif // XE2_QK_MULTIPLICATION}+#endif // !(IS_KV_COMPRESSED && IS_INT4_COMPRESSED)const uint token_idx = partition_idx * SEQ_LEN_PARTITION_SIZE + block_num * SUBGROUPS_PER_WG * SUBGROUP_SIZE + sgid * SUBGROUP_SIZE + sglid;@@ -523,13 +606,19 @@ KERNEL(pa_sdpa_opt)(for (uint block_num = block_start_idx; block_num < block_end_idx; block_num++) {const uint head_idx = head_num_idx / KV_HEADS_GROUP_SIZE;const uint block_offset = block_indices[start_block_idx + block_num] * KV_HEADS_NUM * ADJUSTED_V_HEAD_SIZE * PAGED_ATTENTION_BLOCK_SIZE + head_idx * ADJUSTED_V_HEAD_SIZE * PAGED_ATTENTION_BLOCK_SIZE;+const uint value_offset = block_offset + head_size_idx;#if IS_KV_COMPRESSED- const uint value_comp_offset = block_offset + V_HEAD_SIZE * PAGED_ATTENTION_BLOCK_SIZE;+ const uint packed_block_offset = block_indices[start_block_idx + block_num] * KV_HEADS_NUM * phys_adjusted_v_head_size * PAGED_ATTENTION_BLOCK_SIZE+ + head_idx * phys_adjusted_v_head_size * PAGED_ATTENTION_BLOCK_SIZE;+ const uint head_size_offset = ((head_size_idx / SUBGROUP_SIZE) / U4_ELEMS_PER_BYTE) * SUBGROUP_SIZE + (head_size_idx % SUBGROUP_SIZE);+ const uint packed_value_offset = packed_block_offset + head_size_offset;+ const uint value_comp_offset = packed_block_offset + phys_v_head_size * PAGED_ATTENTION_BLOCK_SIZE;INPUT0_TYPE* value_comp_ptr = value_cache + value_comp_offset;INPUT0_TYPE comp_scale = value_comp_ptr[0 + sglid];INPUT0_TYPE comp_zp = value_comp_ptr[PAGED_ATTENTION_BLOCK_SIZE + sglid];+#endif#define VALUE_VEC_SIZE SUBGROUP_SIZE@@ -538,10 +627,30 @@ KERNEL(pa_sdpa_opt)(#define VALUE_BLOCK_UNCOMPRESSED MAKE_VECTOR_TYPE(INPUT0_TYPE, VALUE_VEC_SIZE)#define TO_VALUE_UNCOMPRESSED_TYPE(val) CAT(convert_, VALUE_UNCOMPRESSED)(val)++#if IS_KV_COMPRESSED && IS_INT4_COMPRESSED+ // INT4 compression for value-cache+ const uint idx_packed = (head_size_idx / SUBGROUP_SIZE) % U4_ELEMS_PER_BYTE;+ VALUE_BLOCK v_vals_packed;++ unroll_for (uint i = 0; i < VALUE_VEC_SIZE; i++) {+ uint index = packed_value_offset + i * phys_v_head_size;+ char packed_value = BLOCK_READN(INPUT2_TYPE, 1, value_cache, index);+ MAKE_VECTOR_TYPE(char, U4_ELEMS_PER_BYTE) buff = unpack_to_char(*(uint4x2_t *)&packed_value);++ if (idx_packed == 0) {+ v_vals_packed[i] = buff.s0;+ } else {+ v_vals_packed[i] = buff.s1;+ }+ }++#else // !(IS_KV_COMPRESSED && IS_INT4_COMPRESSED)VALUE_BLOCK v_vals_packed;unroll_for (uint i = 0; i < VALUE_VEC_SIZE; i++) {v_vals_packed[i] = BLOCK_READN(INPUT2_TYPE, 1, value_cache, value_offset + i * V_HEAD_SIZE);}+#endif#if IS_KV_COMPRESSEDVALUE_BLOCK_UNCOMPRESSED value_vals;@@ -570,19 +679,49 @@ KERNEL(pa_sdpa_opt)(const uint block_offset = block_indices[last_block_idx] * KV_HEADS_NUM * ADJUSTED_V_HEAD_SIZE * PAGED_ATTENTION_BLOCK_SIZE + head_idx * ADJUSTED_V_HEAD_SIZE * PAGED_ATTENTION_BLOCK_SIZE;const uint value_offset = block_offset + head_size_idx;-#if IS_KV_COMPRESSED+#if IS_KV_COMPRESSED && IS_INT4_COMPRESSED+ const uint packed_block_offset = block_indices[last_block_idx] * KV_HEADS_NUM * phys_adjusted_v_head_size * PAGED_ATTENTION_BLOCK_SIZE+ + head_idx * phys_adjusted_v_head_size * PAGED_ATTENTION_BLOCK_SIZE;+ const uint head_size_offset = ((head_size_idx / SUBGROUP_SIZE) / U4_ELEMS_PER_BYTE) * SUBGROUP_SIZE + (head_size_idx % SUBGROUP_SIZE);+ const uint packed_value_offset = packed_block_offset + head_size_offset;++ const uint value_comp_offset = packed_block_offset + phys_v_head_size * PAGED_ATTENTION_BLOCK_SIZE;+ INPUT0_TYPE* value_comp_ptr = value_cache + value_comp_offset;+ INPUT0_TYPE comp_scale = value_comp_ptr[0 + sglid];+ INPUT0_TYPE comp_zp = value_comp_ptr[PAGED_ATTENTION_BLOCK_SIZE + sglid];+#elif IS_KV_COMPRESSED && !IS_INT4_COMPRESSEDconst uint value_comp_offset = block_offset + V_HEAD_SIZE * PAGED_ATTENTION_BLOCK_SIZE;INPUT0_TYPE* value_comp_ptr = value_cache + value_comp_offset;INPUT0_TYPE comp_scale = value_comp_ptr[0 + sglid];INPUT0_TYPE comp_zp = value_comp_ptr[PAGED_ATTENTION_BLOCK_SIZE + sglid];#endif+#if IS_KV_COMPRESSED && IS_INT4_COMPRESSED+ const uint idx_packed = (head_size_idx / SUBGROUP_SIZE) % U4_ELEMS_PER_BYTE;+#endif+MAKE_VECTOR_TYPE(OUTPUT_TYPE, QUERIES_PER_WI) qk_val;unroll_for (uint q_idx = 0; q_idx < QUERIES_PER_WI; q_idx++) {GET_VECTOR_ELEMENT(qk_val, q_idx) = slm_qk_vals[q_idx * SEQ_LEN_PARTITION_SIZE + blocks_num_per_partition * PAGED_ATTENTION_BLOCK_SIZE + sglid];}for (uint i = 0; i < leftovers; i++) {+#if IS_KV_COMPRESSED && IS_INT4_COMPRESSED+ INPUT2_TYPE value_packed = 0;+ uint index = packed_value_offset + i * phys_v_head_size;+ char packed_value = BLOCK_READN(INPUT2_TYPE, 1, value_cache, index);+ MAKE_VECTOR_TYPE(char, U4_ELEMS_PER_BYTE) buff = unpack_to_char(*(uint4x2_t *)&packed_value);++ if (idx_packed == 0) {+ value_packed = buff.s0;+ } else {+ value_packed = buff.s1;+ }++#else // !(IS_KV_COMPRESSED && IS_INT4_COMPRESSED)INPUT2_TYPE value_packed = BLOCK_READN(INPUT2_TYPE, 1, value_cache, value_offset + i * V_HEAD_SIZE);++#endif // !(IS_KV_COMPRESSED && IS_INT4_COMPRESSED)+#if IS_KV_COMPRESSED#define VALUE_UNCOMPRESSED INPUT0_TYPE#define TO_VALUE_UNCOMPRESSED_TYPE(val) CAT(convert_, VALUE_UNCOMPRESSED)(val)diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/paged_attention_opt.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/paged_attention_opt.cppindex 1dfa9339cb8..a0521fd8ea6 100644--- a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/paged_attention_opt.cpp+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/paged_attention_opt.cpp@@ -15,6 +15,7 @@#include <utility>#include "../primitive_ocl_base.hpp"+#include "common_tools.h"#include "common_utils/jitter.hpp"#include "intel_gpu/graph/kernel_impl_params.hpp"#include "intel_gpu/primitives/paged_attention.hpp"@@ -24,6 +25,7 @@#include "primitive_inst.h"#include "sdpa_base.hpp"#include "sdpa_gen_opt.hpp"+namespace ov::intel_gpu::ocl {namespace {@@ -31,10 +33,11 @@ constexpr ov::element::Type softmax_accumulator_type = ov::element::f32;constexpr size_t paged_attention_block_size = 16;constexpr size_t seq_len_partition_size = 256;constexpr size_t subgroup_size = 16;+constexpr size_t u4_elems_per_byte = 2;inline bool get_kv_compressed(const RuntimeParams& params) {auto key_cache_layout = params.input_layouts[PagedAttentionInputIdx::KEY_CACHE];- if (data_type_traits::is_i8_u8(key_cache_layout.data_type)) {+ if (data_type_traits::is_i8_u8(key_cache_layout.data_type) || data_type_traits::is_i4_u4(key_cache_layout.data_type)) {return true;} else {return false;@@ -236,6 +239,32 @@ PagedAttentionStage get_paged_attention_stage(const kernel_impl_params& impl_parreturn PagedAttentionStage::UNKNOWN;}+JitConstants make_uint4_kv_cache_jit_constants(const kernel_impl_params& params) {+ ov::intel_gpu::JitConstants jit;+ const auto desc = params.typed_desc<paged_attention>();+ const auto kv_cache_dt = params.get_program().get_config().get_kv_cache_precision();+ const auto is_key_by_channel = desc->is_key_by_channel;+ auto& kv_dt = params.input_layouts[PagedAttentionInputIdx::KEY].data_type;++ if (data_type_traits::is_i4_u4(kv_cache_dt)) {+ // INT4 compression is packing elements along groups in head which has different scalea and zp+ const auto scales_zp_size = get_element_size(kv_dt) * 4;+ jit.make("IS_INT4_COMPRESSED", true);+ jit.make("PACKED_K_HEAD_SIZE", kernel_selector::Align(desc->k_head_size / u4_elems_per_byte, subgroup_size));+ jit.make("PACKED_ADJUSTED_V_HEAD_SIZE", (kernel_selector::Align(desc->v_head_size / u4_elems_per_byte, subgroup_size)) + scales_zp_size);+ jit.make("PACKED_V_HEAD_SIZE", (kernel_selector::Align(desc->v_head_size / u4_elems_per_byte, subgroup_size)));+ if (is_key_by_channel) {+ jit.make("PACKED_ADJUSTED_K_HEAD_SIZE", (kernel_selector::Align(desc->k_head_size / u4_elems_per_byte, subgroup_size)));+ } else {+ jit.make("PACKED_ADJUSTED_K_HEAD_SIZE", (kernel_selector::Align(desc->k_head_size / u4_elems_per_byte, subgroup_size)) + scales_zp_size);+ }+ } else {+ jit.make("IS_INT4_COMPRESSED", false);+ }++ return jit;+}+class PagedAttentionGeneratorBase : public KernelGenerator {public:explicit PagedAttentionGeneratorBase(std::string_view stage_suffix) : KernelGenerator("paged_attention_opt", stage_suffix) {}@@ -243,6 +272,7 @@ public:auto jit = make_base_jit_constants(params);auto desc = params.typed_desc<paged_attention>();const size_t kv_group_size = desc->heads_num / desc->kv_heads_num;+ jit.make("U4_ELEMS_PER_BYTE", u4_elems_per_byte);jit.make("K_HEAD_SIZE", desc->k_head_size);jit.make("V_HEAD_SIZE", desc->v_head_size);jit.make("HEADS_NUM", desc->heads_num);@@ -253,7 +283,8 @@ public:jit.make("SUBGROUP_SIZE", subgroup_size);jit.make("SLIDING_WINDOW_SIZE", desc->sliding_window);- bool is_kv_compressed = get_kv_compressed(params);+ const auto kv_cache_dt = params.get_program().get_config().get_kv_cache_precision();+ const bool is_kv_compressed = get_kv_compressed(params);jit.make("IS_KV_COMPRESSED", is_kv_compressed);jit.make("XE2_QK_MULTIPLICATION", params.get_device_info().arch == gpu_arch::xe2);jit.make("SG_SCALE_FACTOR", get_pa_sg_number_scale_factor(params.get_device_info(), desc->k_head_size, SDPAStage::SINGLE_TOKEN, is_kv_compressed));@@ -262,7 +293,12 @@ public:if (is_kv_compressed) {auto& kv_dt = params.input_layouts[PagedAttentionInputIdx::KEY].data_type;auto scales_zp_size = get_element_size(kv_dt) * 2; // scale + zp- // jit.make("SCALE_ZP_SIZE_PER_TOKEN", scales_zp_size);+ if (data_type_traits::is_i4_u4(kv_cache_dt))+ scales_zp_size = get_element_size(kv_dt) * 4;++ jit.make("SCALE_ZP_SIZE_PER_TOKEN", scales_zp_size);+ jit.add(make_uint4_kv_cache_jit_constants(params));+if (is_key_by_channel) {jit.make("IS_KEY_BY_CHANNEL", 1);jit.make("ADJUSTED_K_HEAD_SIZE", desc->k_head_size);@@ -598,6 +634,10 @@ public:args.push_back({ArgumentDescriptor::Types::INPUT, PagedAttentionInputIdx::ALIBI}); // alibi}+ if (desc->has_sink_input) {+ args.push_back({ArgumentDescriptor::Types::INPUT, PagedAttentionInputIdx::SINKS}); // sink+ }+args.push_back({ArgumentDescriptor::Types::OUTPUT, 0});add_intermediate_inputs(args, has_scores_output, true, desc->has_score_aggregation);return args;@@ -874,6 +914,7 @@ protected:jit.add(make_layout_jit_constants("OUTPUT" + to_code_string(1), params.input_layouts[value_cache_id], in_offsets_map.at(value_cache_id)));const auto desc = params.typed_desc<paged_attention>();+ const auto kv_cache_dt = params.get_program().get_config().get_kv_cache_precision();const auto is_key_by_channel = desc->is_key_by_channel;OPENVINO_ASSERT(is_key_by_channel == (params.get_program().get_config().get_key_cache_quant_mode() == ov::internal::CacheQuantMode::BY_CHANNEL),"[GPU] Paged Attention key cache quantization mode mismatch: prim.key_cache_by_channel : ",@@ -882,6 +923,7 @@ protected:params.get_program().get_config().get_key_cache_quant_mode());// const auto pa_block_size = static_cast<int32_t>(paged_attention::block_size);+ jit.make("U4_ELEMS_PER_BYTE", u4_elems_per_byte);jit.make("K_HEAD_SIZE", desc->k_head_size);jit.make("V_HEAD_SIZE", desc->v_head_size);jit.make("HEADS_NUM", desc->heads_num);@@ -896,7 +938,12 @@ protected:if (is_kv_compressed) {auto data_type = params.input_layouts[PagedAttentionInputIdx::KEY].data_type; // key tensor data sizeauto scales_zp_size = get_element_size(data_type) * 2; // scale + zp- // jit.make("SCALE_ZP_SIZE_PER_TOKEN", scales_zp_size);+ if (data_type_traits::is_i4_u4(kv_cache_dt))+ scales_zp_size = get_element_size(data_type) * 4;++ jit.make("SCALE_ZP_SIZE_PER_TOKEN", scales_zp_size);+ jit.add(make_uint4_kv_cache_jit_constants(params));+if (is_key_by_channel) {jit.make("IS_KEY_BY_CHANNEL", 1);jit.make("ADJUSTED_K_HEAD_SIZE", desc->k_head_size);@@ -965,7 +1012,13 @@ protected:const auto& key_input = params.input_layouts[0];const auto sequences_number = key_input.get_partial_shape()[0].get_length();size_t head_size_partition = get_num_k_head_size_partitions(desc->is_key_by_channel, desc->k_head_size);- wgs.global = {static_cast<size_t>(sequences_number), heads_number, subgroup_size * head_size_partition};+ const auto kv_cache_dt = params.get_program().get_config().get_kv_cache_precision();+ if (data_type_traits::is_i4_u4(kv_cache_dt) && head_size_partition > 1)+ wgs.global = {static_cast<size_t>(sequences_number),+ heads_number,+ kernel_selector::Align(subgroup_size * head_size_partition / u4_elems_per_byte, subgroup_size)};+ else+ wgs.global = {static_cast<size_t>(sequences_number), heads_number, subgroup_size * head_size_partition};wgs.local = {1, 1, subgroup_size};}@@ -1010,7 +1063,13 @@ protected:const auto is_key_by_channel = desc->is_key_by_channel;jit.make("IS_KEY_BY_CHANNEL", (is_kv_compressed && is_key_by_channel) ? 1 : 0);if (is_kv_compressed) {+ jit.add(make_uint4_kv_cache_jit_constants(params));auto scales_zp_size = get_element_size(original_cache_dt) * 2; // scale + zp;+ const auto kv_cache_dt = params.get_program().get_config().get_kv_cache_precision();+ if (data_type_traits::is_i4_u4(kv_cache_dt)) {+ scales_zp_size = get_element_size(original_cache_dt) * 4;+ }+jit.make("SCALE_ZP_SIZE_PER_TOKEN", scales_zp_size);if (is_key_by_channel) {jit.make("ADJUSTED_HEAD_SIZE", desc->k_head_size);@@ -1274,6 +1333,19 @@ public:if (desc->has_alibi) {return false;}++ // micro_sdpa does not support 4-bit (u4/i4) KV-cache quantization.+ // In MIXED stage, the prefill and generate iterations share the same kernel path;+ // because the generate iteration must read the already-quantized KV-cache that was+ // written during prefill, every kernel in this stage must be able to dequantize 4-bit+ // entries. micro_sdpa currently lacks this dequantization logic, so we fall back to+ // the standard paged-attention kernel (pa_multi_tokens / pa_single_token) which does+ // support INT4 KV-cache.+ if (data_type_traits::is_i4_u4(params.get_program().get_config().get_kv_cache_precision()) &&+ get_paged_attention_stage(params) == PagedAttentionStage::MIXED) {+ return false;+ }+return true;}@@ -1319,6 +1391,7 @@ public:if ((rt_params->stage == PagedAttentionStage::PREFILL || rt_params->stage == PagedAttentionStage::MIXED) && !params.is_dynamic())rt_params->paged_attention_aligned_seq_len = static_cast<size_t>(get_aligned_seq_len(params, rt_params->stage));+rt_params->sdpa_opt_seq_len_partition_size = get_seq_len_partition_size(params.get_device_info(), desc->v_head_size, SDPAStage::MULTI_TOKENS);if (desc->has_score_aggregation) {@@ -1340,9 +1413,16 @@ public:#elsert_params->use_micro_sdpa = false;#endif+rt_params->query_block_size = get_query_block_size(rt_params->stage, rt_params->use_micro_sdpa);if (rt_params->stage == PagedAttentionStage::GENERATE) {+ if (data_type_traits::is_i4_u4(params.get_program().get_config().get_kv_cache_precision())) {+ rt_params->use_gqa_kernel = false;+ rt_params->use_micro_sdpa = false;+ return;+ }+if (rt_params->use_micro_sdpa) {size_t kv_group_size = desc->heads_num / desc->kv_heads_num;rt_params->use_gqa_kernel = (kv_group_size == 8 && desc->k_head_size == 64);@@ -1514,6 +1594,11 @@ public:can_use_micro_sdpa = has_stage(pa_sdpa_micro);if (stage == PagedAttentionStage::GENERATE && (rt_params == nullptr || (rt_params != nullptr && rt_params->use_gqa_kernel == false)))can_use_micro_sdpa = false;++ if (data_type_traits::is_i4_u4(params.get_program().get_config().get_kv_cache_precision()) &&+ get_paged_attention_stage(params) == PagedAttentionStage::MIXED) {+ can_use_micro_sdpa = false;+ }#endifGPU_DEBUG_TRACE_DETAIL << "get_internal_buffer_descs: stage = " << static_cast<size_t>(stage) << std::endl;int64_t paged_attention_aligned_seq_len = -1;@@ -1733,11 +1818,17 @@ public:std::unique_ptr<mem_lock<int32_t, mem_lock_type::write>> micro_sdpa_block_starts_and_gws_mapping_lock = nullptr;if (stage == PagedAttentionStage::MIXED && !use_micro_sdpa) {- size_t sequential_gws_subseq_mapping_idx = 6;- if (has_score_aggregation) {- sequential_gws_subseq_mapping_idx = 9;- } else if (has_scores_output) {- sequential_gws_subseq_mapping_idx = 8;+ // Calculate the index dynamically based on what buffers were actually allocated+ // Base: 0, 1, 2 (3 buffers)+ size_t sequential_gws_subseq_mapping_idx = 3;++ // exp_sums, max_logits, tmp_out (3 buffers)+ sequential_gws_subseq_mapping_idx += 3;+ if (has_scores_output) {+ sequential_gws_subseq_mapping_idx += 2; // buffers 3, 4+ if (has_score_aggregation) {+ sequential_gws_subseq_mapping_idx += 1; // buffer 5+ }}OPENVINO_ASSERT(intermediates_memories.size() > sequential_gws_subseq_mapping_idx,diff --git a/src/plugins/intel_gpu/src/graph/paged_attention.cpp b/src/plugins/intel_gpu/src/graph/paged_attention.cppindex a0a14d94bca..569c7e0e486 100644--- a/src/plugins/intel_gpu/src/graph/paged_attention.cpp+++ b/src/plugins/intel_gpu/src/graph/paged_attention.cpp@@ -40,12 +40,18 @@ std::vector<layout> paged_attention_inst::calc_output_layouts(paged_attention_noconst auto key_cache_idx = cldnn::paged_attention::PagedAttentionInputIdx::KEY_CACHE;const auto& key_cache_ps = impl_param.get_input_layout(key_cache_idx).get_partial_shape();const auto& key_cache_quant_mode = impl_param.get_program().get_config().get_key_cache_quant_mode();+ const auto key_cache_dt = impl_param.get_program().get_config().get_kv_cache_precision();bool key_cache_compressed = impl_param.get_input_layout(key_cache_idx).data_type == ov::element::i8 ||- impl_param.get_input_layout(key_cache_idx).data_type == ov::element::u8;+ impl_param.get_input_layout(key_cache_idx).data_type == ov::element::u8 ||+ data_type_traits::is_i4_u4(key_cache_dt);auto expected_block_size = desc->has_xattention ? paged_attention::block_size_xattn : paged_attention::block_size;if (key_cache_compressed && key_cache_quant_mode == ov::internal::CacheQuantMode::BY_CHANNEL) {- expected_block_size += 4;+ if (data_type_traits::is_i4_u4(key_cache_dt))+ expected_block_size += 8;+ else+ expected_block_size += 4;}+OPENVINO_ASSERT((key_cache_quant_mode == ov::internal::CacheQuantMode::BY_CHANNEL) == desc->is_key_by_channel,"[GPU] Paged Attention key cache quantization mode mismatch: prim.is_key_by_channel : ",desc->is_key_by_channel, " but exec_config : ", impl_param.get_program().get_config().get_key_cache_quant_mode());diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/include/batch_headers/int4_utils.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/include/batch_headers/int4_utils.clindex 88328873df6..db07367152c 100644--- a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/include/batch_headers/int4_utils.cl+++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/include/batch_headers/int4_utils.cl@@ -14,6 +14,20 @@ typedef struct __attribute__ ((packed)) uint4x4_t { uint4x2_t s0; uint4x2_t s1;typedef struct __attribute__ ((packed)) uint4x8_t { uint4x2_t s0; uint4x2_t s1; uint4x2_t s2; uint4x2_t s3; } uint4x8_t;typedef struct __attribute__ ((packed)) uint4x16_t { uint4x2_t s0; uint4x2_t s1; uint4x2_t s2; uint4x2_t s3; uint4x2_t s4; uint4x2_t s5; uint4x2_t s6; uint4x2_t s7; } uint4x16_t;+inline uchar cvt_uint8x2_to_uint4x2(uchar2 v) __attribute__((overloadable)) {+ uchar v0 = 0;+ v0 = (v.s1 & 0x0F) << 4;+ v0 = v0 | (v.s0 & 0x0F);+ return v0;+}++inline char cvt_int8x2_to_uint4x2(char2 v) __attribute__((overloadable)) {+ char v0 = 0;+ v0 = (v.s1 & 0x0F) << 4;+ v0 = v0 | (v.s0 & 0x0F);+ return v0;+}+inline uchar2 cvt_uint4x2_to_uint8x2(uint4x2_t v) __attribute__((overloadable)) {const uchar v0 = v.s0 & 0x0F;const uchar v1 = (v.s0 & 0xF0) >> 4;diff --git a/src/plugins/intel_gpu/src/plugin/transformations/kv_cache_compression.cpp b/src/plugins/intel_gpu/src/plugin/transformations/kv_cache_compression.cppindex b6a29ba35af..b99bb2b1274 100644--- a/src/plugins/intel_gpu/src/plugin/transformations/kv_cache_compression.cpp+++ b/src/plugins/intel_gpu/src/plugin/transformations/kv_cache_compression.cpp@@ -11,6 +11,7 @@#include "intel_gpu/op/read_values.hpp"#include "intel_gpu/plugin/common_utils.hpp"#include "intel_gpu/runtime/debug_configuration.hpp"+#include "intel_gpu/runtime/utils.hpp"#include "ov_ops/dynamic_quantize.hpp"#include "openvino/core/node_vector.hpp"@@ -33,6 +34,7 @@#include <memory>#include "openvino/core/graph_util.hpp"+namespace ov::intel_gpu {namespace {@@ -137,13 +139,12 @@ public:KVCacheCompressionMatcher::KVCacheCompressionMatcher(ov::element::Type compression_dt, bool supports_immad) {using namespace ov::pass::pattern;- if (compression_dt != element::i8 && compression_dt != element::u8)+ if (!cldnn::one_of(compression_dt, {element::i8, element::u8, element::i4, element::u4}))return;const auto quantization_type = ov::op::internal::DynamicQuantize::QuantizationType::Asymmetric;const auto output_storage_type = supports_immad ? ov::op::internal::DynamicQuantize::OutputStorageType::Planar: ov::op::internal::DynamicQuantize::OutputStorageType::InterleavedScalesZP;-bool combine_scales_and_zp = output_storage_type == ov::op::internal::DynamicQuantize::OutputStorageType::InterleavedScalesZP;GPU_DEBUG_LOG << "KV-cache compression configuration: "<< "dt=" << compression_dt << ", "diff --git a/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp b/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cppindex 53499882b4b..4e864eb9b17 100644--- a/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp+++ b/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp@@ -13,6 +13,7 @@#include <string>#include <tuple>#include <vector>+#include <type_traits>#include "intel_gpu/runtime/debug_configuration.hpp"#include "intel_gpu/runtime/itt.hpp"@@ -220,6 +221,11 @@ static bool disable_reduce_decomposition(const std::shared_ptr<const ov::Node> nreturn false;}+template <typename T>+static typename std::enable_if<std::is_integral<T>::value, T>::type align_to(T size, size_t align) {+ return static_cast<T>((size % align == 0) ? size : size - size % align + align);+}+static bool is_decompression_multiply(const std::shared_ptr<const ov::Node> node, bool supports_immad) {std::vector<ov::DiscreteTypeInfo> target_consumers = {ov::opset1::MatMul::get_type_info_static(),ov::op::internal::MOE::get_type_info_static(),@@ -686,12 +692,25 @@ void TransformationsPipeline::apply(std::shared_ptr<ov::Model> func) {// TODO: need to handle group size != block size caseif (precision == ov::element::i8 || precision == ov::element::u8) {block_size += infer_precision.size() * 2;+ } else if (precision == ov::element::i4 || precision == ov::element::u4) {+ head_size = align_to(head_size / 2, 16);+ block_size += infer_precision.size() * 4;}} else {if (precision == ov::element::i8 || precision == ov::element::u8) {head_size += infer_precision.size() * 2 * group_num;+ } else if (precision == ov::element::i4 || precision == ov::element::u4) {+ head_size = align_to(head_size / 2, 16);+ head_size += infer_precision.size() * 4 * group_num;}}+ },+ [&] (ov::element::Type& precision) {+ // Use u8/i8 for cache even if the inference precision is i4/u4,+ // to avoid issue that u4-type cache is called by ov::RemoteTensor in genai.+ if (precision == ov::element::i4 || precision == ov::element::u4) {+ precision = (config.get_kv_cache_precision() == ov::element::i4) ? ov::element::i8 : ov::element::u8;+ }});}@@ -1424,9 +1443,9 @@ void TransformationsPipeline::apply(std::shared_ptr<ov::Model> func) {manager.register_pass<ov::pass::GLUFusion>();manager.register_pass<ov::intel_gpu::IndirectKVCache>();+auto kv_cache_compression_dt = config.get_kv_cache_precision();manager.register_pass<ov::intel_gpu::KVCacheCompression>(kv_cache_compression_dt, device_info.supports_immad);-manager.register_pass<ov::intel_gpu::ConvertConvolutionToInternal>();// This pass should be done after asymmetric quantization matching as it can move zp subtraction upper in the graphdiff --git a/src/plugins/intel_gpu/tests/unit/test_cases/paged_attention_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/paged_attention_gpu_test.cppindex 589f2d3d840..dd336b47e61 100644--- a/src/plugins/intel_gpu/tests/unit/test_cases/paged_attention_gpu_test.cpp+++ b/src/plugins/intel_gpu/tests/unit/test_cases/paged_attention_gpu_test.cpp@@ -15,6 +15,7 @@#include <openvino/reference/xattention.hpp>#include <openvino/reference/adaptive_rkv_diversity.hpp>+#include "openvino/runtime/properties.hpp"#include "openvino/runtime/tensor.hpp"#include "primitive_inst.h"#include "random_generator.hpp"@@ -77,6 +78,7 @@ struct PagedAttentionManager {int sliding_window_size;bool kv_cache_compression;ov::internal::CacheQuantMode key_cache_quant_mode;+ ov::element::Type kv_cache_precision = ov::element::dynamic;bool has_score_aggregation;bool has_xattention;CacheRotationDescriptor rotation_config;@@ -133,7 +135,8 @@ struct PagedAttentionManager {bool has_score_aggregation,bool has_xattention,CacheRotationDescriptor rotation_config,- std::vector<float> threshold)+ std::vector<float> threshold,+ ov::element::Type kv_cache_precision = ov::element::dynamic): num_heads(num_heads), num_kv_heads(num_kv_heads), k_head_size(k_head_size)@@ -142,6 +145,7 @@ struct PagedAttentionManager {, sliding_window_size(sliding_window_size), kv_cache_compression(kv_cache_compression), key_cache_quant_mode(key_cache_quant_mode)+ , kv_cache_precision(kv_cache_precision), has_score_aggregation(has_score_aggregation), has_xattention(has_xattention), rotation_config(rotation_config)@@ -298,16 +302,31 @@ struct PagedAttentionManager {return memory;}+ bool is_int4_kv_cache() const {+ return kv_cache_precision == ov::element::u4 || kv_cache_precision == ov::element::i4;+ }+memory::ptr get_key_cache_memory() {auto key_cache_dt = data_types::f16;auto adjusted_head_size = k_head_size;auto adjusted_block_size = block_size;if (kv_cache_compression) {- key_cache_dt = data_types::i8;+ key_cache_dt = is_int4_kv_cache() ? data_types::u8 : data_types::i8;+ const int scale_zp_bytes = is_int4_kv_cache() ? 8 : 4;if (key_cache_quant_mode == ov::internal::CacheQuantMode::BY_CHANNEL) {- adjusted_block_size += 4;+ if (is_int4_kv_cache()) {+ // u4/i4: stored as u8/i8 with head_size halved (2 u4 packed per byte).+ // Scale/zp for BY_CHANNEL: 4 fp16 values = 8 bytes appended to block_size dim.+ adjusted_head_size = k_head_size / 2; // pack 2 u4 into 1 u8 byte+ }+ adjusted_block_size += scale_zp_bytes;} else {- adjusted_head_size += 4;+ if (is_int4_kv_cache()) {+ // Scale/zp for BY_TOKEN: 2 fp16 values = 4 bytes appended to head_size dim.+ adjusted_head_size = k_head_size / 2 + scale_zp_bytes;+ } else {+ adjusted_head_size += scale_zp_bytes;+ }}}@@ -325,22 +344,89 @@ struct PagedAttentionManager {: block_size;// quantize by channelif (kv_cache_compression && key_cache_quant_mode == ov::internal::CacheQuantMode::BY_CHANNEL) {- for (int head_idx = 0; head_idx < num_kv_heads; head_idx++) {- for (int k_head_size_idx = 0; k_head_size_idx < k_head_size; k_head_size_idx++) {- std::vector<ov::float16> token_block(block_size);- for (int token_idx = 0; token_idx < last_token_idx; ++token_idx) {- size_t input_token_offset = block_idx * block_size + token_idx;- token_block[token_idx] = *(key_data[i].data() + input_token_offset * num_kv_heads * k_head_size + head_idx * k_head_size + k_head_size_idx);+ if (is_int4_kv_cache()) {+ // INT4 BY_CHANNEL: packed layout [num_blocks, kv_heads, k_head_size/2, block_size+8]+ // Each packed dim p corresponds to orig dims p*2 (even) and p*2+1 (odd).+ // Each byte holds two u4 values: lower nibble = even dim, upper nibble = odd dim.+ // Comp region at [block_size..block_size+7]: 4 fp16 = inv_scale0,zp0,inv_scale1,zp1+ const int packed_head_size = k_head_size / 2;+ for (int head_idx = 0; head_idx < num_kv_heads; head_idx++) {+ for (int p = 0; p < packed_head_size; p++) {+ const int dim0 = p * 2;+ const int dim1 = p * 2 + 1;+ // Quantize both dims across tokens in this block+ std::vector<float> vals0(block_size, 0.f), vals1(block_size, 0.f);+ for (int t = 0; t < last_token_idx; ++t) {+ size_t in_off = (static_cast<size_t>(block_idx) * block_size + t) * num_kv_heads * k_head_size+ + head_idx * k_head_size;+ vals0[t] = static_cast<float>(key_data[i].data()[in_off + dim0]);+ vals1[t] = static_cast<float>(key_data[i].data()[in_off + dim1]);+ }+ auto quantize_u4 = [&](const std::vector<float>& vals, int n_vals) {+ float min_v = vals[0], max_v = vals[0];+ for (int t = 1; t < n_vals; ++t) {+ min_v = std::min(min_v, vals[t]);+ max_v = std::max(max_v, vals[t]);+ }+ float range = (max_v == min_v) ? 0.001f : (max_v - min_v);+ const float min_range = std::abs(max_v) * 0.1f;+ if (range <= min_range) range += std::max(1.0f, min_range);+ float scale = 15.0f / range;+ float zp = -min_v * scale;+ std::vector<uint8_t> q(n_vals);+ for (int t = 0; t < n_vals; ++t) {+ int v = static_cast<int>(std::nearbyint(vals[t] * scale + zp));+ v = std::max(0, std::min(15, v));+ q[t] = static_cast<uint8_t>(v);+ }+ return std::make_tuple(q, scale, zp);+ };+ auto [q0, scale0, zp_val0] = quantize_u4(vals0, last_token_idx);+ auto [q1, scale1, zp_val1] = quantize_u4(vals1, last_token_idx);++ const size_t output_block_offset =+ static_cast<size_t>(start_block_idx + block_idx) * num_kv_heads * packed_head_size * adjusted_block_size+ + head_idx * packed_head_size * adjusted_block_size;+ const size_t output_offset = output_block_offset + p * adjusted_block_size;++ // Pack and write u4 data+ std::vector<uint8_t> packed(last_token_idx);+ for (int t = 0; t < last_token_idx; ++t)+ packed[t] = static_cast<uint8_t>((q0[t] & 0xFu) | ((q1[t] & 0xFu) << 4));+ set_values(test_stream, memory, packed.data(), static_cast<size_t>(last_token_idx), output_offset);++ // Write 4 fp16 comp values: inv_scale0, zp0, inv_scale1, zp1+ // Comp region starts at output_offset + block_size (in u8 elements)+ // Accessed via fp16 lock: divide u8 offset by 2 to get fp16 index+ const size_t comp_offset_fp16 = (output_offset + block_size) / 2;+ ov::float16 inv_scale0 = static_cast<float>(1.0f / scale0);+ ov::float16 fp16_zp0 = static_cast<float>(zp_val0);+ ov::float16 inv_scale1 = static_cast<float>(1.0f / scale1);+ ov::float16 fp16_zp1 = static_cast<float>(zp_val1);+ set_values(test_stream, memory, &inv_scale0, 1, comp_offset_fp16 + 0);+ set_values(test_stream, memory, &fp16_zp0, 1, comp_offset_fp16 + 1);+ set_values(test_stream, memory, &inv_scale1, 1, comp_offset_fp16 + 2);+ set_values(test_stream, memory, &fp16_zp1, 1, comp_offset_fp16 + 3);+ }+ }+ } else {+ for (int head_idx = 0; head_idx < num_kv_heads; head_idx++) {+ for (int k_head_size_idx = 0; k_head_size_idx < k_head_size; k_head_size_idx++) {+ std::vector<ov::float16> token_block(block_size);+ for (int token_idx = 0; token_idx < last_token_idx; ++token_idx) {+ size_t input_token_offset = block_idx * block_size + token_idx;+ token_block[token_idx] = *(key_data[i].data() + input_token_offset * num_kv_heads * k_head_size + head_idx * k_head_size + k_head_size_idx);+ }+ auto [quantized_data, scale, zp] = quantize_data(token_block.data(), last_token_idx, true);+ size_t output_block_offset = (start_block_idx + block_idx) * num_kv_heads * adjusted_head_size * adjusted_block_size ++ head_idx * adjusted_head_size * adjusted_block_size;+ size_t output_offset = output_block_offset ++ k_head_size_idx * adjusted_block_size;+ set_values(test_stream, memory, quantized_data.data(), last_token_idx, output_offset);+ size_t comp_offset = (output_offset + block_size)/2;+ set_values(test_stream, memory, &scale, 1, comp_offset);+ set_values(test_stream, memory, &zp, 1, comp_offset + 1);}- auto [quantized_data, scale, zp] = quantize_data(token_block.data(), last_token_idx, true);- size_t output_block_offset = (start_block_idx + block_idx) * num_kv_heads * adjusted_head_size * adjusted_block_size +- head_idx * adjusted_head_size * adjusted_block_size;- size_t output_offset = output_block_offset +- k_head_size_idx * adjusted_block_size;- set_values(test_stream, memory, quantized_data.data(), last_token_idx, output_offset);- size_t comp_offset = (output_offset + block_size)/2;- set_values(test_stream, memory, &scale, 1, comp_offset);- set_values(test_stream, memory, &zp, 1, comp_offset + 1);}}}@@ -357,19 +443,68 @@ struct PagedAttentionManager {size_t output_block_offset = (start_block_idx + block_idx) * num_kv_heads * adjusted_head_size * block_size +head_idx * adjusted_head_size * block_size;- auto [quantized_data, scale, zp] = quantize_data(data_ptr, k_head_size);- for (int k_head_size_idx = 0; k_head_size_idx < k_head_size; k_head_size_idx++) {- auto quantized_data_ptr = quantized_data.data() + k_head_size_idx;-- size_t output_offset = output_block_offset +- k_head_size_idx * block_size +- token_idx;-- set_values(test_stream, memory, quantized_data_ptr, 1, output_offset);+ if (is_int4_kv_cache()) {+ // INT4 BY_TOKEN: [num_blocks, kv_heads, k_head_size/2+8, block_size] u8+ // Kernel packing (SUBGROUP_SIZE=16):+ // Y = pack_group*16 + sglid, where pack_group = d/(2*16), sglid = d%16+ // lower 4bit = q(dim[pack_group*32+sglid])+ // upper 4bit = q(dim[pack_group*32+sglid+16])+ // Scale/ZP: fp16 in comp region at Y=packed_head_size..+ // inv_scale[t] at fp16 idx (comp_base/2 + t)+ // zp[t] at fp16 idx (comp_base/2 + block_size + t)+ const int packed_head_size = k_head_size / 2;+ constexpr int SG = 16; // SUBGROUP_SIZE+ // Compute per-token min/max, then scale/zp in u4 range [0,15]+ float min_v = std::numeric_limits<float>::max();+ float max_v = -std::numeric_limits<float>::max();+ for (int d = 0; d < k_head_size; d++) {+ float v = static_cast<float>(data_ptr[d]);+ min_v = std::min(min_v, v);+ max_v = std::max(max_v, v);+ }+ float range = (max_v == min_v) ? 0.001f : (max_v - min_v);+ const float min_range = std::abs(max_v) * 0.1f;+ if (range <= min_range) range += std::max(1.0f, min_range);+ float token_scale = 15.0f / range;+ float token_zp = -min_v * token_scale;+ std::vector<uint8_t> q(k_head_size);+ for (int d = 0; d < k_head_size; d++) {+ int v = static_cast<int>(std::nearbyint(static_cast<float>(data_ptr[d]) * token_scale + token_zp));+ q[d] = static_cast<uint8_t>(std::max(0, std::min(15, v)));+ }+ // Pack and write: Y=pack_group*SG+sglid → (lower=q[d0], upper=q[d1])+ for (int y = 0; y < packed_head_size; y++) {+ int sglid_val = y % SG;+ int pack_group = y / SG;+ int d0 = pack_group * 2 * SG + sglid_val;+ int d1 = d0 + SG;+ uint8_t packed_byte = q[d0] & 0xFu;+ if (d1 < k_head_size)+ packed_byte |= (q[d1] & 0xFu) << 4;+ size_t offset = output_block_offset + static_cast<size_t>(y) * block_size + token_idx;+ set_values(test_stream, memory, &packed_byte, 1, offset);+ }+ // Write inv_scale and zp as fp16 in the comp region+ size_t comp_offset_fp16 = (output_block_offset + static_cast<size_t>(packed_head_size) * block_size) / 2;+ ov::float16 fp16_inv_scale = static_cast<float>(1.0f / token_scale);+ ov::float16 fp16_zp = static_cast<float>(token_zp);+ set_values(test_stream, memory, &fp16_inv_scale, 1, comp_offset_fp16 + token_idx);+ set_values(test_stream, memory, &fp16_zp, 1, comp_offset_fp16 + block_size + token_idx);+ } else {+ auto [quantized_data, scale, zp] = quantize_data(data_ptr, k_head_size);+ for (int k_head_size_idx = 0; k_head_size_idx < k_head_size; k_head_size_idx++) {+ auto quantized_data_ptr = quantized_data.data() + k_head_size_idx;++ size_t output_offset = output_block_offset ++ k_head_size_idx * block_size ++ token_idx;++ set_values(test_stream, memory, quantized_data_ptr, 1, output_offset);+ }+ size_t comp_offset = (output_block_offset + k_head_size * block_size) / 2;+ set_values(test_stream, memory, &scale, 1, comp_offset + token_idx);+ set_values(test_stream, memory, &zp, 1, comp_offset + block_size + token_idx);}- size_t comp_offset = (output_block_offset + k_head_size * block_size) / 2;- set_values(test_stream, memory, &scale, 1, comp_offset + token_idx);- set_values(test_stream, memory, &zp, 1, comp_offset + block_size + token_idx);}} else {for (int k_head_size_idx = 0; k_head_size_idx < k_head_size; k_head_size_idx++) {@@ -397,10 +532,17 @@ struct PagedAttentionManager {}memory::ptr get_value_cache_memory() {- auto value_cache_dt = kv_cache_compression ? data_types::i8 : data_types::f16;+ auto value_cache_dt = data_types::f16;const int head_size = v_head_size;+ int scale_zp_bytes = 0;+ if (kv_cache_compression) {+ value_cache_dt = is_int4_kv_cache() ? data_types::u8 : data_types::i8;+ scale_zp_bytes = is_int4_kv_cache() ? 8 : 4;+ }- const int adjusted_head_size = head_size + (kv_cache_compression ? 4 : 0);+ // For u4 (INT4), values are packed 2 per byte; the physical head size is halved.+ // PACKED_ADJUSTED_V_HEAD_SIZE = v_head_size/2 + scales_zp_size = 64 + 8 = 72.+ const int adjusted_head_size = is_int4_kv_cache() ? (head_size / 2 + scale_zp_bytes) : (head_size + scale_zp_bytes);const auto num_blocks = block_indices.back() + 1;auto value_cache_shape = ov::PartialShape{static_cast<int64_t>(num_blocks),@@ -434,6 +576,68 @@ struct PagedAttentionManager {(static_cast<size_t>(head_idx) * static_cast<size_t>(block_size) * static_cast<size_t>(head_size));const size_t off = base + static_cast<size_t>(token_idx) * static_cast<size_t>(head_size);set_values(test_stream, memory, src_ptr, head_size, off);+ } else if (is_int4_kv_cache()) {+ // INT4 (u4) BY_TOKEN value cache layout:+ // [num_blocks, kv_heads, block_size, PACKED_ADJUSTED_V_HEAD_SIZE] u8+ // where PACKED_ADJUSTED_V_HEAD_SIZE = v_head_size/2 + scales_zp_size = 64 + 8 = 72.+ // Data: block_base + token * packed_head_size + p (p = 0..packed_head_size-1)+ // Each byte packs pair: byte = (q_even_group & 0xF) | ((q_odd_group & 0xF) << 4)+ // Even group g*2 and odd group g*2+1 of 16 dims each → packed group g of 16 bytes.+ // Comp: block_base + packed_head_size * block_size bytes:+ // Scale (inv_scale = 1.0/scale): fp16[token]+ // ZP: fp16[block_size + token]+ const int packed_head_size = head_size / 2; // = 64++ // Quantize entire token: one scale/zp for all head dims (BY_TOKEN)+ float min_val = std::numeric_limits<float>::max();+ float max_val = std::numeric_limits<float>::lowest();+ for (int d = 0; d < head_size; d++) {+ float v = static_cast<float>(src_ptr[d]);+ min_val = std::min(min_val, v);+ max_val = std::max(max_val, v);+ }+ float diff = (max_val == min_val) ? 0.001f : (max_val - min_val);+ // Expand range if too small (matches kernel logic)+ float min_range = std::abs(max_val * 0.1f);+ if (diff <= min_range)+ diff += std::max(1.0f, min_range);+ float scale_val = 15.0f / diff; // INT4_RANGE = 15 for u4+ float zp_val = -min_val * scale_val;+ ov::float16 inv_scale_fp16 = ov::float16(1.0f / scale_val);+ ov::float16 zp_fp16 = ov::float16(zp_val);++ const size_t block_stride = static_cast<size_t>(adjusted_head_size) * static_cast<size_t>(block_size);+ const size_t block_base =+ (static_cast<size_t>(start_block_idx + block_idx) * static_cast<size_t>(num_kv_heads) + static_cast<size_t>(head_idx)) *+ block_stride;++ // Pack pairs of groups: group (g*2) and (g*2+1), each 16 dims wide.+ // Packed byte = (q0 & 0xF) | ((q1 & 0xF) << 4)+ // Written at: block_base + token * packed_head_size + p, using u8 element offsets.+ const int num_packed_groups = packed_head_size / 16; // = 4+ for (int g = 0; g < num_packed_groups; g++) {+ for (int lane = 0; lane < 16; lane++) {+ int dim_even = (g * 2) * 16 + lane;+ int dim_odd = (g * 2 + 1) * 16 + lane;+ int q0 = static_cast<int>(std::nearbyint(static_cast<float>(src_ptr[dim_even]) * scale_val + zp_val));+ int q1 = static_cast<int>(std::nearbyint(static_cast<float>(src_ptr[dim_odd]) * scale_val + zp_val));+ q0 = std::max(0, std::min(15, q0));+ q1 = std::max(0, std::min(15, q1));+ uint8_t packed_byte = static_cast<uint8_t>((q0 & 0xFu) | (static_cast<uint8_t>(q1 & 0xFu) << 4));+ const size_t packed_pos = g * 16 + lane;+ const size_t byte_off = block_base + static_cast<size_t>(token_idx) * packed_head_size + packed_pos;+ // set_values for u8 memory: element index = byte offset+ set_values(test_stream, memory, &packed_byte, 1, byte_off);+ }+ }++ // Write scale and zp into comp region+ const size_t scale_base_bytes = block_base + static_cast<size_t>(packed_head_size) * static_cast<size_t>(block_size);+ const size_t zp_base_bytes = scale_base_bytes + static_cast<size_t>(block_size) * sizeof(ov::float16);+ const size_t scale_off_f16 = (scale_base_bytes >> 1) + static_cast<size_t>(token_idx);+ const size_t zp_off_f16 = (zp_base_bytes >> 1) + static_cast<size_t>(token_idx);+ set_values(test_stream, memory, &inv_scale_fp16, 1, scale_off_f16);+ set_values(test_stream, memory, &zp_fp16, 1, zp_off_f16);} else {// Compressed Value cache layout:// logical shape: [num_blocks, num_kv_heads, block_size, adjusted_head_size], dt=i8 (adjusted_head_size=head_size+4).@@ -1255,44 +1459,140 @@ private:}}} else {- // Compressed case: read as int8 and dequantize- mem_lock<int8_t, mem_lock_type::read> cache_ptr(key_cache_mem, test_stream);-if (pam.key_cache_quant_mode == ov::internal::CacheQuantMode::BY_CHANNEL) {- // BY_CHANNEL: [num_blocks, num_kv_heads, head_size, block_size+4]- // Each dimension quantized across all tokens in block- for (int block_idx = 0; block_idx < num_blocks; block_idx++) {- const int physical_block = pam.block_indices[blocks_start + block_idx];- const int tokens_in_block = std::min(pam.block_size, total_tokens - block_idx * pam.block_size);+ if (pam.is_int4_kv_cache()) {+ // INT4 BY_CHANNEL: [num_blocks, kv_heads, k_head_size/2, block_size+8] u8+ // Each packed dim p: byte holds two u4 values (lower=even dim, upper=odd dim).+ // Comp at [p, block_size..block_size+7]: 4 fp16 = inv_scale0, zp0, inv_scale1, zp1+ mem_lock<uint8_t, mem_lock_type::read> cache_ptr(key_cache_mem, test_stream);+ const int packed_head_size = pam.k_head_size / 2;+ const int adj_block_size = pam.block_size + 8;++ for (int block_idx = 0; block_idx < num_blocks; block_idx++) {+ const int physical_block = pam.block_indices[blocks_start + block_idx];+ const int tokens_in_block = std::min(pam.block_size, total_tokens - block_idx * pam.block_size);- for (int head_idx = 0; head_idx < pam.num_kv_heads; head_idx++) {- const size_t cache_base = static_cast<size_t>(physical_block) * pam.num_kv_heads * pam.k_head_size * (pam.block_size + 4) +- static_cast<size_t>(head_idx) * pam.k_head_size * (pam.block_size + 4);+ for (int head_idx = 0; head_idx < pam.num_kv_heads; head_idx++) {+ const size_t cache_base = static_cast<size_t>(physical_block) * pam.num_kv_heads * packed_head_size * adj_block_size+ + static_cast<size_t>(head_idx) * packed_head_size * adj_block_size;++ for (int p = 0; p < packed_head_size; p++) {+ const int dim0 = p * 2;+ const int dim1 = p * 2 + 1;+ // Read inv_scale and zp for both dims from comp region+ const size_t comp_byte_off = cache_base + static_cast<size_t>(p) * adj_block_size + pam.block_size;+ const ov::float16* comp = reinterpret_cast<const ov::float16*>(&cache_ptr[comp_byte_off]);+ float inv_scale0 = static_cast<float>(comp[0]);+ float zp0 = static_cast<float>(comp[1]);+ float inv_scale1 = static_cast<float>(comp[2]);+ float zp1 = static_cast<float>(comp[3]);++ for (int token_offset = 0; token_offset < tokens_in_block; token_offset++) {+ const int token_idx = block_idx * pam.block_size + token_offset;+ const size_t byte_off = cache_base + static_cast<size_t>(p) * adj_block_size + token_offset;+ uint8_t packed_byte = cache_ptr[byte_off];+ uint8_t q0 = packed_byte & 0xFu;+ uint8_t q1 = (packed_byte >> 4) & 0xFu;+ float dq0 = (static_cast<float>(q0) - zp0) * inv_scale0;+ float dq1 = (static_cast<float>(q1) - zp1) * inv_scale1;+ const size_t out_base = static_cast<size_t>(head_idx) * total_tokens * pam.k_head_size+ + static_cast<size_t>(token_idx) * pam.k_head_size;+ key_data[out_base + dim0] = ov::float16(dq0);+ key_data[out_base + dim1] = ov::float16(dq1);+ }+ }+ }+ }+ } else {+ // I8/U8 BY_CHANNEL: [num_blocks, num_kv_heads, head_size, block_size+4]+ // Each dimension quantized across all tokens in block+ mem_lock<int8_t, mem_lock_type::read> cache_ptr(key_cache_mem, test_stream);+ const int adj_block_size = pam.block_size + 4;- for (int dim = 0; dim < pam.k_head_size; dim++) {- // Read scale and zero-point for this dimension- const size_t scale_offset = cache_base + static_cast<size_t>(dim) * (pam.block_size + 4) + pam.block_size;- ov::float16 scale = *reinterpret_cast<const ov::float16*>(&cache_ptr[scale_offset]);- ov::float16 zp = *reinterpret_cast<const ov::float16*>(&cache_ptr[scale_offset + 2]);+ for (int block_idx = 0; block_idx < num_blocks; block_idx++) {+ const int physical_block = pam.block_indices[blocks_start + block_idx];+ const int tokens_in_block = std::min(pam.block_size, total_tokens - block_idx * pam.block_size);- // Dequantize all tokens for this dimension- for (int token_offset = 0; token_offset < tokens_in_block; token_offset++) {- const int token_idx = block_idx * pam.block_size + token_offset;- const size_t cache_offset = cache_base + static_cast<size_t>(dim) * (pam.block_size + 4) + token_offset;- const size_t output_offset = static_cast<size_t>(head_idx) * total_tokens * pam.k_head_size +- static_cast<size_t>(token_idx) * pam.k_head_size + dim;+ for (int head_idx = 0; head_idx < pam.num_kv_heads; head_idx++) {+ const size_t cache_base = static_cast<size_t>(physical_block) * pam.num_kv_heads * pam.k_head_size * adj_block_size ++ static_cast<size_t>(head_idx) * pam.k_head_size * adj_block_size;- int8_t quantized_value = cache_ptr[cache_offset];- float dequantized = (static_cast<float>(quantized_value) - static_cast<float>(zp)) * static_cast<float>(scale);- key_data[output_offset] = ov::float16(dequantized);+ for (int dim = 0; dim < pam.k_head_size; dim++) {+ // Read scale and zero-point for this dimension+ const size_t scale_offset = cache_base + static_cast<size_t>(dim) * adj_block_size + pam.block_size;+ ov::float16 scale = *reinterpret_cast<const ov::float16*>(&cache_ptr[scale_offset]);+ ov::float16 zp = *reinterpret_cast<const ov::float16*>(&cache_ptr[scale_offset + 2]);++ // Dequantize all tokens for this dimension+ for (int token_offset = 0; token_offset < tokens_in_block; token_offset++) {+ const int token_idx = block_idx * pam.block_size + token_offset;+ const size_t cache_offset = cache_base + static_cast<size_t>(dim) * adj_block_size + token_offset;+ const size_t output_offset = static_cast<size_t>(head_idx) * total_tokens * pam.k_head_size ++ static_cast<size_t>(token_idx) * pam.k_head_size + dim;++ int8_t quantized_value = cache_ptr[cache_offset];+ float dequantized = (static_cast<float>(quantized_value) - static_cast<float>(zp)) * static_cast<float>(scale);+ key_data[output_offset] = ov::float16(dequantized);+ }}}}}} else {+ // BY_TOKEN+ if (pam.is_int4_kv_cache()) {+ // INT4 BY_TOKEN: [num_blocks, kv_heads, k_head_size/2+8, block_size] u8+ // Packing (SUBGROUP_SIZE=16):+ // Y = pack_group*16 + sglid, where pack_group = d/(2*16), sglid = d%16+ // lower nibble = q(dim[pack_group*32 + sglid])+ // upper nibble = q(dim[pack_group*32 + sglid + 16])+ // Scale/ZP: fp16 in comp region at base + packed_head_size*block_size+ // inv_scale[t] at comp_ptr[t], zp[t] at comp_ptr[block_size + t]+ mem_lock<uint8_t, mem_lock_type::read> cache_ptr(key_cache_mem, test_stream);+ const int packed_head_size = pam.k_head_size / 2;+ const int adj_head_size = packed_head_size + 8;+ constexpr int SG = 16;++ for (int block_idx = 0; block_idx < num_blocks; block_idx++) {+ const int physical_block = pam.block_indices[blocks_start + block_idx];+ const int tokens_in_block = std::min(pam.block_size, total_tokens - block_idx * pam.block_size);++ for (int head_idx = 0; head_idx < pam.num_kv_heads; head_idx++) {+ const size_t cache_base = static_cast<size_t>(physical_block) * pam.num_kv_heads * adj_head_size * pam.block_size ++ static_cast<size_t>(head_idx) * adj_head_size * pam.block_size;+ // Scale and ZP are in the comp region after the packed data+ const size_t comp_byte_base = cache_base + static_cast<size_t>(packed_head_size) * pam.block_size;+ const auto* inv_scale_arr = reinterpret_cast<const ov::float16*>(&cache_ptr[comp_byte_base]);+ const auto* zp_arr = reinterpret_cast<const ov::float16*>(&cache_ptr[comp_byte_base + pam.block_size * 2]);++ for (int token_offset = 0; token_offset < tokens_in_block; token_offset++) {+ const int token_idx = block_idx * pam.block_size + token_offset;+ float inv_scale = static_cast<float>(inv_scale_arr[token_offset]);+ float zp_val = static_cast<float>(zp_arr[token_offset]);+ const size_t out_base = static_cast<size_t>(head_idx) * total_tokens * pam.k_head_size ++ static_cast<size_t>(token_idx) * pam.k_head_size;++ for (int d = 0; d < pam.k_head_size; d++) {+ int sglid_val = d % SG;+ int pack_group = d / (2 * SG);+ int group_in_pack = (d / SG) % 2; // 0=lower nibble, 1=upper nibble+ int y = pack_group * SG + sglid_val;+ const size_t byte_off = cache_base + static_cast<size_t>(y) * pam.block_size + token_offset;+ uint8_t packed_byte = cache_ptr[byte_off];+ uint8_t q_d = (group_in_pack == 0) ? (packed_byte & 0xFu) : ((packed_byte >> 4) & 0xFu);+ key_data[out_base + d] = ov::float16((static_cast<float>(q_d) - zp_val) * inv_scale);+ }+ }+ }+ }++ return key_data;+ }+// BY_TOKEN: [num_blocks, num_kv_heads, head_size+4, block_size]// Token-wise quantization with shared scale/zp per token// Layout: data rows [0..head_size-1], scale at [head_size], zp at [head_size+2] (fp16)+ mem_lock<int8_t, mem_lock_type::read> cache_ptr(key_cache_mem, test_stream);for (int block_idx = 0; block_idx < num_blocks; block_idx++) {const int physical_block = pam.block_indices[blocks_start + block_idx];const int tokens_in_block = std::min(pam.block_size, total_tokens - block_idx * pam.block_size);@@ -1327,8 +1627,9 @@ private:}}}- }- }+ } // end else (i8 BY_TOKEN)+ } // is_compressed+return key_data;}@@ -1384,6 +1685,7 @@ public:}void execute(T& p) {+ ov::element::Type kv_cache_precision = p.kv_cache_precision;PagedAttentionManager pam(rg,get_test_engine(),get_test_stream(),@@ -1399,7 +1701,8 @@ public:p.scores_mode == ScoresMode::SNAPKV,p.has_xattention,p.rotation_config,- p.threshold);+ p.threshold,+ kv_cache_precision);if (p.has_adaptive_rkv) {pam.adaptive_rkv_diversity_block_set_indices_begins.push_back(0);@@ -1657,6 +1960,9 @@ public:// FlashAttn v1 or v2?config.set_property(ov::intel_gpu::could_use_flashattn_v2(p.disable_flashattn_v2));config.set_property(ov::internal::key_cache_quant_mode(p.key_cache_quant_mode));+ if (kv_cache_precision != ov::element::dynamic) {+ config.set_property(ov::hint::kv_cache_precision(kv_cache_precision));+ }network::ptr network = get_network(get_test_engine(), topology, config, get_test_stream_ptr(), false);network->set_input_data("query", query_mem);network->set_input_data("key", key_mem);@@ -1786,6 +2092,7 @@ struct paged_attention_test_params {bool has_adaptive_rkv = false;int start_size = 0; // Common start_size for all sequencesstd::vector<int> evictable_sizes; // Per-sequence evictable sizes+ ov::element::Type kv_cache_precision = ov::element::dynamic;};class paged_attention_test : public PagedAttentionTest<paged_attention_test_params> {};@@ -1967,6 +2274,25 @@ INSTANTIATE_TEST_SUITE_P(smoke_paged_attention, paged_attention_test, ::testing:paged_attention_test_params{ {{84, 256}}, 32, 32, 128, 128, 16, {100.0}, 16, false, ENABLE_CACHE_COMPRESSION,ov::internal::CacheQuantMode::BY_CHANNEL, STATIC_INPUT_PAD, DISABLE_SCORES, PER_TOKEN_ROTATION, DISABLE_FA_V2 }, // 2nd token, per token rotatepaged_attention_test_params{ {{40, 96}, {30, 50}}, 2, 2, 64, 64, 16, {100.0}, 8, false, ENABLE_CACHE_COMPRESSION,ov::internal::CacheQuantMode::BY_CHANNEL, STATIC_INPUT_PAD, ENABLE_SCORES, PER_TOKEN_ROTATION, DISABLE_FA_V2 }, // 2nd token, per token rotatepaged_attention_test_params{ {{128, 130}, {256, 60}}, 2, 2, 48, 64, 16, {100.0}, 128, false, ENABLE_CACHE_COMPRESSION,ov::internal::CacheQuantMode::BY_CHANNEL, STATIC_INPUT_PAD, ENABLE_SCORES, PER_TOKEN_ROTATION, ENABLE_FA_V2 }, // 2nd token, per token rotate+ /* INT4 KV-cache compression (u4+BY_CHANNEL) */+ paged_attention_test_params{ {{10, 0}}, 2, 2, 64, 64, 16, {100.0}, 0, false, ENABLE_CACHE_COMPRESSION, ov::internal::CacheQuantMode::BY_TOKEN, DYNAMIC_INPUT_PAD, DISABLE_SCORES, DISABLE_ROTATION, DISABLE_FA_V2, false, 0, {}, ov::element::u4 }, // 1st token u4+BY_TOKEN+ paged_attention_test_params{ {{256, 0}}, 2, 2, 64, 64, 16, {100.0}, 0, false, ENABLE_CACHE_COMPRESSION, ov::internal::CacheQuantMode::BY_TOKEN, DYNAMIC_INPUT_PAD, DISABLE_SCORES, DISABLE_ROTATION, DISABLE_FA_V2, false, 0, {}, ov::element::u4 }, // 1st token long u4+BY_TOKEN+ paged_attention_test_params{ {{256, 0}}, 2, 2, 64, 64, 16, {100.0}, 0, false, ENABLE_CACHE_COMPRESSION, ov::internal::CacheQuantMode::BY_CHANNEL, DYNAMIC_INPUT_PAD, DISABLE_SCORES, DISABLE_ROTATION, DISABLE_FA_V2, false, 0, {}, ov::element::u4 }, // 1st token long u4+BY_CHANNEL+ paged_attention_test_params{ {{10, 0}, {30, 0}}, 2, 2, 64, 64, 16, {100.0}, 0, false, ENABLE_CACHE_COMPRESSION, ov::internal::CacheQuantMode::BY_TOKEN, DYNAMIC_INPUT_PAD, DISABLE_SCORES, DISABLE_ROTATION, DISABLE_FA_V2, false, 0, {}, ov::element::u4 }, // 1st token + 1st token u4+BY_TOKEN+ paged_attention_test_params{ {{10, 0}, {30, 0}}, 2, 2, 64, 64, 16, {100.0}, 0, false, ENABLE_CACHE_COMPRESSION, ov::internal::CacheQuantMode::BY_CHANNEL, DYNAMIC_INPUT_PAD, DISABLE_SCORES, DISABLE_ROTATION, DISABLE_FA_V2, false, 0, {}, ov::element::u4 }, // 1st token + 1st token u4+BY_CHANNEL+ paged_attention_test_params{ {{1, 34}}, 2, 2, 64, 64, 16, {100.0}, 0, false, ENABLE_CACHE_COMPRESSION, ov::internal::CacheQuantMode::BY_TOKEN, DYNAMIC_INPUT_PAD, DISABLE_SCORES, DISABLE_ROTATION, DISABLE_FA_V2, false, 0, {}, ov::element::u4 }, // 2nd token u4+BY_TOKEN+ paged_attention_test_params{ {{1, 34}, {1, 515}}, 2, 2, 64, 64, 16, {100.0}, 0, false, ENABLE_CACHE_COMPRESSION, ov::internal::CacheQuantMode::BY_TOKEN, DYNAMIC_INPUT_PAD, DISABLE_SCORES, DISABLE_ROTATION, DISABLE_FA_V2, false, 0, {}, ov::element::u4 }, // 2nd token + 2nd token u4+BY_TOKEN+ paged_attention_test_params{ {{1, 300}}, 2, 2, 64, 64, 16, {100.0}, 0, false, ENABLE_CACHE_COMPRESSION, ov::internal::CacheQuantMode::BY_TOKEN, DYNAMIC_INPUT_PAD, DISABLE_SCORES, DISABLE_ROTATION, DISABLE_FA_V2, false, 0, {}, ov::element::u4 }, // 2nd token, past_len>partition_size u4+BY_TOKEN+ paged_attention_test_params{ {{1, 300}}, 2, 2, 64, 64, 16, {100.0}, 0, false, ENABLE_CACHE_COMPRESSION, ov::internal::CacheQuantMode::BY_CHANNEL, DYNAMIC_INPUT_PAD, DISABLE_SCORES, DISABLE_ROTATION, DISABLE_FA_V2, false, 0, {}, ov::element::u4 }, // 2nd token, past_len>partition_size u4+BY_CHANNEL+ /* u4 MIXED mode (generate+prefill in same batch) - covers pa_multi_token sink_ptr fix */+ paged_attention_test_params{ {{1, 34}, {25, 0}, {10, 34}}, 2, 2, 64, 64, 16, {100.0}, 0, false, ENABLE_CACHE_COMPRESSION, ov::internal::CacheQuantMode::BY_TOKEN, DYNAMIC_INPUT_PAD, DISABLE_SCORES, DISABLE_ROTATION, DISABLE_FA_V2, false, 0, {}, ov::element::u4 }, // mixed u4+BY_TOKEN+ paged_attention_test_params{ {{1, 34}, {25, 0}, {10, 34}}, 2, 2, 64, 64, 16, {100.0}, 0, false, ENABLE_CACHE_COMPRESSION, ov::internal::CacheQuantMode::BY_CHANNEL, DYNAMIC_INPUT_PAD, DISABLE_SCORES, DISABLE_ROTATION, DISABLE_FA_V2, false, 0, {}, ov::element::u4 }, // mixed u4+BY_CHANNEL+ /* u4 with larger head size */+ paged_attention_test_params{ {{1, 34}}, 2, 2, 128, 128, 16, {100.0}, 0, false, ENABLE_CACHE_COMPRESSION, ov::internal::CacheQuantMode::BY_TOKEN, DYNAMIC_INPUT_PAD, DISABLE_SCORES, DISABLE_ROTATION, DISABLE_FA_V2, false, 0, {}, ov::element::u4 }, // 2nd token, head_size=128 u4+BY_TOKEN+ paged_attention_test_params{ {{1, 34}}, 2, 2, 128, 128, 16, {100.0}, 0, false, ENABLE_CACHE_COMPRESSION, ov::internal::CacheQuantMode::BY_CHANNEL, DYNAMIC_INPUT_PAD, DISABLE_SCORES, DISABLE_ROTATION, DISABLE_FA_V2, false, 0, {}, ov::element::u4 }, // 2nd token, head_size=128 u4+BY_CHANNEL+ /* u4 with GQA (multi query groups) */+ paged_attention_test_params{ {{1, 34}}, 8, 2, 64, 64, 16, {100.0}, 0, false, ENABLE_CACHE_COMPRESSION, ov::internal::CacheQuantMode::BY_TOKEN, DYNAMIC_INPUT_PAD, DISABLE_SCORES, DISABLE_ROTATION, DISABLE_FA_V2, false, 0, {}, ov::element::u4 }, // 2nd token, GQA 8/2 u4+BY_TOKEN+ paged_attention_test_params{ {{1, 34}}, 8, 2, 64, 64, 16, {100.0}, 0, false, ENABLE_CACHE_COMPRESSION, ov::internal::CacheQuantMode::BY_CHANNEL, DYNAMIC_INPUT_PAD, DISABLE_SCORES, DISABLE_ROTATION, DISABLE_FA_V2, false, 0, {}, ov::element::u4 }, // 2nd token, GQA 8/2 u4+BY_CHANNEL}));INSTANTIATE_TEST_SUITE_P(smoke_cm_xattention, xattention_test, ::testing::ValuesIn(std::vector<paged_attention_test_params>{