A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 14, 05:30 UTC
[Easy] Add str repr for IterationStats (#26232)
Signed-off-by: 22quinn <33176974+22quinn@users.noreply.github.com>
22quinn committed
Oct 4, 2025 at 22:00 UTC
78c1d5bfd2a920bc24f4072ae7d843dbb523a4fe
2 files changed
+26
tests/v1/metrics/test_stats.py
new
+21
@@ -0,0 +1,21 @@
1
+# SPDX-License-Identifier: Apache-2.0
2
+# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
+from vllm.v1.metrics.stats import IterationStats
4
+
5
+
6
+def test_iteration_stats_repr():
7
+ iteration_stats = IterationStats()
8
+ iteration_stats.iteration_timestamp = 0
9
+ expected_repr = ("IterationStats("
10
+ "iteration_timestamp=0, "
11
+ "num_generation_tokens=0, "
12
+ "num_prompt_tokens=0, "
13
+ "num_preempted_reqs=0, "
14
+ "finished_requests=[], "
15
+ "max_num_generation_tokens_iter=[], "
16
+ "n_params_iter=[], "
17
+ "time_to_first_tokens_iter=[], "
18
+ "inter_token_latencies_iter=[], "
19
+ "waiting_lora_adapters={}, "
20
+ "running_lora_adapters={})")
21
+ assert repr(iteration_stats) == expected_repr
vllm/v1/metrics/stats.py
+5
@@ -111,6 +111,11 @@ class IterationStats:
111
self.waiting_lora_adapters: dict[str, int] = {}
112
self.running_lora_adapters: dict[str, int] = {}
113
114
+ def __repr__(self) -> str:
115
+ field_to_value_str = ", ".join(f"{k}={v}"
116
+ for k, v in vars(self).items())
117
+ return f"{self.__class__.__name__}({field_to_value_str})"
118
+
119
def _time_since(self, start: float) -> float:
120
"""Calculate an interval relative to this iteration's timestamp."""
121
return self.iteration_timestamp - start