Evict swa kv cache during decoding (#17220)

This commit is contained in:
Ke Bao
2026-01-19 22:36:52 +08:00
committed by GitHub
parent ebca5879a1
commit ce8a6ac690
8 changed files with 167 additions and 107 deletions
+3 -19
View File
@@ -338,18 +338,7 @@ def alloc_for_extend(
req_pool_indices: request pool indices as list
"""
# free out-of-window swa tokens
if batch.tree_cache.supports_swa() and batch.tree_cache.is_chunk_cache():
for req, pre_len in zip(batch.reqs, batch.prefix_lens):
if batch.enable_overlap:
# In chunked prefill case, when the second extend batch is scheduling, the first extend batch is still running, so we cannot evict swa tokens
if req.extend_batch_idx < 2:
continue
else:
batch.tree_cache.evict_swa(
req, pre_len - batch.tree_cache.chunked_prefill_size
)
else:
batch.tree_cache.evict_swa(req, pre_len)
batch.maybe_evict_swa()
bs = len(batch.reqs)
prefix_tensors = [r.prefix_indices for r in batch.reqs]
@@ -440,13 +429,8 @@ def alloc_for_decode(batch: ScheduleBatch, token_per_req: int) -> torch.Tensor:
Returns:
out_cache_loc: allocated cache locations
"""
if batch.tree_cache.supports_swa() and batch.tree_cache.is_chunk_cache():
for req in batch.reqs:
# We set evict_swa condition here with two reasons:
# 1. In overlap scheduler, we cannot evict swa when req.decode_batch_idx == 0 since the prev extend batch is still running.
# 2. Evict swa every window_size tokens to reduce the overhead.
if req.decode_batch_idx % batch.tree_cache.window_size == 1:
batch.tree_cache.evict_swa(req, req.seqlen - 1)
batch.maybe_evict_swa()
bs = batch.seq_lens.shape[0]