Fix swa eviction frontier for bigram keys (#34870)
This commit is contained in:
@@ -773,16 +773,21 @@ class UnifiedRadixCache(BasePrefixCache):
|
||||
if cl is not None:
|
||||
effective_cache_len = min(effective_cache_len, cl)
|
||||
|
||||
# swa_evicted_seqlen is a raw-token length, but under EAGLE the insert key is
|
||||
# bigram-indexed, so SWA would carve tombstones at the wrong offset (#34653).
|
||||
if (
|
||||
envs.SGLANG_OPT_UNIFIED_CACHE_FREE_OUT_OF_WINDOW_SLOTS.get()
|
||||
and not self.tree_core.is_eagle
|
||||
):
|
||||
radix_key = RadixKey(
|
||||
token_ids[:effective_cache_len],
|
||||
req.extra_key,
|
||||
is_bigram=self.tree_core.is_eagle,
|
||||
cache_salt=req.cache_salt,
|
||||
)
|
||||
|
||||
if envs.SGLANG_OPT_UNIFIED_CACHE_FREE_OUT_OF_WINDOW_SLOTS.get():
|
||||
# The frontier lands a page below page_floor(pre_len + 1), which has to
|
||||
# be where the insert stops, or the leaf it creates keeps less than a
|
||||
# sliding window of live SWA and the match after the insert rejects it.
|
||||
# The insert stops at page_floor(len(radix_key)), and a bigram key is
|
||||
# one shorter than the tokens it spans, so measure the key.
|
||||
for comp in self._components_tuple:
|
||||
comp.free_out_of_window_slots(
|
||||
req, effective_cache_len - 1, insert_params
|
||||
)
|
||||
comp.free_out_of_window_slots(req, len(radix_key) - 1, insert_params)
|
||||
|
||||
if effective_cache_len <= 0:
|
||||
req.prefix_indices = kv_indices_orig.to(dtype=torch.int64, copy=True)
|
||||
@@ -794,12 +799,7 @@ class UnifiedRadixCache(BasePrefixCache):
|
||||
|
||||
kv_indices = kv_indices_orig[:effective_cache_len]
|
||||
|
||||
radix_key = RadixKey(
|
||||
token_ids[:effective_cache_len],
|
||||
req.extra_key,
|
||||
is_bigram=self.tree_core.is_eagle,
|
||||
cache_salt=req.cache_salt,
|
||||
).page_aligned(self.page_size)
|
||||
radix_key = radix_key.page_aligned(self.page_size)
|
||||
page_aligned_len = len(radix_key)
|
||||
values = kv_indices[:page_aligned_len].to(dtype=torch.int64, copy=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user