Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions tests/v1/core/test_kv_cache_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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")
Expand All @@ -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)],
Expand All @@ -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)],
Expand Down Expand Up @@ -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)],
Expand Down
15 changes: 10 additions & 5 deletions tests/v1/core/test_prefix_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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),
Expand Down