Spaces:
Runtime error
Runtime error
Commit ·
4e0c92e
1
Parent(s): 4466f70
fix-table
Browse files- app.py +26 -29
- src/about.py +5 -4
- src/display/css_html_js.py +66 -2
- src/display/utils.py +9 -5
- src/envs.py +3 -3
- src/leaderboard/read_evals.py +19 -21
- src/populate.py +3 -1
- src/submission/check_validity.py +19 -11
- src/submission/submit.py +5 -2
app.py
CHANGED
|
@@ -1,39 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
import
|
| 6 |
-
from pathlib import Path
|
| 7 |
from huggingface_hub import snapshot_download
|
| 8 |
|
| 9 |
from src.about import (
|
| 10 |
-
CITATION_BUTTON_LABEL,
|
| 11 |
-
CITATION_BUTTON_TEXT,
|
| 12 |
-
EVALUATION_QUEUE_TEXT,
|
| 13 |
INTRODUCTION_TEXT,
|
| 14 |
LLM_BENCHMARKS_TEXT,
|
| 15 |
TITLE,
|
| 16 |
)
|
| 17 |
-
from src.display.css_html_js import custom_css
|
| 18 |
from src.display.utils import (
|
| 19 |
BENCHMARK_COLS,
|
| 20 |
COLS,
|
| 21 |
EVAL_COLS,
|
| 22 |
-
EVAL_TYPES,
|
| 23 |
AutoEvalColumn,
|
| 24 |
-
ModelType,
|
| 25 |
fields,
|
| 26 |
-
WeightType,
|
| 27 |
-
Precision
|
| 28 |
)
|
| 29 |
from src.envs import API, EVAL_REQUESTS_PATH, EVAL_RESULTS_PATH, QUEUE_REPO, REPO_ID, RESULTS_REPO, TOKEN
|
| 30 |
from src.populate import get_evaluation_queue_df, get_leaderboard_df
|
| 31 |
-
from src.submission.submit import add_new_eval
|
| 32 |
|
| 33 |
|
| 34 |
def restart_space():
|
| 35 |
API.restart_space(repo_id=REPO_ID)
|
| 36 |
|
|
|
|
| 37 |
ENABLE_REMOTE_DATA_SYNC = False
|
| 38 |
|
| 39 |
if ENABLE_REMOTE_DATA_SYNC:
|
|
@@ -70,6 +65,7 @@ if ENABLE_REMOTE_DATA_SYNC:
|
|
| 70 |
pending_eval_queue_df,
|
| 71 |
) = get_evaluation_queue_df(EVAL_REQUESTS_PATH, EVAL_COLS)
|
| 72 |
|
|
|
|
| 73 |
def init_leaderboard(dataframe):
|
| 74 |
if dataframe is None or dataframe.empty:
|
| 75 |
raise ValueError("Leaderboard DataFrame is empty or None.")
|
|
@@ -93,9 +89,7 @@ def init_leaderboard(dataframe):
|
|
| 93 |
max=150,
|
| 94 |
label="Select the number of parameters (B)",
|
| 95 |
),
|
| 96 |
-
ColumnFilter(
|
| 97 |
-
AutoEvalColumn.still_on_hub.name, type="boolean", label="Deleted/incomplete", default=True
|
| 98 |
-
),
|
| 99 |
],
|
| 100 |
bool_checkboxgroup_label="Hide models",
|
| 101 |
interactive=False,
|
|
@@ -103,7 +97,7 @@ def init_leaderboard(dataframe):
|
|
| 103 |
|
| 104 |
|
| 105 |
demo = gr.Blocks(css=custom_css)
|
| 106 |
-
|
| 107 |
|
| 108 |
def create_score_df(json_path: Path, decimals: int):
|
| 109 |
data = json.loads(json_path.read_text(encoding="utf-8"))
|
|
@@ -128,15 +122,20 @@ def create_score_df(json_path: Path, decimals: int):
|
|
| 128 |
score_cols = [c for c in df.columns if c not in ("ID", "Model")]
|
| 129 |
for col in score_cols:
|
| 130 |
df[col] = df[col].apply(
|
| 131 |
-
lambda v: (
|
| 132 |
-
""
|
| 133 |
-
if pd.isna(v)
|
| 134 |
-
else (f"{float(v):.{decimals}f}" if isinstance(v, (int, float)) else v)
|
| 135 |
-
)
|
| 136 |
)
|
| 137 |
return df
|
| 138 |
|
| 139 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
def create_raw_score_df():
|
| 141 |
raw_path = Path(__file__).resolve().parent / "src" / "raw_score.json"
|
| 142 |
return create_score_df(raw_path, decimals=2)
|
|
@@ -220,8 +219,7 @@ def create_weights_table_html():
|
|
| 220 |
if (r, c) != (r1, c1):
|
| 221 |
covered.add((r, c))
|
| 222 |
|
| 223 |
-
parts = [
|
| 224 |
-
]
|
| 225 |
for r_index, row in enumerate(rows, start=min_row):
|
| 226 |
parts.append("<tr>")
|
| 227 |
for c_index, value in enumerate(row, start=min_col):
|
|
@@ -247,7 +245,9 @@ def create_weights_table_html():
|
|
| 247 |
parts.append("</table></div>")
|
| 248 |
return "".join(parts)
|
| 249 |
|
|
|
|
| 250 |
with demo:
|
|
|
|
| 251 |
gr.HTML(TITLE)
|
| 252 |
gr.Markdown(INTRODUCTION_TEXT, elem_classes="markdown-text")
|
| 253 |
|
|
@@ -262,7 +262,7 @@ with demo:
|
|
| 262 |
wrap=True,
|
| 263 |
column_widths=column_widths,
|
| 264 |
row_count=(len(raw_score_df), "fixed"),
|
| 265 |
-
height=
|
| 266 |
elem_id="raw-score-table",
|
| 267 |
)
|
| 268 |
with gr.TabItem("Weights"):
|
|
@@ -275,7 +275,7 @@ with demo:
|
|
| 275 |
wrap=True,
|
| 276 |
column_widths=column_widths,
|
| 277 |
row_count=(len(unweighted_z_df), "fixed"),
|
| 278 |
-
height=
|
| 279 |
elem_id="unweighted-z-table",
|
| 280 |
)
|
| 281 |
with gr.TabItem("Weighted Z-score"):
|
|
@@ -286,7 +286,7 @@ with demo:
|
|
| 286 |
wrap=True,
|
| 287 |
column_widths=column_widths,
|
| 288 |
row_count=(len(weighted_z_df), "fixed"),
|
| 289 |
-
height=
|
| 290 |
elem_id="weighted-z-table",
|
| 291 |
)
|
| 292 |
|
|
@@ -294,9 +294,6 @@ with demo:
|
|
| 294 |
gr.Markdown(LLM_BENCHMARKS_TEXT, elem_classes="markdown-text")
|
| 295 |
|
| 296 |
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
scheduler = BackgroundScheduler()
|
| 301 |
scheduler.add_job(restart_space, "interval", seconds=1800)
|
| 302 |
scheduler.start()
|
|
|
|
| 1 |
+
import html
|
| 2 |
+
import json
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
import gradio as gr
|
|
|
|
| 6 |
import pandas as pd
|
| 7 |
from apscheduler.schedulers.background import BackgroundScheduler
|
| 8 |
+
from gradio_leaderboard import ColumnFilter, Leaderboard, SelectColumns
|
|
|
|
| 9 |
from huggingface_hub import snapshot_download
|
| 10 |
|
| 11 |
from src.about import (
|
|
|
|
|
|
|
|
|
|
| 12 |
INTRODUCTION_TEXT,
|
| 13 |
LLM_BENCHMARKS_TEXT,
|
| 14 |
TITLE,
|
| 15 |
)
|
| 16 |
+
from src.display.css_html_js import custom_css, custom_js
|
| 17 |
from src.display.utils import (
|
| 18 |
BENCHMARK_COLS,
|
| 19 |
COLS,
|
| 20 |
EVAL_COLS,
|
|
|
|
| 21 |
AutoEvalColumn,
|
|
|
|
| 22 |
fields,
|
|
|
|
|
|
|
| 23 |
)
|
| 24 |
from src.envs import API, EVAL_REQUESTS_PATH, EVAL_RESULTS_PATH, QUEUE_REPO, REPO_ID, RESULTS_REPO, TOKEN
|
| 25 |
from src.populate import get_evaluation_queue_df, get_leaderboard_df
|
|
|
|
| 26 |
|
| 27 |
|
| 28 |
def restart_space():
|
| 29 |
API.restart_space(repo_id=REPO_ID)
|
| 30 |
|
| 31 |
+
|
| 32 |
ENABLE_REMOTE_DATA_SYNC = False
|
| 33 |
|
| 34 |
if ENABLE_REMOTE_DATA_SYNC:
|
|
|
|
| 65 |
pending_eval_queue_df,
|
| 66 |
) = get_evaluation_queue_df(EVAL_REQUESTS_PATH, EVAL_COLS)
|
| 67 |
|
| 68 |
+
|
| 69 |
def init_leaderboard(dataframe):
|
| 70 |
if dataframe is None or dataframe.empty:
|
| 71 |
raise ValueError("Leaderboard DataFrame is empty or None.")
|
|
|
|
| 89 |
max=150,
|
| 90 |
label="Select the number of parameters (B)",
|
| 91 |
),
|
| 92 |
+
ColumnFilter(AutoEvalColumn.still_on_hub.name, type="boolean", label="Deleted/incomplete", default=True),
|
|
|
|
|
|
|
| 93 |
],
|
| 94 |
bool_checkboxgroup_label="Hide models",
|
| 95 |
interactive=False,
|
|
|
|
| 97 |
|
| 98 |
|
| 99 |
demo = gr.Blocks(css=custom_css)
|
| 100 |
+
|
| 101 |
|
| 102 |
def create_score_df(json_path: Path, decimals: int):
|
| 103 |
data = json.loads(json_path.read_text(encoding="utf-8"))
|
|
|
|
| 122 |
score_cols = [c for c in df.columns if c not in ("ID", "Model")]
|
| 123 |
for col in score_cols:
|
| 124 |
df[col] = df[col].apply(
|
| 125 |
+
lambda v: ("" if pd.isna(v) else (f"{float(v):.{decimals}f}" if isinstance(v, (int, float)) else v))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
)
|
| 127 |
return df
|
| 128 |
|
| 129 |
|
| 130 |
+
def dataframe_height(df: pd.DataFrame):
|
| 131 |
+
rows = 0 if df is None else int(getattr(df, "shape", (0, 0))[0])
|
| 132 |
+
row_px = 40
|
| 133 |
+
header_px = 44
|
| 134 |
+
padding_px = 96
|
| 135 |
+
height = header_px + (rows * row_px) + padding_px
|
| 136 |
+
return max(320, min(1200, height))
|
| 137 |
+
|
| 138 |
+
|
| 139 |
def create_raw_score_df():
|
| 140 |
raw_path = Path(__file__).resolve().parent / "src" / "raw_score.json"
|
| 141 |
return create_score_df(raw_path, decimals=2)
|
|
|
|
| 219 |
if (r, c) != (r1, c1):
|
| 220 |
covered.add((r, c))
|
| 221 |
|
| 222 |
+
parts = ['<div class="weights-scroll"><table class="weights-table">']
|
|
|
|
| 223 |
for r_index, row in enumerate(rows, start=min_row):
|
| 224 |
parts.append("<tr>")
|
| 225 |
for c_index, value in enumerate(row, start=min_col):
|
|
|
|
| 245 |
parts.append("</table></div>")
|
| 246 |
return "".join(parts)
|
| 247 |
|
| 248 |
+
|
| 249 |
with demo:
|
| 250 |
+
gr.HTML(custom_js)
|
| 251 |
gr.HTML(TITLE)
|
| 252 |
gr.Markdown(INTRODUCTION_TEXT, elem_classes="markdown-text")
|
| 253 |
|
|
|
|
| 262 |
wrap=True,
|
| 263 |
column_widths=column_widths,
|
| 264 |
row_count=(len(raw_score_df), "fixed"),
|
| 265 |
+
height=dataframe_height(raw_score_df),
|
| 266 |
elem_id="raw-score-table",
|
| 267 |
)
|
| 268 |
with gr.TabItem("Weights"):
|
|
|
|
| 275 |
wrap=True,
|
| 276 |
column_widths=column_widths,
|
| 277 |
row_count=(len(unweighted_z_df), "fixed"),
|
| 278 |
+
height=dataframe_height(unweighted_z_df),
|
| 279 |
elem_id="unweighted-z-table",
|
| 280 |
)
|
| 281 |
with gr.TabItem("Weighted Z-score"):
|
|
|
|
| 286 |
wrap=True,
|
| 287 |
column_widths=column_widths,
|
| 288 |
row_count=(len(weighted_z_df), "fixed"),
|
| 289 |
+
height=dataframe_height(weighted_z_df),
|
| 290 |
elem_id="weighted-z-table",
|
| 291 |
)
|
| 292 |
|
|
|
|
| 294 |
gr.Markdown(LLM_BENCHMARKS_TEXT, elem_classes="markdown-text")
|
| 295 |
|
| 296 |
|
|
|
|
|
|
|
|
|
|
| 297 |
scheduler = BackgroundScheduler()
|
| 298 |
scheduler.add_job(restart_space, "interval", seconds=1800)
|
| 299 |
scheduler.start()
|
src/about.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
from dataclasses import dataclass
|
| 2 |
from enum import Enum
|
| 3 |
|
|
|
|
| 4 |
@dataclass
|
| 5 |
class Task:
|
| 6 |
benchmark: str
|
|
@@ -11,13 +12,13 @@ class Task:
|
|
| 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 |
|
| 18 |
-
NUM_FEWSHOT = 0 # Change with your few shot
|
| 19 |
-
# ---------------------------------------------------
|
| 20 |
|
|
|
|
|
|
|
| 21 |
|
| 22 |
|
| 23 |
# Your leaderboard name
|
|
@@ -28,7 +29,7 @@ INTRODUCTION_TEXT = """
|
|
| 28 |
"""
|
| 29 |
|
| 30 |
# Which evaluations are you running? how can people reproduce what you have?
|
| 31 |
-
LLM_BENCHMARKS_TEXT =
|
| 32 |
## About WebCoderBench
|
| 33 |
|
| 34 |
Web applications (web apps) have become a key arena for large language models (LLMs) to demonstrate code generation capabilities and commercial potential. However, building a benchmark for LLM-generated web apps remains challenging due to:
|
|
|
|
| 1 |
from dataclasses import dataclass
|
| 2 |
from enum import Enum
|
| 3 |
|
| 4 |
+
|
| 5 |
@dataclass
|
| 6 |
class Task:
|
| 7 |
benchmark: str
|
|
|
|
| 12 |
# Select your tasks here
|
| 13 |
# ---------------------------------------------------
|
| 14 |
class Tasks(Enum):
|
| 15 |
+
# task_key in the json file, metric_key in the json file, name to display in the leaderboard
|
| 16 |
task0 = Task("anli_r1", "acc", "ANLI")
|
| 17 |
task1 = Task("logiqa", "acc_norm", "LogiQA")
|
| 18 |
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
NUM_FEWSHOT = 0 # Change with your few shot
|
| 21 |
+
# ---------------------------------------------------
|
| 22 |
|
| 23 |
|
| 24 |
# Your leaderboard name
|
|
|
|
| 29 |
"""
|
| 30 |
|
| 31 |
# Which evaluations are you running? how can people reproduce what you have?
|
| 32 |
+
LLM_BENCHMARKS_TEXT = """
|
| 33 |
## About WebCoderBench
|
| 34 |
|
| 35 |
Web applications (web apps) have become a key arena for large language models (LLMs) to demonstrate code generation capabilities and commercial potential. However, building a benchmark for LLM-generated web apps remains challenging due to:
|
src/display/css_html_js.py
CHANGED
|
@@ -99,10 +99,11 @@ custom_css = """
|
|
| 99 |
overflow-x: auto !important;
|
| 100 |
max-width: 100%;
|
| 101 |
min-width: 0;
|
| 102 |
-
min-height: 78vh;
|
| 103 |
}
|
| 104 |
|
| 105 |
-
#raw-score-table
|
|
|
|
|
|
|
| 106 |
overflow-x: auto !important;
|
| 107 |
max-width: 100%;
|
| 108 |
min-width: 0;
|
|
@@ -153,6 +154,69 @@ custom_css = """
|
|
| 153 |
}
|
| 154 |
"""
|
| 155 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
get_window_url_params = """
|
| 157 |
function(url_params) {
|
| 158 |
const params = new URLSearchParams(window.location.search);
|
|
|
|
| 99 |
overflow-x: auto !important;
|
| 100 |
max-width: 100%;
|
| 101 |
min-width: 0;
|
|
|
|
| 102 |
}
|
| 103 |
|
| 104 |
+
#raw-score-table,
|
| 105 |
+
#unweighted-z-table,
|
| 106 |
+
#weighted-z-table {
|
| 107 |
overflow-x: auto !important;
|
| 108 |
max-width: 100%;
|
| 109 |
min-width: 0;
|
|
|
|
| 154 |
}
|
| 155 |
"""
|
| 156 |
|
| 157 |
+
custom_js = """
|
| 158 |
+
<script>
|
| 159 |
+
(function () {
|
| 160 |
+
const tableIds = ["raw-score-table", "unweighted-z-table", "weighted-z-table"];
|
| 161 |
+
|
| 162 |
+
const nudgeScroll = (el) => {
|
| 163 |
+
const scroller =
|
| 164 |
+
el.querySelector(".table-wrap") ||
|
| 165 |
+
el.querySelector(".wrap") ||
|
| 166 |
+
el.querySelector(".wrap-inner") ||
|
| 167 |
+
el;
|
| 168 |
+
|
| 169 |
+
const x = scroller.scrollLeft || 0;
|
| 170 |
+
scroller.scrollLeft = x + 1;
|
| 171 |
+
scroller.scrollLeft = x;
|
| 172 |
+
scroller.dispatchEvent(new Event("scroll", { bubbles: true }));
|
| 173 |
+
};
|
| 174 |
+
|
| 175 |
+
const forceRelayout = () => {
|
| 176 |
+
window.dispatchEvent(new Event("resize"));
|
| 177 |
+
for (const id of tableIds) {
|
| 178 |
+
const el = document.getElementById(id);
|
| 179 |
+
if (!el) continue;
|
| 180 |
+
nudgeScroll(el);
|
| 181 |
+
}
|
| 182 |
+
};
|
| 183 |
+
|
| 184 |
+
const schedule = () => {
|
| 185 |
+
forceRelayout();
|
| 186 |
+
setTimeout(forceRelayout, 50);
|
| 187 |
+
setTimeout(forceRelayout, 200);
|
| 188 |
+
setTimeout(forceRelayout, 800);
|
| 189 |
+
};
|
| 190 |
+
|
| 191 |
+
const observer = new MutationObserver(() => {
|
| 192 |
+
schedule();
|
| 193 |
+
});
|
| 194 |
+
observer.observe(document.documentElement, {
|
| 195 |
+
subtree: true,
|
| 196 |
+
childList: true,
|
| 197 |
+
attributes: true,
|
| 198 |
+
attributeFilter: ["style", "class", "aria-selected"],
|
| 199 |
+
});
|
| 200 |
+
|
| 201 |
+
document.addEventListener(
|
| 202 |
+
"click",
|
| 203 |
+
(e) => {
|
| 204 |
+
const target = e.target;
|
| 205 |
+
if (!(target instanceof Element)) return;
|
| 206 |
+
if (target.closest("button, [role='tab'], .tab-buttons")) {
|
| 207 |
+
setTimeout(schedule, 0);
|
| 208 |
+
}
|
| 209 |
+
},
|
| 210 |
+
true
|
| 211 |
+
);
|
| 212 |
+
|
| 213 |
+
window.addEventListener("resize", () => setTimeout(forceRelayout, 0));
|
| 214 |
+
window.addEventListener("load", () => setTimeout(schedule, 0));
|
| 215 |
+
schedule();
|
| 216 |
+
})();
|
| 217 |
+
</script>
|
| 218 |
+
"""
|
| 219 |
+
|
| 220 |
get_window_url_params = """
|
| 221 |
function(url_params) {
|
| 222 |
const params = new URLSearchParams(window.location.search);
|
src/display/utils.py
CHANGED
|
@@ -1,10 +1,9 @@
|
|
| 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 |
|
|
@@ -20,12 +19,13 @@ class ColumnContent:
|
|
| 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 |
-
#Scores
|
| 29 |
auto_eval_column_dict.append(["average", ColumnContent, ColumnContent("Average ⬆️", "number", True)])
|
| 30 |
for task in Tasks:
|
| 31 |
auto_eval_column_dict.append([task.name, ColumnContent, ColumnContent(task.value.col_name, "number", True)])
|
|
@@ -43,6 +43,7 @@ auto_eval_column_dict.append(["revision", ColumnContent, ColumnContent("Model sh
|
|
| 43 |
# We use make dataclass to dynamically fill the scores from Tasks
|
| 44 |
AutoEvalColumn = make_dataclass("AutoEvalColumn", auto_eval_column_dict, frozen=True)
|
| 45 |
|
|
|
|
| 46 |
## For the queue columns in the submission tab
|
| 47 |
@dataclass(frozen=True)
|
| 48 |
class EvalQueueColumn: # Queue column
|
|
@@ -53,12 +54,13 @@ class EvalQueueColumn: # Queue column
|
|
| 53 |
weight_type = ColumnContent("weight_type", "str", "Original")
|
| 54 |
status = ColumnContent("status", "str", True)
|
| 55 |
|
|
|
|
| 56 |
## All the model information that we might need
|
| 57 |
@dataclass
|
| 58 |
class ModelDetails:
|
| 59 |
name: str
|
| 60 |
display_name: str = ""
|
| 61 |
-
symbol: str = ""
|
| 62 |
|
| 63 |
|
| 64 |
class ModelType(Enum):
|
|
@@ -83,11 +85,13 @@ class ModelType(Enum):
|
|
| 83 |
return ModelType.IFT
|
| 84 |
return ModelType.Unknown
|
| 85 |
|
|
|
|
| 86 |
class WeightType(Enum):
|
| 87 |
Adapter = ModelDetails("Adapter")
|
| 88 |
Original = ModelDetails("Original")
|
| 89 |
Delta = ModelDetails("Delta")
|
| 90 |
|
|
|
|
| 91 |
class Precision(Enum):
|
| 92 |
float16 = ModelDetails("float16")
|
| 93 |
bfloat16 = ModelDetails("bfloat16")
|
|
@@ -100,6 +104,7 @@ class Precision(Enum):
|
|
| 100 |
return Precision.bfloat16
|
| 101 |
return Precision.Unknown
|
| 102 |
|
|
|
|
| 103 |
# Column selection
|
| 104 |
COLS = [c.name for c in fields(AutoEvalColumn) if not c.hidden]
|
| 105 |
|
|
@@ -107,4 +112,3 @@ EVAL_COLS = [c.name for c in fields(EvalQueueColumn)]
|
|
| 107 |
EVAL_TYPES = [c.type for c in fields(EvalQueueColumn)]
|
| 108 |
|
| 109 |
BENCHMARK_COLS = [t.value.col_name for t in Tasks]
|
| 110 |
-
|
|
|
|
| 1 |
from dataclasses import dataclass, make_dataclass
|
| 2 |
from enum import Enum
|
| 3 |
|
|
|
|
|
|
|
| 4 |
from src.about import Tasks
|
| 5 |
|
| 6 |
+
|
| 7 |
def fields(raw_class):
|
| 8 |
return [v for k, v in raw_class.__dict__.items() if k[:2] != "__" and k[-2:] != "__"]
|
| 9 |
|
|
|
|
| 19 |
hidden: bool = False
|
| 20 |
never_hidden: bool = False
|
| 21 |
|
| 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 |
+
# Scores
|
| 29 |
auto_eval_column_dict.append(["average", ColumnContent, ColumnContent("Average ⬆️", "number", True)])
|
| 30 |
for task in Tasks:
|
| 31 |
auto_eval_column_dict.append([task.name, ColumnContent, ColumnContent(task.value.col_name, "number", True)])
|
|
|
|
| 43 |
# We use make dataclass to dynamically fill the scores from Tasks
|
| 44 |
AutoEvalColumn = make_dataclass("AutoEvalColumn", auto_eval_column_dict, frozen=True)
|
| 45 |
|
| 46 |
+
|
| 47 |
## For the queue columns in the submission tab
|
| 48 |
@dataclass(frozen=True)
|
| 49 |
class EvalQueueColumn: # Queue column
|
|
|
|
| 54 |
weight_type = ColumnContent("weight_type", "str", "Original")
|
| 55 |
status = ColumnContent("status", "str", True)
|
| 56 |
|
| 57 |
+
|
| 58 |
## All the model information that we might need
|
| 59 |
@dataclass
|
| 60 |
class ModelDetails:
|
| 61 |
name: str
|
| 62 |
display_name: str = ""
|
| 63 |
+
symbol: str = "" # emoji
|
| 64 |
|
| 65 |
|
| 66 |
class ModelType(Enum):
|
|
|
|
| 85 |
return ModelType.IFT
|
| 86 |
return ModelType.Unknown
|
| 87 |
|
| 88 |
+
|
| 89 |
class WeightType(Enum):
|
| 90 |
Adapter = ModelDetails("Adapter")
|
| 91 |
Original = ModelDetails("Original")
|
| 92 |
Delta = ModelDetails("Delta")
|
| 93 |
|
| 94 |
+
|
| 95 |
class Precision(Enum):
|
| 96 |
float16 = ModelDetails("float16")
|
| 97 |
bfloat16 = ModelDetails("bfloat16")
|
|
|
|
| 104 |
return Precision.bfloat16
|
| 105 |
return Precision.Unknown
|
| 106 |
|
| 107 |
+
|
| 108 |
# Column selection
|
| 109 |
COLS = [c.name for c in fields(AutoEvalColumn) if not c.hidden]
|
| 110 |
|
|
|
|
| 112 |
EVAL_TYPES = [c.type for c in fields(EvalQueueColumn)]
|
| 113 |
|
| 114 |
BENCHMARK_COLS = [t.value.col_name for t in Tasks]
|
|
|
src/envs.py
CHANGED
|
@@ -4,9 +4,9 @@ from huggingface_hub import HfApi
|
|
| 4 |
|
| 5 |
# Info to change for your repository
|
| 6 |
# ----------------------------------
|
| 7 |
-
TOKEN = os.environ.get("HF_TOKEN")
|
| 8 |
|
| 9 |
-
OWNER = "demo-leaderboard-backend"
|
| 10 |
# ----------------------------------
|
| 11 |
|
| 12 |
REPO_ID = f"{OWNER}/leaderboard"
|
|
@@ -14,7 +14,7 @@ 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")
|
|
|
|
| 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 = "demo-leaderboard-backend" # 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"
|
|
|
|
| 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")
|
src/leaderboard/read_evals.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import glob
|
| 2 |
import json
|
| 3 |
-
import math
|
| 4 |
import os
|
| 5 |
from dataclasses import dataclass
|
| 6 |
|
|
@@ -8,28 +7,28 @@ 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,
|
| 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
|
| 20 |
-
full_model: str
|
| 21 |
-
org: str
|
| 22 |
model: str
|
| 23 |
-
revision: str
|
| 24 |
results: dict
|
| 25 |
precision: Precision = Precision.Unknown
|
| 26 |
-
model_type: ModelType = ModelType.Unknown
|
| 27 |
-
weight_type: WeightType = WeightType.Original
|
| 28 |
-
architecture: str = "Unknown"
|
| 29 |
license: str = "?"
|
| 30 |
likes: int = 0
|
| 31 |
num_params: int = 0
|
| 32 |
-
date: str = ""
|
| 33 |
still_on_hub: bool = False
|
| 34 |
|
| 35 |
@classmethod
|
|
@@ -85,10 +84,10 @@ class EvalResult:
|
|
| 85 |
org=org,
|
| 86 |
model=model,
|
| 87 |
results=results,
|
| 88 |
-
precision=precision,
|
| 89 |
-
revision=
|
| 90 |
still_on_hub=still_on_hub,
|
| 91 |
-
architecture=architecture
|
| 92 |
)
|
| 93 |
|
| 94 |
def update_with_request_file(self, requests_path):
|
|
@@ -105,7 +104,9 @@ class EvalResult:
|
|
| 105 |
self.num_params = request.get("params", 0)
|
| 106 |
self.date = request.get("submitted_time", "")
|
| 107 |
except Exception:
|
| 108 |
-
print(
|
|
|
|
|
|
|
| 109 |
|
| 110 |
def to_dict(self):
|
| 111 |
"""Converts the Eval Result to a dict compatible with our dataframe display"""
|
|
@@ -146,10 +147,7 @@ def get_request_file_for_model(requests_path, model_name, precision):
|
|
| 146 |
for tmp_request_file in request_files:
|
| 147 |
with open(tmp_request_file, "r") as f:
|
| 148 |
req_content = json.load(f)
|
| 149 |
-
if (
|
| 150 |
-
req_content["status"] in ["FINISHED"]
|
| 151 |
-
and req_content["precision"] == precision.split(".")[-1]
|
| 152 |
-
):
|
| 153 |
request_file = tmp_request_file
|
| 154 |
return request_file
|
| 155 |
|
|
@@ -188,7 +186,7 @@ def get_raw_eval_results(results_path: str, requests_path: str) -> list[EvalResu
|
|
| 188 |
results = []
|
| 189 |
for v in eval_results.values():
|
| 190 |
try:
|
| 191 |
-
v.to_dict()
|
| 192 |
results.append(v)
|
| 193 |
except KeyError: # not all eval values present
|
| 194 |
continue
|
|
|
|
| 1 |
import glob
|
| 2 |
import json
|
|
|
|
| 3 |
import os
|
| 4 |
from dataclasses import dataclass
|
| 5 |
|
|
|
|
| 7 |
import numpy as np
|
| 8 |
|
| 9 |
from src.display.formatting import make_clickable_model
|
| 10 |
+
from src.display.utils import AutoEvalColumn, ModelType, Precision, Tasks, WeightType
|
| 11 |
from src.submission.check_validity import is_model_on_hub
|
| 12 |
|
| 13 |
|
| 14 |
@dataclass
|
| 15 |
class EvalResult:
|
| 16 |
+
"""Represents one full evaluation. Built from a combination of the result and request file for a given run."""
|
| 17 |
+
|
| 18 |
+
eval_name: str # org_model_precision (uid)
|
| 19 |
+
full_model: str # org/model (path on hub)
|
| 20 |
+
org: str
|
| 21 |
model: str
|
| 22 |
+
revision: str # commit hash, "" if main
|
| 23 |
results: dict
|
| 24 |
precision: Precision = Precision.Unknown
|
| 25 |
+
model_type: ModelType = ModelType.Unknown # Pretrained, fine tuned, ...
|
| 26 |
+
weight_type: WeightType = WeightType.Original # Original or Adapter
|
| 27 |
+
architecture: str = "Unknown"
|
| 28 |
license: str = "?"
|
| 29 |
likes: int = 0
|
| 30 |
num_params: int = 0
|
| 31 |
+
date: str = "" # submission date of request file
|
| 32 |
still_on_hub: bool = False
|
| 33 |
|
| 34 |
@classmethod
|
|
|
|
| 84 |
org=org,
|
| 85 |
model=model,
|
| 86 |
results=results,
|
| 87 |
+
precision=precision,
|
| 88 |
+
revision=config.get("model_sha", ""),
|
| 89 |
still_on_hub=still_on_hub,
|
| 90 |
+
architecture=architecture,
|
| 91 |
)
|
| 92 |
|
| 93 |
def update_with_request_file(self, requests_path):
|
|
|
|
| 104 |
self.num_params = request.get("params", 0)
|
| 105 |
self.date = request.get("submitted_time", "")
|
| 106 |
except Exception:
|
| 107 |
+
print(
|
| 108 |
+
f"Could not find request file for {self.org}/{self.model} with precision {self.precision.value.name}"
|
| 109 |
+
)
|
| 110 |
|
| 111 |
def to_dict(self):
|
| 112 |
"""Converts the Eval Result to a dict compatible with our dataframe display"""
|
|
|
|
| 147 |
for tmp_request_file in request_files:
|
| 148 |
with open(tmp_request_file, "r") as f:
|
| 149 |
req_content = json.load(f)
|
| 150 |
+
if req_content["status"] in ["FINISHED"] and req_content["precision"] == precision.split(".")[-1]:
|
|
|
|
|
|
|
|
|
|
| 151 |
request_file = tmp_request_file
|
| 152 |
return request_file
|
| 153 |
|
|
|
|
| 186 |
results = []
|
| 187 |
for v in eval_results.values():
|
| 188 |
try:
|
| 189 |
+
v.to_dict() # we test if the dict version is complete
|
| 190 |
results.append(v)
|
| 191 |
except KeyError: # not all eval values present
|
| 192 |
continue
|
src/populate.py
CHANGED
|
@@ -39,7 +39,9 @@ def get_evaluation_queue_df(save_path: str, cols: list) -> list[pd.DataFrame]:
|
|
| 39 |
all_evals.append(data)
|
| 40 |
elif ".md" not in entry:
|
| 41 |
# this is a folder
|
| 42 |
-
sub_entries = [
|
|
|
|
|
|
|
| 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:
|
|
|
|
| 39 |
all_evals.append(data)
|
| 40 |
elif ".md" not in entry:
|
| 41 |
# this is a folder
|
| 42 |
+
sub_entries = [
|
| 43 |
+
e for e in os.listdir(f"{save_path}/{entry}") if os.path.isfile(e) and not e.startswith(".")
|
| 44 |
+
]
|
| 45 |
for sub_entry in sub_entries:
|
| 46 |
file_path = os.path.join(save_path, entry, sub_entry)
|
| 47 |
with open(file_path) as fp:
|
src/submission/check_validity.py
CHANGED
|
@@ -1,8 +1,6 @@
|
|
| 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
|
|
@@ -10,6 +8,7 @@ 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:
|
|
@@ -31,31 +30,38 @@ def check_model_card(repo_id: str) -> tuple[bool, str]:
|
|
| 31 |
|
| 32 |
return True, ""
|
| 33 |
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
| 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(
|
|
|
|
|
|
|
| 38 |
if test_tokenizer:
|
| 39 |
try:
|
| 40 |
-
|
|
|
|
|
|
|
| 41 |
except ValueError as e:
|
|
|
|
|
|
|
| 42 |
return (
|
| 43 |
False,
|
| 44 |
-
|
| 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
|
| 59 |
return False, "was not found on hub!", None
|
| 60 |
|
| 61 |
|
|
@@ -70,10 +76,12 @@ def get_model_size(model_info: ModelInfo, precision: str):
|
|
| 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
|
|
|
|
| 1 |
import json
|
| 2 |
import os
|
|
|
|
| 3 |
from collections import defaultdict
|
|
|
|
| 4 |
|
| 5 |
import huggingface_hub
|
| 6 |
from huggingface_hub import ModelCard
|
|
|
|
| 8 |
from transformers import AutoConfig
|
| 9 |
from transformers.models.auto.tokenization_auto import AutoTokenizer
|
| 10 |
|
| 11 |
+
|
| 12 |
def check_model_card(repo_id: str) -> tuple[bool, str]:
|
| 13 |
"""Checks if the model card and license exist and have been filled"""
|
| 14 |
try:
|
|
|
|
| 30 |
|
| 31 |
return True, ""
|
| 32 |
|
| 33 |
+
|
| 34 |
+
def is_model_on_hub(
|
| 35 |
+
model_name: str, revision: str, token: str = None, trust_remote_code=False, test_tokenizer=False
|
| 36 |
+
) -> tuple[bool, str]:
|
| 37 |
"""Checks if the model model_name is on the hub, and whether it (and its tokenizer) can be loaded with AutoClasses."""
|
| 38 |
try:
|
| 39 |
+
config = AutoConfig.from_pretrained(
|
| 40 |
+
model_name, revision=revision, trust_remote_code=trust_remote_code, token=token
|
| 41 |
+
)
|
| 42 |
if test_tokenizer:
|
| 43 |
try:
|
| 44 |
+
AutoTokenizer.from_pretrained(
|
| 45 |
+
model_name, revision=revision, trust_remote_code=trust_remote_code, token=token
|
| 46 |
+
)
|
| 47 |
except ValueError as e:
|
| 48 |
+
return (False, f"uses a tokenizer which is not in a transformers release: {e}", None)
|
| 49 |
+
except Exception:
|
| 50 |
return (
|
| 51 |
False,
|
| 52 |
+
"'s tokenizer cannot be loaded. Is your tokenizer class in a stable transformers release, and correctly configured?",
|
| 53 |
+
None,
|
| 54 |
)
|
|
|
|
|
|
|
| 55 |
return True, None, config
|
| 56 |
|
| 57 |
except ValueError:
|
| 58 |
return (
|
| 59 |
False,
|
| 60 |
"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.",
|
| 61 |
+
None,
|
| 62 |
)
|
| 63 |
|
| 64 |
+
except Exception:
|
| 65 |
return False, "was not found on hub!", None
|
| 66 |
|
| 67 |
|
|
|
|
| 76 |
model_size = size_factor * model_size
|
| 77 |
return model_size
|
| 78 |
|
| 79 |
+
|
| 80 |
def get_model_arch(model_info: ModelInfo):
|
| 81 |
"""Gets the model architecture from the configuration"""
|
| 82 |
return model_info.config.get("architectures", "Unknown")
|
| 83 |
|
| 84 |
+
|
| 85 |
def already_submitted_models(requested_models_dir: str) -> set[str]:
|
| 86 |
"""Gather a list of already submitted models to avoid duplicates"""
|
| 87 |
depth = 1
|
src/submission/submit.py
CHANGED
|
@@ -3,7 +3,7 @@ import os
|
|
| 3 |
from datetime import datetime, timezone
|
| 4 |
|
| 5 |
from src.display.formatting import styled_error, styled_message, styled_warning
|
| 6 |
-
from src.envs import API, EVAL_REQUESTS_PATH,
|
| 7 |
from src.submission.check_validity import (
|
| 8 |
already_submitted_models,
|
| 9 |
check_model_card,
|
|
@@ -14,6 +14,7 @@ from src.submission.check_validity import (
|
|
| 14 |
REQUESTED_MODELS = None
|
| 15 |
USERS_TO_SUBMISSION_DATES = None
|
| 16 |
|
|
|
|
| 17 |
def add_new_eval(
|
| 18 |
model: str,
|
| 19 |
base_model: str,
|
|
@@ -45,7 +46,9 @@ def add_new_eval(
|
|
| 45 |
|
| 46 |
# Is the model on the hub?
|
| 47 |
if weight_type in ["Delta", "Adapter"]:
|
| 48 |
-
base_model_on_hub, error, _ = is_model_on_hub(
|
|
|
|
|
|
|
| 49 |
if not base_model_on_hub:
|
| 50 |
return styled_error(f'Base model "{base_model}" {error}')
|
| 51 |
|
|
|
|
| 3 |
from datetime import datetime, timezone
|
| 4 |
|
| 5 |
from src.display.formatting import styled_error, styled_message, styled_warning
|
| 6 |
+
from src.envs import API, EVAL_REQUESTS_PATH, QUEUE_REPO, TOKEN
|
| 7 |
from src.submission.check_validity import (
|
| 8 |
already_submitted_models,
|
| 9 |
check_model_card,
|
|
|
|
| 14 |
REQUESTED_MODELS = None
|
| 15 |
USERS_TO_SUBMISSION_DATES = None
|
| 16 |
|
| 17 |
+
|
| 18 |
def add_new_eval(
|
| 19 |
model: str,
|
| 20 |
base_model: str,
|
|
|
|
| 46 |
|
| 47 |
# Is the model on the hub?
|
| 48 |
if weight_type in ["Delta", "Adapter"]:
|
| 49 |
+
base_model_on_hub, error, _ = is_model_on_hub(
|
| 50 |
+
model_name=base_model, revision=revision, token=TOKEN, test_tokenizer=True
|
| 51 |
+
)
|
| 52 |
if not base_model_on_hub:
|
| 53 |
return styled_error(f'Base model "{base_model}" {error}')
|
| 54 |
|