Evict swa kv cache during decoding (#17220)
This commit is contained in:
@@ -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]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user