Skip to content

Commit a7f22dc

Browse files
mispa-mscodex
authored andcommitted
[Mooncake] Guard partial-hit revalidation
Skip the exact-key retry when a cache pool has no existence oracle or the layout has no full-attention group. Add regression coverage for both paths and make long hash fixtures wrap their byte values. Co-authored-by: OpenAI Codex <noreply@openai.com>
1 parent 22cdbe5 commit a7f22dc

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

tests/v1/kv_connector/unit/test_mooncake_store_coordinator.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def _swa(block_size=16, sliding_window=32):
106106

107107

108108
def _hashes(n: int) -> list[BlockHash]:
109-
return [BlockHash(bytes([i + 1]) * 4) for i in range(n)]
109+
return [BlockHash((i + 1).to_bytes(4, byteorder="little")) for i in range(n)]
110110

111111

112112
# ----- Single-group coordinator -----
@@ -278,6 +278,35 @@ def test_coordinator_revalidates_reconciled_partial_tail_key():
278278
assert hit == 32
279279

280280

281+
def test_exact_partial_hit_retry_skips_pool_without_existence_data(monkeypatch):
282+
groups = [
283+
KVCacheGroupSpec(["L0"], _full(32)),
284+
KVCacheGroupSpec(["L1"], _mamba_align(32)),
285+
]
286+
coord = _make_coord(groups, hash_block_size=16)
287+
hs = _hashes(4)
288+
cmap = ExternalCachedBlockPool(16)
289+
290+
def fail_lookup(*_args, **_kwargs):
291+
pytest.fail("receive-side pool has no existence data to revalidate")
292+
293+
monkeypatch.setattr(cmap, "get_cached_block", fail_lookup)
294+
295+
assert coord._exact_partial_hit_key_exists(hs, 48, cmap)
296+
297+
298+
def test_partial_hash_hit_without_full_attention_does_not_revalidate():
299+
groups = [KVCacheGroupSpec(["L0"], _mamba_align(32))]
300+
coord = _make_coord(groups, hash_block_size=16)
301+
hs = _hashes(4)
302+
cmap = ExternalCachedBlockPool(16, {(0, bytes(hs[2]))})
303+
304+
masks, hit = coord.find_longest_cache_hit(hs, max_length=64, cached_block_pool=cmap)
305+
306+
assert hit == 48
307+
assert masks == ([False, True],)
308+
309+
281310
# ----- store_mask -----
282311

283312

vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/coordinator.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ def __init__(
3737
# determined and we just want each spec's manager to apply its own mask.
3838
self._exists = exists
3939
self.hash_block_size = hash_block_size
40+
# Recv-side pools cannot verify whether an exact key exists.
41+
self.tracks_existence = exists is not None
4042
self.null_block = KVCacheBlock(block_id=0)
4143
# Dummy ID 1 for present block for duck-typing.
4244
self._present_block = KVCacheBlock(block_id=1)
@@ -188,13 +190,18 @@ def _exact_partial_hit_key_exists(
188190
"""Whether the reconciled partial FullAttention tail can be loaded."""
189191
if not self.enable_partial_hash_hits:
190192
return True
193+
if not cached_block_pool.tracks_existence:
194+
# Shortening here would desynchronize the mask from token_len.
195+
return True
191196

192197
# Attribute access, not tuple unpacking: SpecGroup carries manager_cls
193198
# and use_eagle here, so the upstream 3-tuple unpack raises ValueError
194199
# on the first lookup. git apply cannot see that -- it is a runtime
195200
# arity mismatch, not a textual conflict.
196201
group = self.attention_groups[0]
197-
assert isinstance(group.spec, FullAttentionSpec)
202+
if not isinstance(group.spec, FullAttentionSpec):
203+
# Recurrent-only layouts have no FullAttention key to revalidate.
204+
return True
198205
hash_idx = hit_length // self.hash_block_size - 1
199206
return (
200207
cached_block_pool.get_cached_block(block_hashes[hash_idx], group.group_ids)

0 commit comments

Comments
 (0)