ArunkumarVR edbeeching HF staff commited on
Commit
19040b4
0 Parent(s):

Duplicate from HuggingFaceH4/open_llm_leaderboard

Browse files

Co-authored-by: Edward Beeching <edbeeching@users.noreply.huggingface.co>

Files changed (7) hide show
  1. .gitattributes +34 -0
  2. .gitignore +6 -0
  3. README.md +14 -0
  4. app.py +491 -0
  5. content.py +130 -0
  6. requirements.txt +67 -0
  7. utils.py +157 -0
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
.gitignore ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ evals/
2
+ venv/
3
+ __pycache__/
4
+ .env
5
+ .ipynb_checkpoints
6
+ *ipynb
README.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Open LLM Leaderboard
3
+ emoji: 🏆
4
+ colorFrom: green
5
+ colorTo: indigo
6
+ sdk: gradio
7
+ sdk_version: 3.27.0
8
+ app_file: app.py
9
+ pinned: true
10
+ license: apache-2.0
11
+ duplicated_from: HuggingFaceH4/open_llm_leaderboard
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,491 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import json
3
+ from datetime import datetime, timezone
4
+
5
+ import numpy as np
6
+ import gradio as gr
7
+ import pandas as pd
8
+
9
+ from apscheduler.schedulers.background import BackgroundScheduler
10
+ from content import *
11
+ from huggingface_hub import Repository, HfApi
12
+ from transformers import AutoConfig
13
+ from utils import get_eval_results_dicts, make_clickable_model
14
+
15
+ # clone / pull the lmeh eval data
16
+ H4_TOKEN = os.environ.get("H4_TOKEN", None)
17
+ LMEH_REPO = "HuggingFaceH4/lmeh_evaluations"
18
+ IS_PUBLIC = bool(os.environ.get("IS_PUBLIC", None))
19
+
20
+ api = HfApi()
21
+
22
+
23
+ def restart_space():
24
+ api.restart_space(repo_id="HuggingFaceH4/open_llm_leaderboard", token=H4_TOKEN)
25
+
26
+
27
+ def get_all_requested_models(requested_models_dir):
28
+ depth = 1
29
+ file_names = []
30
+
31
+ for root, dirs, files in os.walk(requested_models_dir):
32
+ current_depth = root.count(os.sep) - requested_models_dir.count(os.sep)
33
+ if current_depth == depth:
34
+ file_names.extend([os.path.join(root, file) for file in files])
35
+
36
+ return set([file_name.lower().split("./evals/")[1] for file_name in file_names])
37
+
38
+
39
+ repo = None
40
+ requested_models = None
41
+ if H4_TOKEN:
42
+ print("Pulling evaluation requests and results.")
43
+ # try:
44
+ # shutil.rmtree("./evals/")
45
+ # except:
46
+ # pass
47
+
48
+ repo = Repository(
49
+ local_dir="./evals/",
50
+ clone_from=LMEH_REPO,
51
+ use_auth_token=H4_TOKEN,
52
+ repo_type="dataset",
53
+ )
54
+ repo.git_pull()
55
+
56
+ requested_models_dir = "./evals/eval_requests"
57
+ requested_models = get_all_requested_models(requested_models_dir)
58
+
59
+
60
+ # parse the results
61
+ BENCHMARKS = ["arc_challenge", "hellaswag", "hendrycks", "truthfulqa_mc"]
62
+ METRICS = ["acc_norm", "acc_norm", "acc_norm", "mc2"]
63
+
64
+
65
+ def load_results(model, benchmark, metric):
66
+ file_path = os.path.join("evals", model, f"{model}-eval_{benchmark}.json")
67
+ if not os.path.exists(file_path):
68
+ return 0.0, None
69
+
70
+ with open(file_path) as fp:
71
+ data = json.load(fp)
72
+ accs = np.array([v[metric] for k, v in data["results"].items()])
73
+ mean_acc = np.mean(accs)
74
+ return mean_acc, data["config"]["model_args"]
75
+
76
+
77
+ COLS = [
78
+ "Model",
79
+ "Revision",
80
+ "Average ⬆️",
81
+ "ARC (25-shot) ⬆️",
82
+ "HellaSwag (10-shot) ⬆️",
83
+ "MMLU (5-shot) ⬆️",
84
+ "TruthfulQA (0-shot) ⬆️",
85
+ "model_name_for_query", # dummy column to implement search bar (hidden by custom CSS)
86
+ ]
87
+ TYPES = ["markdown", "str", "number", "number", "number", "number", "number", "str"]
88
+
89
+ if not IS_PUBLIC:
90
+ COLS.insert(2, "8bit")
91
+ TYPES.insert(2, "bool")
92
+
93
+ EVAL_COLS = ["model", "revision", "private", "8bit_eval", "is_delta_weight", "status"]
94
+ EVAL_TYPES = ["markdown", "str", "bool", "bool", "bool", "str"]
95
+
96
+ BENCHMARK_COLS = [
97
+ "ARC (25-shot) ⬆️",
98
+ "HellaSwag (10-shot) ⬆️",
99
+ "MMLU (5-shot) ⬆️",
100
+ "TruthfulQA (0-shot) ⬆️",
101
+ ]
102
+
103
+
104
+ def has_no_nan_values(df, columns):
105
+ return df[columns].notna().all(axis=1)
106
+
107
+
108
+ def has_nan_values(df, columns):
109
+ return df[columns].isna().any(axis=1)
110
+
111
+
112
+ def get_leaderboard_df():
113
+ if repo:
114
+ print("Pulling evaluation results for the leaderboard.")
115
+ repo.git_pull()
116
+
117
+ all_data = get_eval_results_dicts(IS_PUBLIC)
118
+
119
+ if not IS_PUBLIC:
120
+ gpt4_values = {
121
+ "Model": f'<a target="_blank" href=https://arxiv.org/abs/2303.08774 style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">gpt4</a>',
122
+ "Revision": "tech report",
123
+ "8bit": None,
124
+ "Average ⬆️": 84.3,
125
+ "ARC (25-shot) ⬆️": 96.3,
126
+ "HellaSwag (10-shot) ⬆️": 95.3,
127
+ "MMLU (5-shot) ⬆️": 86.4,
128
+ "TruthfulQA (0-shot) ⬆️": 59.0,
129
+ "model_name_for_query": "GPT-4",
130
+ }
131
+ all_data.append(gpt4_values)
132
+ gpt35_values = {
133
+ "Model": f'<a target="_blank" href=https://arxiv.org/abs/2303.08774 style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">gpt3.5</a>',
134
+ "Revision": "tech report",
135
+ "8bit": None,
136
+ "Average ⬆️": 71.9,
137
+ "ARC (25-shot) ⬆️": 85.2,
138
+ "HellaSwag (10-shot) ⬆️": 85.5,
139
+ "MMLU (5-shot) ⬆️": 70.0,
140
+ "TruthfulQA (0-shot) ⬆️": 47.0,
141
+ "model_name_for_query": "GPT-3.5",
142
+ }
143
+ all_data.append(gpt35_values)
144
+
145
+ base_line = {
146
+ "Model": "<p>Baseline</p>",
147
+ "Revision": "N/A",
148
+ "8bit": None,
149
+ "Average ⬆️": 25.0,
150
+ "ARC (25-shot) ⬆️": 25.0,
151
+ "HellaSwag (10-shot) ⬆️": 25.0,
152
+ "MMLU (5-shot) ⬆️": 25.0,
153
+ "TruthfulQA (0-shot) ⬆️": 25.0,
154
+ "model_name_for_query": "baseline",
155
+ }
156
+
157
+ all_data.append(base_line)
158
+
159
+ df = pd.DataFrame.from_records(all_data)
160
+ df = df.sort_values(by=["Average ⬆️"], ascending=False)
161
+ df = df[COLS]
162
+
163
+ # filter out if any of the benchmarks have not been produced
164
+ df = df[has_no_nan_values(df, BENCHMARK_COLS)]
165
+ return df
166
+
167
+
168
+ def get_evaluation_queue_df():
169
+ if repo:
170
+ print("Pulling changes for the evaluation queue.")
171
+ repo.git_pull()
172
+
173
+ entries = [
174
+ entry
175
+ for entry in os.listdir("evals/eval_requests")
176
+ if not entry.startswith(".")
177
+ ]
178
+ all_evals = []
179
+
180
+ for entry in entries:
181
+ if ".json" in entry:
182
+ file_path = os.path.join("evals/eval_requests", entry)
183
+ with open(file_path) as fp:
184
+ data = json.load(fp)
185
+
186
+ data["# params"] = "unknown"
187
+ data["model"] = make_clickable_model(data["model"])
188
+ data["revision"] = data.get("revision", "main")
189
+
190
+ all_evals.append(data)
191
+ else:
192
+ # this is a folder
193
+ sub_entries = [
194
+ e
195
+ for e in os.listdir(f"evals/eval_requests/{entry}")
196
+ if not e.startswith(".")
197
+ ]
198
+ for sub_entry in sub_entries:
199
+ file_path = os.path.join("evals/eval_requests", entry, sub_entry)
200
+ with open(file_path) as fp:
201
+ data = json.load(fp)
202
+
203
+ # data["# params"] = get_n_params(data["model"])
204
+ data["model"] = make_clickable_model(data["model"])
205
+ all_evals.append(data)
206
+
207
+ pending_list = [e for e in all_evals if e["status"] == "PENDING"]
208
+ running_list = [e for e in all_evals if e["status"] == "RUNNING"]
209
+ finished_list = [e for e in all_evals if e["status"] == "FINISHED"]
210
+ df_pending = pd.DataFrame.from_records(pending_list)
211
+ df_running = pd.DataFrame.from_records(running_list)
212
+ df_finished = pd.DataFrame.from_records(finished_list)
213
+ return df_finished[EVAL_COLS], df_running[EVAL_COLS], df_pending[EVAL_COLS]
214
+
215
+
216
+ original_df = get_leaderboard_df()
217
+ leaderboard_df = original_df.copy()
218
+ (
219
+ finished_eval_queue_df,
220
+ running_eval_queue_df,
221
+ pending_eval_queue_df,
222
+ ) = get_evaluation_queue_df()
223
+
224
+
225
+ def is_model_on_hub(model_name, revision) -> bool:
226
+ try:
227
+ config = AutoConfig.from_pretrained(model_name, revision=revision)
228
+ return True
229
+
230
+ except Exception as e:
231
+ print("Could not get the model config from the hub.")
232
+ print(e)
233
+ return False
234
+
235
+
236
+ def add_new_eval(
237
+ model: str,
238
+ base_model: str,
239
+ revision: str,
240
+ is_8_bit_eval: bool,
241
+ private: bool,
242
+ is_delta_weight: bool,
243
+ ):
244
+ current_time = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
245
+
246
+ # check the model actually exists before adding the eval
247
+ if revision == "":
248
+ revision = "main"
249
+ if is_delta_weight and not is_model_on_hub(base_model, revision):
250
+ error_message = f'Base model "{base_model}" was not found on hub!'
251
+ print(error_message)
252
+ return f"<p style='color: red; font-size: 20px; text-align: center;'>{error_message}</p>"
253
+
254
+ if not is_model_on_hub(model, revision):
255
+ error_message = f'Model "{model}"was not found on hub!'
256
+ return f"<p style='color: red; font-size: 20px; text-align: center;'>{error_message}</p>"
257
+
258
+ print("adding new eval")
259
+
260
+ eval_entry = {
261
+ "model": model,
262
+ "base_model": base_model,
263
+ "revision": revision,
264
+ "private": private,
265
+ "8bit_eval": is_8_bit_eval,
266
+ "is_delta_weight": is_delta_weight,
267
+ "status": "PENDING",
268
+ "submitted_time": current_time,
269
+ }
270
+
271
+ user_name = ""
272
+ model_path = model
273
+ if "/" in model:
274
+ user_name = model.split("/")[0]
275
+ model_path = model.split("/")[1]
276
+
277
+ OUT_DIR = f"eval_requests/{user_name}"
278
+ os.makedirs(OUT_DIR, exist_ok=True)
279
+ out_path = f"{OUT_DIR}/{model_path}_eval_request_{private}_{is_8_bit_eval}_{is_delta_weight}.json"
280
+
281
+ # Check for duplicate submission
282
+ if out_path.lower() in requested_models:
283
+ duplicate_request_message = "This model has been already submitted."
284
+ return f"<p style='color: orange; font-size: 20px; text-align: center;'>{duplicate_request_message}</p>"
285
+
286
+ with open(out_path, "w") as f:
287
+ f.write(json.dumps(eval_entry))
288
+
289
+ api.upload_file(
290
+ path_or_fileobj=out_path,
291
+ path_in_repo=out_path,
292
+ repo_id=LMEH_REPO,
293
+ token=H4_TOKEN,
294
+ repo_type="dataset",
295
+ )
296
+
297
+ success_message = "Your request has been submitted to the evaluation queue!"
298
+ return f"<p style='color: green; font-size: 20px; text-align: center;'>{success_message}</p>"
299
+
300
+
301
+ def refresh():
302
+ leaderboard_df = get_leaderboard_df()
303
+ (
304
+ finished_eval_queue_df,
305
+ running_eval_queue_df,
306
+ pending_eval_queue_df,
307
+ ) = get_evaluation_queue_df()
308
+ return (
309
+ leaderboard_df,
310
+ finished_eval_queue_df,
311
+ running_eval_queue_df,
312
+ pending_eval_queue_df,
313
+ )
314
+
315
+
316
+ def search_table(df, query):
317
+ filtered_df = df[df["model_name_for_query"].str.contains(query, case=False)]
318
+ return filtered_df
319
+
320
+
321
+ custom_css = """
322
+ #changelog-text {
323
+ font-size: 16px !important;
324
+ }
325
+
326
+ #changelog-text h2 {
327
+ font-size: 18px !important;
328
+ }
329
+
330
+ .markdown-text {
331
+ font-size: 16px !important;
332
+ }
333
+
334
+ #citation-button span {
335
+ font-size: 16px !important;
336
+ }
337
+
338
+ #citation-button textarea {
339
+ font-size: 16px !important;
340
+ }
341
+
342
+ #citation-button > label > button {
343
+ margin: 6px;
344
+ transform: scale(1.3);
345
+ }
346
+
347
+ #leaderboard-table {
348
+ margin-top: 15px
349
+ }
350
+
351
+ #search-bar-table-box > div:first-child {
352
+ background: none;
353
+ border: none;
354
+ }
355
+
356
+ #search-bar {
357
+ padding: 0px;
358
+ width: 30%;
359
+ }
360
+
361
+ /* Hides the final column */
362
+ table td:last-child,
363
+ table th:last-child {
364
+ display: none;
365
+ }
366
+
367
+
368
+ /* Limit the width of the first column so that names don't expand too much */
369
+ table td:first-child,
370
+ table th:first-child {
371
+ max-width: 400px;
372
+ overflow: auto;
373
+ white-space: nowrap;
374
+ }
375
+
376
+ """
377
+
378
+
379
+ demo = gr.Blocks(css=custom_css)
380
+ with demo:
381
+ gr.HTML(TITLE)
382
+ gr.Markdown(INTRODUCTION_TEXT, elem_classes="markdown-text")
383
+
384
+ with gr.Row():
385
+ with gr.Column():
386
+ with gr.Accordion("📙 Citation", open=False):
387
+ citation_button = gr.Textbox(
388
+ value=CITATION_BUTTON_TEXT,
389
+ label=CITATION_BUTTON_LABEL,
390
+ elem_id="citation-button",
391
+ ).style(show_copy_button=True)
392
+ with gr.Column():
393
+ with gr.Accordion("✨ CHANGELOG", open=False):
394
+ changelog = gr.Markdown(CHANGELOG_TEXT, elem_id="changelog-text")
395
+
396
+ with gr.Box(elem_id="search-bar-table-box"):
397
+ search_bar = gr.Textbox(
398
+ placeholder="🔍 Search your model and press ENTER...",
399
+ show_label=False,
400
+ elem_id="search-bar",
401
+ )
402
+
403
+ leaderboard_table = gr.components.Dataframe(
404
+ value=leaderboard_df,
405
+ headers=COLS,
406
+ datatype=TYPES,
407
+ max_rows=5,
408
+ elem_id="leaderboard-table",
409
+ )
410
+
411
+ # Dummy leaderboard for handling the case when the user uses backspace key
412
+ hidden_leaderboard_table_for_search = gr.components.Dataframe(
413
+ value=original_df, headers=COLS, datatype=TYPES, max_rows=5, visible=False
414
+ )
415
+
416
+ search_bar.submit(
417
+ search_table,
418
+ [hidden_leaderboard_table_for_search, search_bar],
419
+ leaderboard_table,
420
+ )
421
+
422
+ gr.Markdown(EVALUATION_QUEUE_TEXT, elem_classes="markdown-text")
423
+
424
+ with gr.Accordion("✅ Finished Evaluations", open=False):
425
+ finished_eval_table = gr.components.Dataframe(
426
+ value=finished_eval_queue_df,
427
+ headers=EVAL_COLS,
428
+ datatype=EVAL_TYPES,
429
+ max_rows=5,
430
+ )
431
+ with gr.Accordion("🔄 Running Evaluation Queue", open=False):
432
+ running_eval_table = gr.components.Dataframe(
433
+ value=running_eval_queue_df,
434
+ headers=EVAL_COLS,
435
+ datatype=EVAL_TYPES,
436
+ max_rows=5,
437
+ )
438
+
439
+ with gr.Accordion("⏳ Pending Evaluation Queue", open=False):
440
+ pending_eval_table = gr.components.Dataframe(
441
+ value=pending_eval_queue_df,
442
+ headers=EVAL_COLS,
443
+ datatype=EVAL_TYPES,
444
+ max_rows=5,
445
+ )
446
+
447
+ refresh_button = gr.Button("Refresh")
448
+ refresh_button.click(
449
+ refresh,
450
+ inputs=[],
451
+ outputs=[
452
+ leaderboard_table,
453
+ finished_eval_table,
454
+ running_eval_table,
455
+ pending_eval_table,
456
+ ],
457
+ )
458
+
459
+ with gr.Accordion("Submit a new model for evaluation"):
460
+ with gr.Row():
461
+ with gr.Column():
462
+ model_name_textbox = gr.Textbox(label="Model name")
463
+ revision_name_textbox = gr.Textbox(label="revision", placeholder="main")
464
+
465
+ with gr.Column():
466
+ is_8bit_toggle = gr.Checkbox(
467
+ False, label="8 bit eval", visible=not IS_PUBLIC
468
+ )
469
+ private = gr.Checkbox(False, label="Private", visible=not IS_PUBLIC)
470
+ is_delta_weight = gr.Checkbox(False, label="Delta weights")
471
+ base_model_name_textbox = gr.Textbox(label="base model (for delta)")
472
+
473
+ submit_button = gr.Button("Submit Eval")
474
+ submission_result = gr.Markdown()
475
+ submit_button.click(
476
+ add_new_eval,
477
+ [
478
+ model_name_textbox,
479
+ base_model_name_textbox,
480
+ revision_name_textbox,
481
+ is_8bit_toggle,
482
+ private,
483
+ is_delta_weight,
484
+ ],
485
+ submission_result,
486
+ )
487
+
488
+ scheduler = BackgroundScheduler()
489
+ scheduler.add_job(restart_space, "interval", seconds=3600)
490
+ scheduler.start()
491
+ demo.queue(concurrency_count=40).launch()
content.py ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ CHANGELOG_TEXT = f"""
2
+ ## [2023-06-05]
3
+ - Increase concurrent thread count to 40
4
+ - Search models on ENTER
5
+
6
+ ## [2023-06-02]
7
+ - Add a typeahead search bar
8
+ - Use webhooks to automatically spawn a new Space when someone opens a PR
9
+ - Start recording `submitted_time` for eval requests
10
+ - Limit column max-width
11
+
12
+ ## [2023-05-30]
13
+ - Add a citation button
14
+ - Simplify Gradio layout
15
+
16
+ ## [2023-05-29]
17
+ - Auto-restart every hour for the latest results
18
+ - Sync with the internal version (minor style changes)
19
+
20
+ ## [2023-05-24]
21
+ - Add a baseline that has 25.0 for all values
22
+ - Add CHANGELOG
23
+
24
+ ## [2023-05-23]
25
+ - Fix a CSS issue that made the leaderboard hard to read in dark mode
26
+
27
+ ## [2023-05-22]
28
+ - Display a success/error message after submitting evaluation requests
29
+ - Reject duplicate submission
30
+ - Do not display results that have incomplete results
31
+ - Display different queues for jobs that are RUNNING, PENDING, FINISHED status
32
+
33
+ ## [2023-05-15]
34
+ - Fix a typo: from "TruthQA" to "TruthfulQA"
35
+
36
+ ## [2023-05-10]
37
+ - Fix a bug that prevented auto-refresh
38
+
39
+ ## [2023-05-10]
40
+ - Release the leaderboard to public
41
+ """
42
+
43
+ TITLE = """<h1 align="center" id="space-title">🤗 Open LLM Leaderboard</h1>"""
44
+
45
+ INTRODUCTION_TEXT = f"""
46
+ 📐 With the plethora of large language models (LLMs) and chatbots being released week upon week, often with grandiose claims of their performance, it can be hard to filter out the genuine progress that is being made by the open-source community and which model is the current state of the art. The 🤗 Open LLM Leaderboard aims to track, rank and evaluate LLMs and chatbots as they are released.
47
+
48
+ 🤗 A key advantage of this leaderboard is that anyone from the community can submit a model for automated evaluation on the 🤗 GPU cluster, as long as it is a 🤗 Transformers model with weights on the Hub. We also support evaluation of models with delta-weights for non-commercial licensed models, such as LLaMa.
49
+
50
+ 📈 We evaluate models on 4 key benchmarks from the <a href="https://github.com/EleutherAI/lm-evaluation-harness" target="_blank"> Eleuther AI Language Model Evaluation Harness </a>, a unified framework to test generative language models on a large number of different evaluation tasks:
51
+ - <a href="https://arxiv.org/abs/1803.05457" target="_blank"> AI2 Reasoning Challenge </a> (25-shot) - a set of grade-school science questions.
52
+ - <a href="https://arxiv.org/abs/1905.07830" target="_blank"> HellaSwag </a> (10-shot) - a test of commonsense inference, which is easy for humans (~95%) but challenging for SOTA models.
53
+ - <a href="https://arxiv.org/abs/2009.03300" target="_blank"> MMLU </a> (5-shot) - a test to measure a text model's multitask accuracy. The test covers 57 tasks including elementary mathematics, US history, computer science, law, and more.
54
+ - <a href="https://arxiv.org/abs/2109.07958" target="_blank"> TruthfulQA </a> (0-shot) - a benchmark to measure whether a language model is truthful in generating answers to questions.
55
+
56
+ We chose these benchmarks as they test a variety of reasoning and general knowledge across a wide variety of fields in 0-shot and few-shot settings.
57
+ """
58
+
59
+ EVALUATION_QUEUE_TEXT = f"""
60
+ # Evaluation Queue for the 🤗 Open LLM Leaderboard, these models will be automatically evaluated on the 🤗 cluster
61
+ """
62
+
63
+ CITATION_BUTTON_LABEL = "Copy the following snippet to cite these results"
64
+ CITATION_BUTTON_TEXT = r"""@misc{open-llm-leaderboard,
65
+ author = {Edward Beeching, Sheon Han, Nathan Lambert, Nazneen Rajani, Omar Sanseviero, Lewis Tunstall, Thomas Wolf},
66
+ title = {Open LLM Leaderboard},
67
+ year = {2023},
68
+ publisher = {Hugging Face},
69
+ howpublished = "\url{https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard}"
70
+
71
+ }
72
+ @software{eval-harness,
73
+ author = {Gao, Leo and
74
+ Tow, Jonathan and
75
+ Biderman, Stella and
76
+ Black, Sid and
77
+ DiPofi, Anthony and
78
+ Foster, Charles and
79
+ Golding, Laurence and
80
+ Hsu, Jeffrey and
81
+ McDonell, Kyle and
82
+ Muennighoff, Niklas and
83
+ Phang, Jason and
84
+ Reynolds, Laria and
85
+ Tang, Eric and
86
+ Thite, Anish and
87
+ Wang, Ben and
88
+ Wang, Kevin and
89
+ Zou, Andy},
90
+ title = {A framework for few-shot language model evaluation},
91
+ month = sep,
92
+ year = 2021,
93
+ publisher = {Zenodo},
94
+ version = {v0.0.1},
95
+ doi = {10.5281/zenodo.5371628},
96
+ url = {https://doi.org/10.5281/zenodo.5371628}
97
+ }
98
+ @misc{clark2018think,
99
+ title={Think you have Solved Question Answering? Try ARC, the AI2 Reasoning Challenge},
100
+ author={Peter Clark and Isaac Cowhey and Oren Etzioni and Tushar Khot and Ashish Sabharwal and Carissa Schoenick and Oyvind Tafjord},
101
+ year={2018},
102
+ eprint={1803.05457},
103
+ archivePrefix={arXiv},
104
+ primaryClass={cs.AI}
105
+ }
106
+ @misc{zellers2019hellaswag,
107
+ title={HellaSwag: Can a Machine Really Finish Your Sentence?},
108
+ author={Rowan Zellers and Ari Holtzman and Yonatan Bisk and Ali Farhadi and Yejin Choi},
109
+ year={2019},
110
+ eprint={1905.07830},
111
+ archivePrefix={arXiv},
112
+ primaryClass={cs.CL}
113
+ }
114
+ @misc{hendrycks2021measuring,
115
+ title={Measuring Massive Multitask Language Understanding},
116
+ author={Dan Hendrycks and Collin Burns and Steven Basart and Andy Zou and Mantas Mazeika and Dawn Song and Jacob Steinhardt},
117
+ year={2021},
118
+ eprint={2009.03300},
119
+ archivePrefix={arXiv},
120
+ primaryClass={cs.CY}
121
+ }
122
+ @misc{lin2022truthfulqa,
123
+ title={TruthfulQA: Measuring How Models Mimic Human Falsehoods},
124
+ author={Stephanie Lin and Jacob Hilton and Owain Evans},
125
+ year={2022},
126
+ eprint={2109.07958},
127
+ archivePrefix={arXiv},
128
+ primaryClass={cs.CL}
129
+ }"""
130
+
requirements.txt ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiofiles==23.1.0
2
+ aiohttp==3.8.4
3
+ aiosignal==1.3.1
4
+ altair==4.2.2
5
+ anyio==3.6.2
6
+ APScheduler==3.10.1
7
+ async-timeout==4.0.2
8
+ attrs==23.1.0
9
+ certifi==2022.12.7
10
+ charset-normalizer==3.1.0
11
+ click==8.1.3
12
+ contourpy==1.0.7
13
+ cycler==0.11.0
14
+ entrypoints==0.4
15
+ fastapi==0.95.1
16
+ ffmpy==0.3.0
17
+ filelock==3.11.0
18
+ fonttools==4.39.3
19
+ frozenlist==1.3.3
20
+ fsspec==2023.4.0
21
+ gradio==3.27.0
22
+ gradio_client==0.1.3
23
+ h11==0.14.0
24
+ httpcore==0.17.0
25
+ httpx==0.24.0
26
+ huggingface-hub==0.13.4
27
+ idna==3.4
28
+ Jinja2==3.1.2
29
+ jsonschema==4.17.3
30
+ kiwisolver==1.4.4
31
+ linkify-it-py==2.0.0
32
+ markdown-it-py==2.2.0
33
+ MarkupSafe==2.1.2
34
+ matplotlib==3.7.1
35
+ mdit-py-plugins==0.3.3
36
+ mdurl==0.1.2
37
+ multidict==6.0.4
38
+ numpy==1.24.2
39
+ orjson==3.8.10
40
+ packaging==23.1
41
+ pandas==2.0.0
42
+ Pillow==9.5.0
43
+ pydantic==1.10.7
44
+ pydub==0.25.1
45
+ pyparsing==3.0.9
46
+ pyrsistent==0.19.3
47
+ python-dateutil==2.8.2
48
+ python-multipart==0.0.6
49
+ pytz==2023.3
50
+ pytz-deprecation-shim==0.1.0.post0
51
+ PyYAML==6.0
52
+ requests==2.28.2
53
+ semantic-version==2.10.0
54
+ six==1.16.0
55
+ sniffio==1.3.0
56
+ starlette==0.26.1
57
+ toolz==0.12.0
58
+ tqdm==4.65.0
59
+ transformers==4.28.1
60
+ typing_extensions==4.5.0
61
+ tzdata==2023.3
62
+ tzlocal==4.3
63
+ uc-micro-py==1.0.1
64
+ urllib3==1.26.15
65
+ uvicorn==0.21.1
66
+ websockets==11.0.1
67
+ yarl==1.8.2
utils.py ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import shutil
3
+ import numpy as np
4
+ import gradio as gr
5
+ from huggingface_hub import Repository, HfApi
6
+ from transformers import AutoConfig, AutoModel
7
+ import json
8
+ from apscheduler.schedulers.background import BackgroundScheduler
9
+ import pandas as pd
10
+ import datetime
11
+ import glob
12
+ from dataclasses import dataclass
13
+ from typing import List, Tuple, Dict
14
+
15
+ # clone / pull the lmeh eval data
16
+ H4_TOKEN = os.environ.get("H4_TOKEN", None)
17
+ LMEH_REPO = "HuggingFaceH4/lmeh_evaluations"
18
+
19
+ METRICS = ["acc_norm", "acc_norm", "acc_norm", "mc2"]
20
+ BENCHMARKS = ["arc_challenge", "hellaswag", "hendrycks", "truthfulqa_mc"]
21
+ BENCH_TO_NAME = {
22
+ "arc_challenge": "ARC (25-shot) ⬆️",
23
+ "hellaswag": "HellaSwag (10-shot) ⬆️",
24
+ "hendrycks": "MMLU (5-shot) ⬆️",
25
+ "truthfulqa_mc": "TruthfulQA (0-shot) ⬆️",
26
+ }
27
+
28
+
29
+ def make_clickable_model(model_name):
30
+ LLAMAS = [
31
+ "huggingface/llama-7b",
32
+ "huggingface/llama-13b",
33
+ "huggingface/llama-30b",
34
+ "huggingface/llama-65b",
35
+ ]
36
+ if model_name in LLAMAS:
37
+ model = model_name.split("/")[1]
38
+ return f'<a target="_blank" href="https://ai.facebook.com/blog/large-language-model-llama-meta-ai/" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{model}</a>'
39
+
40
+ if model_name == "HuggingFaceH4/stable-vicuna-13b-2904":
41
+ link = "https://huggingface.co/" + "CarperAI/stable-vicuna-13b-delta"
42
+ return f'<a target="_blank" href="{link}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">stable-vicuna-13b</a>'
43
+
44
+ if model_name == "HuggingFaceH4/llama-7b-ift-alpaca":
45
+ link = "https://crfm.stanford.edu/2023/03/13/alpaca.html"
46
+ return f'<a target="_blank" href="{link}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">alpaca-13b</a>'
47
+
48
+ # remove user from model name
49
+ # model_name_show = ' '.join(model_name.split('/')[1:])
50
+
51
+ link = "https://huggingface.co/" + model_name
52
+ return f'<a target="_blank" href="{link}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{model_name}</a>'
53
+
54
+
55
+ @dataclass
56
+ class EvalResult:
57
+ eval_name: str
58
+ org: str
59
+ model: str
60
+ revision: str
61
+ is_8bit: bool
62
+ results: dict
63
+
64
+ def to_dict(self):
65
+ if self.org is not None:
66
+ base_model = f"{self.org}/{self.model}"
67
+ else:
68
+ base_model = f"{self.model}"
69
+ data_dict = {}
70
+
71
+ data_dict["eval_name"] = self.eval_name
72
+ data_dict["8bit"] = self.is_8bit
73
+ data_dict["Model"] = make_clickable_model(base_model)
74
+ # dummy column to implement search bar (hidden by custom CSS)
75
+ data_dict["model_name_for_query"] = base_model
76
+ data_dict["Revision"] = self.revision
77
+ data_dict["Average ⬆️"] = round(
78
+ sum([v for k, v in self.results.items()]) / 4.0, 1
79
+ )
80
+ # data_dict["# params"] = get_n_params(base_model)
81
+
82
+ for benchmark in BENCHMARKS:
83
+ if not benchmark in self.results.keys():
84
+ self.results[benchmark] = None
85
+
86
+ for k, v in BENCH_TO_NAME.items():
87
+ data_dict[v] = self.results[k]
88
+
89
+ return data_dict
90
+
91
+
92
+ def parse_eval_result(json_filepath: str) -> Tuple[str, dict]:
93
+ with open(json_filepath) as fp:
94
+ data = json.load(fp)
95
+
96
+ path_split = json_filepath.split("/")
97
+ org = None
98
+ model = path_split[-4]
99
+ is_8bit = path_split[-2] == "8bit"
100
+ revision = path_split[-3]
101
+ if len(path_split) == 7:
102
+ # handles gpt2 type models that don't have an org
103
+ result_key = f"{path_split[-4]}_{path_split[-3]}_{path_split[-2]}"
104
+ else:
105
+ result_key = (
106
+ f"{path_split[-5]}_{path_split[-4]}_{path_split[-3]}_{path_split[-2]}"
107
+ )
108
+ org = path_split[-5]
109
+
110
+ eval_result = None
111
+ for benchmark, metric in zip(BENCHMARKS, METRICS):
112
+ if benchmark in json_filepath:
113
+ accs = np.array([v[metric] for k, v in data["results"].items()])
114
+ mean_acc = round(np.mean(accs) * 100.0, 1)
115
+ eval_result = EvalResult(
116
+ result_key, org, model, revision, is_8bit, {benchmark: mean_acc}
117
+ )
118
+
119
+ return result_key, eval_result
120
+
121
+
122
+ def get_eval_results(is_public) -> List[EvalResult]:
123
+ json_filepaths = glob.glob(
124
+ "evals/eval_results/public/**/16bit/*.json", recursive=True
125
+ )
126
+ if not is_public:
127
+ json_filepaths += glob.glob(
128
+ "evals/eval_results/private/**/*.json", recursive=True
129
+ )
130
+ json_filepaths += glob.glob(
131
+ "evals/eval_results/private/**/*.json", recursive=True
132
+ )
133
+ json_filepaths += glob.glob(
134
+ "evals/eval_results/public/**/8bit/*.json", recursive=True
135
+ ) # include the 8bit evals of public models
136
+ eval_results = {}
137
+
138
+ for json_filepath in json_filepaths:
139
+ result_key, eval_result = parse_eval_result(json_filepath)
140
+ if result_key in eval_results.keys():
141
+ eval_results[result_key].results.update(eval_result.results)
142
+ else:
143
+ eval_results[result_key] = eval_result
144
+
145
+ eval_results = [v for k, v in eval_results.items()]
146
+
147
+ return eval_results
148
+
149
+
150
+ def get_eval_results_dicts(is_public=True) -> List[Dict]:
151
+ eval_results = get_eval_results(is_public)
152
+
153
+ return [e.to_dict() for e in eval_results]
154
+
155
+
156
+ eval_results_dict = get_eval_results_dicts()
157
+ # print(eval_results_dict)