[Bugfix][KV Connector] Propagate EAGLE state across merged Mooncake store groups (#49069)

Signed-off-by: Yifan Qiao <yifanqiao@inferact.ai>
Co-authored-by: xijiade.aihemaiti <3146335281@qq.com>
This commit is contained in:
Yifan Qiao
2026-08-02 19:32:26 -07:00
committed by GitHub
co-authored by xijiade.aihemaiti
parent e42c230e4f
commit 5c4fe4b17e
2 changed files with 118 additions and 39 deletions
@@ -567,3 +567,83 @@ def test_lookup_with_eagle_hybrid_full_plus_mamba_no_overrun():
# FullAttn matches 4 blocks, eagle pops 1 -> 48 verified tokens. The
# Mamba group must serve its state@48 snapshot, not peek to state@64.
assert hit == 48
def test_eagle_flag_propagates_to_all_merged_swa_groups():
"""Regression for MTP x PD external-store 0% prefix hit.
DSV4 splits SWA layers into several KV cache groups sharing one spec, and
only the group containing the MTP layer is annotated ``is_eagle_group``.
The lookup merges equal-spec groups, applies the eagle drop to the merged
group, and requires each chunk hash to exist in EVERY member group — so
the save-side masks must eagle-shift every member, not just the annotated
one. Without propagation the non-annotated groups never store the eagle
proof-run chunks and every external lookup returns 0.
"""
swa = _swa(block_size=16, sliding_window=32)
groups = [
KVCacheGroupSpec(["L0"], _full(64)),
KVCacheGroupSpec(["L1"], swa),
KVCacheGroupSpec(["L2"], swa, is_eagle_group=True),
]
coord = _make_coord(groups, hash_block_size=16, use_eagle=True)
assert coord.eagle_group_ids == {1, 2}
# Save side: both SWA groups must produce identical (eagle-shifted) masks.
masks = coord.store_mask(128, num_prompt_tokens=130)
assert masks[1] == masks[2]
# Round trip: everything store_mask kept is in the store; the eagle
# lookup must then serve a non-zero hit (it was 0 before the fix).
hs = _hashes(128 // 16)
exists = set()
for g_idx, g in enumerate(groups):
ghashes = chunk_hashes_for_block_size(hs, 16, g.kv_cache_spec.block_size)
mask = masks[g_idx]
for i in range(128 // g.kv_cache_spec.block_size):
if mask is None or mask[i]:
exists.add((g_idx, bytes(ghashes[i])))
_masks, hit = coord.find_longest_cache_hit(
hs, max_length=128, cached_block_pool=ExternalCachedBlockPool(16, exists)
)
assert hit == 64
def test_dsv4_five_group_eagle_store_lookup_round_trip():
"""Cover the five KV groups observed with DeepSeek-V4-Flash + MTP.
The two 64-token SWA groups have identical specs, but only one owns the
EAGLE layer. Saving each group through its store mask must still leave a
prefix that the merged SWA lookup can consume.
"""
swa_64_sw128 = _swa(block_size=64, sliding_window=128)
groups = [
KVCacheGroupSpec(["full_mla"], _full(block_size=256)),
KVCacheGroupSpec(["swa"], swa_64_sw128),
KVCacheGroupSpec(["mtp"], swa_64_sw128, is_eagle_group=True),
KVCacheGroupSpec(["c4_state"], _swa(block_size=4, sliding_window=8)),
KVCacheGroupSpec(["c128_state"], _swa(block_size=8, sliding_window=128)),
]
coord = _make_coord(groups, hash_block_size=4, use_eagle=True)
token_len = 768
hashes = _hashes(token_len // coord.hash_block_size)
# Mirror MooncakeStoreWorker's aligned save: only keys selected by each
# group's store mask are visible to the external lookup.
exists: set[tuple[int, bytes]] = set()
store_masks = coord.store_mask(token_len)
for gid, (group, mask) in enumerate(zip(groups, store_masks, strict=True)):
group_hashes = coord.block_hashes_for_spec(hashes, group.kv_cache_spec)
for chunk_id, block_hash in enumerate(group_hashes):
if mask is None or mask[chunk_id]:
exists.add((gid, bytes(block_hash)))
_masks, hit = coord.find_longest_cache_hit(
hashes,
max_length=token_len,
cached_block_pool=ExternalCachedBlockPool(coord.hash_block_size, exists),
)
# The final 256-token segment has no lookahead block, so EAGLE falls back
# to the previous aligned boundary instead of consuming all 768 tokens.
assert hit == 512