[v1][P/D] Fix a edge case in kv cache schedule (#19182)

Co-authored-by: jinghui <jinghui@fb.com>
This commit is contained in:
Jinghui Zhang 2025-06-05 23:32:55 -07:00 committed by GitHub
parent 91a2ef98ea
commit 90b78ec5f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1009,6 +1009,8 @@ class Scheduler(SchedulerInterface):
# Now that the blocks are ready, actually cache them.
block_ids = self.kv_cache_manager.get_block_ids(request.request_id)[0]
num_computed_tokens = len(block_ids) * self.block_size
# Handle the case where num request tokens less then one block.
num_computed_tokens = min(num_computed_tokens, request.num_tokens)
if num_computed_tokens == request.num_tokens:
num_computed_tokens -= 1
self.kv_cache_manager.cache_blocks(