Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from gradio_leaderboard import Leaderboard
|
3 |
+
import plotly.express as px
|
4 |
+
from pathlib import Path
|
5 |
+
import pandas as pd
|
6 |
+
import numpy as np
|
7 |
+
abs_path = Path(__file__).parent
|
8 |
+
|
9 |
+
def parse_model_args(model_args):
|
10 |
+
if "deltazip" in model_args:
|
11 |
+
model_args = model_args.split("deltazip")[1]
|
12 |
+
model_args = model_args.split(",")[0]
|
13 |
+
model_args = model_args.strip(".")
|
14 |
+
model_args = model_args.replace(".", "/")
|
15 |
+
if "espressor/" in model_args:
|
16 |
+
model_args = model_args.split("espressor/")[1]
|
17 |
+
model_args = model_args.split(",")[0]
|
18 |
+
model_args = model_args.strip(".")
|
19 |
+
model_args = model_args.replace(".", "/",1)
|
20 |
+
model_args = model_args.split("_")[0]
|
21 |
+
else:
|
22 |
+
model_args = model_args.split(",")[0]
|
23 |
+
model_args = model_args.replace("pretrained=", "")
|
24 |
+
return model_args
|
25 |
+
|
26 |
+
def parse_model_precision(model_args):
|
27 |
+
if "espressor" in model_args:
|
28 |
+
if 'W8A8_int8' in model_args:
|
29 |
+
precision = 'W8A8_int8'
|
30 |
+
else:
|
31 |
+
precision = model_args.split("_")[-1]
|
32 |
+
else:
|
33 |
+
precision = "Default"
|
34 |
+
return precision
|
35 |
+
|
36 |
+
# Any pandas-compatible data
|
37 |
+
df = pd.read_csv(str(abs_path / "eval_results.csv"))
|
38 |
+
# take acc only
|
39 |
+
df = df[df['metric'] == 'acc']
|
40 |
+
# dedup
|
41 |
+
df = df.drop_duplicates(subset=['model', 'task'])
|
42 |
+
# pivot df, such that the column names are model,task,efficiency
|
43 |
+
# but keep precision in its original place
|
44 |
+
df = df.pivot(index='model', columns='task', values='value').reset_index()
|
45 |
+
|
46 |
+
df['precision'] = df['model'].apply(lambda x: x.split(":")[-1])
|
47 |
+
df['model'] = df['model'].apply(lambda x: x.split(":")[0])
|
48 |
+
|
49 |
+
# average over all columns starting with 'task_'
|
50 |
+
df['avg_acc'] = df.filter(like='task_').mean(axis=1)
|
51 |
+
# keep 2 decimal points for avg_acc, and all tasks_
|
52 |
+
# rename columns starting with 'task_' by removing 'task_'
|
53 |
+
df = df.rename(columns=lambda x: x.replace('task_', ''))
|
54 |
+
numeric_columns = df.select_dtypes(include=[np.number]).columns
|
55 |
+
df[numeric_columns] = (df[numeric_columns]*100).round(2)
|
56 |
+
|
57 |
+
with gr.Blocks() as demo:
|
58 |
+
gr.Markdown("""
|
59 |
+
# 🥇 Efficient LLM Leaderboard
|
60 |
+
""")
|
61 |
+
task_options = [col for col in df.columns if col not in ['model', 'precision']]
|
62 |
+
|
63 |
+
with gr.Row():
|
64 |
+
selected_tasks = gr.CheckboxGroup(choices=task_options, label="Select Tasks")
|
65 |
+
with gr.Row():
|
66 |
+
accuracy_plot = gr.Plot(label="Accuracy Plot")
|
67 |
+
data_table = gr.Dataframe(value=df, label="Result Table")
|
68 |
+
|
69 |
+
def update_outputs(selected_tasks):
|
70 |
+
if not selected_tasks:
|
71 |
+
return df[['model', 'precision']], None
|
72 |
+
filtered_df = df[['model', 'precision'] + selected_tasks]
|
73 |
+
melted_df = filtered_df.melt(id_vars=['model', 'precision'], var_name='task', value_name='accuracy')
|
74 |
+
fig = px.bar(melted_df, x='model', y='accuracy', color='precision', barmode='group', facet_col='task')
|
75 |
+
return filtered_df, fig
|
76 |
+
|
77 |
+
selected_tasks.change(fn=update_outputs, inputs=selected_tasks, outputs=[data_table, accuracy_plot])
|
78 |
+
|
79 |
+
|
80 |
+
if __name__ == "__main__":
|
81 |
+
demo.launch()
|