File size: 12,456 Bytes
7f9a235
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eabde51
7f9a235
eabde51
7f9a235
eabde51
7f9a235
 
 
 
 
eabde51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7f9a235
d1cb523
7f9a235
eabde51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7f9a235
 
 
eabde51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7f9a235
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
import gradio as gr


def get_base_backend_config(backend_name="pytorch"):
    return [
        # seed
        gr.Textbox(
            value=42,
            label=f"{backend_name}.seed",
            info="Sets seed for reproducibility",
        ),
        # inter_op_num_threads
        gr.Textbox(
            value="null",
            label=f"{backend_name}.inter_op_num_threads",
            info="Use null for default and -1 for cpu_count()",
        ),
        # intra_op_num_threads
        gr.Textbox(
            value="null",
            label=f"{backend_name}.intra_op_num_threads",
            info="Use null for default and -1 for cpu_count()",
        ),
        # initial_isolation_check
        gr.Checkbox(
            value=True,
            label=f"{backend_name}.initial_isolation_check",
            info="Makes sure that initially, no other process is running on the target device",
        ),
        # continous_isolation_check
        gr.Checkbox(
            value=True,
            label=f"{backend_name}.continous_isolation_check",
            info="Makes sure that throughout the benchmark, no other process is running on the target device",
        ),
        # delete_cache
        gr.Checkbox(
            value=False,
            label=f"{backend_name}.delete_cache",
            info="Deletes model cache (weights & configs) after benchmark is done",
        ),
    ]


def get_pytorch_config():
    return get_base_backend_config(backend_name="pytorch") + [
        # no_weights
        gr.Checkbox(
            value=False,
            label="pytorch.no_weights",
            info="Generates random weights instead of downloading pretrained ones",
        ),
        # # device_map
        # gr.Dropdown(
        #     value="null",
        #
        #     label="pytorch.device_map",
        #     choices=["null", "auto", "sequential"],
        #     info="Use null for default and `auto` or `sequential` the same way as in `from_pretrained`",
        # ),
        # torch_dtype
        gr.Dropdown(
            value="null",
            label="pytorch.torch_dtype",
            choices=["null", "bfloat16", "float16", "float32", "auto"],
            info="Use null for default and `auto` for automatic dtype selection",
        ),
        # amp_autocast
        gr.Checkbox(
            value=False,
            label="pytorch.amp_autocast",
            info="Enables Pytorch's native Automatic Mixed Precision",
        ),
        # amp_dtype
        gr.Dropdown(
            value="null",
            label="pytorch.amp_dtype",
            info="Use null for default",
            choices=["null", "bfloat16", "float16"],
        ),
        # torch_compile
        gr.Checkbox(
            value=False,
            label="pytorch.torch_compile",
            info="Compiles the model with torch.compile",
        ),
        # bettertransformer
        gr.Checkbox(
            value=False,
            label="pytorch.bettertransformer",
            info="Applies optimum.BetterTransformer for fastpath anf optimized attention",
        ),
        # quantization_scheme
        gr.Dropdown(
            value="null",
            choices=["null", "gptq", "bnb"],
            label="pytorch.quantization_scheme",
            info="Use null for no quantization",
        ),
        # # use_ddp
        # gr.Checkbox(
        #     value=False,
        #
        #     label="pytorch.use_ddp",
        #     info="Uses DistributedDataParallel for multi-gpu training",
        # ),
        # peft_strategy
        gr.Dropdown(
            value="null",
            choices=["null", "lora", "ada_lora", "prompt_tuning", "prefix_tuning", "p_tuning", "ia3"],
            label="pytorch.peft_strategy",
            info="Use null for no PEFT",
        ),
    ]


def get_onnxruntime_config():
    return get_base_backend_config(backend_name="onnxruntime") + [
        # no_weights
        gr.Checkbox(
            value=False,
            label="pytorch.no_weights",
            info="Generates random weights instead of downloading pretrained ones",
        ),
        # export
        gr.Checkbox(
            value=True,
            label="onnxruntime.export",
            info="Exports the model to ONNX",
        ),
        # use_cache
        gr.Checkbox(
            value=True,
            label="onnxruntime.use_cache",
            info="Uses cached ONNX model if available",
        ),
        # use_merged
        gr.Checkbox(
            value=False,
            label="onnxruntime.use_merged",
            info="Uses merged ONNX model if available",
        ),
        # torch_dtype
        gr.Dropdown(
            value="null",
            label="onnxruntime.torch_dtype",
            choices=["null", "bfloat16", "float16", "float32", "auto"],
            info="Use null for default and `auto` for automatic dtype selection",
        ),
        # use_io_binding
        gr.Checkbox(
            value=True,
            label="onnxruntime.use_io_binding",
            info="Uses IO binding for inference",
        ),
        # auto_optimization
        gr.Dropdown(
            value="null",
            label="onnxruntime.auto_optimization",
            choices=["null", "O1", "O2", "O3", "O4"],
            info="Use null for default",
        ),
        # auto_quantization
        gr.Dropdown(
            value="null",
            label="onnxruntime.auto_quantization",
            choices=["null", "arm64", "avx2", "avx512", "avx512_vnni", "tensorrt"],
            info="Use null for default",
        ),
        # optimization
        gr.Checkbox(
            value=False,
            label="onnxruntime.optimization",
            info="Enables manual optimization",
        ),
        # optimization_config
        gr.Dataframe(
            type="array",
            value=[["optimization_level"]],
            headers=["1"],
            row_count=(1, "static"),
            col_count=(1, "dynamic"),
            label="onnxruntime.optimization_config",
        ),
        # quantization
        gr.Checkbox(
            value=False,
            label="onnxruntime.quantization",
            info="Enables manual quantization",
        ),
        # quantization_config
        gr.Dataframe(
            type="array",
            value=[["is_static"]],
            headers=[False],
            row_count=(1, "static"),
            col_count=(1, "dynamic"),
            label="onnxruntime.quantization_config",
            info="Use null for default",
        ),
        # calibration
        gr.Checkbox(
            value=False,
            label="onnxruntime.calibration",
            info="Enables calibration",
        ),
        # calibration_config
        gr.Dataframe(
            type="array",
            value=[["glue"]],
            headers=["dataset_name"],
            row_count=(1, "static"),
            col_count=(1, "dynamic"),
            label="onnxruntime.calibration_config",
            info="Use null for default",
        ),
        # peft_strategy
        gr.Dropdown(
            value="null",
            label="onnxruntime.peft_strategy",
            choices=["null", "lora", "ada_lora", "prompt_tuning", "prefix_tuning", "p_tuning", "ia3"],
            info="Use null for full parameters fine-tuning",
        ),
    ]


def get_openvino_config():
    return get_base_backend_config(backend_name="openvino") + [
        # export
        gr.Checkbox(
            value=True,
            label="openvino.export",
            info="Exports the model to ONNX",
        ),
        # use_cache
        gr.Checkbox(
            value=True,
            label="openvino.use_cache",
            info="Uses cached ONNX model if available",
        ),
        # use_merged
        gr.Checkbox(
            value=False,
            label="openvino.use_merged",
            info="Uses merged ONNX model if available",
        ),
        # reshape
        gr.Checkbox(
            value=False,
            label="openvino.reshape",
            info="Reshapes the model to the input shape",
        ),
        # half
        gr.Checkbox(
            value=False,
            label="openvino.half",
            info="Converts model to half precision",
        ),
        # quantization
        gr.Checkbox(
            value=False,
            label="openvino.quantization",
            info="Enables quantization",
        ),
        # quantization_config
        gr.Dataframe(
            type="array",
            headers=["compression", "input_info", "save_onnx_model"],
            value=[[None, None, None]],
            row_count=(1, "static"),
            col_count=(3, "dynamic"),
            label="openvino.quantization_config",
        ),
        # calibration
        gr.Checkbox(
            value=False,
            label="openvino.calibration",
            info="Enables calibration",
        ),
        # calibration_config
        gr.Dataframe(
            type="array",
            headers=["dataset_name"],
            value=[["glue"]],
            row_count=(1, "static"),
            col_count=(1, "dynamic"),
            label="openvino.calibration_config",
        ),
    ]


def get_neural_compressor_config():
    return get_base_backend_config(backend_name="neural-compressor") + [
        # ptq_quantization
        gr.Checkbox(
            value=False,
            label="neural-compressor.ptq_quantization",
            info="Enables post-training quantization",
        ),
        # ptq_quantization_config
        gr.Dataframe(
            type="array",
            headers=["device"],
            value=[["cpu"]],
            row_count=(1, "static"),
            col_count=(1, "dynamic"),
            label="neural-compressor.ptq_quantization_config",
        ),
        # calibration
        gr.Checkbox(
            value=False,
            label="neural-compressor.calibration",
            info="Enables calibration",
        ),
        # calibration_config
        gr.Dataframe(
            type="array",
            headers=["dataset_name"],
            value=[["glue"]],
            row_count=(1, "static"),
            col_count=(1, "dynamic"),
            label="neural-compressor.calibration_config",
        ),
    ]


def get_inference_config():
    return [
        # duration
        gr.Textbox(
            value=10,
            label="inference.duration",
            info="Minimum duration of benchmark in seconds",
        ),
        # warmup runs
        gr.Textbox(
            value=10,
            label="inference.warmup_runs",
            info="Number of warmup runs before measurements",
        ),
        # memory
        gr.Checkbox(
            value=False,
            label="inference.memory",
            info="Measures the peak memory footprint",
        ),
        # energy
        gr.Checkbox(
            value=False,
            label="inference.energy",
            info="Measures energy consumption and carbon emissions",
        ),
        # input_shapes
        gr.Dataframe(
            type="array",
            value=[[2, 16]],
            row_count=(1, "static"),
            col_count=(2, "dynamic"),
            label="inference.input_shapes",
            headers=["batch_size", "sequence_length"],
            info="Controllable input shapes, add more columns for more inputs",
        ),
        # forward kwargs
        gr.Dataframe(
            type="array",
            value=[[False]],
            headers=["return_dict"],
            row_count=(1, "static"),
            col_count=(1, "dynamic"),
            label="inference.forward_kwargs",
            info="Keyword arguments for the forward pass, add more columns for more arguments",
        ),
    ]


def get_training_config():
    return [
        # warmup steps
        gr.Textbox(
            value=40,
            label="training.warmup_steps",
        ),
        # dataset_shapes
        gr.Dataframe(
            type="array",
            value=[[500, 16]],
            headers=["dataset_size", "sequence_length"],
            row_count=(1, "static"),
            col_count=(2, "dynamic"),
            label="training.dataset_shapes",
        ),
        # training_arguments
        gr.Dataframe(
            value=[[2]],
            type="array",
            row_count=(1, "static"),
            col_count=(1, "dynamic"),
            label="training.training_arguments",
            headers=["per_device_train_batch_size"],
        ),
    ]