2121class StatLoggerBase (ABC ):
2222
2323 @abstractmethod
24- def log (self , scheduler_stats : SchedulerStats ,
25- iteration_stats : IterationStats ):
24+ def record (self , scheduler_stats : SchedulerStats ,
25+ iteration_stats : IterationStats ):
2626 ...
2727
28+ def log (self ): # noqa
29+ pass
30+
2831
2932class LoggingStatLogger (StatLoggerBase ):
3033
3134 def __init__ (self ):
3235 self ._reset (time .monotonic ())
36+ self .last_scheduler_stats = SchedulerStats ()
3337
3438 def _reset (self , now ):
3539 self .last_log_time = now
@@ -41,11 +45,6 @@ def _reset(self, now):
4145 # Prefix cache metrics. TODO: Make the interval configurable.
4246 self .prefix_caching_metrics = PrefixCachingMetrics ()
4347
44- def _local_interval_elapsed (self , now : float ) -> bool :
45- # Log every _LOCAL_LOGGING_INTERVAL_SEC.
46- elapsed_time = now - self .last_log_time
47- return elapsed_time > _LOCAL_LOGGING_INTERVAL_SEC
48-
4948 def _track_iteration_stats (self , iteration_stats : IterationStats ):
5049 # Save tracked stats for token counters.
5150 self .num_prompt_tokens .append (iteration_stats .num_prompt_tokens )
@@ -56,24 +55,26 @@ def _get_throughput(self, tracked_stats: list[int], now: float) -> float:
5655 # Compute summary metrics for tracked stats
5756 return float (np .sum (tracked_stats ) / (now - self .last_log_time ))
5857
59- def log (self , scheduler_stats : SchedulerStats ,
60- iteration_stats : IterationStats ):
58+ def record (self , scheduler_stats : SchedulerStats ,
59+ iteration_stats : IterationStats ):
6160 """Log Stats to standard output."""
6261
6362 self ._track_iteration_stats (iteration_stats )
6463
6564 self .prefix_caching_metrics .observe (scheduler_stats .prefix_cache_stats )
6665
67- now = time .monotonic ()
68- if not self ._local_interval_elapsed (now ):
69- return
66+ self .last_scheduler_stats = scheduler_stats
7067
68+ def log (self ):
69+ now = time .monotonic ()
7170 prompt_throughput = self ._get_throughput (self .num_prompt_tokens , now )
7271 generation_throughput = self ._get_throughput (
7372 self .num_generation_tokens , now )
7473
7574 self ._reset (now )
7675
76+ scheduler_stats = self .last_scheduler_stats
77+
7778 # Format and print output.
7879 logger .info (
7980 "Avg prompt throughput: %.1f tokens/s, "
@@ -274,8 +275,8 @@ def log_metrics_info(self, type: str, config_obj: SupportsMetricsInfo):
274275 labelnames = metrics_info .keys ()).labels (** metrics_info )
275276 info_gauge .set (1 )
276277
277- def log (self , scheduler_stats : SchedulerStats ,
278- iteration_stats : IterationStats ):
278+ def record (self , scheduler_stats : SchedulerStats ,
279+ iteration_stats : IterationStats ):
279280 """Log to prometheus."""
280281 self .gauge_scheduler_running .set (scheduler_stats .num_running_reqs )
281282 self .gauge_scheduler_waiting .set (scheduler_stats .num_waiting_reqs )
0 commit comments