Hch Li commited on
Commit
cf7e82a
·
1 Parent(s): 89c9ca7
.gitattributes DELETED
@@ -1,35 +0,0 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
- *.arrow filter=lfs diff=lfs merge=lfs -text
3
- *.bin filter=lfs diff=lfs merge=lfs -text
4
- *.bz2 filter=lfs diff=lfs merge=lfs -text
5
- *.ckpt filter=lfs diff=lfs merge=lfs -text
6
- *.ftz filter=lfs diff=lfs merge=lfs -text
7
- *.gz filter=lfs diff=lfs merge=lfs -text
8
- *.h5 filter=lfs diff=lfs merge=lfs -text
9
- *.joblib filter=lfs diff=lfs merge=lfs -text
10
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
- *.model filter=lfs diff=lfs merge=lfs -text
13
- *.msgpack filter=lfs diff=lfs merge=lfs -text
14
- *.npy filter=lfs diff=lfs merge=lfs -text
15
- *.npz filter=lfs diff=lfs merge=lfs -text
16
- *.onnx filter=lfs diff=lfs merge=lfs -text
17
- *.ot filter=lfs diff=lfs merge=lfs -text
18
- *.parquet filter=lfs diff=lfs merge=lfs -text
19
- *.pb filter=lfs diff=lfs merge=lfs -text
20
- *.pickle filter=lfs diff=lfs merge=lfs -text
21
- *.pkl filter=lfs diff=lfs merge=lfs -text
22
- *.pt filter=lfs diff=lfs merge=lfs -text
23
- *.pth filter=lfs diff=lfs merge=lfs -text
24
- *.rar filter=lfs diff=lfs merge=lfs -text
25
- *.safetensors filter=lfs diff=lfs merge=lfs -text
26
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
- *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tflite filter=lfs diff=lfs merge=lfs -text
29
- *.tgz filter=lfs diff=lfs merge=lfs -text
30
- *.wasm filter=lfs diff=lfs merge=lfs -text
31
- *.xz filter=lfs diff=lfs merge=lfs -text
32
- *.zip filter=lfs diff=lfs merge=lfs -text
33
- *.zst filter=lfs diff=lfs merge=lfs -text
34
- *tfevents* filter=lfs diff=lfs merge=lfs -text
35
- scale-hf-logo.png filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.gitignore DELETED
@@ -1,14 +0,0 @@
1
- auto_evals/
2
- venv/
3
- __pycache__/
4
- .env
5
- .ipynb_checkpoints
6
- *ipynb
7
- .vscode/
8
-
9
- eval-queue/
10
- eval-results/
11
- eval-queue-bk/
12
- eval-results-bk/
13
- logs/
14
- dataset_repo
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.pre-commit-config.yaml DELETED
@@ -1,53 +0,0 @@
1
- # Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- default_language_version:
16
- python: python3
17
-
18
- ci:
19
- autofix_prs: true
20
- autoupdate_commit_msg: '[pre-commit.ci] pre-commit suggestions'
21
- autoupdate_schedule: quarterly
22
-
23
- repos:
24
- - repo: https://github.com/pre-commit/pre-commit-hooks
25
- rev: v4.3.0
26
- hooks:
27
- - id: check-yaml
28
- - id: check-case-conflict
29
- - id: detect-private-key
30
- - id: check-added-large-files
31
- args: ['--maxkb=1000']
32
- - id: requirements-txt-fixer
33
- - id: end-of-file-fixer
34
- - id: trailing-whitespace
35
-
36
- - repo: https://github.com/PyCQA/isort
37
- rev: 5.12.0
38
- hooks:
39
- - id: isort
40
- name: Format imports
41
-
42
- - repo: https://github.com/psf/black
43
- rev: 22.12.0
44
- hooks:
45
- - id: black
46
- name: Format code
47
- additional_dependencies: ['click==8.0.2']
48
-
49
- - repo: https://github.com/charliermarsh/ruff-pre-commit
50
- # Ruff version.
51
- rev: 'v0.0.267'
52
- hooks:
53
- - id: ruff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Makefile DELETED
@@ -1,13 +0,0 @@
1
- .PHONY: style format
2
-
3
-
4
- style:
5
- python -m black --line-length 119 .
6
- python -m isort .
7
- ruff check --fix .
8
-
9
-
10
- quality:
11
- python -m black --check --line-length 119 .
12
- python -m isort --check-only .
13
- ruff check .
 
 
 
 
 
 
 
 
 
 
 
 
 
 
README.md DELETED
@@ -1,45 +0,0 @@
1
- ---
2
- title: Lmcache Benchmark Lite
3
- emoji: 🥇
4
- colorFrom: green
5
- colorTo: indigo
6
- sdk: gradio
7
- app_file: app.py
8
- pinned: true
9
- license: apache-2.0
10
- ---
11
-
12
- # Start the configuration
13
-
14
- Most of the variables to change for a default leaderboard are in `src/env.py` (replace the path for your leaderboard) and `src/about.py` (for tasks).
15
-
16
- Results files should have the following format and be stored as json files:
17
- ```json
18
- {
19
- "config": {
20
- "model_dtype": "torch.float16", # or torch.bfloat16 or 8bit or 4bit
21
- "model_name": "path of the model on the hub: org/model",
22
- "model_sha": "revision on the hub",
23
- "compressin_method": "delete all"
24
- },
25
- "results": {
26
- "task_name": {
27
- "metric_name": score,
28
- },
29
- "task_name2": {
30
- "metric_name": score,
31
- }
32
- }
33
- }
34
- ```
35
-
36
- Request files are created automatically by this tool.
37
-
38
- If you encounter problem on the space, don't hesitate to restart it to remove the create eval-queue, eval-queue-bk, eval-results and eval-results-bk created folder.
39
-
40
- # Code logic for more complex edits
41
-
42
- You'll find
43
- - the main table' columns names and properties in `src/display/utils.py`
44
- - the logic to read all results and request files, then convert them in dataframe lines, in `src/leaderboard/read_evals.py`, and `src/populate.py`
45
- - the logic to allow or filter submissions in `src/submission/submit.py` and `src/submission/check_validity.py`
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app.py CHANGED
@@ -1,193 +1,102 @@
 
 
1
  import gradio as gr
2
- from gradio_leaderboard import Leaderboard, ColumnFilter, SelectColumns
3
  import pandas as pd
4
- from apscheduler.schedulers.background import BackgroundScheduler
5
- from huggingface_hub import snapshot_download
6
 
7
- from src.about import (
8
- CITATION_BUTTON_LABEL,
9
- CITATION_BUTTON_TEXT,
10
- EVALUATION_QUEUE_TEXT,
11
- INTRODUCTION_TEXT,
12
- LLM_BENCHMARKS_TEXT,
13
- TITLE,
14
- )
15
- from src.display.css_html_js import custom_css
16
- from src.display.utils import (
17
- BENCHMARK_COLS,
18
- COLS,
19
- EVAL_COLS,
20
- EVAL_TYPES,
21
- AutoEvalColumn,
22
- ModelType,
23
- fields,
24
- WeightType,
25
- Precision
26
- )
27
- from src.envs import API, EVAL_REQUESTS_PATH, EVAL_RESULTS_PATH, QUEUE_REPO, REPO_ID, RESULTS_REPO, TOKEN
28
- from src.populate import get_evaluation_queue_df, get_leaderboard_df
29
- from src.submission.submit import add_new_eval
30
-
31
-
32
- def restart_space():
33
- API.restart_space(repo_id=REPO_ID)
34
-
35
- ### Space initialisation
36
- try:
37
- print(EVAL_REQUESTS_PATH)
38
- snapshot_download(
39
- repo_id=QUEUE_REPO, local_dir=EVAL_REQUESTS_PATH, repo_type="dataset", tqdm_class=None, etag_timeout=30, token=TOKEN
40
- )
41
- except Exception:
42
- restart_space()
43
- try:
44
- print(EVAL_RESULTS_PATH)
45
- snapshot_download(
46
- repo_id=RESULTS_REPO, local_dir=EVAL_RESULTS_PATH, repo_type="dataset", tqdm_class=None, etag_timeout=30, token=TOKEN
47
- )
48
- except Exception:
49
- restart_space()
50
-
51
-
52
- LEADERBOARD_DF = get_leaderboard_df(EVAL_RESULTS_PATH, EVAL_REQUESTS_PATH, COLS, BENCHMARK_COLS)
53
-
54
- (
55
- finished_eval_queue_df,
56
- running_eval_queue_df,
57
- pending_eval_queue_df,
58
- ) = get_evaluation_queue_df(EVAL_REQUESTS_PATH, EVAL_COLS)
59
-
60
- def init_leaderboard(dataframe):
61
- if dataframe is None or dataframe.empty:
62
- raise ValueError("Leaderboard DataFrame is empty or None.")
63
- return Leaderboard(
64
- value=dataframe,
65
- datatype=[c.type for c in fields(AutoEvalColumn)],
66
- select_columns=SelectColumns(
67
- default_selection=[c.name for c in fields(AutoEvalColumn) if c.displayed_by_default],
68
- cant_deselect=[c.name for c in fields(AutoEvalColumn) if c.never_hidden],
69
- label="Select Columns to Display:",
70
- ),
71
- search_columns=[AutoEvalColumn.model.name, AutoEvalColumn.license.name],
72
- hide_columns=[c.name for c in fields(AutoEvalColumn) if c.hidden],
73
- filter_columns=[
74
- ColumnFilter(AutoEvalColumn.model_type.name, type="checkboxgroup", label="Model types"),
75
- # ColumnFilter(AutoEvalColumn.precision.name, type="checkboxgroup", label="Precision"),
76
- # ColumnFilter(
77
- # AutoEvalColumn.params.name,
78
- # type="slider",
79
- # min=0.01,
80
- # max=150,
81
- # label="Select the number of parameters (B)",
82
- # ),
83
- # ColumnFilter(
84
- # AutoEvalColumn.still_on_hub.name, type="boolean", label="Deleted/incomplete", default=True
85
- # ),
86
- ],
87
- bool_checkboxgroup_label="Hide models",
88
- interactive=False,
89
- )
90
-
91
-
92
- demo = gr.Blocks(css=custom_css)
93
- with demo:
94
- gr.HTML(TITLE)
95
- gr.Markdown(INTRODUCTION_TEXT, elem_classes="markdown-text")
96
-
97
- with gr.Tabs(elem_classes="tab-buttons") as tabs:
98
- with gr.TabItem("🏅 KV Cache Benchmark", elem_id="llm-benchmark-tab-table", id=0):
99
- leaderboard = init_leaderboard(LEADERBOARD_DF)
100
-
101
- with gr.TabItem("📝 About", elem_id="llm-benchmark-tab-table", id=2):
102
- gr.Markdown(LLM_BENCHMARKS_TEXT, elem_classes="markdown-text")
103
-
104
- with gr.TabItem("🚀 Submit here! ", elem_id="llm-benchmark-tab-table", id=3):
105
- with gr.Column():
106
  with gr.Row():
107
- gr.Markdown(EVALUATION_QUEUE_TEXT, elem_classes="markdown-text")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
 
109
- with gr.Column():
110
- with gr.Accordion(
111
- f"✅ Finished Evaluations ({len(finished_eval_queue_df)})",
112
- open=False,
113
- ):
114
- with gr.Row():
115
- finished_eval_table = gr.components.Dataframe(
116
- value=finished_eval_queue_df,
117
- headers=EVAL_COLS,
118
- datatype=EVAL_TYPES,
119
- row_count=5,
120
- )
121
- with gr.Accordion(
122
- f"🔄 Running Evaluation Queue ({len(running_eval_queue_df)})",
123
- open=False,
124
- ):
125
- with gr.Row():
126
- running_eval_table = gr.components.Dataframe(
127
- value=running_eval_queue_df,
128
- headers=EVAL_COLS,
129
- datatype=EVAL_TYPES,
130
- row_count=5,
131
- )
132
-
133
- with gr.Accordion(
134
- f"⏳ Pending Evaluation Queue ({len(pending_eval_queue_df)})",
135
- open=False,
136
- ):
137
- with gr.Row():
138
- pending_eval_table = gr.components.Dataframe(
139
- value=pending_eval_queue_df,
140
- headers=EVAL_COLS,
141
- datatype=EVAL_TYPES,
142
- row_count=5,
143
- )
144
- with gr.Row():
145
- gr.Markdown("# ✉️✨ Submit your model here!", elem_classes="markdown-text")
146
-
147
- with gr.Row():
148
- with gr.Column():
149
- method_name = gr.Textbox(label="Method name")
150
- paper_link = gr.Textbox(label = "Paper Link")
151
- revision_name_textbox = gr.Textbox(label="Revision commit", placeholder="main")
152
 
 
 
 
 
153
 
154
- with gr.Column():
155
- model_type = gr.Dropdown(
156
- choices=[t.to_str(" : ") for t in ModelType if t != ModelType.Unknown],
157
- label="Model type",
158
- multiselect=False,
159
- value=None,
160
- interactive=True,
161
- )
162
- file_link = gr.Textbox(label = "File Link")
163
- explanatin = gr.Textbox(label = "Explanation")
164
 
165
- submit_button = gr.Button("Submit Eval")
166
- submission_result = gr.Markdown()
167
- submit_button.click(
168
- add_new_eval,
169
- [
170
- method_name,
171
- paper_link,
172
- revision_name_textbox,
173
- model_type,
174
- file_link,
175
- explanatin,
176
- ],
177
- submission_result,
178
- )
179
 
180
- with gr.Row():
181
- with gr.Accordion("📙 Citation", open=False):
182
- citation_button = gr.Textbox(
183
- value=CITATION_BUTTON_TEXT,
184
- label=CITATION_BUTTON_LABEL,
185
- lines=20,
186
- elem_id="citation-button",
187
- show_copy_button=True,
188
- )
189
 
190
- scheduler = BackgroundScheduler()
191
- scheduler.add_job(restart_space, "interval", seconds=1800)
192
- scheduler.start()
193
- demo.queue(default_concurrency_limit=40).launch()
 
1
+ import os
2
+ import json
3
  import gradio as gr
 
4
  import pandas as pd
 
 
5
 
6
+ # Helper function to load data from JSON files
7
+ def load_data(data_dir):
8
+ data = []
9
+ for file_name in os.listdir(data_dir):
10
+ if file_name.endswith(".json"):
11
+ method, model, dataset = file_name.replace(".json", "").split("_")
12
+ with open(os.path.join(data_dir, file_name), "r") as f:
13
+ entry = json.load(f)
14
+ entry.update({"Method": method, "Model": model, "Dataset": dataset})
15
+ data.append(entry)
16
+ return pd.DataFrame(data)
17
+
18
+ def filter_and_display(selected_columns, model_types, datasets):
19
+ filtered = data.copy()
20
+
21
+ # Filter by model types
22
+ if model_types:
23
+ filtered = filtered[filtered["Model"].isin(model_types)]
24
+
25
+ # Filter by datasets and compute average TTFT and Quality across datasets
26
+ if datasets:
27
+ filtered = filtered[filtered["Dataset"].isin(datasets)]
28
+
29
+ if not filtered.empty:
30
+ filtered = filtered.groupby(["Method", "Model"], as_index=False).agg({
31
+ "Quality": "mean",
32
+ "TTFT": "mean",
33
+ "Link": "first" # Keep one link for simplicity
34
+ })
35
+
36
+ # Select columns to display
37
+ display_columns = ["Method", "Model"] + [col for col in ["Quality", "TTFT", "Link"] if col in selected_columns]
38
+ return filtered[display_columns] if not filtered.empty else pd.DataFrame(columns=display_columns)
39
+
40
+ # Load the data from the /data folder
41
+ data_dir = "data"
42
+ data = load_data(data_dir)
43
+
44
+ # Gradio app UI and functionality
45
+ def create_gradio_app():
46
+ with gr.Blocks() as app:
47
+ with gr.Row():
48
+ gr.Markdown(
49
+ """# KV Cache Benchmark
50
+ ### Demo leaderboard
51
+ Intro text
52
+ """)
53
+
54
+ with gr.Tabs():
55
+ with gr.TabItem("KV Cache Benchmark"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  with gr.Row():
57
+ with gr.Column():
58
+ gr.Markdown("### Select Columns to Display")
59
+ columns_to_display = gr.CheckboxGroup(
60
+ choices=["Quality", "TTFT", "Link"],
61
+ label="Columns",
62
+ value=["Quality", "TTFT"]
63
+ )
64
+
65
+ with gr.Column():
66
+ gr.Markdown("### Model Types")
67
+ model_types = gr.CheckboxGroup(
68
+ choices=list(data["Model"].unique()),
69
+ label="Model Types",
70
+ value=list(data["Model"].unique()) # Default to all models
71
+ )
72
+
73
+ with gr.Column():
74
+ gr.Markdown("### Datasets")
75
+ datasets = gr.CheckboxGroup(
76
+ choices=list(data["Dataset"].unique()),
77
+ label="Datasets",
78
+ value=list(data["Dataset"].unique()) # Default to all datasets
79
+ )
80
 
81
+ with gr.Row():
82
+ gr.Markdown("### Filtered Results")
83
+
84
+ results = gr.Dataframe(value=filter_and_display(["Quality", "TTFT"], list(data["Model"].unique()), list(data["Dataset"].unique())), headers=["Method", "Model", "Quality", "TTFT", "Link"])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
 
86
+ def auto_update(selected_columns, model_types, datasets):
87
+ if not model_types or not datasets:
88
+ return pd.DataFrame(columns=["Method", "Model"] + selected_columns)
89
+ return filter_and_display(selected_columns, model_types, datasets)
90
 
91
+ columns_to_display.change(auto_update, inputs=[columns_to_display, model_types, datasets], outputs=[results])
92
+ model_types.change(auto_update, inputs=[columns_to_display, model_types, datasets], outputs=[results])
93
+ datasets.change(auto_update, inputs=[columns_to_display, model_types, datasets], outputs=[results])
 
 
 
 
 
 
 
94
 
95
+ with gr.TabItem("About"):
96
+ gr.Markdown("### About Page Placeholder")
 
 
 
 
 
 
 
 
 
 
 
 
97
 
98
+ return app
 
 
 
 
 
 
 
 
99
 
100
+ if __name__ == "__main__":
101
+ app = create_gradio_app()
102
+ app.launch()
 
data/h2o_Llama3.1-8B-Instruct_musique copy.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "Quality": 1,
3
+ "TTFT":1,
4
+ "Link": "www.google.com"
5
+ }
data/h2o_Llama3.1-8B-Instruct_wikitext.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "Quality": 100,
3
+ "TTFT":100,
4
+ "Link": "www.google.com"
5
+ }
eval-results/.gitattributes DELETED
@@ -1,59 +0,0 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
- *.arrow filter=lfs diff=lfs merge=lfs -text
3
- *.bin filter=lfs diff=lfs merge=lfs -text
4
- *.bz2 filter=lfs diff=lfs merge=lfs -text
5
- *.ckpt filter=lfs diff=lfs merge=lfs -text
6
- *.ftz filter=lfs diff=lfs merge=lfs -text
7
- *.gz filter=lfs diff=lfs merge=lfs -text
8
- *.h5 filter=lfs diff=lfs merge=lfs -text
9
- *.joblib filter=lfs diff=lfs merge=lfs -text
10
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
- *.lz4 filter=lfs diff=lfs merge=lfs -text
12
- *.mds filter=lfs diff=lfs merge=lfs -text
13
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
14
- *.model filter=lfs diff=lfs merge=lfs -text
15
- *.msgpack filter=lfs diff=lfs merge=lfs -text
16
- *.npy filter=lfs diff=lfs merge=lfs -text
17
- *.npz filter=lfs diff=lfs merge=lfs -text
18
- *.onnx filter=lfs diff=lfs merge=lfs -text
19
- *.ot filter=lfs diff=lfs merge=lfs -text
20
- *.parquet filter=lfs diff=lfs merge=lfs -text
21
- *.pb filter=lfs diff=lfs merge=lfs -text
22
- *.pickle filter=lfs diff=lfs merge=lfs -text
23
- *.pkl filter=lfs diff=lfs merge=lfs -text
24
- *.pt filter=lfs diff=lfs merge=lfs -text
25
- *.pth filter=lfs diff=lfs merge=lfs -text
26
- *.rar filter=lfs diff=lfs merge=lfs -text
27
- *.safetensors filter=lfs diff=lfs merge=lfs -text
28
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
29
- *.tar.* filter=lfs diff=lfs merge=lfs -text
30
- *.tar filter=lfs diff=lfs merge=lfs -text
31
- *.tflite filter=lfs diff=lfs merge=lfs -text
32
- *.tgz filter=lfs diff=lfs merge=lfs -text
33
- *.wasm filter=lfs diff=lfs merge=lfs -text
34
- *.xz filter=lfs diff=lfs merge=lfs -text
35
- *.zip filter=lfs diff=lfs merge=lfs -text
36
- *.zst filter=lfs diff=lfs merge=lfs -text
37
- *tfevents* filter=lfs diff=lfs merge=lfs -text
38
- # Audio files - uncompressed
39
- *.pcm filter=lfs diff=lfs merge=lfs -text
40
- *.sam filter=lfs diff=lfs merge=lfs -text
41
- *.raw filter=lfs diff=lfs merge=lfs -text
42
- # Audio files - compressed
43
- *.aac filter=lfs diff=lfs merge=lfs -text
44
- *.flac filter=lfs diff=lfs merge=lfs -text
45
- *.mp3 filter=lfs diff=lfs merge=lfs -text
46
- *.ogg filter=lfs diff=lfs merge=lfs -text
47
- *.wav filter=lfs diff=lfs merge=lfs -text
48
- # Image files - uncompressed
49
- *.bmp filter=lfs diff=lfs merge=lfs -text
50
- *.gif filter=lfs diff=lfs merge=lfs -text
51
- *.png filter=lfs diff=lfs merge=lfs -text
52
- *.tiff filter=lfs diff=lfs merge=lfs -text
53
- # Image files - compressed
54
- *.jpg filter=lfs diff=lfs merge=lfs -text
55
- *.jpeg filter=lfs diff=lfs merge=lfs -text
56
- *.webp filter=lfs diff=lfs merge=lfs -text
57
- # Video files - compressed
58
- *.mp4 filter=lfs diff=lfs merge=lfs -text
59
- *.webm filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eval-results/demo-leaderboard/gpt2-demo/results_2023-11-21T18-10-08.json DELETED
@@ -1,19 +0,0 @@
1
- {
2
- "config": {
3
- "model_name": "H2O/Mistral-7B",
4
- "model_sha": "ac3299b02780836378b9e1e68c6eead546e89f90",
5
- "method": "H2O"
6
- },
7
- "results": {
8
- "anli_r1": {
9
- "acc": 0
10
- },
11
- "logiqa": {
12
- "acc_norm": 0.90
13
- },
14
- "system":{
15
- "latency": 222,
16
- "throughput": 222
17
- }
18
- }
19
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eval-results/demo-leaderboard/gpt2-demo/results_2023-11-22 15:46:20.425378.json DELETED
@@ -1,38 +0,0 @@
1
- {
2
- "results": {
3
- "anli_r1": {
4
- "acc": 0.4,
5
- "acc_stderr": 0.11239029738980327
6
- },
7
- "logiqa": {
8
- "acc": 0.35,
9
- "acc_stderr": 0.10942433098048308,
10
- "acc_norm": 0.3,
11
- "acc_norm_stderr": 0.10513149660756933
12
- },
13
- "system":{
14
- "latency": 222,
15
- "throughput": 222
16
- }
17
- },
18
- "versions": {
19
- "anli_r1": 0,
20
- "logiqa": 0
21
- },
22
- "config": {
23
- "model": "hf-causal-experimental",
24
- "method": "H2O",
25
- "model_args": "pretrained=demo-leaderboard/gpt2-demo,revision=main,dtype=bfloat16",
26
- "num_fewshot": 0,
27
- "batch_size": 1,
28
- "batch_sizes": [],
29
- "device": "cpu",
30
- "no_cache": true,
31
- "limit": 20,
32
- "bootstrap_iters": 100000,
33
- "description_dict": null,
34
- "model_dtype": "bfloat16",
35
- "model_name": "H2O/Llama3.1-8B",
36
- "model_sha": "main"
37
- }
38
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pyproject.toml DELETED
@@ -1,13 +0,0 @@
1
- [tool.ruff]
2
- # Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default.
3
- select = ["E", "F"]
4
- ignore = ["E501"] # line too long (black is taking care of this)
5
- line-length = 119
6
- fixable = ["A", "B", "C", "D", "E", "F", "G", "I", "N", "Q", "S", "T", "W", "ANN", "ARG", "BLE", "COM", "DJ", "DTZ", "EM", "ERA", "EXE", "FBT", "ICN", "INP", "ISC", "NPY", "PD", "PGH", "PIE", "PL", "PT", "PTH", "PYI", "RET", "RSE", "RUF", "SIM", "SLF", "TCH", "TID", "TRY", "UP", "YTT"]
7
-
8
- [tool.isort]
9
- profile = "black"
10
- line_length = 119
11
-
12
- [tool.black]
13
- line-length = 119
 
 
 
 
 
 
 
 
 
 
 
 
 
 
requirements.txt DELETED
@@ -1,16 +0,0 @@
1
- APScheduler
2
- black
3
- datasets
4
- gradio
5
- gradio[oauth]
6
- gradio_leaderboard==0.0.13
7
- gradio_client
8
- huggingface-hub>=0.18.0
9
- matplotlib
10
- numpy
11
- pandas
12
- python-dateutil
13
- tqdm
14
- transformers
15
- tokenizers>=0.15.0
16
- sentencepiece
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/about.py DELETED
@@ -1,50 +0,0 @@
1
- from dataclasses import dataclass
2
- from enum import Enum
3
-
4
- @dataclass
5
- class Task:
6
- benchmark: str
7
- metric: str
8
- col_name: str
9
-
10
-
11
- # Select your tasks here
12
- # ---------------------------------------------------
13
- class Tasks(Enum):
14
- # task_key in the json file, metric_key in the json file, name to display in the leaderboard
15
- task0 = Task("anli_r1", "acc", "ANLI")
16
- task1 = Task("logiqa", "acc_norm", "LogiQA")
17
- task2 = Task("system", "latency", "E2E Latency")
18
- task3 = Task("system", "throughput", "E2E Throughput")
19
-
20
- NUM_FEWSHOT = 0 # Change with your few shot
21
- # ---------------------------------------------------
22
-
23
-
24
-
25
- # Your leaderboard name
26
- TITLE = """<h1 align="center" id="space-title">Demo leaderboard</h1>"""
27
-
28
- # What does your leaderboard evaluate?
29
- INTRODUCTION_TEXT = """
30
- Intro text
31
- """
32
-
33
- # Which evaluations are you running? how can people reproduce what you have?
34
- LLM_BENCHMARKS_TEXT = f"""
35
- ## How it works
36
-
37
- ## Reproducibility
38
- To reproduce our results, here is the commands you can run:
39
-
40
- """
41
-
42
- EVALUATION_QUEUE_TEXT = """
43
- ## Some good practices before submitting a baseline file.
44
- TODO
45
- We will run it for you offline!
46
- """
47
-
48
- CITATION_BUTTON_LABEL = "Copy the following snippet to cite these results"
49
- CITATION_BUTTON_TEXT = r"""KV Benchmark!
50
- """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/display/css_html_js.py DELETED
@@ -1,105 +0,0 @@
1
- custom_css = """
2
-
3
- .markdown-text {
4
- font-size: 16px !important;
5
- }
6
-
7
- #models-to-add-text {
8
- font-size: 18px !important;
9
- }
10
-
11
- #citation-button span {
12
- font-size: 16px !important;
13
- }
14
-
15
- #citation-button textarea {
16
- font-size: 16px !important;
17
- }
18
-
19
- #citation-button > label > button {
20
- margin: 6px;
21
- transform: scale(1.3);
22
- }
23
-
24
- #leaderboard-table {
25
- margin-top: 15px
26
- }
27
-
28
- #leaderboard-table-lite {
29
- margin-top: 15px
30
- }
31
-
32
- #search-bar-table-box > div:first-child {
33
- background: none;
34
- border: none;
35
- }
36
-
37
- #search-bar {
38
- padding: 0px;
39
- }
40
-
41
- /* Limit the width of the first AutoEvalColumn so that names don't expand too much */
42
- #leaderboard-table td:nth-child(2),
43
- #leaderboard-table th:nth-child(2) {
44
- max-width: 400px;
45
- overflow: auto;
46
- white-space: nowrap;
47
- }
48
-
49
- .tab-buttons button {
50
- font-size: 20px;
51
- }
52
-
53
- #scale-logo {
54
- border-style: none !important;
55
- box-shadow: none;
56
- display: block;
57
- margin-left: auto;
58
- margin-right: auto;
59
- max-width: 600px;
60
- }
61
-
62
- #scale-logo .download {
63
- display: none;
64
- }
65
- #filter_type{
66
- border: 0;
67
- padding-left: 0;
68
- padding-top: 0;
69
- }
70
- #filter_type label {
71
- display: flex;
72
- }
73
- #filter_type label > span{
74
- margin-top: var(--spacing-lg);
75
- margin-right: 0.5em;
76
- }
77
- #filter_type label > .wrap{
78
- width: 103px;
79
- }
80
- #filter_type label > .wrap .wrap-inner{
81
- padding: 2px;
82
- }
83
- #filter_type label > .wrap .wrap-inner input{
84
- width: 1px
85
- }
86
- #filter-columns-type{
87
- border:0;
88
- padding:0.5;
89
- }
90
- #filter-columns-size{
91
- border:0;
92
- padding:0.5;
93
- }
94
- #box-filter > .form{
95
- border: 0
96
- }
97
- """
98
-
99
- get_window_url_params = """
100
- function(url_params) {
101
- const params = new URLSearchParams(window.location.search);
102
- url_params = Object.fromEntries(params);
103
- return url_params;
104
- }
105
- """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/display/formatting.py DELETED
@@ -1,27 +0,0 @@
1
- def model_hyperlink(link, model_name):
2
- return f'<a target="_blank" href="{link}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{model_name}</a>'
3
-
4
-
5
- def make_clickable_model(model_name):
6
- link = f"https://huggingface.co/{model_name}"
7
- return model_hyperlink(link, model_name)
8
-
9
-
10
- def styled_error(error):
11
- return f"<p style='color: red; font-size: 20px; text-align: center;'>{error}</p>"
12
-
13
-
14
- def styled_warning(warn):
15
- return f"<p style='color: orange; font-size: 20px; text-align: center;'>{warn}</p>"
16
-
17
-
18
- def styled_message(message):
19
- return f"<p style='color: green; font-size: 20px; text-align: center;'>{message}</p>"
20
-
21
-
22
- def has_no_nan_values(df, columns):
23
- return df[columns].notna().all(axis=1)
24
-
25
-
26
- def has_nan_values(df, columns):
27
- return df[columns].isna().any(axis=1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/display/utils.py DELETED
@@ -1,116 +0,0 @@
1
- from dataclasses import dataclass, make_dataclass
2
- from enum import Enum
3
-
4
- import pandas as pd
5
-
6
- from src.about import Tasks
7
-
8
- def fields(raw_class):
9
- return [v for k, v in raw_class.__dict__.items() if k[:2] != "__" and k[-2:] != "__"]
10
-
11
-
12
- # These classes are for user facing column names,
13
- # to avoid having to change them all around the code
14
- # when a modif is needed
15
- @dataclass
16
- class ColumnContent:
17
- name: str
18
- type: str
19
- displayed_by_default: bool
20
- hidden: bool = False
21
- never_hidden: bool = False
22
-
23
- ## Leaderboard columns
24
- auto_eval_column_dict = []
25
- # Init
26
- auto_eval_column_dict.append(["model_type_symbol", ColumnContent, ColumnContent("T", "str", True, never_hidden=True)])
27
- auto_eval_column_dict.append(["model", ColumnContent, ColumnContent("Model", "markdown", True, never_hidden=True)])
28
- auto_eval_column_dict.append(["method", ColumnContent, ColumnContent("Method", "markdown", True, never_hidden=True)])
29
-
30
- #Scores
31
- # auto_eval_column_dict.append(["average", ColumnContent, ColumnContent("Average ⬆️", "number", True)])
32
- # auto_eval_column_dict.append(["latency", ColumnContent, ColumnContent("E2E Latency", "number", True)])
33
- # auto_eval_column_dict.append(["throughput", ColumnContent, ColumnContent("E2E Throughput", "number", True)])
34
-
35
- for task in Tasks:
36
- auto_eval_column_dict.append([task.name, ColumnContent, ColumnContent(task.value.col_name, "number", True)])
37
- # Model information
38
- auto_eval_column_dict.append(["model_type", ColumnContent, ColumnContent("Type", "str", False)])
39
- auto_eval_column_dict.append(["architecture", ColumnContent, ColumnContent("Architecture", "str", False)])
40
- auto_eval_column_dict.append(["weight_type", ColumnContent, ColumnContent("Weight type", "str", False, True)])
41
- auto_eval_column_dict.append(["precision", ColumnContent, ColumnContent("Precision", "str", False)])
42
- auto_eval_column_dict.append(["license", ColumnContent, ColumnContent("Hub License", "str", False)])
43
- auto_eval_column_dict.append(["params", ColumnContent, ColumnContent("#Params (B)", "number", False)])
44
- auto_eval_column_dict.append(["likes", ColumnContent, ColumnContent("Hub ❤️", "number", False)])
45
- auto_eval_column_dict.append(["still_on_hub", ColumnContent, ColumnContent("Available on the hub", "bool", False)])
46
- auto_eval_column_dict.append(["revision", ColumnContent, ColumnContent("Model sha", "str", False, False)])
47
-
48
- # We use make dataclass to dynamically fill the scores from Tasks
49
- AutoEvalColumn = make_dataclass("AutoEvalColumn", auto_eval_column_dict, frozen=True)
50
-
51
- ## For the queue columns in the submission tab
52
- @dataclass(frozen=True)
53
- class EvalQueueColumn: # Queue column
54
- model = ColumnContent("model", "markdown", True)
55
- revision = ColumnContent("revision", "str", True)
56
- private = ColumnContent("private", "bool", True)
57
- precision = ColumnContent("precision", "str", True)
58
- weight_type = ColumnContent("weight_type", "str", "Original")
59
- status = ColumnContent("status", "str", True)
60
-
61
- ## All the model information that we might need
62
- @dataclass
63
- class ModelDetails:
64
- name: str
65
- display_name: str = ""
66
- symbol: str = "" # emoji
67
-
68
-
69
- class ModelType(Enum):
70
- LLAMA8B = ModelDetails(name="Llama3.1-8B", symbol="🟢")
71
- MISTRAL7B = ModelDetails(name="Mistral-7B-Instruct-v0.1", symbol="🔶")
72
- #Add more models
73
- IFT = ModelDetails(name="instruction-tuned", symbol="⭕")
74
- RL = ModelDetails(name="RL-tuned", symbol="🟦")
75
- Unknown = ModelDetails(name="", symbol="?")
76
-
77
- def to_str(self, separator=" "):
78
- return f"{self.value.symbol}{separator}{self.value.name}"
79
-
80
- @staticmethod
81
- def from_str(type):
82
- print("wwww type", type)
83
- if "Mistral-7B" in type or "🔶" in type:
84
- return ModelType.MISTRAL7B
85
- if "Llama3.1-8B" in type or "🟢" in type:
86
- return ModelType.LLAMA8B
87
- if "RL-tuned" in type or "🟦" in type:
88
- return ModelType.RL
89
- if "instruction-tuned" in type or "⭕" in type:
90
- return ModelType.IFT
91
- return ModelType.Unknown
92
-
93
- class WeightType(Enum):
94
- Adapter = ModelDetails("Adapter")
95
- Original = ModelDetails("Original")
96
- Delta = ModelDetails("Delta")
97
-
98
- class Precision(Enum):
99
- float16 = ModelDetails("float16")
100
- bfloat16 = ModelDetails("bfloat16")
101
- Unknown = ModelDetails("?")
102
-
103
- def from_str(precision):
104
- if precision in ["torch.float16", "float16"]:
105
- return Precision.float16
106
- if precision in ["torch.bfloat16", "bfloat16"]:
107
- return Precision.bfloat16
108
- return Precision.Unknown
109
-
110
- # Column selection
111
- COLS = [c.name for c in fields(AutoEvalColumn) if not c.hidden]
112
-
113
- EVAL_COLS = [c.name for c in fields(EvalQueueColumn)]
114
- EVAL_TYPES = [c.type for c in fields(EvalQueueColumn)]
115
-
116
- BENCHMARK_COLS = [t.value.col_name for t in Tasks]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/envs.py DELETED
@@ -1,25 +0,0 @@
1
- import os
2
-
3
- from huggingface_hub import HfApi
4
-
5
- # Info to change for your repository
6
- # ----------------------------------
7
- TOKEN = os.environ.get("HF_TOKEN") # A read/write token for your org
8
-
9
- OWNER = "lmcache-benchmark" # Change to your org - don't forget to create a results and request dataset, with the correct format!
10
- # ----------------------------------
11
-
12
- REPO_ID = f"{OWNER}/leaderboard"
13
- QUEUE_REPO = f"{OWNER}/requests"
14
- RESULTS_REPO = f"{OWNER}/results"
15
-
16
- # If you setup a cache later, just change HF_HOME
17
- CACHE_PATH=os.getenv("HF_HOME", ".")
18
-
19
- # Local caches
20
- EVAL_REQUESTS_PATH = os.path.join(CACHE_PATH, "eval-queue")
21
- EVAL_RESULTS_PATH = os.path.join(CACHE_PATH, "eval-results")
22
- EVAL_REQUESTS_PATH_BACKEND = os.path.join(CACHE_PATH, "eval-queue-bk")
23
- EVAL_RESULTS_PATH_BACKEND = os.path.join(CACHE_PATH, "eval-results-bk")
24
-
25
- API = HfApi(token=TOKEN)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/leaderboard/read_evals.py DELETED
@@ -1,201 +0,0 @@
1
- import glob
2
- import json
3
- import math
4
- import os
5
- from dataclasses import dataclass
6
-
7
- import dateutil
8
- import numpy as np
9
-
10
- from src.display.formatting import make_clickable_model
11
- from src.display.utils import AutoEvalColumn, ModelType, Tasks, Precision, WeightType
12
- from src.submission.check_validity import is_model_on_hub
13
-
14
-
15
- @dataclass
16
- class EvalResult:
17
- """Represents one full evaluation. Built from a combination of the result and request file for a given run.
18
- """
19
- eval_name: str # org_model_precision (uid)
20
- full_model: str # org/model (path on hub)
21
- org: str
22
- model: str
23
- revision: str # commit hash, "" if main
24
- results: dict
25
- method: str = "Placeholder"
26
- precision: Precision = Precision.Unknown
27
- model_type: ModelType = ModelType.Unknown # Pretrained, fine tuned, ...
28
- weight_type: WeightType = WeightType.Original # Original or Adapter
29
- architecture: str = "Unknown"
30
- license: str = "?"
31
- likes: int = 0
32
- num_params: int = 0
33
- date: str = "" # submission date of request file
34
- still_on_hub: bool = False
35
-
36
- @classmethod
37
- def init_from_json_file(self, json_filepath):
38
- """Inits the result from the specific model result file"""
39
- with open(json_filepath) as fp:
40
- data = json.load(fp)
41
-
42
- config = data.get("config")
43
-
44
- # Precision
45
- precision = Precision.from_str(config.get("model_dtype"))
46
- method = config.get("method")
47
-
48
- # Get model and org
49
- org_and_model = config.get("model_name", config.get("model_args", None))
50
- org_and_model = org_and_model.split("/", 1)
51
-
52
- if len(org_and_model) == 1:
53
- org = None
54
- model = org_and_model[0]
55
- result_key = f"{model}_{precision.value.name}"
56
- else:
57
- org = org_and_model[0]
58
- model = org_and_model[1]
59
- result_key = f"{org}_{model}_{precision.value.name}"
60
- full_model = "/".join(org_and_model)
61
-
62
- still_on_hub, _, model_config = is_model_on_hub(
63
- full_model, config.get("model_sha", "main"), trust_remote_code=True, test_tokenizer=False
64
- )
65
- architecture = "?"
66
- if model_config is not None:
67
- architectures = getattr(model_config, "architectures", None)
68
- if architectures:
69
- architecture = ";".join(architectures)
70
-
71
-
72
- # Extract results available in this file (some results are split in several files)
73
- results = {}
74
- for task in Tasks:
75
- task = task.value
76
-
77
- # We average all scores of a given metric (not all metrics are present in all files)
78
- accs = np.array([v.get(task.metric, None) for k, v in data["results"].items() if task.benchmark == k])
79
- if accs.size == 0 or any([acc is None for acc in accs]):
80
- continue
81
-
82
- mean_acc = np.mean(accs) * 100.0
83
- results[task.benchmark] = mean_acc
84
-
85
- return self(
86
- eval_name=result_key,
87
- full_model=full_model,
88
- org=org,
89
- model=model,
90
- results=results,
91
- precision=precision,
92
- method = method,
93
- revision= config.get("model_sha", ""),
94
- still_on_hub=still_on_hub,
95
- architecture=architecture
96
- )
97
-
98
- def update_with_request_file(self, requests_path):
99
- """Finds the relevant request file for the current model and updates info with it"""
100
- request_file = get_request_file_for_model(requests_path, self.full_model, self.method, self.precision.value.name)
101
-
102
- try:
103
- with open(request_file, "r") as f:
104
- request = json.load(f)
105
- self.model_type = ModelType.from_str(request.get("model_type", ""))
106
- print("WTF", self.model_type)
107
- self.weight_type = WeightType[request.get("weight_type", "Original")]
108
- self.license = request.get("license", "?")
109
- self.likes = request.get("likes", 0)
110
- self.num_params = request.get("params", 0)
111
- self.date = request.get("submitted_time", "")
112
- except Exception:
113
- print(f"Could not find request file for {self.org}/{self.model} with precision {self.precision.value.name}")
114
-
115
- def to_dict(self):
116
- """Converts the Eval Result to a dict compatible with our dataframe display"""
117
- data_dict = {
118
- "eval_name": self.eval_name, # not a column, just a save name,
119
- AutoEvalColumn.precision.name: self.precision.value.name,
120
- AutoEvalColumn.model_type.name: self.model_type.value.name,
121
- AutoEvalColumn.model_type_symbol.name: self.model_type.value.symbol,
122
- AutoEvalColumn.method.name: self.method,
123
- AutoEvalColumn.weight_type.name: self.weight_type.value.name,
124
- AutoEvalColumn.architecture.name: self.architecture,
125
- AutoEvalColumn.model.name: make_clickable_model(self.full_model),
126
- AutoEvalColumn.revision.name: self.revision,
127
- AutoEvalColumn.license.name: self.license,
128
- AutoEvalColumn.likes.name: self.likes,
129
- AutoEvalColumn.params.name: self.num_params,
130
- AutoEvalColumn.still_on_hub.name: self.still_on_hub,
131
- }
132
-
133
- for task in Tasks:
134
- data_dict[task.value.col_name] = self.results[task.value.benchmark]
135
-
136
- return data_dict
137
-
138
-
139
- def get_request_file_for_model(requests_path, model_name, method, precision):
140
- """Selects the correct request file for a given model. Only keeps runs tagged as FINISHED"""
141
- request_files = os.path.join(
142
- requests_path,
143
- f"{model_name}_eval_request_*.json",
144
- )
145
- print(request_files)
146
-
147
- request_files = glob.glob(request_files)
148
-
149
- # Select correct request file (precision)
150
- request_file = ""
151
- request_files = sorted(request_files, reverse=True)
152
- for tmp_request_file in request_files:
153
- with open(tmp_request_file, "r") as f:
154
- req_content = json.load(f)
155
- if (
156
- req_content["status"] in ["FINISHED"]
157
- ):
158
- request_file = tmp_request_file
159
- return request_file
160
-
161
-
162
- def get_raw_eval_results(results_path: str, requests_path: str) -> list[EvalResult]:
163
- """From the path of the results folder root, extract all needed info for results"""
164
- model_result_filepaths = []
165
-
166
- for root, _, files in os.walk(results_path):
167
- # We should only have json files in model results
168
- if len(files) == 0 or any([not f.endswith(".json") for f in files]):
169
- continue
170
-
171
- # Sort the files by date
172
- try:
173
- files.sort(key=lambda x: x.removesuffix(".json").removeprefix("results_")[:-7])
174
- except dateutil.parser._parser.ParserError:
175
- files = [files[-1]]
176
-
177
- for file in files:
178
- model_result_filepaths.append(os.path.join(root, file))
179
-
180
- eval_results = {}
181
- for model_result_filepath in model_result_filepaths:
182
- # Creation of result
183
- eval_result = EvalResult.init_from_json_file(model_result_filepath)
184
- eval_result.update_with_request_file(requests_path)
185
-
186
- # Store results of same eval together
187
- eval_name = eval_result.eval_name
188
- if eval_name in eval_results.keys():
189
- eval_results[eval_name].results.update({k: v for k, v in eval_result.results.items() if v is not None})
190
- else:
191
- eval_results[eval_name] = eval_result
192
-
193
- results = []
194
- for v in eval_results.values():
195
- try:
196
- v.to_dict() # we test if the dict version is complete
197
- results.append(v)
198
- except KeyError: # not all eval values present
199
- continue
200
-
201
- return results
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/populate.py DELETED
@@ -1,58 +0,0 @@
1
- import json
2
- import os
3
-
4
- import pandas as pd
5
-
6
- from src.display.formatting import has_no_nan_values, make_clickable_model
7
- from src.display.utils import AutoEvalColumn, EvalQueueColumn
8
- from src.leaderboard.read_evals import get_raw_eval_results
9
-
10
-
11
- def get_leaderboard_df(results_path: str, requests_path: str, cols: list, benchmark_cols: list) -> pd.DataFrame:
12
- """Creates a dataframe from all the individual experiment results"""
13
- raw_data = get_raw_eval_results(results_path, requests_path)
14
- all_data_json = [v.to_dict() for v in raw_data]
15
-
16
- df = pd.DataFrame.from_records(all_data_json)
17
- print(df.columns)
18
- df = df[cols].round(decimals=2)
19
-
20
- # filter out if any of the benchmarks have not been produced
21
- df = df[has_no_nan_values(df, benchmark_cols)]
22
- return df
23
-
24
-
25
- def get_evaluation_queue_df(save_path: str, cols: list) -> list[pd.DataFrame]:
26
- """Creates the different dataframes for the evaluation queues requestes"""
27
- entries = [entry for entry in os.listdir(save_path) if not entry.startswith(".")]
28
- all_evals = []
29
-
30
- for entry in entries:
31
- if ".json" in entry:
32
- file_path = os.path.join(save_path, entry)
33
- with open(file_path) as fp:
34
- data = json.load(fp)
35
-
36
- data[EvalQueueColumn.model.name] = make_clickable_model(data["model"])
37
- data[EvalQueueColumn.revision.name] = data.get("revision", "main")
38
-
39
- all_evals.append(data)
40
- elif ".md" not in entry:
41
- # this is a folder
42
- sub_entries = [e for e in os.listdir(f"{save_path}/{entry}") if os.path.isfile(e) and not e.startswith(".")]
43
- for sub_entry in sub_entries:
44
- file_path = os.path.join(save_path, entry, sub_entry)
45
- with open(file_path) as fp:
46
- data = json.load(fp)
47
-
48
- data[EvalQueueColumn.model.name] = make_clickable_model(data["model"])
49
- data[EvalQueueColumn.revision.name] = data.get("revision", "main")
50
- all_evals.append(data)
51
-
52
- pending_list = [e for e in all_evals if e["status"] in ["PENDING", "RERUN"]]
53
- running_list = [e for e in all_evals if e["status"] == "RUNNING"]
54
- finished_list = [e for e in all_evals if e["status"].startswith("FINISHED") or e["status"] == "PENDING_NEW_EVAL"]
55
- df_pending = pd.DataFrame.from_records(pending_list, columns=cols)
56
- df_running = pd.DataFrame.from_records(running_list, columns=cols)
57
- df_finished = pd.DataFrame.from_records(finished_list, columns=cols)
58
- return df_finished[cols], df_running[cols], df_pending[cols]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/submission/check_validity.py DELETED
@@ -1,99 +0,0 @@
1
- import json
2
- import os
3
- import re
4
- from collections import defaultdict
5
- from datetime import datetime, timedelta, timezone
6
-
7
- import huggingface_hub
8
- from huggingface_hub import ModelCard
9
- from huggingface_hub.hf_api import ModelInfo
10
- from transformers import AutoConfig
11
- from transformers.models.auto.tokenization_auto import AutoTokenizer
12
-
13
- def check_model_card(repo_id: str) -> tuple[bool, str]:
14
- """Checks if the model card and license exist and have been filled"""
15
- try:
16
- card = ModelCard.load(repo_id)
17
- except huggingface_hub.utils.EntryNotFoundError:
18
- return False, "Please add a model card to your model to explain how you trained/fine-tuned it."
19
-
20
- # Enforce license metadata
21
- if card.data.license is None:
22
- if not ("license_name" in card.data and "license_link" in card.data):
23
- return False, (
24
- "License not found. Please add a license to your model card using the `license` metadata or a"
25
- " `license_name`/`license_link` pair."
26
- )
27
-
28
- # Enforce card content
29
- if len(card.text) < 200:
30
- return False, "Please add a description to your model card, it is too short."
31
-
32
- return True, ""
33
-
34
- def is_model_on_hub(model_name: str, revision: str, token: str = None, trust_remote_code=False, test_tokenizer=False) -> tuple[bool, str]:
35
- """Checks if the model model_name is on the hub, and whether it (and its tokenizer) can be loaded with AutoClasses."""
36
- try:
37
- config = AutoConfig.from_pretrained(model_name, revision=revision, trust_remote_code=trust_remote_code, token=token)
38
- if test_tokenizer:
39
- try:
40
- tk = AutoTokenizer.from_pretrained(model_name, revision=revision, trust_remote_code=trust_remote_code, token=token)
41
- except ValueError as e:
42
- return (
43
- False,
44
- f"uses a tokenizer which is not in a transformers release: {e}",
45
- None
46
- )
47
- except Exception as e:
48
- return (False, "'s tokenizer cannot be loaded. Is your tokenizer class in a stable transformers release, and correctly configured?", None)
49
- return True, None, config
50
-
51
- except ValueError:
52
- return (
53
- False,
54
- "needs to be launched with `trust_remote_code=True`. For safety reason, we do not allow these models to be automatically submitted to the leaderboard.",
55
- None
56
- )
57
-
58
- except Exception as e:
59
- return False, "was not found on hub!", None
60
-
61
-
62
- def get_model_size(model_info: ModelInfo, precision: str):
63
- """Gets the model size from the configuration, or the model name if the configuration does not contain the information."""
64
- try:
65
- model_size = round(model_info.safetensors["total"] / 1e9, 3)
66
- except (AttributeError, TypeError):
67
- return 0 # Unknown model sizes are indicated as 0, see NUMERIC_INTERVALS in app.py
68
-
69
- size_factor = 8 if (precision == "GPTQ" or "gptq" in model_info.modelId.lower()) else 1
70
- model_size = size_factor * model_size
71
- return model_size
72
-
73
- def get_model_arch(model_info: ModelInfo):
74
- """Gets the model architecture from the configuration"""
75
- return model_info.config.get("architectures", "Unknown")
76
-
77
- def already_submitted_models(requested_models_dir: str) -> set[str]:
78
- """Gather a list of already submitted models to avoid duplicates"""
79
- depth = 1
80
- file_names = []
81
- users_to_submission_dates = defaultdict(list)
82
-
83
- for root, _, files in os.walk(requested_models_dir):
84
- current_depth = root.count(os.sep) - requested_models_dir.count(os.sep)
85
- if current_depth == depth:
86
- for file in files:
87
- if not file.endswith(".json"):
88
- continue
89
- with open(os.path.join(root, file), "r") as f:
90
- info = json.load(f)
91
- file_names.append(f"{info['model']}_{info['revision']}_{info['precision']}")
92
-
93
- # Select organisation
94
- if info["model"].count("/") == 0 or "submitted_time" not in info:
95
- continue
96
- organisation, _ = info["model"].split("/")
97
- users_to_submission_dates[organisation].append(info["submitted_time"])
98
-
99
- return set(file_names), users_to_submission_dates
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/submission/submit.py DELETED
@@ -1,56 +0,0 @@
1
- import json
2
- import os
3
- from datetime import datetime, timezone
4
- from huggingface_hub import Repository
5
-
6
- from src.display.formatting import styled_error, styled_message, styled_warning
7
- from src.envs import API, EVAL_REQUESTS_PATH, TOKEN, QUEUE_REPO
8
- from src.submission.check_validity import (
9
- already_submitted_models,
10
- check_model_card,
11
- get_model_size,
12
- is_model_on_hub,
13
- )
14
-
15
- REQUESTED_MODELS = None
16
- USERS_TO_SUBMISSION_DATES = None
17
-
18
- def write_strings_to_dataset(dataset_repo: str, file_name: str, strings: list):
19
- """
20
- Write strings to a new file in a Hugging Face dataset repository.
21
-
22
- Args:
23
- dataset_repo (str): Repository name (e.g., "username/dataset_name").
24
- file_name (str): Name of the new file to create.
25
- strings (list): List of strings to write to the file.
26
- token (str): Hugging Face token for authentication.
27
- """
28
- # Clone the repository locally
29
- repo = Repository(local_dir="dataset_repo", clone_from=dataset_repo)
30
- repo.git_pull() # Ensure you have the latest changes
31
-
32
- # Write strings to the new file
33
- file_path = f"dataset_repo/{file_name}"
34
- with open(file_path, "w") as f:
35
- f.write("\n".join(strings))
36
-
37
- # Commit and push the new file to the repository
38
- repo.git_add(file_name)
39
- repo.git_commit(f"Add new file: {file_name}")
40
- repo.git_push()
41
-
42
- def add_new_eval(
43
- method: str,
44
- paper: str,
45
- revision: str,
46
- model_type: str,
47
- file_link: str,
48
- explanation: str,
49
- ):
50
- str_list = [method, paper, revision, model_type, file_link, explanation]
51
- submission_dataset = "https://huggingface.co/datasets/lmcache-benchmark/submissions"
52
- write_strings_to_dataset(submission_dataset, f"{method}_{model_type}_{revision}_record", str_list)
53
-
54
- return styled_message(
55
- "Your request has been submitted to the evaluation queue!\nPlease wait for up to an hour for the model to show in the PENDING list."
56
- )