From 8ce53a616ebfc337edb73f847fcefe8af8ba769b Mon Sep 17 00:00:00 2001 From: EdalatiAli Date: Mon, 20 Jul 2026 09:18:17 -0400 Subject: [PATCH] [Bugfix] Zero new KV blocks for quantized + sliding-window hybrid caches (#47574) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: EdalatiAli Co-authored-by: Cursor Co-authored-by: Nicolò Lucchesi --- vllm/v1/kv_cache_interface.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/vllm/v1/kv_cache_interface.py b/vllm/v1/kv_cache_interface.py index 7a44d4e1d25..7b694db051b 100644 --- a/vllm/v1/kv_cache_interface.py +++ b/vllm/v1/kv_cache_interface.py @@ -972,6 +972,23 @@ class KVCacheConfig: def has_mamba_layers(self) -> bool: return any(isinstance(g.kv_cache_spec, MambaSpec) for g in self.kv_cache_groups) + @property + def has_mixed_precision_kv_cache(self) -> bool: + """Whether attention groups store their KV cache at more than one precision.""" + kv_cache_precisions = { + (group.kv_cache_spec.dtype, group.kv_cache_spec.kv_quant_mode) + for group in self.kv_cache_groups + if isinstance(group.kv_cache_spec, AttentionSpec) + } + return len(kv_cache_precisions) > 1 + @property def needs_kv_cache_zeroing(self) -> bool: - return self.has_mamba_layers + """Whether newly allocated KV cache blocks must be zeroed before use. + + Required for Mamba layers, whose state is read before it is fully written + (#35219), and for mixed-precision caches, where a block reused across + groups can be reinterpreted under a different precision and decode stale + bytes to NaN/Inf. Uniform-precision caches skip zeroing. + """ + return self.has_mamba_layers or self.has_mixed_precision_kv_cache