[HiSparse] Report host-pool block residency as HiSparse metrics (#59485)

Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Matthew Bonanni
2026-10-09 16:45:34 -06:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 783ac12071
commit 4c43254d52
7 changed files with 147 additions and 6 deletions
@@ -112,6 +112,8 @@ class HiSparseConnectorScheduler:
stats.record_host_usage(
host_pool.get_usage(), len(self.coordinator.pending_spills)
)
if host_pool.metrics_collector is not None:
stats.record_host_evictions(host_pool.metrics_collector.drain_events())
return stats
def build_connector_meta(
@@ -12,6 +12,8 @@ from vllm.distributed.kv_transfer.kv_connector.v1.metrics import (
PromMetric,
PromMetricT,
)
from vllm.v1.metrics.buckets import histogram_buckets
from vllm.v1.metrics.stats import KVCacheEvictionEvent
from vllm.v1.metrics.utils import create_metric_per_engine
_HISPARSE_LEVEL_KEYS = frozenset({"host_cache_usage_perc", "pending_page_transfers"})
@@ -40,6 +42,9 @@ class HiSparseKVConnectorStats(KVConnectorStats):
"host_to_device_bytes": [],
"host_cache_usage_perc": [],
"pending_page_transfers": [],
"host_block_lifetime_seconds": [],
"host_block_idle_before_evict_seconds": [],
"host_block_reuse_gap_seconds": [],
}
def record_snapshot(self, hits: int, misses: int, host_to_device_bytes: int):
@@ -51,6 +56,12 @@ class HiSparseKVConnectorStats(KVConnectorStats):
self.data["host_cache_usage_perc"].append(usage)
self.data["pending_page_transfers"].append(pending_page_transfers)
def record_host_evictions(self, events: list[KVCacheEvictionEvent]) -> None:
for event in events:
self.data["host_block_lifetime_seconds"].append(event.lifetime_seconds)
self.data["host_block_idle_before_evict_seconds"].append(event.idle_seconds)
self.data["host_block_reuse_gap_seconds"].extend(event.reuse_gaps_seconds)
def aggregate(self, other: KVConnectorStats) -> KVConnectorStats:
if not other.is_empty():
for k, v in other.data.items():
@@ -143,6 +154,53 @@ class HiSparsePromMetrics(KVConnectorPromMetrics):
),
}
self.hisparse_histograms: dict[str, Any] = {}
if vllm_config.observability_config.kv_cache_metrics:
residency_buckets = histogram_buckets(
"kv_cache_residency",
overrides=vllm_config.observability_config.custom_histogram_buckets,
)
histogram_host_block_lifetime = self._histogram_cls(
name="vllm:hisparse_host_block_lifetime_seconds",
documentation=(
"Histogram of HiSparse host KV block lifetime from allocation "
"to eviction. Sampled metrics (controlled by "
"--kv-cache-metrics-sample)."
),
buckets=residency_buckets,
labelnames=labelnames,
)
histogram_host_block_idle_before_evict = self._histogram_cls(
name="vllm:hisparse_host_block_idle_before_evict_seconds",
documentation=(
"Histogram of HiSparse host KV block idle time before eviction. "
"Sampled metrics (controlled by --kv-cache-metrics-sample)."
),
buckets=residency_buckets,
labelnames=labelnames,
)
histogram_host_block_reuse_gap = self._histogram_cls(
name="vllm:hisparse_host_block_reuse_gap_seconds",
documentation=(
"Histogram of time gaps between consecutive HiSparse host KV "
"block accesses. Sampled metrics (controlled by "
"--kv-cache-metrics-sample)."
),
buckets=residency_buckets,
labelnames=labelnames,
)
self.hisparse_histograms = {
"host_block_lifetime_seconds": create_metric_per_engine(
histogram_host_block_lifetime, self.per_engine_labelvalues
),
"host_block_idle_before_evict_seconds": create_metric_per_engine(
histogram_host_block_idle_before_evict, self.per_engine_labelvalues
),
"host_block_reuse_gap_seconds": create_metric_per_engine(
histogram_host_block_reuse_gap, self.per_engine_labelvalues
),
}
def observe(self, transfer_stats_data: dict[str, Any], engine_idx: int = 0):
for name, counter in self.hisparse_counters.items():
for value in transfer_stats_data.get(name, []):
@@ -151,3 +209,6 @@ class HiSparsePromMetrics(KVConnectorPromMetrics):
values = transfer_stats_data.get(name, [])
if values:
gauge[engine_idx].set(values[-1])
for name, histogram in self.hisparse_histograms.items():
for value in transfer_stats_data.get(name, []):
histogram[engine_idx].observe(value)