diff --git a/python/sglang/srt/observability/scheduler_metrics_mixin.py b/python/sglang/srt/observability/scheduler_metrics_mixin.py index 18ea325ba..593d6dd58 100644 --- a/python/sglang/srt/observability/scheduler_metrics_mixin.py +++ b/python/sglang/srt/observability/scheduler_metrics_mixin.py @@ -97,7 +97,6 @@ class SchedulerMetricsMixin: self.num_generated_tokens = 0 self.last_decode_stats_tic = time.perf_counter() self.last_prefill_stats_tic = time.perf_counter() - self.last_prefill_tokens = 0 self.last_gen_throughput: float = 0.0 self.last_input_throughput: float = 0.0 self.step_time_dict = defaultdict(list) # Dict[batch size -> step time] @@ -337,10 +336,12 @@ class SchedulerMetricsMixin: ): return - gap_latency = time.perf_counter() - self.last_prefill_stats_tic - self.last_prefill_stats_tic = time.perf_counter() - self.last_input_throughput = self.last_prefill_tokens / gap_latency - self.last_prefill_tokens = prefill_stats.log_input_tokens + now = time.perf_counter() + gap_latency = now - self.last_prefill_stats_tic + self.last_prefill_stats_tic = now + self.last_input_throughput = ( + prefill_stats.log_input_tokens / gap_latency if gap_latency > 0 else 0.0 + ) pool_stats = self.get_pool_stats() token_usage_msg = ", ".join(pool_stats.get_prefill_usage_msg_parts()) + ", "