Convert formatting to use ruff instead of yapf + isort (#26247)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
@@ -7,8 +7,11 @@ from typing import Optional
|
||||
import numpy as np
|
||||
|
||||
from vllm.v1.core.kv_cache_utils import BlockHash
|
||||
from vllm.v1.kv_offload.abstract import (LoadStoreSpec, OffloadingEvent,
|
||||
PrepareStoreOutput)
|
||||
from vllm.v1.kv_offload.abstract import (
|
||||
LoadStoreSpec,
|
||||
OffloadingEvent,
|
||||
PrepareStoreOutput,
|
||||
)
|
||||
from vllm.v1.kv_offload.backends.cpu import CPUBackend
|
||||
from vllm.v1.kv_offload.lru_manager import LRUOffloadingManager
|
||||
from vllm.v1.kv_offload.mediums import CPULoadStoreSpec
|
||||
@@ -26,31 +29,38 @@ def to_hashes(int_hashes: list[int]) -> list[BlockHash]:
|
||||
|
||||
|
||||
def verify_store_output(
|
||||
prepare_store_output: Optional[PrepareStoreOutput],
|
||||
expected_prepare_store_output: ExpectedPrepareStoreOutput):
|
||||
prepare_store_output: Optional[PrepareStoreOutput],
|
||||
expected_prepare_store_output: ExpectedPrepareStoreOutput,
|
||||
):
|
||||
assert prepare_store_output is not None
|
||||
assert (prepare_store_output.block_hashes_to_store == to_hashes(
|
||||
expected_prepare_store_output.block_hashes_to_store))
|
||||
assert (prepare_store_output.block_hashes_evicted == to_hashes(
|
||||
expected_prepare_store_output.block_hashes_evicted))
|
||||
assert prepare_store_output.block_hashes_to_store == to_hashes(
|
||||
expected_prepare_store_output.block_hashes_to_store
|
||||
)
|
||||
assert prepare_store_output.block_hashes_evicted == to_hashes(
|
||||
expected_prepare_store_output.block_hashes_evicted
|
||||
)
|
||||
store_spec = prepare_store_output.store_spec
|
||||
assert isinstance(store_spec, CPULoadStoreSpec)
|
||||
expected_array = np.array(expected_prepare_store_output.store_block_ids,
|
||||
dtype=np.int64)
|
||||
expected_array = np.array(
|
||||
expected_prepare_store_output.store_block_ids, dtype=np.int64
|
||||
)
|
||||
assert np.array_equal(expected_array, store_spec.block_ids)
|
||||
|
||||
|
||||
def verify_load_output(prepare_load_output: LoadStoreSpec,
|
||||
expected_prepare_load_output: list[int]):
|
||||
def verify_load_output(
|
||||
prepare_load_output: LoadStoreSpec, expected_prepare_load_output: list[int]
|
||||
):
|
||||
assert isinstance(prepare_load_output, CPULoadStoreSpec)
|
||||
expected_array = np.array(expected_prepare_load_output, dtype=np.int64)
|
||||
assert np.array_equal(expected_array, prepare_load_output.block_ids)
|
||||
|
||||
|
||||
def verify_events(events: Iterable[OffloadingEvent],
|
||||
block_size: int,
|
||||
expected_stores: tuple[set[int], ...] = (),
|
||||
expected_evictions: tuple[set[int], ...] = ()):
|
||||
def verify_events(
|
||||
events: Iterable[OffloadingEvent],
|
||||
block_size: int,
|
||||
expected_stores: tuple[set[int], ...] = (),
|
||||
expected_evictions: tuple[set[int], ...] = (),
|
||||
):
|
||||
stores: list[set[BlockHash]] = []
|
||||
evictions: list[set[BlockHash]] = []
|
||||
for event in events:
|
||||
@@ -61,8 +71,7 @@ def verify_events(events: Iterable[OffloadingEvent],
|
||||
else:
|
||||
stores.append(set(event.block_hashes))
|
||||
|
||||
def to_hash_sets(
|
||||
int_sets: tuple[set[int], ...]) -> tuple[set[BlockHash], ...]:
|
||||
def to_hash_sets(int_sets: tuple[set[int], ...]) -> tuple[set[BlockHash], ...]:
|
||||
return tuple([set(to_hashes(list(int_set))) for int_set in int_sets])
|
||||
|
||||
assert tuple(evictions) == to_hash_sets(expected_evictions)
|
||||
@@ -86,7 +95,8 @@ def test_cpu_manager():
|
||||
block_hashes_to_store=[1, 2],
|
||||
store_block_ids=[0, 1],
|
||||
block_hashes_evicted=[],
|
||||
))
|
||||
),
|
||||
)
|
||||
|
||||
# lookup [1, 2] -> not ready
|
||||
assert cpu_manager.lookup(to_hashes([1, 2])) == 0
|
||||
@@ -96,9 +106,9 @@ def test_cpu_manager():
|
||||
|
||||
# complete store [1, 2]
|
||||
cpu_manager.complete_store(to_hashes([1, 2]))
|
||||
verify_events(cpu_manager.take_events(),
|
||||
block_size=block_size,
|
||||
expected_stores=({1, 2}, ))
|
||||
verify_events(
|
||||
cpu_manager.take_events(), block_size=block_size, expected_stores=({1, 2},)
|
||||
)
|
||||
|
||||
# lookup [1, 2]
|
||||
assert cpu_manager.lookup(to_hashes([1])) == 1
|
||||
@@ -113,12 +123,13 @@ def test_cpu_manager():
|
||||
block_hashes_to_store=[3, 4, 5],
|
||||
store_block_ids=[2, 3, 0],
|
||||
block_hashes_evicted=[1],
|
||||
))
|
||||
),
|
||||
)
|
||||
|
||||
# verify eviction event
|
||||
verify_events(cpu_manager.take_events(),
|
||||
block_size=block_size,
|
||||
expected_evictions=({1}, ))
|
||||
verify_events(
|
||||
cpu_manager.take_events(), block_size=block_size, expected_evictions=({1},)
|
||||
)
|
||||
|
||||
# prepare store with no space
|
||||
assert cpu_manager.prepare_store(to_hashes([1, 6])) is None
|
||||
@@ -144,7 +155,8 @@ def test_cpu_manager():
|
||||
block_hashes_to_store=[6, 7, 8],
|
||||
store_block_ids=[3, 2, 1],
|
||||
block_hashes_evicted=[2, 3, 4],
|
||||
))
|
||||
),
|
||||
)
|
||||
|
||||
# complete store [6, 7, 8]
|
||||
cpu_manager.complete_store(to_hashes([6, 7, 8]))
|
||||
@@ -160,7 +172,8 @@ def test_cpu_manager():
|
||||
block_hashes_to_store=[9],
|
||||
store_block_ids=[1],
|
||||
block_hashes_evicted=[8],
|
||||
))
|
||||
),
|
||||
)
|
||||
|
||||
# complete store [7, 9] with failure
|
||||
cpu_manager.complete_store(to_hashes([7, 9]), success=False)
|
||||
@@ -169,7 +182,9 @@ def test_cpu_manager():
|
||||
assert cpu_manager.lookup(to_hashes([7])) == 1
|
||||
assert cpu_manager.lookup(to_hashes([9])) == 0
|
||||
|
||||
verify_events(cpu_manager.take_events(),
|
||||
block_size=block_size,
|
||||
expected_stores=({3, 4, 5}, {6, 7, 8}),
|
||||
expected_evictions=({2, 3, 4}, {8}))
|
||||
verify_events(
|
||||
cpu_manager.take_events(),
|
||||
block_size=block_size,
|
||||
expected_stores=({3, 4, 5}, {6, 7, 8}),
|
||||
expected_evictions=({2, 3, 4}, {8}),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user