[Metrics] Add test for multi-modal cache stats logging (#26588)

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
This commit is contained in:
Mark McLoughlin
2025-10-10 16:00:50 +00:00
committed by GitHub
parent 7b03584de8
commit e519281920
3 changed files with 30 additions and 4 deletions
+1 -4
View File
@@ -60,7 +60,6 @@ class LoggingStatLogger(StatLoggerBase):
self._reset(time.monotonic())
self.last_scheduler_stats = SchedulerStats()
self.last_mm_cache_stats: Optional[MultiModalCacheStats] = None
# Caching metrics. This cannot be reset.
# TODO: Make the interval configurable.
@@ -115,8 +114,6 @@ class LoggingStatLogger(StatLoggerBase):
if mm_cache_stats:
self.mm_caching_metrics.observe(mm_cache_stats)
self.last_mm_cache_stats = mm_cache_stats
def log(self):
now = time.monotonic()
prompt_throughput = self._get_throughput(self.num_prompt_tokens, now)
@@ -157,7 +154,7 @@ class LoggingStatLogger(StatLoggerBase):
scheduler_stats.kv_cache_usage * 100,
self.prefix_caching_metrics.hit_rate * 100,
]
if self.last_mm_cache_stats:
if not self.mm_caching_metrics.empty:
log_parts.append("MM cache hit rate: %.1f%%")
log_args.append(self.mm_caching_metrics.hit_rate * 100)
+5
View File
@@ -96,6 +96,11 @@ class CachingMetrics:
self.aggregated_query_hit = 0
self.query_queue.clear()
@property
def empty(self) -> bool:
"""Return true if no requests have been observed."""
return self.aggregated_requests == 0
@property
def hit_rate(self) -> float:
"""Calculate the hit rate for the past N requests."""