Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 17,086 Bytes
12efa10 42d6492 01cd9ce d981793 01cd9ce 12efa10 653f70c 12efa10 42d6492 12efa10 42d6492 12efa10 01cd9ce 12efa10 4db3879 12efa10 4db3879 12efa10 ca48878 6b21330 7e61b6b ca48878 6b21330 ca48878 7e61b6b ca48878 7e61b6b 6b21330 12efa10 ca48878 7e61b6b 378e964 ca48878 e60f602 6b21330 7e61b6b ca48878 6b21330 ca48878 bdeb2a3 aaf9571 01cd9ce 03d9dfb 6b21330 e1a8888 378e964 e60f602 ca48878 6b21330 ca48878 bdeb2a3 ca48878 7e61b6b 6b21330 ca48878 18ef3dc ca48878 6b21330 ca48878 e1a8888 bcbf716 bdeb2a3 bcbf716 12efa10 ca48878 12efa10 01cd9ce 6b21330 01cd9ce 6b21330 01cd9ce 1cda853 01cd9ce 1cda853 01cd9ce 6b21330 1cda853 cb2c8cb 1cda853 6b21330 01cd9ce 6b21330 01cd9ce 2fe1d39 a0ce5c3 01cd9ce 2fe1d39 a92eec7 01cd9ce 2fe1d39 01cd9ce 2d5cded 2fe1d39 01cd9ce d981793 01cd9ce d981793 2fe1d39 d981793 01cd9ce 12efa10 0e0c765 98e8d9a 12efa10 ca48878 12efa10 ca48878 01cd9ce d981793 cb2c8cb aaf9571 cb2c8cb aaf9571 cb2c8cb 01cd9ce d981793 fcef1fd d981793 cb2c8cb d981793 12efa10 aaf9571 d981793 12efa10 b1b8113 12efa10 653f70c b1b8113 12efa10 ba3e489 12efa10 852dbdd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 |
import gradio as gr
import pandas as pd
from apscheduler.schedulers.background import BackgroundScheduler
#from huggingface_hub import snapshot_download
import re
import plotly.graph_objects as go
from src.about import (
CITATION_BUTTON_LABEL,
CITATION_BUTTON_TEXT,
EVALUATION_QUEUE_TEXT,
INTRODUCTION_TEXT,
LLM_BENCHMARKS_TEXT,
TITLE,
FOOTER_TEXT
)
from src.display.css_html_js import custom_css
from src.display.utils import (
BENCHMARK_COLS,
COLS,
EVAL_COLS,
EVAL_TYPES,
AutoEvalColumn,
# ModelType,
fields,
#WeightType,
#Precision
)
from src.envs import API, EVAL_REQUESTS_PATH, EVAL_RESULTS_PATH, QUEUE_REPO, REPO_ID, RESULTS_REPO, TOKEN
from src.populate import get_evaluation_queue_df, get_leaderboard_df
from src.submission.submit import add_new_eval
from src.leaderboard.read_evals import get_model_answers_html_file
skills = ['MMLU', 'General Knowledge', 'Reasoning & Math', 'Translation (incl Dialects)', 'Trust & Safety', 'Writing (incl Dialects)', 'RAG QA', 'Reading Comprehension', 'Arabic Language & Grammar', 'Diacritization', 'Dialect Detection', 'Sentiment Analysis', 'Summarization', 'Instruction Following', 'Transliteration', 'Paraphrasing', 'Entity Extraction', 'Long Context', 'Coding', 'Hallucination', 'Function Calling', 'Structuring']
def restart_space():
API.restart_space(repo_id=REPO_ID)
### Space initialisation
"""
try:
print(EVAL_REQUESTS_PATH)
snapshot_download(
repo_id=QUEUE_REPO, local_dir=EVAL_REQUESTS_PATH, repo_type="dataset", tqdm_class=None, etag_timeout=30, token=TOKEN
)
except Exception:
restart_space()
try:
print(EVAL_RESULTS_PATH)
snapshot_download(
repo_id=RESULTS_REPO, local_dir=EVAL_RESULTS_PATH, repo_type="dataset", tqdm_class=None, etag_timeout=30, token=TOKEN
)
except Exception:
restart_space()
"""
LEADERBOARD_DF = get_leaderboard_df(EVAL_RESULTS_PATH, EVAL_REQUESTS_PATH, COLS, BENCHMARK_COLS)
(
finished_eval_queue_df,
running_eval_queue_df,
pending_eval_queue_df,
) = get_evaluation_queue_df(EVAL_REQUESTS_PATH, EVAL_COLS)
def hide_skill_columns(dataframe, exceptions=[]):
return dataframe[[c.name for c in fields(AutoEvalColumn) if c.displayed_by_default or c.name in exceptions]]
def perform_cell_formatting(dataframe):
styler = dataframe.style.format(precision=2, decimal=".").apply(
lambda rows: [
"background-color: red;color: white !important" if (value >0) else "color: green !important;" for value in rows
],
subset=["Contamination Score"],
axis=1
)
return styler
def make_column_bold(df_col):
return df_col.apply(lambda x: "<b>"+str(x)+"</b>")
def init_leaderboard(dataframe):
dataframe = hide_skill_columns(dataframe)
dataframe.loc[:,"Benchmark Score (0-10)"] = make_column_bold(dataframe["Benchmark Score (0-10)"])
styler = perform_cell_formatting(dataframe)
return gr.Dataframe(
value=styler,
datatype="markdown",
wrap=False,
show_fullscreen_button=False,
interactive=False,
column_widths=[30,50,40,150,60,60,60],
max_height=450,
elem_classes="leaderboard_col_style",
show_search="filter",
max_chars=None
)
def init_skill_leaderboard(dataframe):
## create selector for model skills, based on the selector filter the dataframe
skills_dropdown = gr.Dropdown(choices=skills, label="Select Skill", value=skills[0])
def filter_dataframe(skill):
filtered_df = dataframe.sort_values(by=[skill], ascending=False).reset_index(drop=True)
filtered_df = hide_skill_columns(filtered_df, exceptions=[skill])
new_skill_name = skill+" Score"
filtered_df.rename(columns={skill: new_skill_name}, inplace=True)
filtered_df[new_skill_name] = make_column_bold(filtered_df[new_skill_name])
## reorder columns of filtered_df and insert skill in the middle
filtered_df = filtered_df[list(filtered_df.columns[:4]) + [new_skill_name] + list(filtered_df.columns[4:-1])]
filtered_df["Rank"] = range(1, len(filtered_df) + 1)
styler = perform_cell_formatting(filtered_df)
return gr.Dataframe(
value=styler,
datatype="markdown",
wrap=True,
show_fullscreen_button=False,
interactive=False,
column_widths=[30,50,40,150,60,60,60,80],
max_height=420,
elem_classes="leaderboard_col_style"
)
leaderboard_by_skill = filter_dataframe(skills[0])
skills_dropdown.change(filter_dataframe, inputs=skills_dropdown, outputs=leaderboard_by_skill)
return leaderboard_by_skill
def init_size_leaderboard(dataframe):
dataframe = hide_skill_columns(dataframe)
dataframe.loc[:,"Benchmark Score (0-10)"] = make_column_bold(dataframe["Benchmark Score (0-10)"])
size_keys = ["Large","Medium","Small","Nano"]
size_names = ["Large (More than 35B Parameter)","Medium (~35B)","Small (~10B)","Nano (~3B)"]
sizes_dropdown = gr.Dropdown(choices=size_names, label="Select Model Size", value=size_names[0])
def filter_dataframe(size_name):
##map size name to size key
size_name_mapped_to_key = size_keys[size_names.index(size_name)]
##slice array from 0 to index of size
size_list = size_keys[size_keys.index(size_name_mapped_to_key):]
filtered_df = dataframe[dataframe["Size"].isin(size_list)].reset_index(drop=True)
filtered_df["Rank"] = range(1, len(filtered_df) + 1)
styler = perform_cell_formatting(filtered_df)
return gr.Dataframe(
value=styler,
datatype="markdown",
wrap=True,
show_fullscreen_button=False,
interactive=False,
column_widths=[30,50,40,150,60,60,60],
max_height=420,
elem_classes="leaderboard_col_style"
)
leaderboard_by_skill = filter_dataframe(size_names[0])
sizes_dropdown.change(filter_dataframe, inputs=sizes_dropdown, outputs=leaderboard_by_skill)
return leaderboard_by_skill
def strip_html_tags(model_name):
return re.sub('<[^<]+?>', '', model_name)
def get_model_info_blocks(chosen_model_name):
model_names = LEADERBOARD_DF["Model Name"].unique().tolist()
model_names_clean = [strip_html_tags(model_name) for model_name in model_names]
model_name_full = model_names[model_names_clean.index(chosen_model_name)]
filtered_df = LEADERBOARD_DF[LEADERBOARD_DF["Model Name"]==model_name_full].reset_index(drop=True)
skills_bar_df = pd.DataFrame({
'Skills': skills,
'Benchmark Score (0-10)': filtered_df[skills].values[0]
})
skills_bar_df = skills_bar_df.sort_values(by=['Benchmark Score (0-10)'], ascending=False).reset_index(drop=True)
def get_metric_html(metric_title):
return f"<div class='deep-dive-metric'><b>{metric_title}</b><span class='ddm-value'>{{}}</div>"
with gr.Accordion("Model Details"):
with gr.Row():
model_name = gr.HTML(get_metric_html("Model Name").format(chosen_model_name))
with gr.Row():
benchmark_score = gr.HTML(get_metric_html("Benchmark Score (0-10)").format(str(filtered_df["Benchmark Score (0-10)"][0])))
rank = gr.HTML(get_metric_html("Benchmark Rank").format(filtered_df["Rank"][0]))
speed = gr.HTML(get_metric_html("Speed <br/>(words per second)").format(filtered_df["Speed (words/sec)"][0]))
contamination = gr.HTML(get_metric_html("Contamination Score").format(filtered_df["Contamination Score"][0]))
size = gr.HTML(get_metric_html("Size Category").format(filtered_df["Size"][0]))
with gr.Row():
skills_bar = gr.BarPlot(
value=skills_bar_df,
x="Skills",
y="Benchmark Score (0-10)",
width=500,
height=500,
x_label_angle=45,
color="Skills",
color_title=None,
label=f"{chosen_model_name} model skills",
sort="-y"
)
html_file_content,download_file_path = get_model_answers_html_file(EVAL_RESULTS_PATH, chosen_model_name)
if html_file_content == "EMPTY":
answers_html = gr.Markdown("")
else:
with gr.Row():
gr.Markdown(f"""
<a href='{download_file_path}' target='_blank'>Download model answers here</a>
""")
with gr.Row():
##strip style and script tags from html
html_file_content = re.sub('<style.*?>.*?</style>', '', html_file_content, flags=re.DOTALL)
html_file_content = re.sub('<script.*?>.*?</script>', '', html_file_content, flags=re.DOTALL)
html_file_content = html_file_content.replace('<html lang="ar" dir="rtl">','<html>')
answers_html = gr.HTML(html_file_content,max_height=500,show_label=True,
label="Model Responses", container=True, elem_classes="model_responses_container")
return model_name,benchmark_score,rank,speed,contamination,size,skills_bar,answers_html
def init_compare_tab(dataframe):
model_names = dataframe["Model Name"].unique().tolist()
model_names_clean = [strip_html_tags(model_name) for model_name in model_names]
with gr.Row():
models_dropdown = gr.Dropdown(choices=model_names_clean, label="Select Models",
value=model_names_clean[0], multiselect=True)
def draw_radar_chart(models):
print(models)
fig = go.Figure()
for model_name in models:
model_name_full = model_names[model_names_clean.index(model_name)]
skill_scores = dataframe[dataframe["Model Name"] == model_name_full][skills].values[0]
fig.add_trace(go.Scatterpolar(
r=skill_scores,
theta=skills,
fill='toself',
name=model_name,
))
fig.update_layout(
polar=dict(
radialaxis=dict(visible=True)
),
showlegend=True,
height=500,
width=900,
margin=dict(l=0, r=0, t=40, b=40),
legend=dict(
orientation="h",
yanchor="bottom",
y=-0.2,
xanchor="center",
x=0.5
)
)
return gr.Plot(value=fig)
radar_chart = draw_radar_chart(models_dropdown.value)
models_dropdown.change(draw_radar_chart, inputs=models_dropdown, outputs=radar_chart)
return radar_chart
demo = gr.Blocks(css=custom_css)
with demo:
gr.HTML(TITLE, elem_classes="abl_header")
gr.HTML(INTRODUCTION_TEXT, elem_classes="abl_desc_text")
with gr.Tabs(elem_classes="tab-buttons") as tabs:
with gr.TabItem("π
Leaderboard - Top Models", elem_id="llm-benchmark-tab-table", id=0):
leaderboard = init_leaderboard(LEADERBOARD_DF)
with gr.TabItem("π
Top by Size", elem_id="llm-benchmark-tab-size", id=1):
leaderboard = init_size_leaderboard(LEADERBOARD_DF)
with gr.TabItem("π
Top by Skill", elem_id="llm-benchmark-tab-skills", id=2):
leaderboard = init_skill_leaderboard(LEADERBOARD_DF)
with gr.TabItem("βοΈ Compare", elem_id="llm-benchmark-tab-compare", id=3):
init_compare_tab(LEADERBOARD_DF)
with gr.TabItem("π¬ Deep Dive", elem_id="llm-benchmark-tab-compare", id=4):
model_names = LEADERBOARD_DF["Model Name"].unique().tolist()
model_names_clean = [strip_html_tags(model_name) for model_name in model_names]
with gr.Row():
models_dropdown = gr.Dropdown(choices=model_names_clean, label="Select Model", value=model_names_clean[0])
model_name,benchmark_score,rank,speed,contamination,size,skills_bar,answers_html = get_model_info_blocks(models_dropdown.value)
models_dropdown.change(get_model_info_blocks, inputs=models_dropdown, outputs=[model_name,benchmark_score,rank,speed,contamination,size,skills_bar,answers_html])
with gr.TabItem("π Submit here", elem_id="llm-benchmark-tab-submit", id=5):
with gr.Row():
gr.Markdown("# Submit your model", elem_classes="markdown-text")
with gr.Column():
gr.Markdown("### Please confirm that you understand and accept the conditions below before submitting your model:")
prereqs_checkboxes = gr.CheckboxGroup(["I have successfully run the ABB benchmark script on my model using my own infrastructure, and I am not using the Leaderboard for testing purposes",
"I understand that my account/org has only one submission per month",
"I understand that I can't submit models more than 15B parameters (learn more in the FAQ)",
"I understand that submitting contaminated models, or models intended to test the contamination score, may result in actions from our side, including banning. We also reserve the right to delete any model we deem contaminated without prior notice"],
label=None, info=None,
elem_classes="submit_prereq_checkboxes_container",
container=False)
with gr.Row():
with gr.Column():
model_name_textbox = gr.Textbox(label="Model name", placeholder="org/model-name" )
submit_button = gr.Button("Submit Eval", variant="huggingface", interactive=False )
prereqs_checkboxes.change(
fn=lambda choices: gr.update(interactive=len(choices) == 4),
inputs=prereqs_checkboxes,
outputs=submit_button
)
submission_result = gr.Markdown()
submit_button.click(
add_new_eval,
[
model_name_textbox,
],
submission_result,
)
with gr.Column():
with gr.Row():
gr.Markdown(EVALUATION_QUEUE_TEXT, elem_classes="markdown-text")
with gr.Column():
with gr.Accordion(
f"β
Finished Evaluations ({len(finished_eval_queue_df)})",
open=False,
):
with gr.Row():
finished_eval_table = gr.components.Dataframe(
value=finished_eval_queue_df,
headers=EVAL_COLS,
datatype=EVAL_TYPES,
row_count=5,
)
with gr.Accordion(
f"π Running Evaluation Queue ({len(running_eval_queue_df)})",
open=False,
):
with gr.Row():
running_eval_table = gr.components.Dataframe(
value=running_eval_queue_df,
headers=EVAL_COLS,
datatype=EVAL_TYPES,
row_count=5,
)
with gr.Accordion(
f"β³ Pending Evaluation Queue ({len(pending_eval_queue_df)})",
open=False,
):
with gr.Row():
pending_eval_table = gr.components.Dataframe(
value=pending_eval_queue_df,
headers=EVAL_COLS,
datatype=EVAL_TYPES,
row_count=5,
)
with gr.TabItem("π FAQ", elem_id="llm-benchmark-tab-faq", id=6):
gr.Markdown(LLM_BENCHMARKS_TEXT, elem_classes="markdown-text")
with gr.Row():
with gr.Accordion("π Citation", open=False):
citation_button = gr.Textbox(
value=CITATION_BUTTON_TEXT,
label=CITATION_BUTTON_LABEL,
lines=10,
elem_id="citation-button",
show_copy_button=True,
)
with gr.Row():
gr.HTML(FOOTER_TEXT)
scheduler = BackgroundScheduler()
scheduler.add_job(restart_space, "interval", seconds=3600)
scheduler.start()
demo.queue(default_concurrency_limit=40).launch(ssr_mode=False) |