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 KV-cache compression for systolic platforms by default (#29328)
Sergey Shlyapnikovc1e81b060677
diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/pa_sdpa_opt.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/pa_sdpa_opt.clindex ee8100b45ee..079e3e3e2ff 100644--- a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/pa_sdpa_opt.cl+++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/pa_sdpa_opt.cl@@ -124,24 +124,26 @@ KERNEL(pa_sdpa_opt)({#if STORE_QUERY_TO_SLM- const uint query_idx_local = sgid * SUBGROUP_SIZE + sglid;- const uint query_idx = INPUT0_OFFSET +- seq_idx * (HEAD_SIZE * HEADS_NUM + INPUT0_PAD_BEFORE_FEATURE_NUM + INPUT0_PAD_AFTER_FEATURE_NUM) +- head_num_idx * HEAD_SIZE +- query_idx_local;+ if (sgid < HEAD_SIZE / SUBGROUP_SIZE) {+ const uint query_idx_local = sgid * SUBGROUP_SIZE + sglid;+ const uint query_idx = INPUT0_OFFSET ++ seq_idx * (HEAD_SIZE * HEADS_NUM + INPUT0_PAD_BEFORE_FEATURE_NUM + INPUT0_PAD_AFTER_FEATURE_NUM) ++ head_num_idx * HEAD_SIZE ++ query_idx_local;- INPUT0_TYPE q_val = BLOCK_READN(INPUT0_TYPE, 1, query, query_idx);+ INPUT0_TYPE q_val = BLOCK_READN(INPUT0_TYPE, 1, query, query_idx);- // Apply scale value directly to the query input to improve accuracy in case of a high range of input data+ // Apply scale value directly to the query input to improve accuracy in case of a high range of input data#ifdef SCALE_VAL- q_val = TO_INPUT0_TYPE(SCALE_VAL) * q_val;+ q_val = TO_INPUT0_TYPE(SCALE_VAL) * q_val;#else- q_val = *scale * q_val;+ q_val = *scale * q_val;#endif- slm_query[query_idx_local] = q_val;+ slm_query[query_idx_local] = q_val;- barrier(CLK_LOCAL_MEM_FENCE);+ barrier(CLK_LOCAL_MEM_FENCE);+ }#elseINPUT0_TYPE q_val[HEAD_SIZE / SUBGROUP_SIZE];unroll_for (uint i = 0; i < HEAD_SIZE / SUBGROUP_SIZE; i++) {diff --git a/src/plugins/intel_gpu/src/runtime/execution_config.cpp b/src/plugins/intel_gpu/src/runtime/execution_config.cppindex 7708d2c1cb1..47d95a26c09 100644--- a/src/plugins/intel_gpu/src/runtime/execution_config.cpp+++ b/src/plugins/intel_gpu/src/runtime/execution_config.cpp@@ -8,6 +8,7 @@#include "openvino/core/model.hpp"#include "openvino/op/loop.hpp"#include "openvino/op/lstm_sequence.hpp"+#include "openvino/op/paged_attention.hpp"#include "openvino/op/search_sorted.hpp"#include "openvino/op/stft.hpp"#include "ov_ops/dynamic_quantize.hpp"@@ -135,6 +136,7 @@ void ExecutionConfig::apply_model_specific_options(const IRemoteContext* contextconst auto& ops = model.get_ops();+ auto is_paged_attention_model = false;std::function<void(std::shared_ptr<Node>)> process_op = [&, this](std::shared_ptr<Node> op) {if (requires_new_shape_infer(op)) {m_allow_new_shape_infer = true;@@ -158,12 +160,28 @@ void ExecutionConfig::apply_model_specific_options(const IRemoteContext* context}}}++ if (ov::is_type<ov::op::PagedAttentionExtension>(op)) {+ is_paged_attention_model = true;+ }};for (const auto& op : ops) {process_op(op);}+ const auto& info = dynamic_cast<const RemoteContextImpl*>(context)->get_engine().get_device_info();+ if (!is_set_by_user(ov::hint::kv_cache_precision) || get_kv_cache_precision() == ov::element::dynamic) {+ if (is_paged_attention_model || !info.supports_immad) {+ // Enable KV-cache compression by default for:+ // 1) Non-systolic platforms in case of SDPA-based models+ // 2) For any platforms in case of PagedAttention-based model+ m_kv_cache_precision = ov::element::i8;+ } else {+ m_kv_cache_precision = get_inference_precision();+ }+ }+m_optimize_data = true;}@@ -185,15 +203,6 @@ void ExecutionConfig::finalize_impl(const IRemoteContext* context) {m_queue_type = QueueTypes::in_order;}- if (!is_set_by_user(ov::hint::kv_cache_precision) || get_kv_cache_precision() == ov::element::dynamic) {- if (info.supports_immad) { // MFDNN-11755- m_kv_cache_precision = get_inference_precision();- } else {- // Enable KV-cache compression by default for non-systolic platforms only- m_kv_cache_precision = ov::element::i8;- }- }-// Enable dynamic quantization by default for non-systolic platformsif (!is_set_by_user(ov::hint::dynamic_quantization_group_size) && get_dynamic_quantization_group_size() == 0 && !info.supports_immad) {m_dynamic_quantization_group_size = 32;@@ -203,6 +212,11 @@ void ExecutionConfig::finalize_impl(const IRemoteContext* context) {m_optimize_data = true;}+ // Replace UINT8 KV-cache compression data type with INT8, as plugin is supposed to work with INT8 internally+ if (get_kv_cache_precision() == ov::element::u8) {+ m_kv_cache_precision = ov::element::i8;+ }+#ifdef ENABLE_DEBUG_CAPS// For now we apply env/config only for build with debug caps, but it can be updated in the future to allow// reading release options for any build type