Unify memory management across (overlap, non-overlap) x (page>=1) x (spec, non-spec, spec v2) x (retract, finished) (#12224)
This commit is contained in:
@@ -341,21 +341,21 @@ class RadixCache(BasePrefixCache):
|
||||
|
||||
def cache_finished_req(self, req: Req, is_insert: bool = True):
|
||||
"""Cache request when it finishes."""
|
||||
all_token_len = len(req.origin_input_ids) + max(len(req.output_ids) - 1, 0)
|
||||
committed_kv_len = req.pop_committed_kv_cache()
|
||||
if self.disable:
|
||||
kv_indices = self.req_to_token_pool.req_to_token[
|
||||
req.req_pool_idx, :all_token_len
|
||||
req.req_pool_idx, :committed_kv_len
|
||||
]
|
||||
self.token_to_kv_pool_allocator.free(kv_indices)
|
||||
self.req_to_token_pool.free(req.req_pool_idx)
|
||||
return
|
||||
|
||||
token_ids = (req.origin_input_ids + req.output_ids)[:all_token_len]
|
||||
token_ids = (req.origin_input_ids + req.output_ids)[:committed_kv_len]
|
||||
# For EAGLE radix cache, we will convert the key to bigram key, e.g. [1,2,3,4] -> [(1,2), (2,3), (3,4)], the length will -1. ((len([(1,2), (2,3), (3,4)]) = len([1,2,3,4]) - 1))
|
||||
# So for the corresponding kv length should also -1. Then we get the actual_kv_len, and use it to do later calculation and slicing.
|
||||
actual_kv_len = all_token_len - 1 if self.is_eagle else all_token_len
|
||||
actual_kv_len = committed_kv_len - 1 if self.is_eagle else committed_kv_len
|
||||
kv_indices = self.req_to_token_pool.req_to_token[
|
||||
req.req_pool_idx, :all_token_len
|
||||
req.req_pool_idx, :committed_kv_len
|
||||
]
|
||||
|
||||
if self.page_size != 1:
|
||||
|
||||
Reference in New Issue
Block a user