21
21
class StatLoggerBase (ABC ):
22
22
23
23
@abstractmethod
24
- def log (self , scheduler_stats : SchedulerStats ,
25
- iteration_stats : IterationStats ):
24
+ def record (self , scheduler_stats : SchedulerStats ,
25
+ iteration_stats : IterationStats ):
26
26
...
27
27
28
+ def log (self ): # noqa
29
+ pass
30
+
28
31
29
32
class LoggingStatLogger (StatLoggerBase ):
30
33
31
34
def __init__ (self ):
32
35
self ._reset (time .monotonic ())
36
+ self .last_scheduler_stats = SchedulerStats ()
33
37
34
38
def _reset (self , now ):
35
39
self .last_log_time = now
@@ -41,11 +45,6 @@ def _reset(self, now):
41
45
# Prefix cache metrics. TODO: Make the interval configurable.
42
46
self .prefix_caching_metrics = PrefixCachingMetrics ()
43
47
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
-
49
48
def _track_iteration_stats (self , iteration_stats : IterationStats ):
50
49
# Save tracked stats for token counters.
51
50
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:
56
55
# Compute summary metrics for tracked stats
57
56
return float (np .sum (tracked_stats ) / (now - self .last_log_time ))
58
57
59
- def log (self , scheduler_stats : SchedulerStats ,
60
- iteration_stats : IterationStats ):
58
+ def record (self , scheduler_stats : SchedulerStats ,
59
+ iteration_stats : IterationStats ):
61
60
"""Log Stats to standard output."""
62
61
63
62
self ._track_iteration_stats (iteration_stats )
64
63
65
64
self .prefix_caching_metrics .observe (scheduler_stats .prefix_cache_stats )
66
65
67
- now = time .monotonic ()
68
- if not self ._local_interval_elapsed (now ):
69
- return
66
+ self .last_scheduler_stats = scheduler_stats
70
67
68
+ def log (self ):
69
+ now = time .monotonic ()
71
70
prompt_throughput = self ._get_throughput (self .num_prompt_tokens , now )
72
71
generation_throughput = self ._get_throughput (
73
72
self .num_generation_tokens , now )
74
73
75
74
self ._reset (now )
76
75
76
+ scheduler_stats = self .last_scheduler_stats
77
+
77
78
# Format and print output.
78
79
logger .info (
79
80
"Avg prompt throughput: %.1f tokens/s, "
@@ -274,8 +275,8 @@ def log_metrics_info(self, type: str, config_obj: SupportsMetricsInfo):
274
275
labelnames = metrics_info .keys ()).labels (** metrics_info )
275
276
info_gauge .set (1 )
276
277
277
- def log (self , scheduler_stats : SchedulerStats ,
278
- iteration_stats : IterationStats ):
278
+ def record (self , scheduler_stats : SchedulerStats ,
279
+ iteration_stats : IterationStats ):
279
280
"""Log to prometheus."""
280
281
self .gauge_scheduler_running .set (scheduler_stats .num_running_reqs )
281
282
self .gauge_scheduler_waiting .set (scheduler_stats .num_waiting_reqs )
0 commit comments