[Bugfix] Zero new KV blocks for quantized + sliding-window hybrid caches (#47574)

Signed-off-by: EdalatiAli <aliedalati@cohere.com> Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Nicolò Lucchesi <nlucches@redhat.com>

EdalatiAli committed Jul 20, 2026 at 09:18 UTC 8ce53a616ebfc337edb73f847fcefe8af8ba769b
1 file changed +18 -1
vllm/v1/kv_cache_interface.py
+18 -1
@@ -972,6 +972,23 @@ class KVCacheConfig:
972 def has_mamba_layers(self) -> bool:
973 return any(isinstance(g.kv_cache_spec, MambaSpec) for g in self.kv_cache_groups)
974
975 + @property
976 + def has_mixed_precision_kv_cache(self) -> bool:
977 + """Whether attention groups store their KV cache at more than one precision."""
978 + kv_cache_precisions = {
979 + (group.kv_cache_spec.dtype, group.kv_cache_spec.kv_quant_mode)
980 + for group in self.kv_cache_groups
981 + if isinstance(group.kv_cache_spec, AttentionSpec)
982 + }
983 + return len(kv_cache_precisions) > 1
984 +
985 @property
986 def needs_kv_cache_zeroing(self) -> bool:
977 - return self.has_mamba_layers
987 + """Whether newly allocated KV cache blocks must be zeroed before use.
988 +
989 + Required for Mamba layers, whose state is read before it is fully written
990 + (#35219), and for mixed-precision caches, where a block reused across
991 + groups can be reinterpreted under a different precision and decode stale
992 + bytes to NaN/Inf. Uniform-precision caches skip zeroing.
993 + """
994 + return self.has_mamba_layers or self.has_mixed_precision_kv_cache