[Metrics] Expose cached prompt tokens by cache tier (#56318)
Signed-off-by: Cam Quilici <cjquilici@gmail.com> Signed-off-by: Cam Quilici <cameron@semianalysis.com> Co-authored-by: Cam Quilici <cameron@semianalysis.com> Co-authored-by: Nick Hill <nickhill123@gmail.com> Co-authored-by: Yifan Qiao <yifanqiao@inferact.ai>
This commit is contained in:
co-authored by
Cam Quilici
Nick Hill
Yifan Qiao
parent
ad0f67a7ec
commit
e37e51dd24
@@ -18,6 +18,7 @@ if TYPE_CHECKING:
|
||||
|
||||
from vllm.v1.kv_hints import KvHintsEnvelope
|
||||
from vllm.v1.kv_offload.config import OffloadingConfig
|
||||
from vllm.v1.metrics.cache_hit_source import CacheHitSource
|
||||
|
||||
# `OffloadKey` identifies an offloaded block. It combines a block hash with
|
||||
# its KV cache group index, encoded as raw bytes to avoid tuple GC overhead.
|
||||
@@ -248,6 +249,18 @@ class OffloadingManager(ABC):
|
||||
"""
|
||||
pass
|
||||
|
||||
def get_load_source(
|
||||
self, key: OffloadKey, req_context: ReqContext
|
||||
) -> CacheHitSource:
|
||||
"""Return the cache tier that supplied a successful lookup.
|
||||
|
||||
This is queried only after ``lookup`` resolves to ``HIT``. Composing
|
||||
managers can override it to retain the origin across asynchronous
|
||||
promotion into a primary tier. The default keeps out-of-tree managers
|
||||
compatible while making unknown provenance explicit.
|
||||
"""
|
||||
return CacheHitSource.EXTERNAL_UNSPECIFIED
|
||||
|
||||
@abstractmethod
|
||||
def prepare_load(
|
||||
self,
|
||||
|
||||
@@ -27,6 +27,7 @@ from vllm.v1.kv_offload.cpu.common import (
|
||||
)
|
||||
from vllm.v1.kv_offload.cpu.policies.base import CachePolicy, ChunkStatus
|
||||
from vllm.v1.kv_offload.cpu.policies.factory import CachePolicyFactory
|
||||
from vllm.v1.metrics.cache_hit_source import CacheHitSource
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
@@ -193,6 +194,12 @@ class CPUOffloadingManager(OffloadingManager):
|
||||
return LookupResult.HIT_PENDING
|
||||
return LookupResult.HIT
|
||||
|
||||
@override
|
||||
def get_load_source(
|
||||
self, key: OffloadKey, req_context: ReqContext
|
||||
) -> CacheHitSource:
|
||||
return CacheHitSource.HOST
|
||||
|
||||
@override
|
||||
def prepare_load(
|
||||
self,
|
||||
|
||||
@@ -24,6 +24,7 @@ from vllm.v1.kv_offload.base import (
|
||||
from vllm.v1.kv_offload.tiering.backpressure import (
|
||||
BackpressureDetector,
|
||||
)
|
||||
from vllm.v1.metrics.cache_hit_source import CacheHitSource
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from vllm.distributed.kv_transfer.kv_connector.v1.offloading.metrics import (
|
||||
@@ -141,6 +142,17 @@ class SecondaryTierManager(ABC):
|
||||
"""
|
||||
|
||||
medium: ClassVar[Medium | None] = None
|
||||
# Cache tier reported for hits served from this tier. Derived from
|
||||
# ``medium`` unless a subclass sets it; ``None`` medium means unknown.
|
||||
cache_hit_source: ClassVar[CacheHitSource] = CacheHitSource.EXTERNAL_UNSPECIFIED
|
||||
|
||||
def __init_subclass__(cls, **kwargs: Any) -> None:
|
||||
super().__init_subclass__(**kwargs)
|
||||
if "cache_hit_source" not in cls.__dict__ and cls.medium is not None:
|
||||
cls.cache_hit_source = {
|
||||
Medium.CPU: CacheHitSource.HOST,
|
||||
Medium.STORAGE: CacheHitSource.DISK,
|
||||
}[cls.medium]
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
||||
@@ -54,6 +54,7 @@ from vllm.v1.kv_offload.tiering.base import (
|
||||
TransferJob,
|
||||
)
|
||||
from vllm.v1.kv_offload.tiering.metrics import TieringMetricsTracker
|
||||
from vllm.v1.metrics.cache_hit_source import CacheHitSource
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
@@ -232,6 +233,11 @@ class TieringOffloadingManager(OffloadingManager):
|
||||
# complete_store(), since complete_store() can still submit cascades.
|
||||
self._req_state: dict[str, RequestState] = {}
|
||||
|
||||
# Preserve the original tier for this request's cache-hit metrics,
|
||||
# even after its KV blocks are promoted into host memory
|
||||
# (otherwise a disk or P2P hit would be mislabeled as a host hit).
|
||||
self._request_load_sources: dict[str, dict[OffloadKey, CacheHitSource]] = {}
|
||||
|
||||
# Cached ParentManager wrappers for each secondary tier.
|
||||
self._tier_parents: dict[SecondaryTierManager, _SecondaryTierFacingParent] = {
|
||||
tier: _SecondaryTierFacingParent(self, tier_idx)
|
||||
@@ -293,6 +299,13 @@ class TieringOffloadingManager(OffloadingManager):
|
||||
successful_keys = ()
|
||||
failed_keys = transfer_job.keys
|
||||
|
||||
load_sources = self._request_load_sources.get(transfer_job.req_context.req_id)
|
||||
if load_sources is not None:
|
||||
source = self.secondary_tiers[job_metadata.tier_idx].cache_hit_source
|
||||
for key in failed_keys:
|
||||
if load_sources.get(key) == source:
|
||||
del load_sources[key]
|
||||
|
||||
if successful_keys:
|
||||
self.primary_tier.complete_write(
|
||||
successful_keys,
|
||||
@@ -464,6 +477,15 @@ class TieringOffloadingManager(OffloadingManager):
|
||||
return LookupResult.RETRY
|
||||
return LookupResult.MISS
|
||||
|
||||
@override
|
||||
def get_load_source(
|
||||
self, key: OffloadKey, req_context: ReqContext
|
||||
) -> CacheHitSource:
|
||||
load_sources = self._request_load_sources.get(req_context.req_id)
|
||||
if load_sources is not None and key in load_sources:
|
||||
return load_sources[key]
|
||||
return self.primary_tier.get_load_source(key, req_context)
|
||||
|
||||
def _initiate_promotion(
|
||||
self,
|
||||
tier_idx: int,
|
||||
@@ -501,6 +523,10 @@ class TieringOffloadingManager(OffloadingManager):
|
||||
|
||||
store_spec = primary_write_result.store_spec
|
||||
assert isinstance(store_spec, CPULoadStoreSpec)
|
||||
load_sources = self._request_load_sources.setdefault(req_context.req_id, {})
|
||||
source = self.secondary_tiers[tier_idx].cache_hit_source
|
||||
for promoted_key in primary_write_result.keys_to_store:
|
||||
load_sources[promoted_key] = source
|
||||
# Defer submit_load to on_schedule_end(). Group by (tier, request) so
|
||||
# each request's chunks are submitted as one batched job per tier.
|
||||
tier_pending = self._pending_load_submissions.setdefault(tier_idx, {})
|
||||
@@ -848,6 +874,7 @@ class TieringOffloadingManager(OffloadingManager):
|
||||
continue
|
||||
tier.on_request_finished(state.req_context)
|
||||
self._metrics.on_request_finished(state.req_context)
|
||||
self._request_load_sources.pop(req_id, None)
|
||||
del self._req_state[req_id]
|
||||
|
||||
@override
|
||||
@@ -930,6 +957,7 @@ class TieringOffloadingManager(OffloadingManager):
|
||||
# reset below invalidates; their submit_load() has not yet been
|
||||
# called so no tier I/O is touching that memory.
|
||||
self._pending_load_submissions.clear()
|
||||
self._request_load_sources.clear()
|
||||
self._metrics.assert_idle()
|
||||
|
||||
finished_req_ids = []
|
||||
|
||||
@@ -11,7 +11,7 @@ import time
|
||||
import uuid
|
||||
from collections.abc import Iterable, Sequence
|
||||
from dataclasses import dataclass, field
|
||||
from typing import TYPE_CHECKING, Any
|
||||
from typing import TYPE_CHECKING, Any, ClassVar
|
||||
|
||||
from typing_extensions import override
|
||||
|
||||
@@ -35,6 +35,7 @@ from vllm.v1.kv_offload.tiering.base import (
|
||||
from vllm.v1.kv_offload.tiering.p2p.control import ControlTransport, ZmqTransport
|
||||
from vllm.v1.kv_offload.tiering.p2p.data import DataTransport, NixlTransport
|
||||
from vllm.v1.kv_offload.tiering.p2p.session import P2PSession
|
||||
from vllm.v1.metrics.cache_hit_source import CacheHitSource
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from vllm.v1.kv_offload.base import OffloadingSpec
|
||||
@@ -206,6 +207,8 @@ class P2PSecondaryTierManager(SecondaryTierManager):
|
||||
and existing sessions are polled even when no requests are scheduled.
|
||||
"""
|
||||
|
||||
cache_hit_source: ClassVar[CacheHitSource] = CacheHitSource.P2P
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
offloading_spec: OffloadingSpec,
|
||||
|
||||
Reference in New Issue
Block a user