vllm.v1.metrics.stats
¶
Classes:
-
BaseCacheStats–Stores cache hit statistics.
-
CachingMetrics–Metrics for caching with a hit rate of the most recent N requests.
-
FinishedRequestStats–Stats associated with a finished request.
-
IterationStats–Stats associated with a single set of EngineCoreOutputs.
-
KVCacheEvictionEvent–Single KV cache block eviction sample.
-
LoRARequestStates–A per-LoRA count of running and waiting requests.
-
LoRAStats–Tracks waiting and running request IDs for a single LoRA.
-
MultiModalCacheStats–Stores multi-modal cache hit statistics.
-
PrefillStats–Breakdown of a scheduled prefill computation.
-
PrefixCacheStats–Stores prefix cache hit statistics.
-
PromptTokenStats–Breakdown of prompt tokens by source.
-
RequestSpecDecodeMetrics–Per-output-sequence speculative-decoding statistics accumulator.
-
RequestStateStats–Stats that need to be tracked across delta updates.
-
SchedulerIterationDetails–Scheduler-side details for one engine iteration.
-
SchedulerStats–Stats associated with the scheduler.
BaseCacheStats
dataclass
¶
Stores cache hit statistics.
Attributes:
-
hits(int) –The number of hits in these requests.
-
queries(int) –The number of queries in these requests.
-
requests(int) –The number of requests in this update.
-
reset(bool) –Whether the cache was reset.
hits = 0
class-attribute
instance-attribute
¶
The number of hits in these requests.
queries = 0
class-attribute
instance-attribute
¶
The number of queries in these requests.
requests = 0
class-attribute
instance-attribute
¶
The number of requests in this update.
reset = False
class-attribute
instance-attribute
¶
Whether the cache was reset.
CachingMetrics
¶
Metrics for caching with a hit rate of the most recent N requests.
Parameters:
Methods:
Attributes:
-
empty(bool) –Return true if no requests have been observed.
-
hit_rate(float) –Calculate the hit rate for the past N requests.
empty
property
¶
Return true if no requests have been observed.
hit_rate
property
¶
Calculate the hit rate for the past N requests.
observe(stats)
¶
Observe the prefix caching for a set of requests.
This function is called with information gathered when new requests are being scheduled and are looking for computed blocks.
When there are more than max_recent_requests requests, the oldest set
of requests are removed from the metrics.
Parameters:
-
(stats¶BaseCacheStats) –The prefix cache stats.
reset()
¶
Reset the metrics.
FinishedRequestStats
dataclass
¶
Stats associated with a finished request.
IterationStats
¶
Stats associated with a single set of EngineCoreOutputs.
Attributes:
-
num_prompt_tokens(int) –Total prompt tokens (for backward compatibility).
KVCacheEvictionEvent
dataclass
¶
Single KV cache block eviction sample.
LoRARequestStates
¶
A per-LoRA count of running and waiting requests.
LoRAStats
¶
Tracks waiting and running request IDs for a single LoRA.
MultiModalCacheStats
dataclass
¶
Bases: BaseCacheStats
Stores multi-modal cache hit statistics.
- reset: Whether reset_mm_cache was invoked.
- queries: Refers to the number of multi-modal data items
that were queried.
Methods:
-
record–Aggregate request information into the stats.
record(num_queries, num_hits)
¶
Aggregate request information into the stats.
PrefillStats
dataclass
¶
Breakdown of a scheduled prefill computation.
Fields
num_prompt_tokens: Total number of tokens to be prefilled. num_computed_tokens: Tokens to be prefilled locally (actual compute work). num_cached_tokens: Tokens to be prefilled without actual compute work. num_local_cached_tokens: Tokens to be prefilled from local prefix cache. num_external_cached_tokens: Tokens to be prefilled from external KV transfer. num_cache_creation_tokens: Tokens computed and written to the prefix cache.
PrefixCacheStats
dataclass
¶
Bases: BaseCacheStats
Stores prefix cache hit statistics.
- reset: Whether reset_prefix_cache was invoked.
- queries: Refers to the number of tokens that were queried.
Methods:
-
record–Aggregate request information into the stats.
Attributes:
-
hits_by_source(dict[CacheHitSource, int]) –hitssplit by the cache tier that supplied them (connector stats only). -
preempted_hits(int) –The
hitsnumber for preempted requests. -
preempted_queries(int) –The
queriesnumber for preempted requests. -
preempted_requests(int) –The number of previously preempted requests in this update.
hits_by_source = field(default_factory=dict)
class-attribute
instance-attribute
¶
hits split by the cache tier that supplied them (connector stats only).
preempted_hits = 0
class-attribute
instance-attribute
¶
The hits number for preempted requests.
preempted_queries = 0
class-attribute
instance-attribute
¶
The queries number for preempted requests.
preempted_requests = 0
class-attribute
instance-attribute
¶
The number of previously preempted requests in this update.
record(num_tokens, num_hits, preempted, hits_by_source=None)
¶
Aggregate request information into the stats.
PromptTokenStats
dataclass
¶
Breakdown of prompt tokens by source.
Fields
computed: Tokens prefilled locally (actual compute work). local_cache_hit: Tokens from local prefix cache. external_kv_transfer: Tokens from external KV transfer. cached_tokens: Tokens skipped during prefill (from scheduler). total: Total prompt tokens.
Invariants
computed + local_cache_hit + external_kv_transfer = total local_cache_hit + external_kv_transfer = cached_tokens
Methods:
-
get_by_source–Get token count by source label.
-
update_from_output–Update stats from a prefill output.
RequestSpecDecodeMetrics
dataclass
¶
Per-output-sequence speculative-decoding statistics accumulator.
Accumulates, over one sequence's verify steps, a histogram of accepted
draft-token counts (j, draft-only) and the total number of proposed
draft tokens. When detailed is requested it also records the ordered
per-step accepted/proposed sequences (summary omits them). Tracked per
engine Request (one per sampled sequence, so n > 1 yields one per
child), surfaced via EngineCoreOutput and the response
metrics.speculative_decoding for single-sequence requests (see
to_dict).
Fields
num_spec_tokens: Configured num_speculative_tokens (the max k);
also the histogram's upper bound.
histogram: Dense counts indexed by accepted draft tokens j
(length num_spec_tokens + 1).
num_draft_tokens: Total proposed draft tokens, including
grammar-invalid ones.
per_step_accepted: Ordered accepted-draft count per verify step
(detailed only; empty otherwise).
per_step_drafted: Ordered proposed-draft count per verify step
(detailed only; empty otherwise).
num_verified_tokens: Total draft tokens the target model ran a forward
pass on.
per_step_verified: Ordered verified-draft count per verify step
(detailed only; empty otherwise).
Methods:
-
to_dict–Payload matching
SpeculativeDecodingMetricsfor the response.
to_dict()
¶
Payload matching SpeculativeDecodingMetrics for the response.
acceptance_histogram is a dense list indexed by accepted draft count
j (length num_spec_tokens + 1). mean_acceptance_length
includes the bonus token (j + 1); draft_acceptance_rate is
draft-only, full precision. Per-step arrays are included only when
populated (detailed level).
RequestStateStats
dataclass
¶
Stats that need to be tracked across delta updates.
SchedulerIterationDetails
dataclass
¶
Scheduler-side details for one engine iteration.
SchedulerStats
dataclass
¶
Stats associated with the scheduler.