Skip to content

Commit 45bfa49

Browse files
[Tests] fix initialization of kv hash in tests (vllm-project#24273)
Signed-off-by: Mickael Seznec <mickael@mistral.ai>
1 parent fd2f105 commit 45bfa49

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

tests/v1/core/test_kv_cache_utils.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@
3030
# yapf: enable
3131

3232

33+
@pytest.fixture(autouse=True)
34+
def _auto_init_hash_fn(request):
35+
hash_fn: Callable
36+
if "hash_fn" in request.fixturenames:
37+
hash_fn = init_none_hash(request.getfixturevalue("hash_fn"))
38+
else:
39+
hash_fn = sha256
40+
init_none_hash(hash_fn)
41+
42+
3343
def make_request(
3444
request_id: str,
3545
prompt_token_ids: list[int],
@@ -424,7 +434,6 @@ def test_generate_block_hash_extra_keys_cache_salt():
424434

425435
@pytest.mark.parametrize("hash_fn", [sha256, sha256_cbor])
426436
def test_hash_block_tokens(hash_fn):
427-
init_none_hash(hash_fn)
428437
parent_block_hash = BlockHash(b"123")
429438
curr_block_token_ids = (1, 2, 3)
430439
extra_keys = ("key1", "key2")
@@ -437,8 +446,6 @@ def test_hash_block_tokens(hash_fn):
437446

438447
@pytest.mark.parametrize("hash_fn", [sha256, sha256_cbor])
439448
def test_request_block_hasher(hash_fn):
440-
kv_cache_utils.init_none_hash(hash_fn)
441-
442449
request = make_request(
443450
request_id="0",
444451
prompt_token_ids=[_ for _ in range(6)],
@@ -461,8 +468,6 @@ def test_request_block_hasher(hash_fn):
461468

462469
@pytest.mark.parametrize("hash_fn", [sha256, sha256_cbor])
463470
def test_hash_tokens_different_mm_input(hash_fn):
464-
init_none_hash(hash_fn)
465-
466471
request1 = make_request(
467472
request_id="0",
468473
prompt_token_ids=[_ for _ in range(6)],
@@ -491,8 +496,6 @@ def test_hash_tokens_different_mm_input(hash_fn):
491496

492497
@pytest.mark.parametrize("hash_fn", [sha256, sha256_cbor])
493498
def test_hash_request_tokens_no_mm_inputs(hash_fn):
494-
kv_cache_utils.init_none_hash(hash_fn)
495-
496499
request = make_request(
497500
request_id="0",
498501
prompt_token_ids=[_ for _ in range(6)],

tests/v1/core/test_prefix_caching.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@
2525
KVCacheGroupSpec, SlidingWindowSpec)
2626

2727

28+
@pytest.fixture(autouse=True)
29+
def _auto_init_hash_fn(request):
30+
hash_fn: Callable
31+
if "hash_fn" in request.fixturenames:
32+
hash_fn = init_none_hash(request.getfixturevalue("hash_fn"))
33+
else:
34+
hash_fn = sha256
35+
init_none_hash(hash_fn)
36+
37+
2838
def make_request(
2939
request_id: str,
3040
prompt_token_ids: list[int],
@@ -105,7 +115,6 @@ def make_kv_cache_config_hybrid_model(block_size: int,
105115

106116
@pytest.mark.parametrize("hash_fn", [sha256, sha256_cbor])
107117
def test_prefill(hash_fn):
108-
init_none_hash(hash_fn)
109118

110119
block_size = 16
111120
manager = KVCacheManager(
@@ -736,7 +745,6 @@ def test_cache_blocks(hash_fn):
736745
This is a unit test that tests the correctness of the _cache_full_blocks
737746
function of KVCacheManager.
738747
"""
739-
init_none_hash(hash_fn)
740748

741749
block_size = 4
742750
block_pool = BlockPool(
@@ -849,7 +857,6 @@ def test_mm_prefix_caching():
849857
"""
850858
This tests that the multi-modal prefix caching is correct.
851859
"""
852-
kv_cache_utils.init_none_hash(sha256)
853860

854861
block_size = 16
855862
manager = KVCacheManager(
@@ -942,8 +949,6 @@ def test_cache_key_salting():
942949
This tests that cache salts are applied during hashing and the cache
943950
is separated cache as expected.
944951
"""
945-
kv_cache_utils.init_none_hash(sha256)
946-
947952
block_size = 16
948953
manager = KVCacheManager(
949954
make_kv_cache_config(block_size, 11),

0 commit comments

Comments
 (0)