Upload folder using huggingface_hub
Browse files- __pycache__/env.cpython-312.pyc +0 -0
- app.py +26 -0
- env.py +17 -0
- requirements.txt +2 -0
- utils.py +310 -0
__pycache__/env.cpython-312.pyc
ADDED
Binary file (701 Bytes). View file
|
|
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from env import TASK
|
2 |
+
from utils import run_pipeline, update_examples
|
3 |
+
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
+
|
7 |
+
with gr.Blocks(
|
8 |
+
title="YourBench Leaderboard",
|
9 |
+
css="button { margin: 0 10px; padding: 5px 15px; }",
|
10 |
+
) as app:
|
11 |
+
# DISPLAY TABLE AND ANALYSIS
|
12 |
+
title = gr.Markdown(f"YourBench auto-Leaderboard for {TASK}")
|
13 |
+
leaderboard = gr.DataFrame(label="Results", interactive=False)
|
14 |
+
samples_ix = gr.Number(label="Example Index", value=0, step=1, info="Navigate through different examples")
|
15 |
+
with gr.Tab("Hardest samples"):
|
16 |
+
hard_samples = gr.HTML()
|
17 |
+
with gr.Tab("Easiest samples"):
|
18 |
+
easy_samples = gr.HTML()
|
19 |
+
with gr.Tab("All samples"):
|
20 |
+
all_samples = gr.HTML()
|
21 |
+
|
22 |
+
samples_ix.change(update_examples, samples_ix, [easy_samples, hard_samples, all_samples])
|
23 |
+
|
24 |
+
app.load(run_pipeline, [samples_ix], [leaderboard, easy_samples, hard_samples, all_samples])
|
25 |
+
|
26 |
+
app.launch()
|
env.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
|
4 |
+
INIT_MODELS = [
|
5 |
+
# 70B
|
6 |
+
("Qwen/Qwen2.5-72B-Instruct", "novita"),
|
7 |
+
("meta-llama/Llama-3.3-70B-Instruct", "novita"),
|
8 |
+
("deepseek-ai/DeepSeek-R1-Distill-Llama-70B", "novita"),
|
9 |
+
# 20 to 30B
|
10 |
+
("Qwen/QwQ-32B", "novita"),
|
11 |
+
("mistralai/Mistral-Small-24B-Instruct-2501", "together"),
|
12 |
+
]
|
13 |
+
MODELS = [m[0] for m in INIT_MODELS]
|
14 |
+
TASK = os.getenv("TASK")
|
15 |
+
# With storage
|
16 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
17 |
+
ORG_NAME = os.getenv("ORG_NAME")
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
datasets
|
2 |
+
huggingface_hub
|
utils.py
ADDED
@@ -0,0 +1,310 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
from typing import Any
|
3 |
+
|
4 |
+
from env import TASK, MODELS, ORG_NAME
|
5 |
+
|
6 |
+
import gradio as gr
|
7 |
+
from datasets import Dataset, load_dataset
|
8 |
+
|
9 |
+
KNOWN_METRIC_LABELS = {
|
10 |
+
"accuracy": "Accuracy",
|
11 |
+
"accuracy_stderr": "Accuracy (stderr)",
|
12 |
+
}
|
13 |
+
|
14 |
+
def aggregate_results() -> list:
|
15 |
+
"""Extract scores for each model and return list of result dictionaries."""
|
16 |
+
all_results = []
|
17 |
+
for model_path in MODELS:
|
18 |
+
try:
|
19 |
+
path = f"{ORG_NAME}/details_{model_path.replace('/', '__')}_private"
|
20 |
+
dataset = load_dataset(path, "results", split="latest")
|
21 |
+
config = json.loads(dataset["config_general"][0])
|
22 |
+
results = json.loads(dataset["results"][0])
|
23 |
+
|
24 |
+
_, model = model_path.split("/")
|
25 |
+
duration = round(config["end_time"] - config["start_time"], 2)
|
26 |
+
|
27 |
+
result = {
|
28 |
+
"Model": model,
|
29 |
+
"Duration (s)": duration,
|
30 |
+
}
|
31 |
+
|
32 |
+
for metric, metric_values in results.items():
|
33 |
+
if metric == "all":
|
34 |
+
continue
|
35 |
+
|
36 |
+
for raw_metric_name, metric_value in metric_values.items():
|
37 |
+
base_name = raw_metric_name.split("(")[0].strip()
|
38 |
+
pretty_label = KNOWN_METRIC_LABELS.get(base_name, raw_metric_name)
|
39 |
+
|
40 |
+
if isinstance(metric_value, float):
|
41 |
+
metric_value = round(metric_value, 3)
|
42 |
+
|
43 |
+
result[pretty_label] = metric_value
|
44 |
+
|
45 |
+
all_results.append(result)
|
46 |
+
|
47 |
+
except Exception as e:
|
48 |
+
print(f"Error processing {model_path} {ORG_NAME}: {e}")
|
49 |
+
|
50 |
+
# Sort final result by Accuracy
|
51 |
+
all_results.sort(key=lambda r: r.get("Accuracy", 0), reverse=True)
|
52 |
+
|
53 |
+
return all_results
|
54 |
+
|
55 |
+
|
56 |
+
def extract_dataviz() -> tuple[list[dict[str, Any]], list[dict[str, Any]], list[dict[str, Any]]]:
|
57 |
+
"""Extract best, worst, and all samples for visualization"""
|
58 |
+
sample_index_map = {}
|
59 |
+
|
60 |
+
for model_path in MODELS:
|
61 |
+
try:
|
62 |
+
dataset_path = f"{ORG_NAME}/details_{model_path.replace('/', '__')}_private"
|
63 |
+
split_name = f"custom_{TASK.replace('/', '_')}_0"
|
64 |
+
dataset = load_dataset(dataset_path, split_name, split="latest")
|
65 |
+
|
66 |
+
for idx, row in enumerate(dataset):
|
67 |
+
prompt = row["full_prompt"]
|
68 |
+
gold = row.get("gold", "")
|
69 |
+
gold = gold[0] if isinstance(gold, list) and gold else gold
|
70 |
+
score = list(row["metrics"].values())[0]
|
71 |
+
predictions = row.get("predictions", [])
|
72 |
+
prediction = predictions[0] if predictions else ""
|
73 |
+
|
74 |
+
if idx not in sample_index_map:
|
75 |
+
sample_index_map[idx] = {
|
76 |
+
"ix": idx,
|
77 |
+
"prompt": prompt,
|
78 |
+
"gold": gold,
|
79 |
+
"model_scores": [],
|
80 |
+
"models": [],
|
81 |
+
}
|
82 |
+
|
83 |
+
if model_path not in sample_index_map[idx]["models"]:
|
84 |
+
sample_index_map[idx][f"{model_path}_score"] = row["metrics"]
|
85 |
+
sample_index_map[idx][f"{model_path}_prediction"] = prediction
|
86 |
+
sample_index_map[idx]["model_scores"].append(score)
|
87 |
+
sample_index_map[idx]["models"].append(model_path)
|
88 |
+
|
89 |
+
except Exception as e:
|
90 |
+
print(f"Error processing {model_path}: {e}")
|
91 |
+
|
92 |
+
all_samples = sorted(sample_index_map.values(), key=lambda r: r["ix"])
|
93 |
+
|
94 |
+
hard_samples = [sample for sample in all_samples if sum(sample["model_scores"]) == 0]
|
95 |
+
|
96 |
+
easy_samples = [sample for sample in all_samples if sum(sample["model_scores"]) == len(sample["model_scores"])]
|
97 |
+
|
98 |
+
return easy_samples, hard_samples, all_samples
|
99 |
+
|
100 |
+
|
101 |
+
def samples_to_box_display(samples: list[dict[str, Any]], example_index: int = 0) -> str:
|
102 |
+
"""
|
103 |
+
Adapted from Nathan's code https://huggingface.co/spaces/SaylorTwift/OpenEvalsModelDetails/
|
104 |
+
Support both light and dark themes
|
105 |
+
"""
|
106 |
+
if not samples:
|
107 |
+
return "No samples in this category!"
|
108 |
+
|
109 |
+
sample = samples[example_index]
|
110 |
+
outputs = []
|
111 |
+
|
112 |
+
for model in sample["models"]:
|
113 |
+
try:
|
114 |
+
outputs.append({
|
115 |
+
"Model": model,
|
116 |
+
"Prediction": sample[f"{model}_prediction"],
|
117 |
+
"Prompt": sample["prompt"],
|
118 |
+
"Metrics": sample[f"{model}_score"],
|
119 |
+
"Gold": sample["gold"],
|
120 |
+
})
|
121 |
+
except (KeyError, IndexError):
|
122 |
+
continue
|
123 |
+
|
124 |
+
if not outputs:
|
125 |
+
return "No results found for the selected combination."
|
126 |
+
|
127 |
+
# CSS for theme compatibility
|
128 |
+
css = """
|
129 |
+
<style>
|
130 |
+
:root {
|
131 |
+
--primary-bg: #f5f5f5;
|
132 |
+
--secondary-bg: #ffffff;
|
133 |
+
--gold-bg: #e6f3e6;
|
134 |
+
--text-color: #333333;
|
135 |
+
--border-color: #ddd;
|
136 |
+
}
|
137 |
+
|
138 |
+
@media (prefers-color-scheme: dark) {
|
139 |
+
:root {
|
140 |
+
--primary-bg: #2a2a2a;
|
141 |
+
--secondary-bg: #333333;
|
142 |
+
--gold-bg: #2a3a2a;
|
143 |
+
--text-color: #e0e0e0;
|
144 |
+
--border-color: #555;
|
145 |
+
}
|
146 |
+
}
|
147 |
+
|
148 |
+
.box-container {
|
149 |
+
max-width: 800px;
|
150 |
+
margin: 0 auto;
|
151 |
+
color: var(--text-color);
|
152 |
+
}
|
153 |
+
|
154 |
+
.gold-box {
|
155 |
+
background: var(--gold-bg);
|
156 |
+
padding: 20px;
|
157 |
+
border-radius: 10px;
|
158 |
+
margin-bottom: 20px;
|
159 |
+
}
|
160 |
+
|
161 |
+
.model-box {
|
162 |
+
background: var(--primary-bg);
|
163 |
+
padding: 20px;
|
164 |
+
margin-bottom: 20px;
|
165 |
+
border-radius: 10px;
|
166 |
+
}
|
167 |
+
|
168 |
+
.content-section {
|
169 |
+
background: var(--secondary-bg);
|
170 |
+
padding: 15px;
|
171 |
+
border-radius: 5px;
|
172 |
+
margin-top: 10px;
|
173 |
+
}
|
174 |
+
|
175 |
+
.metric-row {
|
176 |
+
padding: 5px;
|
177 |
+
border-bottom: 1px solid var(--border-color);
|
178 |
+
}
|
179 |
+
|
180 |
+
h2, h3 {
|
181 |
+
color: var(--text-color);
|
182 |
+
}
|
183 |
+
|
184 |
+
pre, code {
|
185 |
+
white-space: pre-wrap;
|
186 |
+
word-wrap: break-word;
|
187 |
+
margin: 0;
|
188 |
+
color: var(--text-color);
|
189 |
+
}
|
190 |
+
</style>
|
191 |
+
"""
|
192 |
+
|
193 |
+
# Create HTML output with all models
|
194 |
+
html_output = f"{css}<div class='box-container'>\n\n"
|
195 |
+
|
196 |
+
# Show gold answer at the top with distinct styling
|
197 |
+
if outputs:
|
198 |
+
html_output += "<div class='gold-box'>\n"
|
199 |
+
html_output += "<h3 style='margin-top: 0;'>Ground Truth</h3>\n"
|
200 |
+
html_output += "<div style='overflow-x: auto; max-width: 100%;'>\n"
|
201 |
+
html_output += f"<pre><code>{outputs[0]['Gold']}</code></pre>\n"
|
202 |
+
html_output += "</div>\n"
|
203 |
+
html_output += "</div>\n"
|
204 |
+
|
205 |
+
for output in outputs:
|
206 |
+
html_output += "<div class='model-box'>\n"
|
207 |
+
html_output += f"<h2 style='margin-top: 0;'>{output['Model']}</h2>\n"
|
208 |
+
|
209 |
+
# Format metrics as a clean table
|
210 |
+
html_output += "<details open style='margin-bottom: 15px;'>\n"
|
211 |
+
html_output += "<summary><h3 style='display: inline; margin: 0;'>Metrics</h3></summary>\n"
|
212 |
+
metrics = output["Metrics"]
|
213 |
+
if isinstance(metrics, str):
|
214 |
+
metrics = eval(metrics)
|
215 |
+
html_output += "<div style='overflow-x: auto;'>\n"
|
216 |
+
html_output += "<table style='width: 100%; margin: 10px 0; border-collapse: collapse;'>\n"
|
217 |
+
for key, value in metrics.items():
|
218 |
+
if isinstance(value, float):
|
219 |
+
value = f"{value:.3f}"
|
220 |
+
html_output += f"<tr class='metric-row'><td><strong>{key}</strong></td><td>{value}</td></tr>\n"
|
221 |
+
html_output += "</table>\n"
|
222 |
+
html_output += "</div>\n"
|
223 |
+
html_output += "</details>\n\n"
|
224 |
+
|
225 |
+
# Handle prompt formatting with better styling
|
226 |
+
html_output += "<details style='margin-bottom: 15px;'>\n"
|
227 |
+
html_output += "<summary><h3 style='display: inline; margin: 0;'>Prompt</h3></summary>\n"
|
228 |
+
html_output += "<div class='content-section'>\n"
|
229 |
+
|
230 |
+
prompt_text = output["Prompt"]
|
231 |
+
if isinstance(prompt_text, list):
|
232 |
+
for i, msg in enumerate(prompt_text):
|
233 |
+
if isinstance(msg, dict) and "content" in msg:
|
234 |
+
role = msg.get("role", "message").title()
|
235 |
+
html_output += "<div style='margin-bottom: 10px;'>\n"
|
236 |
+
html_output += f"<strong>{role}:</strong>\n"
|
237 |
+
html_output += "<div style='overflow-x: auto;'>\n"
|
238 |
+
html_output += f"<pre><code>{msg['content']}</code></pre>\n"
|
239 |
+
html_output += "</div>\n"
|
240 |
+
html_output += "</div>\n"
|
241 |
+
else:
|
242 |
+
html_output += "<div style='margin-bottom: 10px;'>\n"
|
243 |
+
html_output += "<div style='overflow-x: auto;'>\n"
|
244 |
+
html_output += f"<pre><code>{json.dumps(msg, indent=2)}</code></pre>\n"
|
245 |
+
html_output += "</div>\n"
|
246 |
+
html_output += "</div>\n"
|
247 |
+
else:
|
248 |
+
html_output += "<div style='overflow-x: auto;'>\n"
|
249 |
+
if isinstance(prompt_text, dict) and "content" in prompt_text:
|
250 |
+
html_output += f"<pre><code>{prompt_text['content']}</code></pre>\n"
|
251 |
+
else:
|
252 |
+
html_output += f"<pre><code>{prompt_text}</code></pre>\n"
|
253 |
+
html_output += "</div>\n"
|
254 |
+
|
255 |
+
html_output += "</div>\n"
|
256 |
+
html_output += "</details>\n\n"
|
257 |
+
|
258 |
+
# Style prediction output - now in a collapsible section
|
259 |
+
html_output += "<details open style='margin-bottom: 15px;'>\n"
|
260 |
+
html_output += "<summary><h3 style='display: inline; margin: 0;'>Prediction</h3>"
|
261 |
+
# Add word count in a muted style
|
262 |
+
word_count = len(output["Prediction"].split())
|
263 |
+
html_output += f"<span style='color: inherit; opacity: 0.7; font-size: 0.8em; margin-left: 10px;'>({word_count} words)</span>"
|
264 |
+
html_output += "</summary>\n"
|
265 |
+
html_output += "<div class='content-section'>\n"
|
266 |
+
html_output += "<div style='overflow-x: auto;'>\n"
|
267 |
+
html_output += f"<pre><code>{output['Prediction']}</code></pre>\n"
|
268 |
+
html_output += "</div>\n"
|
269 |
+
html_output += "</div>\n"
|
270 |
+
html_output += "</details>\n"
|
271 |
+
html_output += "</div>\n\n"
|
272 |
+
|
273 |
+
html_output += "</div>"
|
274 |
+
return html_output
|
275 |
+
|
276 |
+
|
277 |
+
def run_pipeline(samples_ix: int = 0) -> tuple[Any, Any, Any, Any]:
|
278 |
+
"""Run evaluation pipeline and return results for display"""
|
279 |
+
results = aggregate_results()
|
280 |
+
easy_samples, hard_samples, all_samples = extract_dataviz()
|
281 |
+
|
282 |
+
return (
|
283 |
+
gr.Dataframe(Dataset.from_list(results).to_pandas(), visible=True),
|
284 |
+
gr.HTML(
|
285 |
+
samples_to_box_display(easy_samples, samples_ix),
|
286 |
+
label="Easiest samples (always found)",
|
287 |
+
visible=True,
|
288 |
+
),
|
289 |
+
gr.HTML(
|
290 |
+
samples_to_box_display(hard_samples, samples_ix),
|
291 |
+
label="Hardest samples (always failed)",
|
292 |
+
visible=True,
|
293 |
+
),
|
294 |
+
gr.HTML(
|
295 |
+
samples_to_box_display(all_samples, samples_ix),
|
296 |
+
label="All samples",
|
297 |
+
visible=True,
|
298 |
+
),
|
299 |
+
)
|
300 |
+
|
301 |
+
|
302 |
+
def update_examples(samples_ix: int = 0) -> tuple[str, str, str]:
|
303 |
+
"""Return HTML strings for easy, hard, and all samples"""
|
304 |
+
easy_samples, hard_samples, all_samples = extract_dataviz()
|
305 |
+
|
306 |
+
return (
|
307 |
+
samples_to_box_display(easy_samples, samples_ix),
|
308 |
+
samples_to_box_display(hard_samples, samples_ix),
|
309 |
+
samples_to_box_display(all_samples, samples_ix),
|
310 |
+
)
|