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