Repository navigation
[Bugfix] Zero new KV blocks for quantized + sliding-window hybrid caches - #47574
Conversation
Hybrid configs mixing a block-dropping attention type (sliding-window / chunked-local) with a quantized (FP8/NVFP4) KV cache could read stale bytes from reused blocks, decoding to NaN. Extend needs_kv_cache_zeroing to cover them. Signed-off-by: EdalatiAli <aliedalati@cohere.com> Co-authored-by: Cursor <cursoragent@cursor.com>
14e0b47 to
a7f997a
Compare
| @property | ||
| def has_block_dropping_layers(self) -> bool: | ||
| """Any group uses an attention type that frees KV blocks mid-request | ||
| (sliding-window or chunked-local).""" | ||
| return any( | ||
| isinstance(g.kv_cache_spec, (SlidingWindowSpec, ChunkedLocalAttentionSpec)) | ||
| for g in self.kv_cache_groups | ||
| ) | ||
|
|
||
| @property | ||
| def has_quantized_kv_cache(self) -> bool: | ||
| """Any group stores its KV cache in a quantized dtype (FP8/NVFP4).""" | ||
| return any( | ||
| isinstance(g.kv_cache_spec, AttentionSpec) | ||
| and g.kv_cache_spec.kv_quant_mode != KVQuantMode.NONE | ||
| for g in self.kv_cache_groups | ||
| ) |
There was a problem hiding this comment.
I feel the condition is a little bit off. The fundamental issue is that we have multiple KV cache groups stored at different precisions, right? Any way to capture that more directly?
There was a problem hiding this comment.
Agreed. Switched to has_mixed_precision_kv_cache to directly capture the case. Thank you for the comment!
NickLucche
left a comment
There was a problem hiding this comment.
@EdalatiAli I might be reading it wrong, but aren't we also including models that are not using different dtypes per sw/fa layers (in fact any model that uses SW and kv fp8 which is quite common)?
I believe we should only target those with hybrid accuracy.
Signed-off-by: EdalatiAli <aliedalati@cohere.com>
There was a problem hiding this comment.
I think this is addressing a more generic issue when mixing dtypes in kv cache, which is one may argue is also what happens with mamba.
Anyways I am happy with the revised check, although we might consider merging mamba/fa condition, I think the current check form might be clearer.
Thanks @EdalatiAli !
|
@NickLucche Thank you for the insightful comments! |
…hes (vllm-project#47574) Signed-off-by: EdalatiAli <aliedalati@cohere.com> Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Nicolò Lucchesi <nlucches@redhat.com>
|
Has any test been done for PD? For Mamba, we found that GPU zero ops and PD transfer may have a data race. @NickLucche @tlrmchlsmth |
…hes (vllm-project#47574) Signed-off-by: EdalatiAli <aliedalati@cohere.com> Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Nicolò Lucchesi <nlucches@redhat.com>
Purpose
A hybrid KV cache that quantizes full-attention layers but keeps sliding-window layers in higher precision (
--kv-cache-dtype fp8 --kv-cache-dtype-skip-layers sliding_window) produces NaN / all-zero output once the input exceeds the sliding window. Uniform fp8 and bf16 are fine; only the hybrid combo fails (seen on Blackwell + FlashInfer).Root cause
Attention groups share one block pool. The sliding-window group frees blocks mid-request; those pages get reallocated to the fp8 group and read back including slots not written this step. As bf16 that leftover is harmless
garbage, but as fp8 it decodes to NaN/Inf and corrupts attention. The existing zeroing guard (
needs_kv_cache_zeroing) was gated only on Mamba (#35219), so this config was left exposed.Fix
Extend
needs_kv_cache_zeroingto also fire for block-dropping attention (sliding-window / chunked-local) + quantized (FP8/NVFP4) KV cache:Uniform / unquantized caches stay
False→ zero overhead.Test Plan
niah_single_1) evals onCohereLabs/command-a-plus-05-2026-w4a4with various kv cache quantization options, before and after the fix.lm-eval-harness0.4.x.Serve the hybrid config:
--kv-cache-dtype fp8alone, and with no--kv-cache-dtypeflag for the bf16 reference):Test Result
Essential Elements of an Effective PR Description Checklist
supported_models.mdandexamplesfor a new model.