[kv_offload] Add multi-tier KV cache offloading framework (#40020)
Signed-off-by: Ronen Schaffer <ronen.schaffer@ibm.com>
This commit is contained in:
@@ -262,6 +262,43 @@ def test_cpu_manager():
|
||||
)
|
||||
|
||||
|
||||
def test_prepare_load_preserves_key_order():
|
||||
"""block_ids[i] must correspond to keys[i] (co-indexed invariant)."""
|
||||
manager = CPUOffloadingManager(num_blocks=4, cache_policy="lru")
|
||||
|
||||
key_a, key_b, key_c = to_key(0), to_key(1), to_key(2)
|
||||
|
||||
# Store all three keys and learn their block ID assignments
|
||||
store_output = manager.prepare_store([key_a, key_b, key_c], _EMPTY_REQ_CTX)
|
||||
assert store_output is not None
|
||||
assert isinstance(store_output.store_spec, CPULoadStoreSpec)
|
||||
key_to_block_id = {
|
||||
k: int(bid)
|
||||
for k, bid in zip(store_output.keys_to_store, store_output.store_spec.block_ids)
|
||||
}
|
||||
manager.complete_store([key_a, key_b, key_c], _EMPTY_REQ_CTX)
|
||||
|
||||
# Forward order: [a, b, c]
|
||||
spec_fwd = manager.prepare_load([key_a, key_b, key_c], _EMPTY_REQ_CTX)
|
||||
assert isinstance(spec_fwd, CPULoadStoreSpec)
|
||||
assert [int(x) for x in spec_fwd.block_ids] == [
|
||||
key_to_block_id[key_a],
|
||||
key_to_block_id[key_b],
|
||||
key_to_block_id[key_c],
|
||||
]
|
||||
manager.complete_load([key_a, key_b, key_c], _EMPTY_REQ_CTX) # order irrelevant
|
||||
|
||||
# Arbitrary permutation: [b, c, a]
|
||||
spec_perm = manager.prepare_load([key_b, key_c, key_a], _EMPTY_REQ_CTX)
|
||||
assert isinstance(spec_perm, CPULoadStoreSpec)
|
||||
assert [int(x) for x in spec_perm.block_ids] == [
|
||||
key_to_block_id[key_b],
|
||||
key_to_block_id[key_c],
|
||||
key_to_block_id[key_a],
|
||||
]
|
||||
manager.complete_load([key_a, key_b, key_c], _EMPTY_REQ_CTX) # order irrelevant
|
||||
|
||||
|
||||
class TestARCPolicy:
|
||||
"""Unit tests for CPUOffloadingManager with ARC eviction policy."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user