A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 14, 05:30 UTC
[Tests] fix initialization of kv hash in tests (#24273)
Signed-off-by: Mickael Seznec <mickael@mistral.ai>
Mickaël Seznec committed
Sep 15, 2025 at 23:48 UTC
45bfa49cb804b0090f32980aaa68f9cad409d15b
2 files changed
+20
-12
tests/v1/core/test_kv_cache_utils.py
+10
-7
@@ -30,6 +30,16 @@ from vllm.v1.request import Request
30
# yapf: enable
31
32
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
+
43
def make_request(
44
request_id: str,
45
prompt_token_ids: list[int],
@@ -424,7 +434,6 @@ def test_generate_block_hash_extra_keys_cache_salt():
434
435
@pytest.mark.parametrize("hash_fn", [sha256, sha256_cbor])
436
def test_hash_block_tokens(hash_fn):
427
- init_none_hash(hash_fn)
437
parent_block_hash = BlockHash(b"123")
438
curr_block_token_ids = (1, 2, 3)
439
extra_keys = ("key1", "key2")
@@ -437,8 +446,6 @@ def test_hash_block_tokens(hash_fn):
446
447
@pytest.mark.parametrize("hash_fn", [sha256, sha256_cbor])
448
def test_request_block_hasher(hash_fn):
440
- kv_cache_utils.init_none_hash(hash_fn)
441
-
449
request = make_request(
450
request_id="0",
451
prompt_token_ids=[_ for _ in range(6)],
@@ -461,8 +468,6 @@ def test_request_block_hasher(hash_fn):
468
469
@pytest.mark.parametrize("hash_fn", [sha256, sha256_cbor])
470
def test_hash_tokens_different_mm_input(hash_fn):
464
- init_none_hash(hash_fn)
465
-
471
request1 = make_request(
472
request_id="0",
473
prompt_token_ids=[_ for _ in range(6)],
@@ -491,8 +496,6 @@ def test_hash_tokens_different_mm_input(hash_fn):
496
497
@pytest.mark.parametrize("hash_fn", [sha256, sha256_cbor])
498
def test_hash_request_tokens_no_mm_inputs(hash_fn):
494
- kv_cache_utils.init_none_hash(hash_fn)
495
-
499
request = make_request(
500
request_id="0",
501
prompt_token_ids=[_ for _ in range(6)],
tests/v1/core/test_prefix_caching.py
+10
-5
@@ -25,6 +25,16 @@ from vllm.v1.kv_cache_interface import (FullAttentionSpec, KVCacheConfig,
25
KVCacheGroupSpec, SlidingWindowSpec)
26
27
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
+
38
def make_request(
39
request_id: str,
40
prompt_token_ids: list[int],
@@ -105,7 +115,6 @@ def make_kv_cache_config_hybrid_model(block_size: int,
115
116
@pytest.mark.parametrize("hash_fn", [sha256, sha256_cbor])
117
def test_prefill(hash_fn):
108
- init_none_hash(hash_fn)
118
119
block_size = 16
120
manager = KVCacheManager(
@@ -736,7 +745,6 @@ def test_cache_blocks(hash_fn):
745
This is a unit test that tests the correctness of the _cache_full_blocks
746
function of KVCacheManager.
747
"""
739
- init_none_hash(hash_fn)
748
749
block_size = 4
750
block_pool = BlockPool(
@@ -849,7 +857,6 @@ def test_mm_prefix_caching():
857
"""
858
This tests that the multi-modal prefix caching is correct.
859
"""
852
- kv_cache_utils.init_none_hash(sha256)
860
861
block_size = 16
862
manager = KVCacheManager(
@@ -942,8 +949,6 @@ def test_cache_key_salting():
949
This tests that cache salts are applied during hashing and the cache
950
is separated cache as expected.
951
"""
945
- kv_cache_utils.init_none_hash(sha256)
946
-
952
block_size = 16
953
manager = KVCacheManager(
954
make_kv_cache_config(block_size, 11),