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, 21:00 UTC
[v1] Add `__repr__` to KVCacheBlock to avoid recursive print (#14081)
Chen Zhang committed
Mar 2, 2025 at 04:46 UTC
d54990da477557565768443b458ba0346781413e
1 file changed
+13
vllm/v1/core/kv_cache_utils.py
+13
@@ -128,6 +128,19 @@ class KVCacheBlock:
128
"""Reset the block hash when the block is evicted."""
129
self._block_hash = None
130
131
+ def __repr__(self) -> str:
132
+ # Use block_id instead of KVCacheBlock object to avoid calling __repr__
133
+ # on KVCacheBlock object recursively.
134
+ prev_block_id = self.prev_free_block.block_id \
135
+ if self.prev_free_block else None
136
+ next_block_id = self.next_free_block.block_id \
137
+ if self.next_free_block else None
138
+ return (f"KVCacheBlock(block_id={self.block_id}, "
139
+ f"ref_cnt={self.ref_cnt}, "
140
+ f"_block_hash={self._block_hash}, "
141
+ f"prev_free_block={prev_block_id}, "
142
+ f"next_free_block={next_block_id})")
143
+
144
145
class FreeKVCacheBlockQueue:
146
"""This class organizes a list of KVCacheBlock objects to a doubly linked