[KV Offloading] Add basic offloading metrics (#45958)
Signed-off-by: srinivas_oo7 <sklinkedin0120@gmail.com> Signed-off-by: Srinivas Krovvidi <194645829+Srinivasoo7@users.noreply.github.com> Co-authored-by: srinivas_oo7 <sklinkedin0120@gmail.com> Co-authored-by: Or Ozeri <or@ozery.com> Co-authored-by: Or Ozeri <oro@il.ibm.com>
This commit is contained in:
co-authored by
srinivas_oo7
Or Ozeri
Or Ozeri
parent
dd5c299fbe
commit
e040899a00
@@ -224,6 +224,64 @@ def test_cpu_manager_reports_cache_usage_gauge():
|
||||
check_usage_stats(manager, 0.0)
|
||||
|
||||
|
||||
def test_cpu_manager_reports_allocation_size_histogram():
|
||||
manager = make_cpu_manager(num_blocks=4, cache_policy="lru")
|
||||
|
||||
manager.prepare_store(to_keys([1, 2]), _EMPTY_REQ_CTX)
|
||||
manager.complete_store(to_keys([1, 2]), _EMPTY_REQ_CTX)
|
||||
manager.prepare_store(to_keys([1, 2, 3]), _EMPTY_REQ_CTX)
|
||||
|
||||
stats = manager.get_stats()
|
||||
|
||||
assert stats is not None
|
||||
reduced = stats.reduce()
|
||||
assert reduced[f"{CPUOffloadingMetrics.CPU_ALLOCATION_SIZE}_count"] == 2
|
||||
assert reduced[f"{CPUOffloadingMetrics.CPU_ALLOCATION_SIZE}_sum"] == 3
|
||||
|
||||
# The cache-usage gauge is always reported, so get_stats() never returns
|
||||
# None, but the histogram has nothing new once its samples are consumed.
|
||||
second_stats = manager.get_stats()
|
||||
assert second_stats is not None
|
||||
assert f"{CPUOffloadingMetrics.CPU_ALLOCATION_SIZE}_count" not in (
|
||||
second_stats.reduce()
|
||||
)
|
||||
|
||||
|
||||
def test_cpu_manager_reports_allocation_size_on_allocation_failure(monkeypatch):
|
||||
manager = make_cpu_manager(num_blocks=4, cache_policy="lru")
|
||||
|
||||
def fail_allocate_blocks(keys):
|
||||
raise RuntimeError("allocation failed")
|
||||
|
||||
monkeypatch.setattr(manager, "_allocate_blocks", fail_allocate_blocks)
|
||||
|
||||
with pytest.raises(RuntimeError, match="allocation failed"):
|
||||
manager.prepare_store(to_keys([1, 2, 3]), _EMPTY_REQ_CTX)
|
||||
|
||||
stats = manager.get_stats()
|
||||
|
||||
assert stats is not None
|
||||
reduced = stats.reduce()
|
||||
assert reduced[f"{CPUOffloadingMetrics.CPU_ALLOCATION_SIZE}_count"] == 1
|
||||
assert reduced[f"{CPUOffloadingMetrics.CPU_ALLOCATION_SIZE}_sum"] == 3
|
||||
|
||||
|
||||
def test_cpu_manager_reports_allocation_size_on_eviction_failure():
|
||||
manager = make_cpu_manager(num_blocks=1, cache_policy="lru")
|
||||
|
||||
manager.prepare_store(to_keys([1]), _EMPTY_REQ_CTX)
|
||||
manager.get_stats()
|
||||
|
||||
assert manager.prepare_store(to_keys([2]), _EMPTY_REQ_CTX) is None
|
||||
|
||||
stats = manager.get_stats()
|
||||
|
||||
assert stats is not None
|
||||
reduced = stats.reduce()
|
||||
assert reduced[f"{CPUOffloadingMetrics.CPU_ALLOCATION_SIZE}_count"] == 1
|
||||
assert reduced[f"{CPUOffloadingMetrics.CPU_ALLOCATION_SIZE}_sum"] == 1
|
||||
|
||||
|
||||
def test_cpu_manager():
|
||||
"""
|
||||
Tests CPUOffloadingManager with lru policy.
|
||||
|
||||
@@ -21,7 +21,7 @@ from vllm.v1.kv_cache_interface import (
|
||||
KVCacheGroupSpec,
|
||||
KVCacheTensor,
|
||||
)
|
||||
from vllm.v1.kv_offload.base import OffloadingSpec
|
||||
from vllm.v1.kv_offload.base import OffloadingHistogramMetadata, OffloadingSpec
|
||||
from vllm.v1.kv_offload.cpu.spec import CPUOffloadingSpec
|
||||
from vllm.v1.kv_offload.factory import OffloadingSpecFactory
|
||||
from vllm.v1.kv_offload.tiering.spec import TieringOffloadingSpec
|
||||
@@ -248,8 +248,8 @@ def test_duplicate_registration_raises():
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_build_metric_definitions_empty_below_threshold():
|
||||
"""store_threshold < 2 → only base metric (no stores_skipped)."""
|
||||
def test_build_metric_definitions_below_threshold():
|
||||
"""store_threshold < 2 keeps stores_skipped disabled."""
|
||||
from vllm.v1.kv_offload.cpu.common import CPUOffloadingMetrics
|
||||
|
||||
config = _make_vllm_config(store_threshold=1)
|
||||
@@ -258,6 +258,32 @@ def test_build_metric_definitions_empty_below_threshold():
|
||||
config.kv_transfer_config.kv_connector_extra_config
|
||||
)
|
||||
assert CPUOffloadingMetrics.STORES_SKIPPED not in metrics
|
||||
assert CPUOffloadingMetrics.CPU_ALLOCATION_SIZE in metrics
|
||||
|
||||
|
||||
def test_build_metric_definitions_allocation_size_histogram():
|
||||
"""CPU allocation size is always reported as a histogram."""
|
||||
from vllm.v1.kv_offload.cpu.common import CPUOffloadingMetrics
|
||||
|
||||
config = _make_vllm_config(store_threshold=0)
|
||||
spec_cls = OffloadingSpecFactory.get_spec_cls(config)
|
||||
metrics = spec_cls.build_metric_definitions(
|
||||
config.kv_transfer_config.kv_connector_extra_config
|
||||
)
|
||||
metadata = metrics[CPUOffloadingMetrics.CPU_ALLOCATION_SIZE]
|
||||
assert isinstance(metadata, OffloadingHistogramMetadata)
|
||||
assert metadata.buckets == (
|
||||
1,
|
||||
4,
|
||||
16,
|
||||
64,
|
||||
256,
|
||||
1024,
|
||||
4096,
|
||||
16384,
|
||||
65536,
|
||||
262144,
|
||||
)
|
||||
|
||||
|
||||
def test_build_metric_definitions_returns_counter_at_threshold():
|
||||
|
||||
Reference in New Issue
Block a user