Skip to content

Commit ba80305

Browse files
xiaobochen123LeiWang1999
authored andcommitted
[Core] Optimize evictor-v2 performance (vllm-project#7193)
Signed-off-by: LeiWang1999 <[email protected]>
1 parent 3060667 commit ba80305

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

vllm/core/evictor_v2.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ def evict(self) -> Tuple[int, int]:
9191
# at the start of OrderedDict. Loop through all these blocks to
9292
# find the one with maximum number of hashed tokens.
9393
for _id, block in self.free_table.items():
94-
if evicted_block.last_accessed > block.last_accessed or (
95-
evicted_block.last_accessed == block.last_accessed and
94+
if evicted_block.last_accessed < block.last_accessed:
95+
break
96+
if (evicted_block.last_accessed == block.last_accessed and
9697
evicted_block.num_hashed_tokens < block.num_hashed_tokens):
9798
evicted_block = block
9899
evicted_block_id = _id
@@ -109,6 +110,7 @@ def add(self, block_id: int, content_hash: int, num_hashed_tokens: int,
109110

110111
def update(self, block_id: int, last_accessed: float):
111112
self.free_table[block_id].last_accessed = last_accessed
113+
self.free_table.move_to_end(block_id)
112114

113115
def remove(self, block_id: int):
114116
if block_id not in self.free_table:

0 commit comments

Comments
 (0)