@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / b10e519895
Fork 0

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 15, 16:00 UTC

[V1][Minor] Optimize get_cached_block (#16135)

Woosuk Kwon committed Apr 6, 2025 at 13:48 UTC b10e51989551cd80dd74079429ccf91f0807bd92
1 file changed +5 -5
vllm/v1/core/block_pool.py
+5 -5
@@ -67,11 +67,11 @@ class BlockPool:
67 Returns:
68 The cached block if it exists, or None.
69 """
70 - if block_hash in self.cached_block_hash_to_block:
71 - first_block_id = list(
72 - self.cached_block_hash_to_block[block_hash].keys())[0]
73 - return self.cached_block_hash_to_block[block_hash][first_block_id]
74 - return None
70 + cached_blocks = self.cached_block_hash_to_block.get(block_hash)
71 + if not cached_blocks:
72 + return None
73 + first_block_id = next(iter(cached_blocks))
74 + return cached_blocks[first_block_id]
75
76 def cache_full_blocks(
77 self,