Skip to content

Commit a7ca7a6

Browse files
heheda12345Akshat-Tripathi
authored andcommitted
[v1] Add __repr__ to KVCacheBlock to avoid recursive print (vllm-project#14081)
1 parent b029cc4 commit a7ca7a6

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

vllm/v1/core/kv_cache_utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,19 @@ def reset_hash(self):
128128
"""Reset the block hash when the block is evicted."""
129129
self._block_hash = None
130130

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+
131144

132145
class FreeKVCacheBlockQueue:
133146
"""This class organizes a list of KVCacheBlock objects to a doubly linked

0 commit comments

Comments
 (0)