EAGLE cache fix for SWARadixCache (#11231)
Co-authored-by: Hanming Lu <69857889+hanming-lu@users.noreply.github.com>
This commit is contained in:
@@ -326,6 +326,8 @@ class RadixCache(BasePrefixCache):
|
||||
|
||||
token_ids = (req.origin_input_ids + req.output_ids)[:-1]
|
||||
all_token_len = len(token_ids)
|
||||
# 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
|
||||
kv_indices = self.req_to_token_pool.req_to_token[
|
||||
req.req_pool_idx, :all_token_len
|
||||
@@ -349,7 +351,8 @@ class RadixCache(BasePrefixCache):
|
||||
|
||||
old_prefix_len = len(req.prefix_indices)
|
||||
if self.is_eagle and old_prefix_len > req.last_matched_prefix_len:
|
||||
# prefix_indices attached partial part (for page_size > 1) and one unmatched token (for EAGLE)
|
||||
# In EAGLE chunked prefill case, the prefix_indices included one unmatched token (kv_indices[actual_kv_len:])
|
||||
# Here we -1 to make sure the kv of the unmatched token can be freed correctly to avoid memory leak
|
||||
old_prefix_len -= 1
|
||||
|
||||
# Radix Cache takes one ref in memory pool
|
||||
@@ -370,7 +373,8 @@ class RadixCache(BasePrefixCache):
|
||||
|
||||
token_ids = req.fill_ids
|
||||
all_token_len = len(token_ids)
|
||||
# The actual kv len for EAGLE is len(token_ids), since EAGLE uses bigram key
|
||||
# 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
|
||||
kv_indices = self.req_to_token_pool.req_to_token[
|
||||
req.req_pool_idx, :all_token_len
|
||||
@@ -393,7 +397,8 @@ class RadixCache(BasePrefixCache):
|
||||
|
||||
old_prefix_len = len(req.prefix_indices)
|
||||
if self.is_eagle and old_prefix_len > req.last_matched_prefix_len:
|
||||
# prefix_indices attached partial part (for page_size > 1) and one unmatched token (for EAGLE)
|
||||
# In EAGLE chunked prefill case, the prefix_indices included one unmatched token (kv_indices[actual_kv_len:])
|
||||
# Here we -1 to make sure the kv of the unmatched token can be freed correctly to avoid memory leak
|
||||
old_prefix_len -= 1
|
||||
|
||||
# Radix Cache takes one ref in memory pool
|
||||
|
||||
Reference in New Issue
Block a user