Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
vllm_cscc
Commits
ca30c3c8
Unverified
Commit
ca30c3c8
authored
Oct 21, 2024
by
Kuntai Du
Committed by
GitHub
Oct 22, 2024
Browse files
[Core] Remove evictor_v1 (#9572)
parent
c0292211
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
1 addition
and
107 deletions
+1
-107
vllm/core/block/prefix_caching_block.py
vllm/core/block/prefix_caching_block.py
+1
-1
vllm/core/evictor.py
vllm/core/evictor.py
+0
-0
vllm/core/evictor_v1.py
vllm/core/evictor_v1.py
+0
-106
No files found.
vllm/core/block/prefix_caching_block.py
View file @
ca30c3c8
...
...
@@ -7,7 +7,7 @@ from vllm.core.block.common import (CacheMetricData, CopyOnWriteTracker,
from
vllm.core.block.interfaces
import
Block
,
BlockAllocator
,
BlockId
,
Device
from
vllm.core.block.naive_block
import
(
BlockPool
,
NaiveBlock
,
NaiveBlockAllocator
)
from
vllm.core.evictor
_v2
import
EvictionPolicy
,
Evictor
,
make_evictor
from
vllm.core.evictor
import
EvictionPolicy
,
Evictor
,
make_evictor
PrefixHash
=
int
...
...
vllm/core/evictor
_v2
.py
→
vllm/core/evictor.py
View file @
ca30c3c8
File moved
vllm/core/evictor_v1.py
deleted
100644 → 0
View file @
c0292211
import
enum
from
abc
import
ABC
,
abstractmethod
from
typing
import
OrderedDict
from
vllm.block
import
PhysicalTokenBlock
class
EvictionPolicy
(
enum
.
Enum
):
"""Enum for eviction policy used by make_evictor to instantiate the correct
Evictor subclass.
"""
LRU
=
enum
.
auto
()
class
Evictor
(
ABC
):
"""The Evictor subclasses should be used by the BlockAllocator class to
handle eviction of freed PhysicalTokenBlocks.
"""
@
abstractmethod
def
__init__
(
self
):
pass
@
abstractmethod
def
__contains__
(
self
,
block_hash
:
int
)
->
bool
:
pass
@
abstractmethod
def
evict
(
self
)
->
PhysicalTokenBlock
:
"""Runs the eviction algorithm and returns the evicted block"""
pass
@
abstractmethod
def
add
(
self
,
block
:
PhysicalTokenBlock
):
"""Adds block to the evictor, making it a candidate for eviction"""
pass
@
abstractmethod
def
remove
(
self
,
block_hash
:
int
)
->
PhysicalTokenBlock
:
"""Simply removes the block with the hash value block_hash from the
evictor. Caller is responsible for making sure that block_hash is
contained in the evictor before calling remove. Should be used to
"bring back" blocks that have been freed but not evicted yet.
"""
pass
@
property
@
abstractmethod
def
num_blocks
(
self
)
->
int
:
pass
class
LRUEvictor
(
Evictor
):
"""Evicts in a least-recently-used order using the last_accessed timestamp
that's recorded in the PhysicalTokenBlock. If there are multiple blocks with
the same last_accessed time, then the one with the largest num_hashed_tokens
will be evicted. If two blocks each have the lowest last_accessed time and
highest num_hashed_tokens value, then one will be chose arbitrarily
"""
def
__init__
(
self
):
self
.
free_table
:
OrderedDict
[
int
,
PhysicalTokenBlock
]
=
OrderedDict
()
def
__contains__
(
self
,
block_hash
:
int
)
->
bool
:
return
block_hash
in
self
.
free_table
def
evict
(
self
)
->
PhysicalTokenBlock
:
if
len
(
self
.
free_table
)
==
0
:
raise
ValueError
(
"No usable cache memory left"
)
evicted_block
=
next
(
iter
(
self
.
free_table
.
values
()))
# The blocks with the lowest timestamps should be placed consecutively
# at the start of OrderedDict. Loop through all these blocks to
# find the one with maximum number of hashed tokens.
for
_
,
block
in
self
.
free_table
.
items
():
if
evicted_block
.
last_accessed
<
block
.
last_accessed
:
break
if
evicted_block
.
num_hashed_tokens
<
block
.
num_hashed_tokens
:
evicted_block
=
block
self
.
free_table
.
pop
(
evicted_block
.
block_hash
)
evicted_block
.
computed
=
False
return
evicted_block
def
add
(
self
,
block
:
PhysicalTokenBlock
):
self
.
free_table
[
block
.
block_hash
]
=
block
def
remove
(
self
,
block_hash
:
int
)
->
PhysicalTokenBlock
:
if
block_hash
not
in
self
.
free_table
:
raise
ValueError
(
"Attempting to remove block that's not in the evictor"
)
block
:
PhysicalTokenBlock
=
self
.
free_table
[
block_hash
]
self
.
free_table
.
pop
(
block_hash
)
return
block
@
property
def
num_blocks
(
self
)
->
int
:
return
len
(
self
.
free_table
)
def
make_evictor
(
eviction_policy
:
EvictionPolicy
)
->
Evictor
:
if
eviction_policy
==
EvictionPolicy
.
LRU
:
return
LRUEvictor
()
else
:
raise
ValueError
(
f
"Unknown cache eviction policy:
{
eviction_policy
}
"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment