[Bugfix][KV Cache] Prevent negative external block allocation (#52707)
Signed-off-by: haic0 <149741444+haic0@users.noreply.github.com> Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -317,9 +317,10 @@ class SingleTypeKVCacheManager(ABC):
|
||||
return
|
||||
|
||||
req_blocks = self.req_to_blocks[request_id]
|
||||
allocated_blocks = self.block_pool.get_new_blocks(
|
||||
cdiv(num_total_computed_tokens, self.block_size) - len(req_blocks)
|
||||
num_new_blocks = max(
|
||||
0, cdiv(num_total_computed_tokens, self.block_size) - len(req_blocks)
|
||||
)
|
||||
allocated_blocks = self.block_pool.get_new_blocks(num_new_blocks)
|
||||
req_blocks.extend(allocated_blocks)
|
||||
if self._record_new_block_ids:
|
||||
self.new_block_ids.extend(b.block_id for b in allocated_blocks)
|
||||
|
||||
Reference in New Issue
Block a user