A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 14, 00:30 UTC
[Core][Perf] Only invoke save_new_computed_blocks when computed blocks are not empty (#27799)
Signed-off-by: Jialin Ouyang <Jialin.Ouyang@gmail.com>
Jialin Ouyang committed
Oct 30, 2025 at 12:47 UTC
4b68c4a55b0fa5846d180532ae7e58db85101e07
2 files changed
+7
-6
vllm/v1/core/kv_cache_manager.py
+6
-5
@@ -306,11 +306,12 @@ class KVCacheManager:
306
"Computed blocks should be empty when prefix caching is disabled"
307
)
308
309
- # Append the new computed blocks to the request blocks until now to
310
- # avoid the case where the new blocks cannot be allocated.
311
- self.coordinator.save_new_computed_blocks(
312
- request.request_id, new_computed_block_list
313
- )
309
+ if new_computed_block_list is not self.empty_kv_cache_blocks.blocks:
310
+ # Append the new computed blocks to the request blocks until now to
311
+ # avoid the case where the new blocks cannot be allocated.
312
+ self.coordinator.save_new_computed_blocks(
313
+ request.request_id, new_computed_block_list
314
+ )
315
316
new_blocks = self.coordinator.allocate_new_blocks(
317
request.request_id, num_tokens_need_slot, num_encoder_tokens
vllm/v1/core/single_type_kv_cache_manager.py
+1
-1
@@ -151,7 +151,7 @@ class SingleTypeKVCacheManager(ABC):
151
num_tokens: The total number of tokens that need to be cached
152
(including tokens that are already cached).
153
"""
154
- num_cached_blocks = self.num_cached_block[request.request_id]
154
+ num_cached_blocks = self.num_cached_block.get(request.request_id, 0)
155
num_full_blocks = num_tokens // self.block_size
156
157
if num_cached_blocks >= num_full_blocks: