Skip to content

Commit 649a86d

Browse files
committed
Updates for pydantic export with polymorphism and general cleanup
1 parent dbc4789 commit 649a86d

28 files changed

+218
-394
lines changed

src/guidellm/backend/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Backend,
33
BackendType,
44
)
5-
from .openai import OpenAIHTTPBackend
5+
from .openai import CHAT_COMPLETIONS_PATH, TEXT_COMPLETIONS_PATH, OpenAIHTTPBackend
66
from .response import (
77
RequestArgs,
88
ResponseSummary,
@@ -18,4 +18,6 @@
1818
"Backend",
1919
"BackendType",
2020
"OpenAIHTTPBackend",
21+
"TEXT_COMPLETIONS_PATH",
22+
"CHAT_COMPLETIONS_PATH",
2123
]

src/guidellm/backend/openai.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
)
1717
from guidellm.config import settings
1818

19-
__all__ = ["OpenAIHTTPBackend"]
19+
__all__ = ["OpenAIHTTPBackend", "TEXT_COMPLETIONS_PATH", "CHAT_COMPLETIONS_PATH"]
2020

2121

2222
TEXT_COMPLETIONS_PATH = "/v1/completions"

src/guidellm/backend/response.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from typing import Any, Dict, Literal, Optional
22

3-
from pydantic import BaseModel, computed_field
3+
from pydantic import computed_field
44

55
from guidellm.config import settings
6+
from guidellm.objects.pydantic import StandardBaseModel
67

78
__all__ = [
89
"StreamingResponseType",
@@ -15,7 +16,7 @@
1516
StreamingResponseType = Literal["start", "iter"]
1617

1718

18-
class StreamingTextResponse(BaseModel):
19+
class StreamingTextResponse(StandardBaseModel):
1920
"""
2021
A model representing the response content for a streaming text request.
2122
@@ -40,7 +41,7 @@ class StreamingTextResponse(BaseModel):
4041
request_id: Optional[str] = None
4142

4243

43-
class RequestArgs(BaseModel):
44+
class RequestArgs(StandardBaseModel):
4445
"""
4546
A model representing the arguments for a request to a backend.
4647
Biases towards an HTTP request, but can be used for other types of backends.
@@ -60,7 +61,7 @@ class RequestArgs(BaseModel):
6061
http2: Optional[bool] = None
6162

6263

63-
class ResponseSummary(BaseModel):
64+
class ResponseSummary(StandardBaseModel):
6465
"""
6566
A model representing a summary of a backend request.
6667
Always returned as the final iteration of a streaming request.

src/guidellm/benchmark/aggregator.py

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
Union,
1414
)
1515

16-
from pydantic import BaseModel, Field
16+
from pydantic import Field
1717

1818
from guidellm.backend import ResponseSummary
1919
from guidellm.benchmark.benchmark import (
@@ -24,15 +24,33 @@
2424
GenerativeTextErrorStats,
2525
GenerativeTextResponseStats,
2626
)
27-
from guidellm.benchmark.profile import Profile
27+
from guidellm.benchmark.profile import (
28+
AsyncProfile,
29+
ConcurrentProfile,
30+
Profile,
31+
SweepProfile,
32+
SynchronousProfile,
33+
ThroughputProfile,
34+
)
2835
from guidellm.config import settings
29-
from guidellm.objects import RunningStats, Serializable, TimeRunningStats
30-
from guidellm.request import GenerationRequest
36+
from guidellm.objects import RunningStats, StandardBaseModel, TimeRunningStats
37+
from guidellm.request import (
38+
GenerationRequest,
39+
GenerativeRequestLoaderDescription,
40+
RequestLoaderDescription,
41+
)
3142
from guidellm.scheduler import (
3243
REQ,
3344
RES,
45+
AsyncConstantStrategy,
46+
AsyncPoissonStrategy,
47+
ConcurrentStrategy,
48+
GenerativeRequestsWorkerDescription,
3449
SchedulerRequestResult,
3550
SchedulingStrategy,
51+
SynchronousStrategy,
52+
ThroughputStrategy,
53+
WorkerDescription,
3654
)
3755
from guidellm.utils import check_load_processor
3856

@@ -43,7 +61,7 @@
4361
]
4462

4563

46-
class BenchmarkAggregator(ABC, BaseModel, Generic[BENCH, REQ, RES]):
64+
class BenchmarkAggregator(ABC, StandardBaseModel, Generic[BENCH, REQ, RES]):
4765
"""
4866
A pydantic base class representing the base class for aggregating benchmark results.
4967
The purpose is to receive and process results from a Benchmarker as it iterates
@@ -55,25 +73,43 @@ class BenchmarkAggregator(ABC, BaseModel, Generic[BENCH, REQ, RES]):
5573
fully calculated.
5674
"""
5775

76+
type_: Literal["benchmark_aggregator"] = "benchmark_aggregator"
5877
run_id: str = Field(
5978
description=(
6079
"The unique identifier for the encompasing benchmark run that this "
6180
"benchmark was a part of."
6281
)
6382
)
64-
profile: Profile = Field(
83+
profile: Union[
84+
AsyncProfile,
85+
SweepProfile,
86+
ConcurrentProfile,
87+
ThroughputProfile,
88+
SynchronousProfile,
89+
Profile,
90+
] = Field(
6591
description=(
6692
"The profile used for the entire benchamrk run that the strategy for "
6793
"the active benchmark was pulled from."
68-
)
94+
),
95+
discriminator="type_",
6996
)
7097
strategy_index: int = Field(
7198
description=(
7299
"The index of the strategy in the profile that was used for this benchmark."
73100
)
74101
)
75-
strategy: SchedulingStrategy = Field(
76-
description="The scheduling strategy used to run this benchmark. "
102+
strategy: Union[
103+
ConcurrentStrategy,
104+
SchedulingStrategy,
105+
ThroughputStrategy,
106+
SynchronousStrategy,
107+
AsyncPoissonStrategy,
108+
AsyncConstantStrategy,
109+
SchedulingStrategy,
110+
] = Field(
111+
description="The scheduling strategy used to run this benchmark. ",
112+
discriminator="type_",
77113
)
78114
max_number: Optional[int] = Field(
79115
description="The maximum number of requests to run for this benchmark, if any."
@@ -105,25 +141,31 @@ class BenchmarkAggregator(ABC, BaseModel, Generic[BENCH, REQ, RES]):
105141
"if any. These are requests that were not included in the final results."
106142
)
107143
)
108-
worker_description: Optional[Serializable] = Field(
144+
worker_description: Optional[
145+
Union[GenerativeRequestsWorkerDescription, WorkerDescription]
146+
] = Field(
109147
description=(
110148
"The description and specifics for the worker used to resolve requests "
111149
"for this benchmark."
112-
)
150+
),
151+
discriminator="type_",
113152
)
114-
request_loader_description: Optional[Serializable] = Field(
153+
request_loader_description: Optional[
154+
Union[GenerativeRequestLoaderDescription, RequestLoaderDescription]
155+
] = Field(
115156
description=(
116157
"The description and specifics for the request loader used to create "
117158
"requests for this benchmark."
118-
)
159+
),
160+
discriminator="type_",
119161
)
120162
extras: Dict[str, Any] = Field(
121163
description=(
122164
"Any additional information or metadata that was passed for this benchmark."
123165
)
124166
)
125167

126-
results: List[SchedulerRequestResult[GenerationRequest, ResponseSummary]] = Field(
168+
results: List[SchedulerRequestResult[REQ, RES]] = Field(
127169
default_factory=list,
128170
description=(
129171
"The list of all results from the benchmark (complete, incomplete, error), "
@@ -423,6 +465,9 @@ def compile(self) -> BENCH:
423465
class GenerativeBenchmarkAggregator(
424466
BenchmarkAggregator[GenerativeBenchmark, GenerationRequest, ResponseSummary]
425467
):
468+
type_: Literal["generative_benchmark_aggregator"] = (
469+
"generative_benchmark_aggregator"
470+
)
426471
processor: Optional[Union[str, Path, Any]] = Field(
427472
description=(
428473
"The tokenizer to use for calculating token counts when none are "

src/guidellm/benchmark/benchmark.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from guidellm.benchmark.profile import Profile
88
from guidellm.objects import (
9-
Serializable,
9+
StandardBaseModel,
1010
StatusDistributionSummary,
1111
)
1212
from guidellm.scheduler import SchedulerRequestInfo, SchedulingStrategy
@@ -22,7 +22,7 @@
2222
]
2323

2424

25-
class BenchmarkArgs(Serializable):
25+
class BenchmarkArgs(StandardBaseModel):
2626
"""
2727
A serializable model representing the arguments used to specify a benchmark run
2828
and how data was collected for it.
@@ -74,7 +74,7 @@ class BenchmarkArgs(Serializable):
7474
)
7575

7676

77-
class BenchmarkRunStats(Serializable):
77+
class BenchmarkRunStats(StandardBaseModel):
7878
"""
7979
A serializable model representing the run process statistics for the
8080
entire benchmark run across all requests including warmup and cooldown.
@@ -196,7 +196,7 @@ def total(self) -> int:
196196
return self.total_successful + self.total_incomplete + self.total_errored
197197

198198

199-
class Benchmark(Serializable):
199+
class Benchmark(StandardBaseModel):
200200
"""
201201
The base serializable model representing a benchmark run and its results.
202202
Specific benchmarker implementations should extend this model to include
@@ -228,13 +228,13 @@ class Benchmark(Serializable):
228228
"The process statistics for the entire benchmark run across all requests."
229229
)
230230
)
231-
worker: Optional[Serializable] = Field(
231+
worker: Optional[StandardBaseModel] = Field(
232232
description=(
233233
"The description and specifics for the worker used to resolve requests "
234234
"for this benchmark."
235235
)
236236
)
237-
request_loader: Optional[Serializable] = Field(
237+
request_loader: Optional[StandardBaseModel] = Field(
238238
description=(
239239
"The description and specifics for the request loader used to create "
240240
"requests for this benchmark."
@@ -257,7 +257,7 @@ class Benchmark(Serializable):
257257
BENCH = TypeVar("BENCH", bound=Benchmark)
258258

259259

260-
class GenerativeTextResponseStats(Serializable):
260+
class GenerativeTextResponseStats(StandardBaseModel):
261261
"""
262262
A serializable model representing the request values, response values, and
263263
statistics for a generative text response.
@@ -660,8 +660,8 @@ def from_stats(
660660
errored: List[GenerativeTextErrorStats],
661661
args: BenchmarkArgs,
662662
run_stats: BenchmarkRunStats,
663-
worker: Optional[Serializable],
664-
requests_loader: Optional[Serializable],
663+
worker: Optional[StandardBaseModel],
664+
requests_loader: Optional[StandardBaseModel],
665665
extras: Optional[Dict[str, Any]],
666666
) -> "GenerativeBenchmark":
667667
"""

src/guidellm/benchmark/benchmarker.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from guidellm.benchmark.aggregator import AGG, BENCH, GenerativeBenchmarkAggregator
2121
from guidellm.benchmark.benchmark import GenerativeBenchmark
2222
from guidellm.benchmark.profile import Profile
23-
from guidellm.objects import Serializable
23+
from guidellm.objects import StandardBaseModel
2424
from guidellm.request import GenerationRequest
2525
from guidellm.scheduler import (
2626
REQ,
@@ -35,7 +35,7 @@
3535
__all__ = ["Benchmarker", "BenchmarkerResult", "GenerativeBenchmarker"]
3636

3737

38-
class BenchmarkerResult(Serializable, Generic[AGG, BENCH, REQ, RES]):
38+
class BenchmarkerResult(StandardBaseModel, Generic[AGG, BENCH, REQ, RES]):
3939
type_: Literal[
4040
"run_start",
4141
"run_complete",
@@ -54,7 +54,7 @@ class BenchmarkerResult(Serializable, Generic[AGG, BENCH, REQ, RES]):
5454
current_result: Optional[SchedulerRequestResult[REQ, RES]] = None
5555

5656

57-
class BenchmarkerStrategyLimits(Serializable):
57+
class BenchmarkerStrategyLimits(StandardBaseModel):
5858
requests_loader_size: Optional[int] = Field(
5959
description="Size of the request loader.",
6060
)
@@ -125,7 +125,7 @@ def __init__(
125125
self,
126126
worker: RequestsWorker[REQ, RES],
127127
request_loader: Iterable[REQ],
128-
requests_loader_description: Optional[Serializable] = None,
128+
requests_loader_description: Optional[StandardBaseModel] = None,
129129
benchmark_save_extras: Optional[Dict[str, Any]] = None,
130130
):
131131
self.worker = worker
@@ -291,7 +291,7 @@ def __init__(
291291
self,
292292
backend: Backend,
293293
request_loader: Iterable[GenerationRequest],
294-
request_loader_description: Optional[Serializable] = None,
294+
request_loader_description: Optional[StandardBaseModel] = None,
295295
benchmark_save_extras: Optional[Dict[str, Any]] = None,
296296
processor: Optional[Union[str, Path, PreTrainedTokenizer]] = None,
297297
processor_args: Optional[Dict[str, Any]] = None,

0 commit comments

Comments
 (0)