diff --git a/tests/v1/core/test_kv_cache_utils.py b/tests/v1/core/test_kv_cache_utils.py index d1427f5eaf44..319e6e84fba1 100644 --- a/tests/v1/core/test_kv_cache_utils.py +++ b/tests/v1/core/test_kv_cache_utils.py @@ -30,6 +30,16 @@ # yapf: enable +@pytest.fixture(autouse=True) +def _auto_init_hash_fn(request): + hash_fn: Callable + if "hash_fn" in request.fixturenames: + hash_fn = init_none_hash(request.getfixturevalue("hash_fn")) + else: + hash_fn = sha256 + init_none_hash(hash_fn) + + def make_request( request_id: str, prompt_token_ids: list[int], @@ -424,7 +434,6 @@ def test_generate_block_hash_extra_keys_cache_salt(): @pytest.mark.parametrize("hash_fn", [sha256, sha256_cbor]) def test_hash_block_tokens(hash_fn): - init_none_hash(hash_fn) parent_block_hash = BlockHash(b"123") curr_block_token_ids = (1, 2, 3) extra_keys = ("key1", "key2") @@ -437,8 +446,6 @@ def test_hash_block_tokens(hash_fn): @pytest.mark.parametrize("hash_fn", [sha256, sha256_cbor]) def test_request_block_hasher(hash_fn): - kv_cache_utils.init_none_hash(hash_fn) - request = make_request( request_id="0", prompt_token_ids=[_ for _ in range(6)], @@ -461,8 +468,6 @@ def test_request_block_hasher(hash_fn): @pytest.mark.parametrize("hash_fn", [sha256, sha256_cbor]) def test_hash_tokens_different_mm_input(hash_fn): - init_none_hash(hash_fn) - request1 = make_request( request_id="0", prompt_token_ids=[_ for _ in range(6)], @@ -491,8 +496,6 @@ def test_hash_tokens_different_mm_input(hash_fn): @pytest.mark.parametrize("hash_fn", [sha256, sha256_cbor]) def test_hash_request_tokens_no_mm_inputs(hash_fn): - kv_cache_utils.init_none_hash(hash_fn) - request = make_request( request_id="0", prompt_token_ids=[_ for _ in range(6)], diff --git a/tests/v1/core/test_prefix_caching.py b/tests/v1/core/test_prefix_caching.py index 659d768bcf2e..3cf9d9369676 100644 --- a/tests/v1/core/test_prefix_caching.py +++ b/tests/v1/core/test_prefix_caching.py @@ -25,6 +25,16 @@ KVCacheGroupSpec, SlidingWindowSpec) +@pytest.fixture(autouse=True) +def _auto_init_hash_fn(request): + hash_fn: Callable + if "hash_fn" in request.fixturenames: + hash_fn = init_none_hash(request.getfixturevalue("hash_fn")) + else: + hash_fn = sha256 + init_none_hash(hash_fn) + + def make_request( request_id: str, prompt_token_ids: list[int], @@ -105,7 +115,6 @@ def make_kv_cache_config_hybrid_model(block_size: int, @pytest.mark.parametrize("hash_fn", [sha256, sha256_cbor]) def test_prefill(hash_fn): - init_none_hash(hash_fn) block_size = 16 manager = KVCacheManager( @@ -736,7 +745,6 @@ def test_cache_blocks(hash_fn): This is a unit test that tests the correctness of the _cache_full_blocks function of KVCacheManager. """ - init_none_hash(hash_fn) block_size = 4 block_pool = BlockPool( @@ -849,7 +857,6 @@ def test_mm_prefix_caching(): """ This tests that the multi-modal prefix caching is correct. """ - kv_cache_utils.init_none_hash(sha256) block_size = 16 manager = KVCacheManager( @@ -942,8 +949,6 @@ def test_cache_key_salting(): This tests that cache salts are applied during hashing and the cache is separated cache as expected. """ - kv_cache_utils.init_none_hash(sha256) - block_size = 16 manager = KVCacheManager( make_kv_cache_config(block_size, 11),