Skip to content

Commit 9aabcf9

Browse files
Merge pull request #7 from huggingface/fix-onnx-openvino-for-cpu
fix number of models
2 parents 7f02627 + fb4abd2 commit 9aabcf9

File tree

11 files changed

+132
-13
lines changed

11 files changed

+132
-13
lines changed

.dockerignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
optimum-benchmark
2+
3+
**/*.pyc
4+
**/*.pyo
5+
**/*.mo
6+
.gitignore
7+
.git/
8+
**/__pycache__/
9+
Dockerfile
10+
db.sqlite3
11+
**/*.md
12+
build
13+
.venv
14+
ruff_cache
15+
*.egg-info
16+
*.egg
17+
*.dist-info
18+
*.whl
19+
*.tar.gz
20+
*.zip
21+
*.rar
22+
*.7z
23+
*.iso

.github/workflows/benchmark_cpu_openvino.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
MACHINE: ${{ matrix.machine.name }}
5151
HF_TOKEN: ${{ secrets.HF_TOKEN }}
5252
DISABLE_WARNINGS: 1
53-
BENCHMARK_TOP_N: 3
53+
BENCHMARK_TOP_N: 50
5454
with:
5555
image: ${{ env.IMAGE }}
5656
options: |

.github/workflows/benchmark_cpu_pytorch.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
SUBSET: ${{ matrix.subset }}
5050
MACHINE: ${{ matrix.machine.name }}
5151
HF_TOKEN: ${{ secrets.HF_TOKEN }}
52-
BENCHMARK_TOP_N: 3
52+
BENCHMARK_TOP_N: 50
5353
with:
5454
image: ${{ env.IMAGE }}
5555
options: |

.github/workflows/benchmark_cuda_pytorch.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
SUBSET: ${{ matrix.subset }}
5454
MACHINE: ${{ matrix.machine.name }}
5555
HF_TOKEN: ${{ secrets.HF_TOKEN }}
56-
BENCHMARK_TOP_N: 3
56+
BENCHMARK_TOP_N: 50
5757
with:
5858
image: ${{ env.IMAGE }}
5959
options: |

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,5 @@ outputs/
186186
.env
187187
wip/
188188

189-
*.csv
189+
*.csv
190+
optimum-benchmark/

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,11 @@ cpu-pytorch-container:
3333
docker build -t cpu-pytorch -f docker/cpu-pytorch/Dockerfile .
3434
# docker run -it --rm --pid host cpu-pytorch /bin/bash
3535
docker run -it --rm --pid host cpu-pytorch
36+
37+
collector-container:
38+
docker build -t collector -f docker/collector/Dockerfile .
39+
docker run -it --rm --pid host collector
40+
41+
cpu-openvino-container:
42+
docker build -t cpu-openvino -f docker/cpu-openvino/Dockerfile .
43+
docker run -it --rm --pid host cpu-openvino

docker/collector/Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM python:3.12-slim
2+
3+
WORKDIR /workspace
4+
5+
# Install git
6+
RUN apt-get update && apt-get install -y git && apt-get clean && rm -rf /var/lib/apt/lists/*
7+
8+
COPY setup.py .
9+
COPY pyproject.toml .
10+
11+
RUN pip install -e .
12+
13+
COPY . .
14+
15+
CMD ["llm-perf", "update-leaderboard"]

docker/cpu-openvino/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM ghcr.io/huggingface/optimum-benchmark:latest-cpu
2+
3+
WORKDIR /workspace
4+
5+
COPY setup.py .
6+
# COPY pyproject.toml .
7+
8+
RUN pip install -e .[openvino]
9+
10+
COPY . .
11+
12+
CMD ["llm-perf", "run-benchmark", "--hardware", "cpu", "--backend", "openvino"]

llm_perf/common/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def get_top_llm_list(n: int = 10) -> list[str]:
5252

5353

5454
if is_debug_mode():
55-
CANONICAL_PRETRAINED_OPEN_LLM_LIST = ["gpt2"]
55+
CANONICAL_PRETRAINED_OPEN_LLM_LIST = ["bigscience/bloomz-560m"]
5656
else:
5757
CANONICAL_PRETRAINED_OPEN_LLM_LIST = get_top_llm_list(n=get_benchmark_top_n())
5858
print(

llm_perf/hardware.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,6 @@
3333
subsets:
3434
- unquantized
3535
backends:
36-
- pytorch
36+
- pytorch
37+
- openvino
38+
- onnxruntime

llm_perf/update_llm_perf_leaderboard.py

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22
from glob import glob
33

44
import pandas as pd
5-
from huggingface_hub import create_repo, snapshot_download, upload_file
5+
from huggingface_hub import create_repo, snapshot_download, upload_file, repo_exists
66
from optimum_benchmark import Benchmark
7+
import requests
8+
import json
79

810
from llm_perf.common.hardware_config import load_hardware_configs
11+
from huggingface_hub.utils import disable_progress_bars
12+
13+
disable_progress_bars()
914

1015
REPO_TYPE = "dataset"
1116
MAIN_REPO_ID = "optimum-benchmark/llm-perf-leaderboard"
@@ -14,6 +19,43 @@
1419
PERF_DF = "perf-df-{backend}-{hardware}-{subset}-{machine}.csv"
1520
LLM_DF = "llm-df.csv"
1621

22+
def patch_json(file):
23+
"""
24+
Patch a JSON file by adding a 'stdev_' key with the same value as 'stdev' for all occurrences,
25+
but only if 'stdev_' doesn't already exist at the same level.
26+
This is to make the old optimum benchmark compatible with the new one.
27+
28+
This function reads a JSON file, recursively traverses the data structure,
29+
and for each dictionary that contains a 'stdev' key without a corresponding 'stdev_' key,
30+
it adds a 'stdev_' key with the same value. The modified data is then written back to the file.
31+
32+
Args:
33+
file (str): The path to the JSON file to be patched.
34+
35+
Returns:
36+
None
37+
"""
38+
with open(file, "r") as f:
39+
data = json.load(f)
40+
41+
def add_stdev_(obj):
42+
if isinstance(obj, dict):
43+
new_items = []
44+
for key, value in obj.items():
45+
if key == "stdev" and "stdev_" not in obj:
46+
new_items.append(("stdev_", value))
47+
if isinstance(value, (dict, list)):
48+
add_stdev_(value)
49+
for key, value in new_items:
50+
obj[key] = value
51+
elif isinstance(obj, list):
52+
for item in obj:
53+
add_stdev_(item)
54+
55+
add_stdev_(data)
56+
57+
with open(file, "w") as f:
58+
json.dump(data, f, indent=4)
1759

1860
def gather_benchmarks(subset: str, machine: str, backend: str, hardware: str):
1961
"""
@@ -23,11 +65,14 @@ def gather_benchmarks(subset: str, machine: str, backend: str, hardware: str):
2365
subset=subset, machine=machine, backend=backend, hardware=hardware
2466
)
2567
snapshot = snapshot_download(
26-
repo_type=REPO_TYPE, repo_id=perf_repo_id, allow_patterns=["**/benchmark.json"]
68+
repo_type=REPO_TYPE,
69+
repo_id=perf_repo_id,
70+
allow_patterns=["**/benchmark.json"],
2771
)
2872

2973
dfs = []
3074
for file in glob(f"{snapshot}/**/benchmark.json", recursive=True):
75+
patch_json(file)
3176
dfs.append(Benchmark.from_json(file).to_dataframe())
3277
benchmarks = pd.concat(dfs, ignore_index=True)
3378

@@ -42,6 +87,17 @@ def gather_benchmarks(subset: str, machine: str, backend: str, hardware: str):
4287
path_in_repo=perf_df,
4388
path_or_fileobj=perf_df,
4489
)
90+
print(f"Uploaded {perf_df} to {MAIN_REPO_ID}")
91+
92+
93+
# def check_if_url_exists(url: str):
94+
# """
95+
# Check if a URL exists
96+
# """
97+
# repo_exists
98+
# print(f"response: {response}")
99+
# return response.status_code == 200
100+
45101

46102

47103
def update_perf_dfs():
@@ -67,15 +123,17 @@ def update_perf_dfs():
67123
print(f" • Machine: {hardware_config.machine}")
68124
print(f" • Hardware Type: {hardware_config.hardware}")
69125
url = f"{PERF_REPO_ID.format(subset=subset, machine=hardware_config.machine, backend=backend, hardware=hardware_config.hardware)}"
70-
print(
71-
f"Check that URL exists: https://huggingface.co/datasets/{url}"
72-
)
73-
raise e
126+
127+
does_exist = repo_exists(url, repo_type="dataset")
128+
129+
if does_exist:
130+
print(f"Dataset exists: {url} but could not be processed")
131+
74132

75133

76134
scrapping_script = """
77135
git clone https://github.com/Weyaxi/scrape-open-llm-leaderboard.git
78-
pip install -r scrape-open-llm-leaderboard/requirements.txt
136+
pip install -r scrape-open-llm-leaderboard/requirements.txt -q
79137
python scrape-open-llm-leaderboard/main.py
80138
rm -rf scrape-open-llm-leaderboard
81139
"""

0 commit comments

Comments
 (0)