6
6
import click
7
7
8
8
from guidellm .backend import BackendType
9
- from guidellm .benchmark import ProfileType , benchmark_generative_text
9
+ from guidellm .benchmark import ProfileType
10
+ from guidellm .benchmark .entrypoints import benchmark_with_scenario
11
+ from guidellm .benchmark .scenario import GenerativeTextScenario
10
12
from guidellm .config import print_config
11
13
from guidellm .scheduler import StrategyType
12
14
@@ -38,6 +40,19 @@ def parse_number_str(ctx, param, value): # noqa: ARG001
38
40
) from err
39
41
40
42
43
+ def set_if_not_default (ctx : click .Context , ** kwargs ):
44
+ """
45
+ Set the value of a click option if it is not the default value.
46
+ This is useful for setting options that are not None by default.
47
+ """
48
+ values = {}
49
+ for k , v in kwargs .items ():
50
+ if ctx .get_parameter_source (k ) != click .core .ParameterSource .DEFAULT :
51
+ values [k ] = v
52
+
53
+ return values
54
+
55
+
41
56
@click .group ()
42
57
def cli ():
43
58
pass
@@ -46,6 +61,14 @@ def cli():
46
61
@cli .command (
47
62
help = "Run a benchmark against a generative model using the specified arguments."
48
63
)
64
+ @click .option (
65
+ "--scenario" ,
66
+ type = str ,
67
+ default = None ,
68
+ help = (
69
+ "TODO: A scenario or path to config"
70
+ ),
71
+ )
49
72
@click .option (
50
73
"--target" ,
51
74
required = True ,
@@ -59,20 +82,20 @@ def cli():
59
82
"The type of backend to use to run requests against. Defaults to 'openai_http'."
60
83
f" Supported types: { ', ' .join (get_args (BackendType ))} "
61
84
),
62
- default = "openai_http" ,
85
+ default = GenerativeTextScenario . backend_type ,
63
86
)
64
87
@click .option (
65
88
"--backend-args" ,
66
89
callback = parse_json ,
67
- default = None ,
90
+ default = GenerativeTextScenario . backend_args ,
68
91
help = (
69
92
"A JSON string containing any arguments to pass to the backend as a "
70
93
"dict with **kwargs."
71
94
),
72
95
)
73
96
@click .option (
74
97
"--model" ,
75
- default = None ,
98
+ default = GenerativeTextScenario . model ,
76
99
type = str ,
77
100
help = (
78
101
"The ID of the model to benchmark within the backend. "
@@ -81,7 +104,7 @@ def cli():
81
104
)
82
105
@click .option (
83
106
"--processor" ,
84
- default = None ,
107
+ default = GenerativeTextScenario . processor ,
85
108
type = str ,
86
109
help = (
87
110
"The processor or tokenizer to use to calculate token counts for statistics "
@@ -91,7 +114,7 @@ def cli():
91
114
)
92
115
@click .option (
93
116
"--processor-args" ,
94
- default = None ,
117
+ default = GenerativeTextScenario . processor_args ,
95
118
callback = parse_json ,
96
119
help = (
97
120
"A JSON string containing any arguments to pass to the processor constructor "
@@ -110,6 +133,7 @@ def cli():
110
133
)
111
134
@click .option (
112
135
"--data-args" ,
136
+ default = GenerativeTextScenario .data_args ,
113
137
callback = parse_json ,
114
138
help = (
115
139
"A JSON string containing any arguments to pass to the dataset creation "
@@ -118,7 +142,7 @@ def cli():
118
142
)
119
143
@click .option (
120
144
"--data-sampler" ,
121
- default = None ,
145
+ default = GenerativeTextScenario . data_sampler ,
122
146
type = click .Choice (["random" ]),
123
147
help = (
124
148
"The data sampler type to use. 'random' will add a random shuffle on the data. "
@@ -136,7 +160,7 @@ def cli():
136
160
)
137
161
@click .option (
138
162
"--rate" ,
139
- default = None ,
163
+ default = GenerativeTextScenario . rate ,
140
164
callback = parse_number_str ,
141
165
help = (
142
166
"The rates to run the benchmark at. "
@@ -150,6 +174,7 @@ def cli():
150
174
@click .option (
151
175
"--max-seconds" ,
152
176
type = float ,
177
+ default = GenerativeTextScenario .max_seconds ,
153
178
help = (
154
179
"The maximum number of seconds each benchmark can run for. "
155
180
"If None, will run until max_requests or the data is exhausted."
@@ -158,6 +183,7 @@ def cli():
158
183
@click .option (
159
184
"--max-requests" ,
160
185
type = int ,
186
+ default = GenerativeTextScenario .max_requests ,
161
187
help = (
162
188
"The maximum number of requests each benchmark can run for. "
163
189
"If None, will run until max_seconds or the data is exhausted."
@@ -166,7 +192,7 @@ def cli():
166
192
@click .option (
167
193
"--warmup-percent" ,
168
194
type = float ,
169
- default = None ,
195
+ default = GenerativeTextScenario . warmup_percent ,
170
196
help = (
171
197
"The percent of the benchmark (based on max-seconds, max-requets, "
172
198
"or lenth of dataset) to run as a warmup and not include in the final results. "
@@ -176,6 +202,7 @@ def cli():
176
202
@click .option (
177
203
"--cooldown-percent" ,
178
204
type = float ,
205
+ default = GenerativeTextScenario .cooldown_percent ,
179
206
help = (
180
207
"The percent of the benchmark (based on max-seconds, max-requets, or lenth "
181
208
"of dataset) to run as a cooldown and not include in the final results. "
@@ -185,16 +212,19 @@ def cli():
185
212
@click .option (
186
213
"--disable-progress" ,
187
214
is_flag = True ,
215
+ default = not GenerativeTextScenario .show_progress ,
188
216
help = "Set this flag to disable progress updates to the console" ,
189
217
)
190
218
@click .option (
191
219
"--display-scheduler-stats" ,
192
220
is_flag = True ,
221
+ default = GenerativeTextScenario .show_progress_scheduler_stats ,
193
222
help = "Set this flag to display stats for the processes running the benchmarks" ,
194
223
)
195
224
@click .option (
196
225
"--disable-console-outputs" ,
197
226
is_flag = True ,
227
+ default = not GenerativeTextScenario .output_console ,
198
228
help = "Set this flag to disable console output" ,
199
229
)
200
230
@click .option (
@@ -211,6 +241,7 @@ def cli():
211
241
@click .option (
212
242
"--output-extras" ,
213
243
callback = parse_json ,
244
+ default = GenerativeTextScenario .output_extras ,
214
245
help = "A JSON string of extra data to save with the output benchmarks" ,
215
246
)
216
247
@click .option (
@@ -220,15 +251,16 @@ def cli():
220
251
"The number of samples to save in the output file. "
221
252
"If None (default), will save all samples."
222
253
),
223
- default = None ,
254
+ default = GenerativeTextScenario . output_sampling ,
224
255
)
225
256
@click .option (
226
257
"--random-seed" ,
227
- default = 42 ,
258
+ default = GenerativeTextScenario . random_seed ,
228
259
type = int ,
229
260
help = "The random seed to use for benchmarking to ensure reproducibility." ,
230
261
)
231
262
def benchmark (
263
+ scenario ,
232
264
target ,
233
265
backend_type ,
234
266
backend_args ,
@@ -252,30 +284,48 @@ def benchmark(
252
284
output_sampling ,
253
285
random_seed ,
254
286
):
287
+ click_ctx = click .get_current_context ()
288
+
289
+ # If a scenario file was specified read from it
290
+ # TODO: This should probably be a factory method
291
+ if scenario is None :
292
+ _scenario = {}
293
+ else :
294
+ # TODO: Support pre-defined scenarios
295
+ # TODO: Support other formats
296
+ with Path (scenario ).open () as f :
297
+ _scenario = json .load (f )
298
+
299
+ # If any command line arguments are specified, override the scenario
300
+ _scenario .update (set_if_not_default (
301
+ click_ctx ,
302
+ target = target ,
303
+ backend_type = backend_type ,
304
+ backend_args = backend_args ,
305
+ model = model ,
306
+ processor = processor ,
307
+ processor_args = processor_args ,
308
+ data = data ,
309
+ data_args = data_args ,
310
+ data_sampler = data_sampler ,
311
+ rate_type = rate_type ,
312
+ rate = rate ,
313
+ max_seconds = max_seconds ,
314
+ max_requests = max_requests ,
315
+ warmup_percent = warmup_percent ,
316
+ cooldown_percent = cooldown_percent ,
317
+ show_progress = not disable_progress ,
318
+ show_progress_scheduler_stats = display_scheduler_stats ,
319
+ output_console = not disable_console_outputs ,
320
+ output_path = output_path ,
321
+ output_extras = output_extras ,
322
+ output_sampling = output_sampling ,
323
+ random_seed = random_seed ,
324
+ ))
325
+
255
326
asyncio .run (
256
- benchmark_generative_text (
257
- target = target ,
258
- backend_type = backend_type ,
259
- backend_args = backend_args ,
260
- model = model ,
261
- processor = processor ,
262
- processor_args = processor_args ,
263
- data = data ,
264
- data_args = data_args ,
265
- data_sampler = data_sampler ,
266
- rate_type = rate_type ,
267
- rate = rate ,
268
- max_seconds = max_seconds ,
269
- max_requests = max_requests ,
270
- warmup_percent = warmup_percent ,
271
- cooldown_percent = cooldown_percent ,
272
- show_progress = not disable_progress ,
273
- show_progress_scheduler_stats = display_scheduler_stats ,
274
- output_console = not disable_console_outputs ,
275
- output_path = output_path ,
276
- output_extras = output_extras ,
277
- output_sampling = output_sampling ,
278
- random_seed = random_seed ,
327
+ benchmark_with_scenario (
328
+ scenario = GenerativeTextScenario (** _scenario )
279
329
)
280
330
)
281
331
0 commit comments