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
a1f3610f
Unverified
Commit
a1f3610f
authored
Jul 23, 2025
by
Jialin Ouyang
Committed by
GitHub
Jul 23, 2025
Browse files
[Core] Add basic unit test for maybe_evict_cached_block (#21400)
Signed-off-by:
Jialin Ouyang
<
Jialin.Ouyang@gmail.com
>
parent
4ecedd18
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
0 deletions
+67
-0
tests/v1/core/test_prefix_caching.py
tests/v1/core/test_prefix_caching.py
+67
-0
No files found.
tests/v1/core/test_prefix_caching.py
View file @
a1f3610f
...
...
@@ -1097,6 +1097,73 @@ def test_prefix_cache_stats_disabled():
assert
manager
.
prefix_cache_stats
is
None
def
test_maybe_evict_cached_block
():
pool
=
BlockPool
(
num_gpu_blocks
=
4
,
enable_caching
=
True
)
block_hash0
=
BlockHashWithGroupId
(
block_hash
=
BlockHash
(
hash_value
=
10
,
token_ids
=
(
100
,
)),
group_id
=
1000
)
block_hash1
=
BlockHashWithGroupId
(
block_hash
=
BlockHash
(
hash_value
=
20
,
token_ids
=
(
200
,
)),
group_id
=
2000
)
block_hash2
=
BlockHashWithGroupId
(
block_hash
=
BlockHash
(
hash_value
=
30
,
token_ids
=
(
300
,
)),
group_id
=
3000
)
block_hashes
=
[
block_hash0
,
block_hash1
,
block_hash2
,
# block3 had the exact same block_hash as the first block
block_hash0
,
]
assert
len
(
pool
.
blocks
)
==
len
(
block_hashes
)
# Manually add all blocks to cached_blocks
for
block
,
block_hash
in
zip
(
pool
.
blocks
,
block_hashes
):
block
.
block_hash
=
block_hash
pool
.
cached_block_hash_to_block
[
block_hash
][
block
.
block_id
]
=
block
block0
,
block1
,
block2
,
block3
=
pool
.
blocks
assert
pool
.
cached_block_hash_to_block
==
{
block_hash0
:
{
block0
.
block_id
:
block0
,
block3
.
block_id
:
block3
},
block_hash1
:
{
block1
.
block_id
:
block1
},
block_hash2
:
{
block2
.
block_id
:
block2
}
}
# Evict block1
pool
.
_maybe_evict_cached_block
(
block1
)
assert
pool
.
cached_block_hash_to_block
==
{
block_hash0
:
{
block0
.
block_id
:
block0
,
block3
.
block_id
:
block3
},
block_hash2
:
{
block2
.
block_id
:
block2
}
}
# Evict block0: block_hash0 entry should NOT be removed, as block3
# also use the same hash
pool
.
_maybe_evict_cached_block
(
block0
)
assert
pool
.
cached_block_hash_to_block
==
{
block_hash0
:
{
block3
.
block_id
:
block3
},
block_hash2
:
{
block2
.
block_id
:
block2
}
}
# Evict block2
pool
.
_maybe_evict_cached_block
(
block2
)
assert
pool
.
cached_block_hash_to_block
==
{
block_hash0
:
{
3
:
block3
}}
# Evict block3
pool
.
_maybe_evict_cached_block
(
block3
)
assert
pool
.
cached_block_hash_to_block
==
{}
@
pytest
.
mark
.
parametrize
(
"blocks_to_cache"
,
[
2
,
3
,
10
])
def
test_kv_cache_events
(
blocks_to_cache
:
int
):
block_size
=
16
...
...
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