Unverified Commit 78c1d5bf authored by 22quinn's avatar 22quinn Committed by GitHub
Browse files

[Easy] Add str repr for IterationStats (#26232)


Signed-off-by: default avatar22quinn <33176974+22quinn@users.noreply.github.com>
parent 59a85c36
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from vllm.v1.metrics.stats import IterationStats
def test_iteration_stats_repr():
iteration_stats = IterationStats()
iteration_stats.iteration_timestamp = 0
expected_repr = ("IterationStats("
"iteration_timestamp=0, "
"num_generation_tokens=0, "
"num_prompt_tokens=0, "
"num_preempted_reqs=0, "
"finished_requests=[], "
"max_num_generation_tokens_iter=[], "
"n_params_iter=[], "
"time_to_first_tokens_iter=[], "
"inter_token_latencies_iter=[], "
"waiting_lora_adapters={}, "
"running_lora_adapters={})")
assert repr(iteration_stats) == expected_repr
......@@ -111,6 +111,11 @@ class IterationStats:
self.waiting_lora_adapters: dict[str, int] = {}
self.running_lora_adapters: dict[str, int] = {}
def __repr__(self) -> str:
field_to_value_str = ", ".join(f"{k}={v}"
for k, v in vars(self).items())
return f"{self.__class__.__name__}({field_to_value_str})"
def _time_since(self, start: float) -> float:
"""Calculate an interval relative to this iteration's timestamp."""
return self.iteration_timestamp - start
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment