From b10e51989551cd80dd74079429ccf91f0807bd92 Mon Sep 17 00:00:00 2001 From: Woosuk Kwon Date: Sun, 6 Apr 2025 13:48:14 -0700 Subject: [PATCH] [V1][Minor] Optimize get_cached_block (#16135) --- vllm/v1/core/block_pool.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/vllm/v1/core/block_pool.py b/vllm/v1/core/block_pool.py index 43f30f71..74f3f785 100644 --- a/vllm/v1/core/block_pool.py +++ b/vllm/v1/core/block_pool.py @@ -67,11 +67,11 @@ class BlockPool: Returns: The cached block if it exists, or None. """ - if block_hash in self.cached_block_hash_to_block: - first_block_id = list( - self.cached_block_hash_to_block[block_hash].keys())[0] - return self.cached_block_hash_to_block[block_hash][first_block_id] - return None + cached_blocks = self.cached_block_hash_to_block.get(block_hash) + if not cached_blocks: + return None + first_block_id = next(iter(cached_blocks)) + return cached_blocks[first_block_id] def cache_full_blocks( self,