From 869f78732b64454293d2ba42ae0008386fdaa6a6 Mon Sep 17 00:00:00 2001 From: Wentao Ye <44945378+yewentao256@users.noreply.github.com> Date: Mon, 7 Sep 2026 22:34:48 -0400 Subject: [PATCH] [Kimi Bug] Fix kimi k3 AssertionError assert 0 <= checkpoint_idx < len(blocks) (#55747) Signed-off-by: yewentao256 --- .../test_partial_prefix_cache_hits.py | 2 +- vllm/v1/core/single_type_kv_cache_manager.py | 27 +++++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/tests/v1/core/prefix_cache/test_partial_prefix_cache_hits.py b/tests/v1/core/prefix_cache/test_partial_prefix_cache_hits.py index aeffc96453..59213cef9f 100644 --- a/tests/v1/core/prefix_cache/test_partial_prefix_cache_hits.py +++ b/tests/v1/core/prefix_cache/test_partial_prefix_cache_hits.py @@ -651,7 +651,7 @@ def test_hash_aligned_query_end_uses_regular_partial_tail(): assert new_blocks is not None mamba_manager = manager.coordinator.single_type_managers[1] - assert mamba_manager._checkpoint_positions[request.request_id] == 0 + assert request.request_id not in mamba_manager._checkpoints mamba_blocks = manager.get_blocks(request.request_id).blocks[1] assert sum(not block.is_null for block in mamba_blocks) == 1 diff --git a/vllm/v1/core/single_type_kv_cache_manager.py b/vllm/v1/core/single_type_kv_cache_manager.py index 0403ba416a..3a488856f9 100644 --- a/vllm/v1/core/single_type_kv_cache_manager.py +++ b/vllm/v1/core/single_type_kv_cache_manager.py @@ -1431,9 +1431,9 @@ class MambaManager(SingleTypeKVCacheManager): self.last_state_block_idx: dict[str, int] = {} # The set of the requests that have been allocated blocks self._allocated_block_reqs: set[str] = set() - # Absolute checkpoint position selected by the scheduler for the - # current allocation. - self._checkpoint_positions: dict[str, int] = {} + # checkpoint position and reserved block index for the current + # allocation. + self._checkpoints: dict[str, tuple[int, int]] = {} # Requests that registered their own last-prompt-boundary partial # tail (producers). A later CoW hands its private copy to the # connector; a request that finishes first hands off this table @@ -1722,7 +1722,14 @@ class MambaManager(SingleTypeKVCacheManager): checkpoint_position = 0 checkpoint_block = int(checkpoint_position > 0) if not apply_admission_cap: - self._checkpoint_positions[request_id] = checkpoint_position + if checkpoint_position > 0: + checkpoint_idx = cdiv(num_tokens, self.block_size) - 2 + self._checkpoints[request_id] = ( + checkpoint_position, + checkpoint_idx, + ) + else: + self._checkpoints.pop(request_id, None) if num_new_blocks > 0: blocks_allocated = request_id in self._allocated_block_reqs if not (checkpoint_block and blocks_allocated): @@ -1760,8 +1767,7 @@ class MambaManager(SingleTypeKVCacheManager): num_required_blocks = ( cdiv(num_tokens, self.block_size) + self.num_speculative_blocks ) - checkpoint_position = self._checkpoint_positions.get(request_id, 0) - checkpoint_block = int(checkpoint_position > 0) + checkpoint_block = int(request_id in self._checkpoints) partial_hit = self._partial_hit_reqs.get(request_id) has_partial_hit = partial_hit is not None # `num_required_blocks` might be less than `len(req_blocks)` if blocks are @@ -1893,7 +1899,7 @@ class MambaManager(SingleTypeKVCacheManager): if self.mamba_cache_mode == "align": self._allocated_block_reqs.discard(request_id) self.last_state_block_idx.pop(request_id, None) - self._checkpoint_positions.pop(request_id, None) + self._checkpoints.pop(request_id, None) self._producer_partial_tail_reqs.pop(request_id, None) # An offer is only guaranteed to hold committed bytes until the end # of the pass that made it. This request's blocks are going back to @@ -1963,10 +1969,9 @@ class MambaManager(SingleTypeKVCacheManager): ) -> BlockHashWithGroupId | None: hash_block_size = self.block_pool.hash_block_size # Re-key the reserved block at its exported checkpoint boundary. - checkpoint_position = self._checkpoint_positions.get(request.request_id, 0) - if checkpoint_position > 0: - # TODO: Store the reserved slot explicitly for multi-module MTP. - checkpoint_idx = cdiv(num_tokens, self.block_size) - 2 + checkpoint = self._checkpoints.get(request.request_id) + if checkpoint is not None: + checkpoint_position, checkpoint_idx = checkpoint blocks = self.req_to_blocks[request.request_id] assert 0 <= checkpoint_idx < len(blocks) checkpoint_block = blocks[checkpoint_idx]