|
26 | 26 | )
|
27 | 27 |
|
28 | 28 | from guidellm.benchmark.aggregator import Aggregator, CompilableAggregator
|
29 |
| -from guidellm.benchmark.objects import BenchmarkT |
| 29 | +from guidellm.benchmark.objects import BenchmarkerDict, BenchmarkT, SchedulerDict |
30 | 30 | from guidellm.benchmark.profile import Profile
|
31 | 31 | from guidellm.scheduler import (
|
32 | 32 | BackendInterface,
|
|
41 | 41 | SchedulingStrategy,
|
42 | 42 | )
|
43 | 43 | from guidellm.utils import InfoMixin, ThreadSafeSingletonMixin
|
| 44 | +from guidellm.utils.pydantic_utils import StandardBaseDict |
44 | 45 |
|
45 | 46 | __all__ = ["Benchmarker"]
|
46 | 47 |
|
@@ -114,9 +115,7 @@ async def run(
|
114 | 115 | request,
|
115 | 116 | request_info,
|
116 | 117 | scheduler_state,
|
117 |
| - ) in Scheduler[ |
118 |
| - BackendInterface, RequestT, MeasuredRequestTimingsT, ResponseT |
119 |
| - ]().run( |
| 118 | + ) in Scheduler[RequestT, MeasuredRequestTimingsT, ResponseT]().run( |
120 | 119 | requests=requests,
|
121 | 120 | backend=backend,
|
122 | 121 | strategy=strategy,
|
@@ -200,43 +199,65 @@ def _compile_benchmark_kwargs(
|
200 | 199 | benchmark_kwargs = {
|
201 | 200 | "run_id": run_id,
|
202 | 201 | "run_index": run_index,
|
203 |
| - "scheduler": { |
204 |
| - "strategy": strategy, |
205 |
| - "constraints": { |
206 |
| - key: InfoMixin.extract_from_obj(val) for key, val in constraints |
| 202 | + "scheduler": SchedulerDict( |
| 203 | + strategy=strategy, |
| 204 | + constraints={ |
| 205 | + key: InfoMixin.extract_from_obj(val) |
| 206 | + for key, val in constraints.items() |
207 | 207 | },
|
208 |
| - "state": scheduler_state, |
209 |
| - }, |
210 |
| - "benchmarker": { |
211 |
| - "profile": profile, |
212 |
| - "requests": InfoMixin.extract_from_obj(requests), |
213 |
| - "backend": InfoMixin.extract_from_obj(backend), |
214 |
| - "environment": InfoMixin.extract_from_obj(environment), |
215 |
| - "aggregators": { |
| 208 | + state=scheduler_state, |
| 209 | + ), |
| 210 | + "benchmarker": BenchmarkerDict( |
| 211 | + profile=profile, |
| 212 | + requests=InfoMixin.extract_from_obj(requests), |
| 213 | + backend=backend.info, |
| 214 | + environment=environment.info, |
| 215 | + aggregators={ |
216 | 216 | key: InfoMixin.extract_from_obj(aggregator)
|
217 | 217 | for key, aggregator in aggregators.items()
|
218 | 218 | },
|
219 |
| - }, |
220 |
| - "system": {}, |
221 |
| - "extras": {}, |
| 219 | + ), |
| 220 | + "env_args": StandardBaseDict(), |
| 221 | + "extras": StandardBaseDict(), |
222 | 222 | }
|
| 223 | + |
| 224 | + def _combine( |
| 225 | + existing: dict[str, Any] | StandardBaseDict, |
| 226 | + addition: dict[str, Any] | StandardBaseDict, |
| 227 | + ) -> dict[str, Any] | StandardBaseDict: |
| 228 | + if not isinstance(existing, (dict, StandardBaseDict)): |
| 229 | + raise ValueError( |
| 230 | + f"Existing value {existing} (type: {type(existing).__name__}) " |
| 231 | + f"is not a valid type for merging." |
| 232 | + ) |
| 233 | + if not isinstance(addition, (dict, StandardBaseDict)): |
| 234 | + raise ValueError( |
| 235 | + f"Addition value {addition} (type: {type(addition).__name__}) " |
| 236 | + f"is not a valid type for merging." |
| 237 | + ) |
| 238 | + |
| 239 | + add_kwargs = ( |
| 240 | + addition if isinstance(addition, dict) else addition.model_dump() |
| 241 | + ) |
| 242 | + |
| 243 | + if isinstance(existing, dict): |
| 244 | + return {**add_kwargs, **existing} |
| 245 | + |
| 246 | + return existing.__class__(**{**add_kwargs, **existing.model_dump()}) |
| 247 | + |
223 | 248 | for key, aggregator in aggregators.items():
|
224 | 249 | if not isinstance(aggregator, CompilableAggregator):
|
225 | 250 | continue
|
226 | 251 |
|
227 | 252 | compiled = aggregator.compile(aggregators_state[key], scheduler_state)
|
228 | 253 |
|
229 |
| - if key not in benchmark_kwargs: |
230 |
| - benchmark_kwargs[key] = compiled |
231 |
| - continue |
232 |
| - |
233 |
| - existing_val = benchmark_kwargs[key] |
234 |
| - if not (isinstance(existing_val, dict) and isinstance(compiled, dict)): |
235 |
| - raise ValueError( |
236 |
| - f"Key '{key}' already exists with value {existing_val} " |
237 |
| - f"(type: {type(existing_val).__name__}) and cannot be " |
238 |
| - f"overwritten with {compiled} (type: {type(compiled).__name__})" |
239 |
| - ) |
240 |
| - existing_val.update(compiled) |
| 254 | + for field_name, field_val in compiled.items(): |
| 255 | + if field_name in benchmark_kwargs: |
| 256 | + # If the key already exists, merge the values |
| 257 | + benchmark_kwargs[field_name] = _combine( |
| 258 | + benchmark_kwargs[field_name], field_val |
| 259 | + ) |
| 260 | + else: |
| 261 | + benchmark_kwargs[field_name] = field_val |
241 | 262 |
|
242 | 263 | return benchmark_kwargs
|
0 commit comments