mirror of
https://github.com/FlashML-org/FreeToken.git
synced 2026-12-04 04:05:44 +08:00
fix(kvcache): clone inserted radix keys to release request buffers (#559)
This commit is contained in:
@@ -98,7 +98,10 @@ class HybridRadixCache:
|
||||
node, prefix_len = self._walk(input_ids)
|
||||
if prefix_len != insert_len:
|
||||
new_node = RadixTreeNode(self.key_fn)
|
||||
new_node.set_key_value(input_ids[prefix_len:], kv_indices[prefix_len:].clone())
|
||||
# A view would keep the request's full output-budget token buffer alive.
|
||||
new_node.set_key_value(
|
||||
input_ids[prefix_len:].clone(), kv_indices[prefix_len:].clone()
|
||||
)
|
||||
new_node.set_parent(node)
|
||||
self.full_evictable += new_node.length
|
||||
node = new_node
|
||||
|
||||
@@ -167,7 +167,10 @@ class RadixPrefixCache(BasePrefixCache):
|
||||
node, prefix_len = self._tree_walk(input_ids)
|
||||
if prefix_len != insert_len: # NOTE: prefix_len < insert_len
|
||||
new_node = RadixTreeNode(self.key_fn)
|
||||
new_node.set_key_value(input_ids[prefix_len:], indices[prefix_len:].clone())
|
||||
# A view would keep the request's full output-budget token buffer alive.
|
||||
new_node.set_key_value(
|
||||
input_ids[prefix_len:].clone(), indices[prefix_len:].clone()
|
||||
)
|
||||
new_node.set_parent(node)
|
||||
self.evictable_size += new_node.length
|
||||
node = new_node
|
||||
|
||||
@@ -215,7 +215,8 @@ class SWARadixCache:
|
||||
# then a live (non-tombstone) leaf for the in-window remainder (never a tombstone leaf --
|
||||
# the clamp + the free_swa -page_size margin guarantee a live tail).
|
||||
if total < insert_len:
|
||||
suffix_ids = input_ids[total:]
|
||||
# Both suffix nodes can share this copy without retaining the request buffer.
|
||||
suffix_ids = input_ids[total:].clone()
|
||||
suffix_kv = kv_indices[total:].clone()
|
||||
boundary = max(0, min(swa_evicted_seqlen, insert_len) - total)
|
||||
boundary = min(boundary, max(0, len(suffix_ids) - self.page_size))
|
||||
|
||||
Reference in New Issue
Block a user