Commit
โข
4d423a9
1
Parent(s):
c9751c2
add everything
Browse files- .gitignore +2 -0
- README.md +10 -5
- app.py +253 -4
- config_store.py +131 -0
- huggy_bench.png +0 -0
- packages.txt +1 -0
- requirements.txt +1 -0
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
__pycache__
|
2 |
+
runs
|
README.md
CHANGED
@@ -1,13 +1,18 @@
|
|
1 |
---
|
2 |
-
title: OpenVINO
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.44.0
|
8 |
app_file: app.py
|
|
|
|
|
|
|
|
|
|
|
9 |
pinned: false
|
10 |
license: apache-2.0
|
11 |
---
|
12 |
|
13 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: OpenVINO Benchmark
|
3 |
+
emoji: ๐๏ธ
|
4 |
+
colorFrom: purple
|
5 |
+
colorTo: indigo
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.44.0
|
8 |
app_file: app.py
|
9 |
+
hf_oauth: true
|
10 |
+
hf_oauth_scopes:
|
11 |
+
- read-repos
|
12 |
+
- write-repos
|
13 |
+
- manage-repos
|
14 |
pinned: false
|
15 |
license: apache-2.0
|
16 |
---
|
17 |
|
18 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
CHANGED
@@ -1,7 +1,256 @@
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
def greet(name):
|
4 |
-
return "Hello " + name + "!!"
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import time
|
3 |
+
import traceback
|
4 |
import gradio as gr
|
5 |
+
from huggingface_hub import create_repo, whoami
|
6 |
|
|
|
|
|
7 |
|
8 |
+
from config_store import (
|
9 |
+
get_process_config,
|
10 |
+
get_inference_config,
|
11 |
+
get_openvino_config,
|
12 |
+
get_pytorch_config,
|
13 |
+
)
|
14 |
+
from optimum_benchmark.launchers.base import Launcher # noqa
|
15 |
+
from optimum_benchmark.backends.openvino.utils import TASKS_TO_OVMODEL
|
16 |
+
from optimum_benchmark.backends.transformers_utils import TASKS_TO_MODEL_LOADERS
|
17 |
+
from optimum_benchmark import (
|
18 |
+
BenchmarkConfig,
|
19 |
+
PyTorchConfig,
|
20 |
+
OVConfig,
|
21 |
+
ProcessConfig,
|
22 |
+
InferenceConfig,
|
23 |
+
Benchmark,
|
24 |
+
)
|
25 |
+
from optimum_benchmark.logging_utils import setup_logging
|
26 |
+
|
27 |
+
|
28 |
+
DEVICE = "cpu"
|
29 |
+
LAUNCHER = "process"
|
30 |
+
SCENARIO = "inference"
|
31 |
+
BACKENDS = ["openvino", "pytorch"]
|
32 |
+
MODELS = [
|
33 |
+
"google-bert/bert-base-uncased",
|
34 |
+
"openai-community/gpt2",
|
35 |
+
]
|
36 |
+
TASKS = set(TASKS_TO_OVMODEL.keys()) & set(TASKS_TO_MODEL_LOADERS.keys())
|
37 |
+
|
38 |
+
|
39 |
+
def run_benchmark(kwargs, oauth_token: gr.OAuthToken):
|
40 |
+
if oauth_token.token is None:
|
41 |
+
gr.Error("Please login to be able to run the benchmark.")
|
42 |
+
return tuple(None for _ in BACKENDS)
|
43 |
+
|
44 |
+
timestamp = time.strftime("%Y-%m-%d-%H-%M-%S")
|
45 |
+
username = whoami(oauth_token.token)["name"]
|
46 |
+
repo_id = f"{username}/benchmarks"
|
47 |
+
token = oauth_token.token
|
48 |
+
|
49 |
+
create_repo(repo_id, token=token, repo_type="dataset", exist_ok=True)
|
50 |
+
gr.Info(f'Benchmark will be pushed to "{username}/benchmarks" on the Hub')
|
51 |
+
|
52 |
+
configs = {
|
53 |
+
"process": {},
|
54 |
+
"inference": {},
|
55 |
+
"openvino": {},
|
56 |
+
"pytorch": {},
|
57 |
+
}
|
58 |
+
|
59 |
+
for key, value in kwargs.items():
|
60 |
+
if key.label == "model":
|
61 |
+
model = value
|
62 |
+
elif key.label == "task":
|
63 |
+
task = value
|
64 |
+
elif key.label == "backends":
|
65 |
+
backends = value
|
66 |
+
elif "." in key.label:
|
67 |
+
backend, argument = key.label.split(".")
|
68 |
+
configs[backend][argument] = value
|
69 |
+
else:
|
70 |
+
continue
|
71 |
+
|
72 |
+
for key in configs.keys():
|
73 |
+
for k, v in configs[key].items():
|
74 |
+
if "kwargs" in k:
|
75 |
+
configs[key][k] = eval(v)
|
76 |
+
|
77 |
+
configs["process"] = ProcessConfig(**configs.pop("process"))
|
78 |
+
configs["inference"] = InferenceConfig(**configs.pop("inference"))
|
79 |
+
|
80 |
+
configs["openvino"] = OVConfig(
|
81 |
+
task=task,
|
82 |
+
model=model,
|
83 |
+
device=DEVICE,
|
84 |
+
**configs["openvino"],
|
85 |
+
)
|
86 |
+
configs["pytorch"] = PyTorchConfig(
|
87 |
+
task=task,
|
88 |
+
model=model,
|
89 |
+
device=DEVICE,
|
90 |
+
**configs["pytorch"],
|
91 |
+
)
|
92 |
+
|
93 |
+
outputs = {
|
94 |
+
"openvino": "Running benchmark for OpenVINO backend",
|
95 |
+
"pytorch": "Running benchmark for PyTorch backend",
|
96 |
+
}
|
97 |
+
|
98 |
+
yield tuple(outputs[b] for b in BACKENDS)
|
99 |
+
|
100 |
+
for backend in backends:
|
101 |
+
try:
|
102 |
+
benchmark_name = f"{timestamp}/{backend}"
|
103 |
+
benchmark_config = BenchmarkConfig(
|
104 |
+
name=benchmark_name,
|
105 |
+
backend=configs[backend],
|
106 |
+
launcher=configs[LAUNCHER],
|
107 |
+
scenario=configs[SCENARIO],
|
108 |
+
)
|
109 |
+
benchmark_config.push_to_hub(
|
110 |
+
repo_id=repo_id, subfolder=benchmark_name, token=oauth_token.token
|
111 |
+
)
|
112 |
+
benchmark_report = Benchmark.launch(benchmark_config)
|
113 |
+
benchmark_report.push_to_hub(
|
114 |
+
repo_id=repo_id, subfolder=benchmark_name, token=oauth_token.token
|
115 |
+
)
|
116 |
+
benchmark = Benchmark(config=benchmark_config, report=benchmark_report)
|
117 |
+
benchmark.push_to_hub(
|
118 |
+
repo_id=repo_id, subfolder=benchmark_name, token=oauth_token.token
|
119 |
+
)
|
120 |
+
gr.Info(f"Pushed benchmark to {username}/benchmarks/{benchmark_name}")
|
121 |
+
|
122 |
+
outputs[backend] = f"\n{benchmark_report.to_markdown_text()}"
|
123 |
+
|
124 |
+
yield tuple(outputs[b] for b in BACKENDS)
|
125 |
+
|
126 |
+
except Exception:
|
127 |
+
gr.Error(f"Error while running benchmark for {backend}")
|
128 |
+
|
129 |
+
outputs[backend] = f"\n{traceback.format_exc()}"
|
130 |
+
|
131 |
+
yield tuple(outputs[b] for b in BACKENDS)
|
132 |
+
|
133 |
+
|
134 |
+
def build_demo():
|
135 |
+
with gr.Blocks() as demo:
|
136 |
+
# add login button
|
137 |
+
gr.LoginButton(min_width=250)
|
138 |
+
|
139 |
+
# add image
|
140 |
+
gr.Markdown(
|
141 |
+
"""<img src="https://huggingface.co/spaces/optimum/optimum-benchmark-ui/resolve/main/huggy_bench.png" style="display: block; margin-left: auto; margin-right: auto; width: 30%;">"""
|
142 |
+
)
|
143 |
+
|
144 |
+
# title text
|
145 |
+
gr.Markdown(
|
146 |
+
"<h1 style='text-align: center'>๐ค Optimum-Benchmark Interface ๐๏ธ</h1>"
|
147 |
+
)
|
148 |
+
|
149 |
+
# explanation text
|
150 |
+
gr.HTML(
|
151 |
+
"<h3 style='text-align: center'>"
|
152 |
+
"Zero code Gradio interface of "
|
153 |
+
"<a href='https://github.com/huggingface/optimum-benchmark.git'>"
|
154 |
+
"Optimum-Benchmark"
|
155 |
+
"</a>"
|
156 |
+
"<br>"
|
157 |
+
"</h3>"
|
158 |
+
"<p style='text-align: center'>"
|
159 |
+
"This Space uses Optimum Benchmark to automatically benchmark a model from the Hub on different backends."
|
160 |
+
"<br>"
|
161 |
+
"The results (config and report) will be pushed under your namespace in a benchmark repository on the Hub."
|
162 |
+
)
|
163 |
+
|
164 |
+
model = gr.Dropdown(
|
165 |
+
label="model",
|
166 |
+
choices=MODELS,
|
167 |
+
value=MODELS[0],
|
168 |
+
info="Model to run the benchmark on.",
|
169 |
+
)
|
170 |
+
task = gr.Dropdown(
|
171 |
+
label="task",
|
172 |
+
choices=TASKS,
|
173 |
+
value="feature-extraction",
|
174 |
+
info="Task to run the benchmark on.",
|
175 |
+
)
|
176 |
+
backends = gr.CheckboxGroup(
|
177 |
+
interactive=True,
|
178 |
+
label="backends",
|
179 |
+
choices=BACKENDS,
|
180 |
+
value=BACKENDS,
|
181 |
+
info="Backends to run the benchmark on.",
|
182 |
+
)
|
183 |
+
|
184 |
+
with gr.Row():
|
185 |
+
with gr.Accordion(label="Process Config", open=False, visible=True):
|
186 |
+
process_config = get_process_config()
|
187 |
+
|
188 |
+
with gr.Row():
|
189 |
+
with gr.Accordion(label="Scenario Config", open=False, visible=True):
|
190 |
+
inference_config = get_inference_config()
|
191 |
+
|
192 |
+
with gr.Row() as backend_configs:
|
193 |
+
with gr.Accordion(label="OpenVINO Config", open=False, visible=True):
|
194 |
+
openvino_config = get_openvino_config()
|
195 |
+
with gr.Accordion(label="PyTorch Config", open=False, visible=True):
|
196 |
+
pytorch_config = get_pytorch_config()
|
197 |
+
# with gr.Accordion(label="IPEX Config", open=False, visible=True):
|
198 |
+
# ipex_config = get_ipex_config()
|
199 |
+
|
200 |
+
backends.change(
|
201 |
+
inputs=backends,
|
202 |
+
outputs=backend_configs.children,
|
203 |
+
fn=lambda values: [
|
204 |
+
gr.update(visible=value in values) for value in BACKENDS
|
205 |
+
],
|
206 |
+
)
|
207 |
+
|
208 |
+
with gr.Row():
|
209 |
+
button = gr.Button(value="Run Benchmark", variant="primary")
|
210 |
+
|
211 |
+
with gr.Row() as md_output:
|
212 |
+
with gr.Accordion(label="OpenVINO Output", open=True, visible=True):
|
213 |
+
openvino_output = gr.Markdown()
|
214 |
+
with gr.Accordion(label="PyTorch Output", open=True, visible=True):
|
215 |
+
pytorch_output = gr.Markdown()
|
216 |
+
# with gr.Accordion(label="IPEX Output", open=True, visible=True):
|
217 |
+
# ipex_output = gr.Markdown()
|
218 |
+
|
219 |
+
backends.change(
|
220 |
+
inputs=backends,
|
221 |
+
outputs=md_output.children,
|
222 |
+
fn=lambda values: [
|
223 |
+
gr.update(visible=value in values) for value in BACKENDS
|
224 |
+
],
|
225 |
+
)
|
226 |
+
|
227 |
+
button.click(
|
228 |
+
fn=run_benchmark,
|
229 |
+
inputs={
|
230 |
+
task,
|
231 |
+
model,
|
232 |
+
backends,
|
233 |
+
*process_config.values(),
|
234 |
+
*inference_config.values(),
|
235 |
+
*openvino_config.values(),
|
236 |
+
*pytorch_config.values(),
|
237 |
+
# *ipex_config.values(),
|
238 |
+
},
|
239 |
+
outputs={
|
240 |
+
openvino_output,
|
241 |
+
pytorch_output,
|
242 |
+
# ipex_output,
|
243 |
+
},
|
244 |
+
concurrency_limit=1,
|
245 |
+
)
|
246 |
+
|
247 |
+
return demo
|
248 |
+
|
249 |
+
|
250 |
+
if __name__ == "__main__":
|
251 |
+
os.environ["LOG_TO_FILE"] = "0"
|
252 |
+
os.environ["LOG_LEVEL"] = "INFO"
|
253 |
+
setup_logging(level="INFO", prefix="MAIN-PROCESS")
|
254 |
+
|
255 |
+
demo = build_demo()
|
256 |
+
demo.queue(max_size=10).launch()
|
config_store.py
ADDED
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
|
4 |
+
def get_process_config():
|
5 |
+
return {
|
6 |
+
"process.numactl": gr.Checkbox(
|
7 |
+
value=False,
|
8 |
+
label="process.numactl",
|
9 |
+
info="Runs the model with numactl",
|
10 |
+
),
|
11 |
+
"process.numactl_kwargs": gr.Textbox(
|
12 |
+
label="process.numactl_kwargs",
|
13 |
+
value="{'cpunodebind': 0, 'membind': 0}",
|
14 |
+
info="Additional python dict of kwargs to pass to numactl",
|
15 |
+
),
|
16 |
+
}
|
17 |
+
|
18 |
+
|
19 |
+
def get_inference_config():
|
20 |
+
return {
|
21 |
+
"inference.warmup_runs": gr.Slider(
|
22 |
+
step=1,
|
23 |
+
value=10,
|
24 |
+
minimum=0,
|
25 |
+
maximum=10,
|
26 |
+
label="inference.warmup_runs",
|
27 |
+
info="Number of warmup runs",
|
28 |
+
),
|
29 |
+
"inference.duration": gr.Slider(
|
30 |
+
step=1,
|
31 |
+
value=10,
|
32 |
+
minimum=0,
|
33 |
+
maximum=10,
|
34 |
+
label="inference.duration",
|
35 |
+
info="Minimum duration of the benchmark in seconds",
|
36 |
+
),
|
37 |
+
"inference.iterations": gr.Slider(
|
38 |
+
step=1,
|
39 |
+
value=10,
|
40 |
+
minimum=0,
|
41 |
+
maximum=10,
|
42 |
+
label="inference.iterations",
|
43 |
+
info="Minimum number of iterations of the benchmark",
|
44 |
+
),
|
45 |
+
"inference.latency": gr.Checkbox(
|
46 |
+
value=True,
|
47 |
+
label="inference.latency",
|
48 |
+
info="Measures the latency of the model",
|
49 |
+
),
|
50 |
+
"inference.memory": gr.Checkbox(
|
51 |
+
value=False,
|
52 |
+
label="inference.memory",
|
53 |
+
info="Measures the peak memory consumption",
|
54 |
+
),
|
55 |
+
}
|
56 |
+
|
57 |
+
|
58 |
+
def get_pytorch_config():
|
59 |
+
return {
|
60 |
+
"pytorch.torch_dtype": gr.Dropdown(
|
61 |
+
value="float32",
|
62 |
+
label="pytorch.torch_dtype",
|
63 |
+
choices=["bfloat16", "float16", "float32", "auto"],
|
64 |
+
info="The dtype to use for the model",
|
65 |
+
),
|
66 |
+
"pytorch.torch_compile": gr.Checkbox(
|
67 |
+
value=False,
|
68 |
+
label="pytorch.torch_compile",
|
69 |
+
info="Compiles the model with torch.compile",
|
70 |
+
),
|
71 |
+
}
|
72 |
+
|
73 |
+
|
74 |
+
def get_onnxruntime_config():
|
75 |
+
return {
|
76 |
+
"onnxruntime.export": gr.Checkbox(
|
77 |
+
value=True,
|
78 |
+
label="onnxruntime.export",
|
79 |
+
info="Exports the model to ONNX",
|
80 |
+
),
|
81 |
+
"onnxruntime.use_cache": gr.Checkbox(
|
82 |
+
value=True,
|
83 |
+
label="onnxruntime.use_cache",
|
84 |
+
info="Uses cached ONNX model if available",
|
85 |
+
),
|
86 |
+
"onnxruntime.use_merged": gr.Checkbox(
|
87 |
+
value=True,
|
88 |
+
label="onnxruntime.use_merged",
|
89 |
+
info="Uses merged ONNX model if available",
|
90 |
+
),
|
91 |
+
"onnxruntime.torch_dtype": gr.Dropdown(
|
92 |
+
value="float32",
|
93 |
+
label="onnxruntime.torch_dtype",
|
94 |
+
choices=["bfloat16", "float16", "float32", "auto"],
|
95 |
+
info="The dtype to use for the model",
|
96 |
+
),
|
97 |
+
}
|
98 |
+
|
99 |
+
|
100 |
+
def get_openvino_config():
|
101 |
+
return {
|
102 |
+
"openvino.export": gr.Checkbox(
|
103 |
+
value=True,
|
104 |
+
label="openvino.export",
|
105 |
+
info="Exports the model to ONNX",
|
106 |
+
),
|
107 |
+
"openvino.use_cache": gr.Checkbox(
|
108 |
+
value=True,
|
109 |
+
label="openvino.use_cache",
|
110 |
+
info="Uses cached ONNX model if available",
|
111 |
+
),
|
112 |
+
"openvino.use_merged": gr.Checkbox(
|
113 |
+
value=True,
|
114 |
+
label="openvino.use_merged",
|
115 |
+
info="Uses merged ONNX model if available",
|
116 |
+
),
|
117 |
+
"openvino.reshape": gr.Checkbox(
|
118 |
+
value=False,
|
119 |
+
label="openvino.reshape",
|
120 |
+
info="Reshapes the model to the input shape",
|
121 |
+
),
|
122 |
+
"openvino.half": gr.Checkbox(
|
123 |
+
value=False,
|
124 |
+
label="openvino.half",
|
125 |
+
info="Converts model to half precision",
|
126 |
+
),
|
127 |
+
}
|
128 |
+
|
129 |
+
|
130 |
+
def get_ipex_config():
|
131 |
+
return {}
|
huggy_bench.png
ADDED
packages.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
numactl
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
optimum-benchmark[openvino]@git+https://github.com/huggingface/optimum-benchmark.git@markdown-report
|