Skip to content

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

[GPU] Extend dynamic quantize KV-cache kernel to head sizes up to 512 (#38466)

Eddy Kim33e63ae1bfbf
diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/dynamic_quantize/dynamic_quantize_kernel_opt_kv_cache.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/dynamic_quantize/dynamic_quantize_kernel_opt_kv_cache.cpp
index 19f3c8e70da..f02faaa6ed7 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/kernels/dynamic_quantize/dynamic_quantize_kernel_opt_kv_cache.cpp
+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/dynamic_quantize/dynamic_quantize_kernel_opt_kv_cache.cpp
@@ -291,8 +291,11 @@ bool DynamicQuantizeKernelKVCache::Validate(const Params& params) const {
DO_NOT_USE_THIS_KERNEL(params.layerID);
}
- // Limit the size of the innermost dimension
- if (input_dims.back().v > 256) {
+ // Limit the size of the innermost dimension.
+ // 512 matches the SDPA fusion head-size limit (transformations_pipeline.cpp): above it SDPA decomposes,
+ // so a compressed KV-cache never needs a larger innermost dimension here. The ref kernel fallback cannot
+ // append, so keeping this in sync with the fusion limit is what keeps the append path selectable.
+ if (input_dims.back().v > 512) {
DO_NOT_USE_THIS_KERNEL(params.layerID);
}
diff --git a/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/kv_cache_sdpa.cpp b/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/kv_cache_sdpa.cpp
index d60a87add8d..d9f5bed8fd5 100644
--- a/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/kv_cache_sdpa.cpp
+++ b/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/kv_cache_sdpa.cpp
@@ -472,6 +472,16 @@ std::vector<Params> get_test_params() {
// Compressed beam search (batch > 1 exercises indirect sdpa_opt path on IMMAD)
p.push_back({with_rearrange, with_mask, !with_scale, causal, compressed, 2, ov::element::Type_t::bf16, 10, 4, 64, 64, 1, {0, 2, 1, 3}});
+ // Compressed KV-cache with head size >= 256: the new token must be appended by the dynamic quantize kernel that supports append mode.
+ for (size_t hs : {256u, 512u}) {
+ // The test mask is not shifted by the past length, so at q=1 only the first key is visible and the appended token is not checked.
+ p.push_back({with_rearrange, with_mask, !with_scale, !causal, compressed, 1, ov::element::Type_t::f16, 5, 4, hs, hs, 1, {0, 1, 2, 3}});
+ // Without a mask all keys are visible, so the appended token contributes to the result.
+ p.push_back({with_rearrange, !with_mask, !with_scale, !causal, compressed, 1, ov::element::Type_t::f16, 5, 4, hs, hs, 1, {0, 1, 2, 3}});
+ }
+ // Same head size without compression
+ p.push_back({with_rearrange, with_mask, !with_scale, !causal, !compressed, 1, ov::element::Type_t::f16, 5, 4, 512, 512, 1, {0, 1, 2, 3}});
+
return p;
}
diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/dynamic_quantize_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/dynamic_quantize_gpu_test.cpp
index bd3efc2ec40..5ee68d78e86 100644
--- a/src/plugins/intel_gpu/tests/unit/test_cases/dynamic_quantize_gpu_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/test_cases/dynamic_quantize_gpu_test.cpp
@@ -425,6 +425,11 @@ TEST_F(dynamic_quantization_gpu_tests, simple_quantizing_kv_cache_asym_planar_i8
data_types::i8, data_types::f16, data_types::i8, OutputStorageType::Planar, "dynamic_quantize_gpu_kv_cache");
}
+TEST_F(dynamic_quantization_gpu_tests, simple_quantizing_kv_cache_asym_planar_i8_zp_head512) {
+ this->test_dynamic_quantization(false, {-1, 4, -1, 512}, {1, 4, 35, 512}, QuantizationType::Asymmetric, UINT64_MAX,
+ data_types::i8, data_types::f16, data_types::i8, OutputStorageType::Planar, "dynamic_quantize_gpu_kv_cache");
+}
+
TEST_F(dynamic_quantization_gpu_tests, simple_quantizing_kv_cache_batched_asym_planar_i8_zp) {
this->test_dynamic_quantization(false, {-1, 4, -1, 64}, {1, 4, 35, 64}, QuantizationType::Asymmetric, UINT64_MAX,
data_types::i8, data_types::f16, data_types::i8, OutputStorageType::Planar, "dynamic_quantize_gpu_kv_cache");