From 94d14629247955c69d40bdf2a9d7e3bd45954452 Mon Sep 17 00:00:00 2001 From: Oxana Korzh Date: Mon, 28 Sep 2026 10:05:10 -0600 Subject: [PATCH] [Bugfix][Kimi-K3] Refresh DSpark context KV cache pointers after the KV cache is re-bound (#58814) Signed-off-by: Oxana Korzh Co-authored-by: Claude Opus 5.5 (1M context) --- vllm/models/kimi_k3/nvidia/dspark_mla.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/vllm/models/kimi_k3/nvidia/dspark_mla.py b/vllm/models/kimi_k3/nvidia/dspark_mla.py index 0baff884cc..37207d7bc9 100644 --- a/vllm/models/kimi_k3/nvidia/dspark_mla.py +++ b/vllm/models/kimi_k3/nvidia/dspark_mla.py @@ -376,7 +376,12 @@ class K3DSparkModel(nn.Module): self, cache_layers: list[MultiHeadLatentAttention], ) -> bool: - if not hasattr(self, "_layers_share_kv_block_layout"): + key = tuple(cl.kv_cache.data_ptr() for cl in cache_layers) + if getattr(self, "_kv_cache_ptrs_key", None) != key: + assert not torch.cuda.is_current_stream_capturing() + self._kv_cache_ptrs_key = key + if hasattr(self, "_context_cache_ptrs"): + del self._context_cache_ptrs ref_cache = cache_layers[0].kv_cache self._layers_share_kv_block_layout = all( cl.kv_cache.size(1) == ref_cache.size(1)