[Bugfix][Mooncake] Use the EAGLE replay boundary when retaining sliding-window tails (#61012)

Signed-off-by: Stu Cao <stu@primeintellect.ai>
Signed-off-by: Yifan Qiao <yifanqiao@inferact.ai>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: Yifan Qiao <yifanqiao@inferact.ai>
Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
Stu Cao
2026-10-11 09:15:18 +00:00
committed by GitHub
co-authored by Claude Fable 5.1 Yifan Qiao Codex
parent 1789f09588
commit 2339bd39d6
4 changed files with 85 additions and 27 deletions
+29 -22
View File
@@ -62,6 +62,30 @@ def _validate_prefix_cache_retention_interval(
)
def replay_boundaries(
num_prompt_tokens: int, scheduler_block_size: int, use_eagle: bool
) -> tuple[int, ...]:
"""Positions a later request replaying a prompt can resume at.
A hit is the shortest across all groups, so every group retains state
at each position; EAGLE groups also keep the block above, which they
match and drop back from (see ``reachable_block_mask``).
Two positions are reachable: a resend of the identical prompt is capped
at ``num_tokens - 1`` (its last token is recomputed for logits), a
longer sibling matches the final aligned block. They differ only on a
block-aligned prompt, where retaining just the higher one collapses the
resend's hit to 0. The alignment is the scheduler block size, not the
finer hash granularity, which would over-estimate the reach.
"""
if not use_eagle:
return (num_prompt_tokens - 1,)
block = scheduler_block_size
resend = (num_prompt_tokens - 1) // block * block
extension = num_prompt_tokens // block * block
return tuple(sorted({max(resend - block, 0), max(extension - block, 0)}))
class KVCacheCoordinator(ABC):
"""Coordinate the KV cache of different KV cache groups."""
@@ -319,27 +343,6 @@ class KVCacheCoordinator(ABC):
for manager in self.single_type_managers
)
def get_replay_boundaries(self, request: Request) -> tuple[int, ...]:
"""Positions a later request replaying this prompt can resume at.
A hit is the shortest across all groups, so every group retains state
at each position; EAGLE groups also keep the block above, which they
match and drop back from (see ``reachable_block_mask``).
Two positions are reachable: a resend of the identical prompt is capped
at ``num_tokens - 1`` (its last token is recomputed for logits), a
longer sibling matches the final aligned block. They differ only on a
block-aligned prompt, where retaining just the higher one collapses the
resend's hit to 0. The alignment is the scheduler block size, not the
finer hash granularity, which would over-estimate the reach.
"""
if not self.eagle_group_ids:
return (request.num_prompt_tokens - 1,)
block = self.scheduler_block_size
resend = (request.num_prompt_tokens - 1) // block * block
extension = request.num_prompt_tokens // block * block
return tuple(sorted({max(resend - block, 0), max(extension - block, 0)}))
def get_num_cacheable_tokens(
self, num_computed_tokens: int, kv_cache_group_id: int
) -> int:
@@ -358,7 +361,11 @@ class KVCacheCoordinator(ABC):
(including tokens that are already cached).
"""
boundaries = self.get_replay_boundaries(request)
boundaries = replay_boundaries(
request.num_prompt_tokens,
self.scheduler_block_size,
use_eagle=bool(self.eagle_group_ids),
)
for group_id, manager in enumerate(self.single_type_managers):
if not manager.enable_caching:
continue
+2 -2
View File
@@ -492,7 +492,7 @@ class SingleTypeKVCacheManager(ABC):
boundary; a positive multiple of ``scheduler_block_size`` keeps
a tail once per that-sized segment. Only SWA acts on it.
replay_boundaries: Positions a later request replaying this prompt
can resume at, from ``get_replay_boundaries``.
can resume at, from ``replay_boundaries``.
"""
if not self.kv_cache_spec.prefix_cacheable:
@@ -505,7 +505,7 @@ class SingleTypeKVCacheManager(ABC):
# Token boundaries whose reachable tail must be retained under sparse
# retention: every position a replaying sibling can resume at (see
# ``get_replay_boundaries``) and any detected shared-prefix junction.
# ``replay_boundaries``) and any detected shared-prefix junction.
reachable_boundaries = [*replay_boundaries]
if request.shared_prefix_boundary:
reachable_boundaries.append(request.shared_prefix_boundary)