[Metrics][KV Offload] Add vllm:kv_offload_config_info - generic info metrics for offloading the offloading connector (#56867)

Signed-off-by: Amir Friedman <Amir.Friedman1@ibm.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: Or Ozeri <oro@il.ibm.com>
This commit is contained in:
Amir Friedman
2026-10-14 12:34:37 +00:00
committed by GitHub
co-authored by Claude Opus 5 Or Ozeri
parent 3a5a6b11a3
commit 775fefa804
17 changed files with 926 additions and 42 deletions
+57 -3
View File
@@ -3,8 +3,8 @@
"""Core abstractions for KV cache offloading in vLLM v1."""
from abc import ABC, abstractmethod
from collections.abc import Collection, Iterable, Sequence
from dataclasses import dataclass, field
from collections.abc import Collection, Iterable, Mapping, Sequence
from dataclasses import dataclass, field, fields
from enum import Enum, auto
from typing import TYPE_CHECKING, Any, ClassVar, NamedTuple, NewType, TypeVar
@@ -214,7 +214,12 @@ class OffloadingCounterMetadata(OffloadingMetricMetadata):
@dataclass(frozen=True)
class OffloadingGaugeMetadata(OffloadingMetricMetadata):
pass
# Gauge-only in prometheus_client: how MultiProcessCollector merges samples
# written by different API-server processes. Offloading stats reach one
# frontend per step as complete per-engine snapshots, so the freshest write
# is the correct value and summing would multiply it by the number of
# participating frontends.
multiprocess_mode: str = "mostrecent"
@dataclass(frozen=True)
@@ -232,6 +237,36 @@ class OffloadingKVEventsConfig:
self_describing_kv_events: bool
# The labels of one info metric series: a label name mapped to its value.
ConfigInfoMapping = Mapping[str, str | int | float | bool]
@dataclass(frozen=True)
class ConfigInfo:
"""Static facts that one component publishes on vllm:kv_offload_config_info.
Each field is one label. The OffloadingSpec declares the names with
config_info_keys(), and the OffloadingManager fills the values with
as_config_info(). A declared name that the manager does not fill reads
empty, and an undeclared name is dropped. The values must stay fixed for
the process lifetime. Document each field in
docs/features/kv_offloading_usage.md. See CPUOffloadingInfo for an example.
"""
@classmethod
def config_info_keys(cls) -> tuple[str, ...]:
"""Return one label name for each field, in field order."""
return tuple(info.name for info in fields(cls))
def as_config_info(self) -> ConfigInfoMapping:
"""Return the label values. A None value becomes "None", not empty."""
values = (getattr(self, info.name) for info in fields(self))
return {
key: "None" if value is None else value
for key, value in zip(self.config_info_keys(), values)
}
class OffloadingManager(ABC):
@abstractmethod
def lookup(self, key: OffloadKey, req_context: ReqContext) -> LookupResult:
@@ -416,6 +451,13 @@ class OffloadingManager(ABC):
"""Return collected metrics since last call, or None if disabled."""
return None
def config_info(self) -> Sequence[ConfigInfoMapping]:
"""Return the info metric labels, one mapping for each series.
The scheduler reads this once. See ConfigInfo.
"""
return [{}]
def shutdown(self) -> None:
"""Shutdown the manager and release any resources."""
return
@@ -602,6 +644,18 @@ class OffloadingSpec(ABC):
"""Return Prometheus metric definitions emitted by this spec."""
return {}
@classmethod
def config_info_keys(cls, extra_config: dict[str, Any]) -> tuple[str, ...]:
"""Return the info metric label names that the manager fills.
See ConfigInfo.
Args:
extra_config: kv_connector_extra_config of this instance.
"""
return ()
def __init__(self, config: OffloadingConfig):
self.config = config
self.extra_config = config.extra_config
+11 -1
View File
@@ -1,8 +1,10 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from dataclasses import dataclass
import numpy as np
from vllm.v1.kv_offload.base import BlockIDsLoadStoreSpec
from vllm.v1.kv_offload.base import BlockIDsLoadStoreSpec, ConfigInfo
class CPUOffloadingMetrics:
@@ -24,3 +26,11 @@ class CPULoadStoreSpec(BlockIDsLoadStoreSpec):
@property
def chunk_ids(self) -> np.ndarray:
return self.block_ids
@dataclass(frozen=True)
class CPUOffloadingInfo(ConfigInfo):
"""Static facts about the CPU offload tier."""
# Chunk slots in the tier. Chunks, not GPU blocks.
cpu_num_chunks: int
+11 -1
View File
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from collections import OrderedDict
from collections.abc import Collection, Iterable
from collections.abc import Collection, Iterable, Sequence
from dataclasses import dataclass, field
from typing_extensions import override
@@ -10,6 +10,7 @@ from vllm.distributed.kv_transfer.kv_connector.v1.offloading.metrics import (
OffloadingConnectorStats,
)
from vllm.v1.kv_offload.base import (
ConfigInfoMapping,
LoadStoreSpec,
LookupResult,
Medium,
@@ -23,6 +24,7 @@ from vllm.v1.kv_offload.base import (
)
from vllm.v1.kv_offload.cpu.common import (
CPULoadStoreSpec,
CPUOffloadingInfo,
CPUOffloadingMetrics,
)
from vllm.v1.kv_offload.cpu.policies.base import CachePolicy, ChunkStatus
@@ -66,6 +68,9 @@ class CPUOffloadingManager(OffloadingManager):
):
self.medium: Medium = Medium.CPU
self._num_chunks: int = num_chunks
self._config_info: ConfigInfoMapping = CPUOffloadingInfo(
cpu_num_chunks=num_chunks
).as_config_info()
self._num_allocated_chunks: int = 0
self._free_list: list[int] = []
self.events: list[OffloadingEvent] | None = [] if enable_events else None
@@ -446,6 +451,11 @@ class CPUOffloadingManager(OffloadingManager):
yield from self.events
self.events.clear()
@override
def config_info(self) -> Sequence[ConfigInfoMapping]:
"""Report the CPU cache facts of the one cache this manager holds."""
return [self._config_info]
def get_stats(self) -> OffloadingConnectorStats | None:
stats = OffloadingConnectorStats()
+7 -1
View File
@@ -17,7 +17,7 @@ from vllm.v1.kv_offload.base import (
OffloadingWorker,
)
from vllm.v1.kv_offload.config import OffloadingConfig
from vllm.v1.kv_offload.cpu.common import CPUOffloadingMetrics
from vllm.v1.kv_offload.cpu.common import CPUOffloadingInfo, CPUOffloadingMetrics
from vllm.v1.kv_offload.cpu.gpu_worker import CPUOffloadingWorker
from vllm.v1.kv_offload.cpu.manager import CPUOffloadingManager
from vllm.v1.kv_offload.cpu.shared_offload_region import SharedOffloadRegion
@@ -136,6 +136,12 @@ class CPUOffloadingSpec(OffloadingSpec):
"cache_policy_module_path"
)
@classmethod
@override
def config_info_keys(cls, extra_config: dict[str, Any]) -> tuple[str, ...]:
"""Return the label names CPUOffloadingManager.config_info() fills."""
return CPUOffloadingInfo.config_info_keys()
@override
def get_manager(self) -> OffloadingManager:
if not self._manager:
+23
View File
@@ -11,6 +11,7 @@ from typing import TYPE_CHECKING, Any, ClassVar
import numpy as np
from vllm.v1.kv_offload.base import (
ConfigInfoMapping,
Locality,
LookupResult,
Medium,
@@ -36,6 +37,8 @@ if TYPE_CHECKING:
# Type alias for job IDs used in async transfer tracking
JobId = int
TIER_LABEL = "tier"
class TieringOffloadingMetrics:
"""Metric names for TieringOffloadingManager."""
@@ -370,3 +373,23 @@ class SecondaryTierManager(ABC):
def get_stats(self) -> "OffloadingConnectorStats | None":
"""Return and reset metric observations collected by this tier."""
return None
@classmethod
def config_info_keys(cls, tier_config: dict[str, Any]) -> tuple[str, ...]:
"""Return the info metric label names of this tier.
TieringOffloadingSpec merges the names of all tiers and adds
TIER_LABEL, so a tier must not declare it. See ConfigInfo.
Args:
tier_config: Configuration dict of this tier.
"""
return ()
def config_info(self) -> ConfigInfoMapping:
"""Return the info metric labels of this tier, for its one series.
TieringOffloadingManager adds TIER_LABEL. See ConfigInfo.
"""
return {}
+26 -1
View File
@@ -10,11 +10,14 @@ TieringOffloadingManager without requiring actual storage or network backends.
import logging
from collections.abc import Iterable
from typing import TYPE_CHECKING, ClassVar
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, ClassVar
from typing_extensions import override
from vllm.v1.kv_offload.base import (
ConfigInfo,
ConfigInfoMapping,
LookupResult,
Medium,
OffloadKey,
@@ -34,6 +37,17 @@ if TYPE_CHECKING:
from vllm.v1.kv_offload.tiering.backpressure import BackpressureDetector
@dataclass(frozen=True)
class ExampleTierInfo(ConfigInfo):
"""Config facts of one ExampleSecondaryTierManager.
A field name is the label name. A secondary tier needs no name of its own
for the tier, because the tier label tells the series of the tiers apart.
"""
example_info: int
class ExampleSecondaryTierManager(SecondaryTierManager):
"""A simple in-memory secondary tier.
@@ -69,6 +83,8 @@ class ExampleSecondaryTierManager(SecondaryTierManager):
backpressure_detector=backpressure_detector,
)
self._config_info = ExampleTierInfo(example_info=custom_param)
logger.info(
"ExampleSecondaryTierManager initialized with custom_param=%d", custom_param
)
@@ -81,6 +97,15 @@ class ExampleSecondaryTierManager(SecondaryTierManager):
assert primary_kv_view.strides is not None
self._chunk_size = primary_kv_view.strides[0]
@classmethod
@override
def config_info_keys(cls, tier_config: dict[str, Any]) -> tuple[str, ...]:
return ExampleTierInfo.config_info_keys()
@override
def config_info(self) -> ConfigInfoMapping:
return self._config_info.as_config_info()
@override
def lookup(self, key: OffloadKey, req_context: ReqContext) -> LookupResult:
"""Check whether a chunk exists in this secondary tier.
+1 -1
View File
@@ -523,7 +523,7 @@ class KVCRSecondaryTierManager(SecondaryTierManager):
stats = cast(OffloadingConnectorStats | None, self._kvcr.get_stats())
if stats is not None:
# Add the framework namespace only at the vLLM boundary.
for metrics in stats.data.values():
for metrics in stats.metric_sections():
for name in tuple(metrics):
metrics[_vllm_metric_name(name)] = metrics.pop(name)
return stats
+22
View File
@@ -32,6 +32,7 @@ from vllm.distributed.kv_transfer.kv_connector.v1.offloading.metrics import (
)
from vllm.logger import init_logger
from vllm.v1.kv_offload.base import (
ConfigInfoMapping,
LoadStoreSpec,
LookupResult,
OffloadingEvent,
@@ -47,6 +48,7 @@ from vllm.v1.kv_offload.cpu.common import CPULoadStoreSpec
from vllm.v1.kv_offload.cpu.manager import CPUOffloadingManager
from vllm.v1.kv_offload.cpu.shared_offload_region import SharedOffloadRegion
from vllm.v1.kv_offload.tiering.base import (
TIER_LABEL,
JobId,
JobResult,
ParentManager,
@@ -1007,6 +1009,26 @@ class TieringOffloadingManager(OffloadingManager):
return stats
@override
def config_info(self) -> Sequence[ConfigInfoMapping]:
"""Return one mapping for each tier, primary tier first, with TIER_LABEL.
Raises:
ValueError: If the primary tier returns more than one mapping.
"""
(primary_info,) = self.primary_tier.config_info()
primary_tier_info = dict(primary_info)
primary_tier_info[TIER_LABEL] = self._metrics.primary_tier_label[0]
tier_infos = [primary_tier_info]
for tier in self.secondary_tiers:
tier_info = dict(tier.config_info())
tier_info[TIER_LABEL] = self._metrics.tier_label(self._tier_index[tier])[0]
tier_infos.append(tier_info)
return tier_infos
@override
def shutdown(self) -> None:
"""Shut down secondary tiers before releasing primary resources.
+67 -24
View File
@@ -69,7 +69,11 @@ from vllm.v1.kv_offload.config import OffloadingConfig
from vllm.v1.kv_offload.cpu.gpu_worker import CPUOffloadingWorker
from vllm.v1.kv_offload.cpu.shared_offload_region import SharedOffloadRegion
from vllm.v1.kv_offload.cpu.spec import CPUOffloadingSpec
from vllm.v1.kv_offload.tiering.base import TieringOffloadingMetrics
from vllm.v1.kv_offload.tiering.base import (
TIER_LABEL,
SecondaryTierManager,
TieringOffloadingMetrics,
)
from vllm.v1.kv_offload.tiering.factory import SecondaryTierFactory
from vllm.v1.kv_offload.tiering.manager import (
CPUPrimaryTierOffloadingManager,
@@ -105,7 +109,7 @@ class TieringOffloadingSpec(CPUOffloadingSpec):
"Histogram of blocking time spent in a per-chunk tier lookup "
"that resolved as a hit or miss, labeled by tier, in seconds."
),
labelnames=("tier",),
labelnames=(TIER_LABEL,),
buckets=(
0.00001,
0.00005,
@@ -128,7 +132,7 @@ class TieringOffloadingSpec(CPUOffloadingSpec):
"first returning retry until that same tier lookup resolves "
"as a hit or miss, labeled by tier, in seconds."
),
labelnames=("tier",),
labelnames=(TIER_LABEL,),
buckets=(
0.0001,
0.0005,
@@ -149,35 +153,35 @@ class TieringOffloadingSpec(CPUOffloadingSpec):
"Total bytes read from secondary tiers into the primary tier, "
"labeled by tier."
),
labelnames=("tier",),
labelnames=(TIER_LABEL,),
)
metrics[TieringOffloadingMetrics.READ_TIME] = OffloadingCounterMetadata(
documentation=(
"Total time spent reading from secondary tiers into the primary "
"tier, in seconds, labeled by tier."
),
labelnames=("tier",),
labelnames=(TIER_LABEL,),
)
metrics[TieringOffloadingMetrics.WRITE_BYTES] = OffloadingCounterMetadata(
documentation=(
"Total bytes written from the primary tier to secondary tiers, "
"labeled by tier."
),
labelnames=("tier",),
labelnames=(TIER_LABEL,),
)
metrics[TieringOffloadingMetrics.WRITE_TIME] = OffloadingCounterMetadata(
documentation=(
"Total time spent writing from the primary tier to secondary "
"tiers, in seconds, labeled by tier."
),
labelnames=("tier",),
labelnames=(TIER_LABEL,),
)
metrics[TieringOffloadingMetrics.PROMOTION_JOB_FAILURES] = (
OffloadingCounterMetadata(
documentation=(
"Number of failed secondary-tier promotion jobs, labeled by tier."
),
labelnames=("tier",),
labelnames=(TIER_LABEL,),
)
)
metrics[TieringOffloadingMetrics.CASCADE_JOB_FAILURES] = (
@@ -185,18 +189,18 @@ class TieringOffloadingSpec(CPUOffloadingSpec):
documentation=(
"Number of failed secondary-tier cascade jobs, labeled by tier."
),
labelnames=("tier",),
labelnames=(TIER_LABEL,),
)
)
metrics[TieringOffloadingMetrics.CHUNK_QUERIES] = OffloadingCounterMetadata(
documentation=(
"Number of chunk lookup queries sent to a tier, labeled by tier."
),
labelnames=("tier",),
labelnames=(TIER_LABEL,),
)
metrics[TieringOffloadingMetrics.CHUNK_HITS] = OffloadingCounterMetadata(
documentation="Number of chunk lookup hits in a tier, labeled by tier.",
labelnames=("tier",),
labelnames=(TIER_LABEL,),
)
metrics[TieringOffloadingMetrics.PROMOTION_ALLOCATION_FAILURES] = (
OffloadingCounterMetadata(
@@ -212,7 +216,7 @@ class TieringOffloadingSpec(CPUOffloadingSpec):
"Current fraction of primary-tier space used by writes from "
"secondary tiers, labeled by tier."
),
labelnames=("tier",),
labelnames=(TIER_LABEL,),
)
)
metrics[TieringOffloadingMetrics.PRIMARY_READ_USAGE_PERC] = (
@@ -221,7 +225,7 @@ class TieringOffloadingSpec(CPUOffloadingSpec):
"Current fraction of primary-tier space used by reads to "
"secondary tiers, labeled by tier."
),
labelnames=("tier",),
labelnames=(TIER_LABEL,),
)
)
metrics[TieringOffloadingMetrics.ACTIVE_PROMOTION_JOBS] = (
@@ -229,22 +233,17 @@ class TieringOffloadingSpec(CPUOffloadingSpec):
documentation=(
"Number of active secondary-tier promotion jobs, labeled by tier."
),
labelnames=("tier",),
labelnames=(TIER_LABEL,),
)
)
metrics[TieringOffloadingMetrics.ACTIVE_CASCADE_JOBS] = OffloadingGaugeMetadata(
documentation=(
"Number of active secondary-tier cascade jobs, labeled by tier."
),
labelnames=("tier",),
labelnames=(TIER_LABEL,),
)
secondary_tier_configs = extra_config.get("secondary_tiers", [])
if not isinstance(secondary_tier_configs, list):
raise ValueError("secondary_tiers must be a list of tier configurations")
for tier_config in secondary_tier_configs:
assert isinstance(tier_config, dict)
tier_cls = SecondaryTierFactory.get_tier_class(tier_config)
for tier_config, tier_cls in cls._get_secondary_tiers(extra_config):
metrics.update(tier_cls.build_metric_definitions(tier_config))
metrics[TieringOffloadingMetrics.BACKPRESSURE_STORE_LATENCY_EMA] = (
@@ -253,7 +252,7 @@ class TieringOffloadingSpec(CPUOffloadingSpec):
"Exponential moving average of store latency "
"for back-pressure detection, in s/MiB."
),
labelnames=("tier",),
labelnames=(TIER_LABEL,),
)
)
metrics[TieringOffloadingMetrics.BACKPRESSURE_STORES_DROPPED] = (
@@ -262,7 +261,7 @@ class TieringOffloadingSpec(CPUOffloadingSpec):
"Number of store operations dropped due to "
"back-pressure on a secondary tier."
),
labelnames=("tier",),
labelnames=(TIER_LABEL,),
)
)
metrics[TieringOffloadingMetrics.BACKPRESSURE_BLOCKS_DROPPED] = (
@@ -270,7 +269,7 @@ class TieringOffloadingSpec(CPUOffloadingSpec):
documentation=(
"Number of blocks dropped due to back-pressure on a secondary tier."
),
labelnames=("tier",),
labelnames=(TIER_LABEL,),
)
)
@@ -426,6 +425,50 @@ class TieringOffloadingSpec(CPUOffloadingSpec):
return self._manager
@classmethod
@override
def config_info_keys(cls, extra_config: dict[str, Any]) -> tuple[str, ...]:
"""Return TIER_LABEL and the label names of all tiers, with no repeat."""
# dict.fromkeys() keeps one copy of a name that two tier types share.
keys = dict.fromkeys(super().config_info_keys(extra_config))
keys[TIER_LABEL] = None
for tier_config, tier_cls in cls._get_secondary_tiers(extra_config):
tier_keys = tier_cls.config_info_keys(tier_config)
assert TIER_LABEL not in tier_keys, (
f"{tier_cls.__name__} must not declare the reserved label "
f"{TIER_LABEL!r}"
)
keys.update(dict.fromkeys(tier_keys))
return tuple(keys)
@classmethod
def _get_secondary_tiers(
cls, extra_config: dict[str, Any]
) -> list[tuple[dict[str, Any], type[SecondaryTierManager]]]:
"""Resolve every configured secondary tier to its manager class.
Args:
extra_config: kv_connector_extra_config of this instance.
Returns:
One (tier config, tier class) pair for each secondary tier, in
configuration order. That order sets the tier index.
Raises:
ValueError: If secondary_tiers is not a list.
"""
secondary_tier_configs = extra_config.get("secondary_tiers", [])
if not isinstance(secondary_tier_configs, list):
raise ValueError("secondary_tiers must be a list of tier configurations")
tiers = []
for tier_config in secondary_tier_configs:
assert isinstance(tier_config, dict)
tier_cls = SecondaryTierFactory.get_tier_class(tier_config)
tiers.append((tier_config, tier_cls))
return tiers
@override
def _uses_shared_region(self) -> bool:
# Tiering always allocates on the shared region (every platform), so the