[Metrics][P/D] Add KV-fetch stage gauges for async KV loads (#58874)

Signed-off-by: Zijing Liu <liuzijing2014@gmail.com>
Signed-off-by: Nick Hill <nickhill123@gmail.com>
Co-authored-by: Nick Hill <nickhill123@gmail.com>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Zijing Liu
2026-10-02 01:24:33 +00:00
committed by GitHub
co-authored by Nick Hill Claude Opus 5.5
parent eec3c36a47
commit d58da79de7
5 changed files with 116 additions and 0 deletions
+40
View File
@@ -26,6 +26,7 @@ from vllm.v1.metrics.buckets import histogram_buckets
from vllm.v1.metrics.perf import PerfMetricsLogging, PerfMetricsProm
from vllm.v1.metrics.prometheus import unregister_vllm_metrics
from vllm.v1.metrics.stats import (
KV_FETCH_STAGES,
CachingMetrics,
IterationStats,
MultiModalCacheStats,
@@ -292,6 +293,13 @@ class LoggingStatLogger(StatLoggerBase):
log_parts.append("Deferred: %d reqs")
log_args.append(self.last_scheduler_stats.num_skipped_waiting_reqs)
kv_fetch = self.last_scheduler_stats.num_kv_fetch_reqs_by_stage
if any(kv_fetch.values()):
log_parts.append(
"KV fetch: %d waiting to start, %d in progress, %d completed waiting"
)
log_args.extend(kv_fetch.get(stage, 0) for stage in KV_FETCH_STAGES)
if self.num_preemptions > 0:
log_parts.append("Preemptions: %d")
log_args.append(self.num_preemptions)
@@ -393,6 +401,10 @@ class AggregatedLoggingStatLogger(LoggingStatLogger, AggregateStatLoggerBase):
self.last_scheduler_stats.num_skipped_waiting_reqs += (
last_scheduler_stats.num_skipped_waiting_reqs
)
engine_kv_fetch = last_scheduler_stats.num_kv_fetch_reqs_by_stage
total_kv_fetch = self.last_scheduler_stats.num_kv_fetch_reqs_by_stage
for stage, num_reqs in engine_kv_fetch.items():
total_kv_fetch[stage] = total_kv_fetch.get(stage, 0) + num_reqs
self.last_scheduler_stats.kv_cache_usage += (
last_scheduler_stats.kv_cache_usage
)
@@ -547,6 +559,30 @@ class PrometheusStatLogger(AggregateStatLoggerBase):
gauge_waiting_by_reason, per_engine_labelvalues_with_reason
)
self.gauge_kv_fetch_by_stage: dict[str, dict[int, Gauge]] = {}
kv_transfer_config = vllm_config.kv_transfer_config
if kv_transfer_config is not None and kv_transfer_config.is_kv_consumer:
gauge_kv_fetch_by_stage = self._gauge_cls(
name="vllm:num_requests_kv_fetch_by_stage",
documentation=(
"Number of waiting requests by async KV load stage. "
"Stage labels: 'waiting_to_start' = needs an async KV load "
"that has not started; 'in_progress' = load started and not "
"yet reported finished; 'completed_waiting' = load finished, "
"request not running yet."
),
multiprocess_mode="mostrecent",
labelnames=labelnames + ["stage"],
)
for stage in KV_FETCH_STAGES:
per_engine_labelvalues_with_stage = {
idx: labelvalues + [stage]
for idx, labelvalues in per_engine_labelvalues.items()
}
self.gauge_kv_fetch_by_stage[stage] = create_metric_per_engine(
gauge_kv_fetch_by_stage, per_engine_labelvalues_with_stage
)
gauge_engine_sleep_state = self._gauge_cls(
name="vllm:engine_sleep_state",
documentation=(
@@ -1062,6 +1098,10 @@ class PrometheusStatLogger(AggregateStatLoggerBase):
self.gauge_waiting_by_reason[WAITING_REASON_DEFERRED][engine_idx].set(
scheduler_stats.num_skipped_waiting_reqs
)
for stage, gauges in self.gauge_kv_fetch_by_stage.items():
gauges[engine_idx].set(
scheduler_stats.num_kv_fetch_reqs_by_stage.get(stage, 0)
)
self.gauge_kv_cache_usage[engine_idx].set(scheduler_stats.kv_cache_usage)
self.counter_prefix_cache_queries[engine_idx].inc(
+12
View File
@@ -182,6 +182,16 @@ class SchedulerIterationDetails:
is_dummy: bool = False
KV_FETCH_WAITING_TO_START = "waiting_to_start"
KV_FETCH_IN_PROGRESS = "in_progress"
KV_FETCH_COMPLETED_WAITING = "completed_waiting"
KV_FETCH_STAGES = (
KV_FETCH_WAITING_TO_START,
KV_FETCH_IN_PROGRESS,
KV_FETCH_COMPLETED_WAITING,
)
@dataclass
class SchedulerStats:
"""Stats associated with the scheduler."""
@@ -192,6 +202,8 @@ class SchedulerStats:
# waiting requests deferred by transient constraints or a blocked status
num_skipped_waiting_reqs: int = 0
num_kv_fetch_reqs_by_stage: dict[str, int] = field(default_factory=dict)
# These are used for internal DP load-balancing.
step_counter: int = 0
current_wave: int = 0