File size: 8,140 Bytes
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
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.Textbox(
            value="null",
            label="pytorch.peft_strategy",
        ),
    ]


def get_onnxruntime_config():
    return get_base_backend_config(backend_name="onnxruntime")
        # no_weights



    # no_weights: bool = False

    # # export options
    # export: bool = True
    # use_cache: bool = True
    # use_merged: bool = False
    # torch_dtype: Optional[str] = None

    # # provider options
    # provider: str = "${infer_provider:${device}}"
    # device_id: Optional[int] = "${oc.deprecated:backend.provider_options.device_id}"
    # provider_options: Dict[str, Any] = field(default_factory=lambda: {"device_id": "${infer_device_id:${device}}"})

    # # inference options
    # use_io_binding: bool = "${is_gpu:${device}}"
    # enable_profiling: bool = "${oc.deprecated:backend.session_options.enable_profiling}"
    # session_options: Dict[str, Any] = field(
    #     default_factory=lambda: {"enable_profiling": "${is_profiling:${benchmark.name}}"}
    # )

    # # optimization options
    # optimization: bool = False
    # optimization_config: Dict[str, Any] = field(default_factory=dict)

    # # quantization options
    # quantization: bool = False
    # quantization_config: Dict[str, Any] = field(default_factory=dict)

    # # calibration options
    # calibration: bool = False
    # calibration_config: Dict[str, Any] = field(default_factory=dict)

    # # null, O1, O2, O3, O4
    # auto_optimization: Optional[str] = None
    # auto_optimization_config: Dict[str, Any] = field(default_factory=dict)

    # # null, arm64, avx2, avx512, avx512_vnni, tensorrt
    # auto_quantization: Optional[str] = None
    # auto_quantization_config: Dict[str, Any] = field(default_factory=dict)

    # # ort-training is basically a different package so we might need to seperate these two backends in the future
    # use_inference_session: bool = "${is_inference:${benchmark.name}}"

    # # training options
    # use_ddp: bool = False
    # ddp_config: Dict[str, Any] = field(default_factory=dict)

    # # peft options
    # peft_strategy: Optional[str] = None
    # peft_config: Dict[str, Any] = field(default_factory=dict)

def get_openvino_config():
    return get_base_backend_config(backend_name="openvino")


def get_neural_compressor_config():
    return get_base_backend_config(backend_name="neural_compressor")


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"],
        ),
    ]