|
1 | 1 | import random |
2 | 2 | from collections import defaultdict |
3 | 3 | from math import ceil |
4 | | -from typing import List, Optional, Tuple, TYPE_CHECKING, Union |
| 4 | +from typing import TYPE_CHECKING, Optional, Union |
5 | 5 |
|
6 | | -from pydantic import BaseModel, computed_field |
| 6 | +from pydantic import BaseModel |
7 | 7 |
|
8 | 8 | if TYPE_CHECKING: |
9 | 9 | from guidellm.benchmark.benchmark import GenerativeBenchmark |
10 | 10 |
|
11 | 11 | from guidellm.objects.statistics import DistributionSummary |
12 | 12 |
|
| 13 | + |
13 | 14 | class Bucket(BaseModel): |
14 | 15 | value: Union[float, int] |
15 | 16 | count: int |
16 | 17 |
|
17 | 18 | @staticmethod |
18 | 19 | def from_data( |
19 | | - data: Union[List[float], List[int]], |
| 20 | + data: Union[list[float], list[int]], |
20 | 21 | bucket_width: Optional[float] = None, |
21 | 22 | n_buckets: Optional[int] = None, |
22 | | - ) -> Tuple[List["Bucket"], float]: |
| 23 | + ) -> tuple[list["Bucket"], float]: |
23 | 24 | if not data: |
24 | 25 | return [], 1.0 |
25 | 26 |
|
@@ -125,10 +126,14 @@ def from_benchmarks(cls, benchmarks: list["GenerativeBenchmark"]): |
125 | 126 | ] |
126 | 127 |
|
127 | 128 | prompt_tokens = [ |
128 | | - float(req.prompt_tokens) for bm in benchmarks for req in bm.requests.successful |
| 129 | + float(req.prompt_tokens) |
| 130 | + for bm in benchmarks |
| 131 | + for req in bm.requests.successful |
129 | 132 | ] |
130 | 133 | output_tokens = [ |
131 | | - float(req.output_tokens) for bm in benchmarks for req in bm.requests.successful |
| 134 | + float(req.output_tokens) |
| 135 | + for bm in benchmarks |
| 136 | + for req in bm.requests.successful |
132 | 137 | ] |
133 | 138 |
|
134 | 139 | prompt_token_buckets, _prompt_token_bucket_width = Bucket.from_data( |
@@ -190,10 +195,9 @@ def percentile_rows(self) -> list[dict[str, float]]: |
190 | 195 | {"percentile": name, "value": value} |
191 | 196 | for name, value in self.percentiles.model_dump().items() |
192 | 197 | ] |
193 | | - filtered_rows = list( |
| 198 | + return list( |
194 | 199 | filter(lambda row: row["percentile"] in ["p50", "p90", "p95", "p99"], rows) |
195 | 200 | ) |
196 | | - return filtered_rows |
197 | 201 |
|
198 | 202 | @classmethod |
199 | 203 | def from_distribution_summary( |
|
0 commit comments