41
41
NonDistributedEnvironment ,
42
42
StrategyType ,
43
43
)
44
- from guidellm .utils import Console , InfoMixin , ConsoleUpdateStep
44
+ from guidellm .utils import Console , InfoMixin
45
45
46
46
__all__ = [
47
47
"benchmark_generative_text" ,
63
63
| Path
64
64
)
65
65
66
- ProcessorType = str | Path | PreTrainedTokenizerBase
67
-
68
66
OutputFormatType = (
69
67
tuple [str , ...]
70
68
| list [str ]
73
71
)
74
72
75
73
76
- # TODO: Determine final location of the helper functions.
77
-
78
-
79
74
async def initialize_backend (
80
75
backend : BackendType | Backend ,
81
76
target : str ,
82
77
model : str | None ,
83
78
backend_kwargs : dict [str , Any ] | None ,
84
- console_step : ConsoleUpdateStep ,
85
79
) -> Backend :
86
80
backend = (
87
81
Backend .create (
@@ -90,121 +84,46 @@ async def initialize_backend(
90
84
if not isinstance (backend , Backend )
91
85
else backend
92
86
)
93
- console_step .update (f"{ backend .__class__ .__name__ } backend initialized" )
94
87
await backend .process_startup ()
95
88
await backend .validate ()
96
- console_step .finish (
97
- title = f"{ backend .__class__ .__name__ } backend initialized" ,
98
- details = backend .info ,
99
- status_level = "success" ,
100
- )
101
89
return backend
102
90
103
91
104
- async def resolve_processor (
105
- processor : ProcessorType | None ,
106
- model : str | None ,
107
- backend : BackendType | Backend ,
108
- console_step : ConsoleUpdateStep ,
109
- ) -> ProcessorType :
110
- if processor is not None :
111
- console_step .finish (
112
- title = "Processor resolved" ,
113
- details = f"Using processor '{ processor } '" ,
114
- status_level = "success" ,
115
- )
116
- elif model is not None :
117
- console_step .finish (
118
- title = "Processor resolved" ,
119
- details = f"Using model '{ model } ' as processor" ,
120
- status_level = "success" ,
121
- )
122
- processor = model
123
- else :
124
- console_step .update (
125
- title = "Resolving processor from backend.default_model" ,
126
- status_level = "info" ,
127
- )
128
- processor = await backend .default_model ()
129
- console_step .finish (
130
- title = "Processor resolved" ,
131
- details = (
132
- f"Using model '{ processor } ' from backend "
133
- f"{ backend .__class__ .__name__ } as processor"
134
- ),
135
- status_level = "success" ,
136
- )
137
- await backend .process_shutdown ()
138
- return processor
139
-
140
-
141
- async def init_request_loader (
142
- data : DataType ,
143
- data_args : dict [str , Any ] | None ,
144
- processor : ProcessorType ,
145
- console_step : ConsoleUpdateStep ,
146
- ) -> GenerativeRequestLoader :
147
- request_loader = GenerativeRequestLoader (
148
- data = data ,
149
- data_args = data_args ,
150
- processor = processor ,
151
- processor_args = processor_args ,
152
- shuffle = data_sampler == "random" ,
153
- random_seed = random_seed ,
154
- )
155
- unique_requests = request_loader .num_unique_items (raise_err = False )
156
- console_step .finish (
157
- title = (
158
- f"Request loader initialized with { unique_requests } unique requests "
159
- f"from { data } "
160
- ),
161
- details = InfoMixin .extract_from_obj (request_loader ),
162
- status_level = "success" ,
163
- )
164
- return request_loader
165
-
166
92
async def resolve_profile (
167
93
constraint_inputs : dict [str , int | float ],
168
- profile : Profile | None ,
94
+ profile : Profile | str | None ,
169
95
rate : list [float ] | None ,
170
96
random_seed : int ,
171
97
constraints : dict [str , ConstraintInitializer | Any ],
172
- console_step : ConsoleUpdateStep ,
173
98
):
174
99
for key , val in constraint_inputs .items ():
175
100
if val is not None :
176
101
constraints [key ] = val
177
102
if not isinstance (profile , Profile ):
178
- profile = Profile .create (
179
- rate_type = profile ,
180
- rate = rate ,
181
- random_seed = random_seed ,
182
- constraints = {** constraints },
183
- )
103
+ if isinstance (profile , str ):
104
+ profile = Profile .create (
105
+ rate_type = profile ,
106
+ rate = rate ,
107
+ random_seed = random_seed ,
108
+ constraints = {** constraints },
109
+ )
110
+ else :
111
+ raise ValueError (f"Expected string for profile; got { type (profile )} " )
112
+
184
113
elif constraints :
185
114
raise ValueError (
186
115
"Constraints must be empty when providing a Profile instance. "
187
116
f"Provided constraints: { constraints } ; provided profile: { profile } "
188
117
)
189
- console_step .finish (
190
- title = f"{ profile .__class__ .__name__ } profile resolved" ,
191
- details = InfoMixin .extract_from_obj (profile ),
192
- status_level = "success" ,
193
- )
118
+ return profile
194
119
195
120
async def resolve_output_formats (
196
121
output_formats : OutputFormatType ,
197
122
output_path : str | Path | None ,
198
- console_step : ConsoleUpdateStep ,
199
123
) -> dict [str , GenerativeBenchmarkerOutput ]:
200
124
output_formats = GenerativeBenchmarkerOutput .resolve (
201
125
output_formats = (output_formats or {}), output_path = output_path
202
126
)
203
- console_step .finish (
204
- title = "Output formats resolved" ,
205
- details = {key : str (val ) for key , val in output_formats .items ()},
206
- status_level = "success" ,
207
- )
208
127
return output_formats
209
128
210
129
async def finalize_outputs (
@@ -217,8 +136,6 @@ async def finalize_outputs(
217
136
output_format_results [key ] = output_result
218
137
return output_format_results
219
138
220
- # End of helper functions.
221
-
222
139
223
140
async def benchmark_with_scenario (scenario : Scenario , ** kwargs ):
224
141
"""
@@ -273,20 +190,68 @@ async def benchmark_generative_text( # noqa: C901
273
190
with console .print_update_step (
274
191
title = f"Initializing backend { backend } "
275
192
) as console_step :
276
- backend = await initialize_backend (backend )
193
+ backend = await initialize_backend (backend , target , model , backend_kwargs )
194
+ console_step .finish (
195
+ title = f"{ backend .__class__ .__name__ } backend initialized" ,
196
+ details = backend .info ,
197
+ status_level = "success" ,
198
+ )
277
199
278
200
with console .print_update_step (title = "Resolving processor" ) as console_step :
279
- await resolve_processor (processor , model , backend , console_step )
201
+ if processor is not None :
202
+ console_step .finish (
203
+ title = "Processor resolved" ,
204
+ details = f"Using processor '{ processor } '" ,
205
+ status_level = "success" ,
206
+ )
207
+ elif model is not None :
208
+ console_step .finish (
209
+ title = "Processor resolved" ,
210
+ details = f"Using model '{ model } ' as processor" ,
211
+ status_level = "success" ,
212
+ )
213
+ processor = model
214
+ else :
215
+ console_step .update (
216
+ title = "Resolving processor from backend.default_model" ,
217
+ status_level = "info" ,
218
+ )
219
+ processor = await backend .default_model ()
220
+ console_step .finish (
221
+ title = "Processor resolved" ,
222
+ details = (
223
+ f"Using model '{ processor } ' from backend "
224
+ f"{ backend .__class__ .__name__ } as processor"
225
+ ),
226
+ status_level = "success" ,
227
+ )
228
+ await backend .process_shutdown ()
280
229
281
230
with console .print_update_step (
282
231
title = f"Initializing request loader from { data } "
283
232
) as console_step :
284
- request_loader = init_request_loader (data , data_args , processor , console_step )
233
+ request_loader = GenerativeRequestLoader (
234
+ data = data ,
235
+ data_args = data_args ,
236
+ processor = processor ,
237
+ processor_args = processor_args ,
238
+ shuffle = data_sampler == "random" ,
239
+ random_seed = random_seed ,
240
+ )
241
+ unique_requests = request_loader .num_unique_items (raise_err = False )
242
+ console_step .finish (
243
+ title = (
244
+ f"Request loader initialized with { unique_requests } unique requests "
245
+ f"from { data } "
246
+ ),
247
+ details = InfoMixin .extract_from_obj (request_loader ),
248
+ status_level = "success" ,
249
+ )
285
250
286
251
with console .print_update_step (
287
252
title = f"Resolving profile { profile } "
288
253
) as console_step :
289
- resolve_profile (
254
+ profile = await resolve_profile (
290
255
{
291
256
"max_seconds" : max_seconds ,
292
257
"max_requests" : max_requests ,
@@ -298,7 +263,11 @@ async def benchmark_generative_text( # noqa: C901
298
263
rate ,
299
264
random_seed ,
300
265
constraints ,
301
- console_step ,
266
+ )
267
+ console_step .finish (
268
+ title = f"{ profile .__class__ .__name__ } profile resolved" ,
269
+ details = InfoMixin .extract_from_obj (profile ),
270
+ status_level = "success" ,
302
271
)
303
272
304
273
with console .print_update_step (
@@ -321,7 +290,12 @@ async def benchmark_generative_text( # noqa: C901
321
290
)
322
291
323
292
with console .print_update_step (title = "Resolving output formats" ) as console_step :
324
- resolved_output_formats = resolve_output_formats (output_formats , output_path , console_step )
293
+ resolved_output_formats = await resolve_output_formats (output_formats , output_path )
294
+ console_step .finish (
295
+ title = "Output formats resolved" ,
296
+ details = {key : str (val ) for key , val in resolved_output_formats .items ()},
297
+ status_level = "success" ,
298
+ )
325
299
326
300
progress_group = BenchmarkerProgressGroup (
327
301
instances = progress or [], enabled = bool (progress )
@@ -355,7 +329,7 @@ async def benchmark_generative_text( # noqa: C901
355
329
if benchmark :
356
330
report .benchmarks .append (benchmark )
357
331
358
- output_format_results = finalize_outputs (report , resolved_output_formats )
332
+ output_format_results = await finalize_outputs (report , resolved_output_formats )
359
333
360
334
console .print ("\n \n " )
361
335
console .print_update (
@@ -386,7 +360,12 @@ async def reimport_benchmarks_report(
386
360
console_step .finish (f"Import of old benchmarks complete; loaded { len (report .benchmarks )} benchmark(s)" )
387
361
388
362
with console .print_update_step (title = "Resolving output formats" ) as console_step :
389
- resolved_output_formats = await resolve_output_formats (output_formats , output_path , console_step )
363
+ resolved_output_formats = await resolve_output_formats (output_formats , output_path )
364
+ console_step .finish (
365
+ title = "Output formats resolved" ,
366
+ details = {key : str (val ) for key , val in resolved_output_formats .items ()},
367
+ status_level = "success" ,
368
+ )
390
369
391
370
output_format_results = await finalize_outputs (report , resolved_output_formats )
392
371
0 commit comments