Spaces:
Running
Running
File size: 7,402 Bytes
c8763bd 0eea6c1 c8763bd 9dc4521 d262fb3 0eea6c1 c8763bd d262fb3 708b21b c8763bd dcfabfb e02ef37 930b7c1 dcfabfb 930b7c1 6640b32 efc3d5b d262fb3 c8763bd a18f8de e2c5bda efc3d5b 930b7c1 00642fb 930b7c1 efc3d5b 930b7c1 efc3d5b 930b7c1 efc3d5b 930b7c1 efc3d5b 930b7c1 c8763bd 930b7c1 c8763bd 0eea6c1 b075f8f d2ef1d3 f208a6d d2ef1d3 f208a6d d2ef1d3 f208a6d d2ef1d3 02f02af 0830b0b 8e785e9 d262fb3 c8763bd 8e785e9 f208a6d 4e5004d 02f02af f208a6d 02f02af b075f8f 8e785e9 c8763bd 708b21b a0b186b 708b21b a18f8de 708b21b 8e785e9 708b21b a18f8de 708b21b a18f8de 8e785e9 a18f8de b075f8f 8e785e9 35b1013 8e785e9 e985813 8e785e9 53e3aab 35b1013 b075f8f 708b21b 9dc4521 00642fb d262fb3 0eea6c1 d262fb3 c8763bd 5aacd58 c8763bd d262fb3 c8763bd |
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 |
import os
import json
import gradio as gr
import pandas as pd
from apscheduler.schedulers.background import BackgroundScheduler
from src.assets.text_content import TITLE, INTRODUCTION_TEXT, CITATION_BUTTON_LABEL, CITATION_BUTTON_TEXT
from src.utils import restart_space, load_dataset_repo, make_clickable_model
from src.assets.css_html_js import custom_css, get_window_url_params
LLM_PERF_LEADERBOARD_REPO = "optimum/llm-perf-leaderboard"
LLM_PERF_DATASET_REPO = "optimum/llm-perf-dataset"
OPTIMUM_TOKEN = os.environ.get("OPTIMUM_TOKEN", None)
COLUMNS_MAPPING = {
"model": "Model π€",
"backend.name": "Backend π",
"backend.torch_dtype": "Datatype π₯",
"average": "Average H4 Score β¬οΈ",
"generate.throughput(tokens/s)": "Throughput (tokens/s) β¬οΈ",
}
COLUMNS_DATATYPES = ["markdown", "str", "str", "number", "number", "number"]
SORTING_COLUMN = ["Throughput (tokens/s) β¬οΈ"]
llm_perf_dataset_repo = load_dataset_repo(LLM_PERF_DATASET_REPO, OPTIMUM_TOKEN)
def get_benchmark_df(benchmark):
if llm_perf_dataset_repo:
llm_perf_dataset_repo.git_pull()
# load
bench_df = pd.read_csv(
f"./llm-perf-dataset/reports/{benchmark}/inference_report.csv")
scores_df = pd.read_csv(
f"./llm-perf-dataset/reports/average_scores.csv")
# merge on model
bench_df = bench_df.merge(
scores_df, how="left", left_on="model", right_on="model")
# preprocess
bench_df["model"] = bench_df["model"].apply(make_clickable_model)
# filter
bench_df = bench_df[list(COLUMNS_MAPPING.keys())]
# rename
bench_df.rename(columns=COLUMNS_MAPPING, inplace=True)
# sort
bench_df.sort_values(by=SORTING_COLUMN, ascending=False, inplace=True)
return bench_df
def change_tab(query_param):
query_param = query_param.replace("'", '"')
query_param = json.loads(query_param)
if (
isinstance(query_param, dict)
and "tab" in query_param
and query_param["tab"] == "evaluation"
):
return gr.Tabs.update(selected=1)
else:
return gr.Tabs.update(selected=0)
def submit_query(single_df, multi_df, text, backends, datatypes, threshold):
print("submit_query")
print(text)
print(backends)
print(datatypes)
print(threshold)
filtered_single = single_df[
single_df["Model π€"].str.contains(text) &
single_df["Backend π"].isin(backends) &
single_df["Datatype π₯"].isin(datatypes) &
(single_df["Average H4 Score β¬οΈ"] >= threshold)
]
filtered_multi = multi_df[
multi_df["Model π€"].str.contains(text) &
multi_df["Backend π"].isin(backends) &
multi_df["Datatype π₯"].isin(datatypes) &
(multi_df["Average H4 Score β¬οΈ"] >= threshold)
]
return filtered_single, filtered_multi
# Define demo interface
demo = gr.Blocks(css=custom_css)
with demo:
gr.HTML(TITLE)
gr.Markdown(INTRODUCTION_TEXT, elem_classes="markdown-text")
with gr.Row():
search_bar = gr.Textbox(
label="Search π",
info="Search for a model and press Submit π",
elem_id="search-bar",
)
backend_checkboxes = gr.CheckboxGroup(
choices=["pytorch", "onnxruntime"],
value=["pytorch"],
label="Backends π",
info="Select the backends",
elem_id="backend-checkboxes",
)
datatype_checkboxes = gr.CheckboxGroup(
choices=["float32", "float16"],
value=["float32", "float16"],
label="Datatypes π₯",
info="Select the load datatypes",
elem_id="datatype-checkboxes",
)
with gr.Row():
threshold_slider = gr.Slider(
label="H4 Threshold π",
info="Filter by average H4 score",
value=0.0,
elem_id="threshold-slider",
)
with gr.Row():
submit_button = gr.Button(
value="Submit π",
info="Submit the filters",
elem_id="submit-button",
)
with gr.Tabs(elem_classes="tab-buttons") as tabs:
with gr.TabItem("π₯οΈ A100-80GB Benchmark ποΈ", elem_id="A100-benchmark", id=0):
SINGLE_A100_TEXT = """<h3>Single-GPU (1xA100):</h3>
<ul>
<li>Singleton Batch (1)</li>
<li>Thousand Tokens (1000)</li>
</ul>
"""
gr.HTML(SINGLE_A100_TEXT)
single_A100_df = get_benchmark_df(benchmark="1xA100-80GB")
# Original leaderboard table
single_A100_leaderboard = gr.components.Dataframe(
value=single_A100_df,
datatype=COLUMNS_DATATYPES,
headers=list(COLUMNS_MAPPING.values()),
elem_id="1xA100-table",
)
# Dummy Leaderboard table for handling the case when the user uses backspace key
single_A100_for_search = gr.components.Dataframe(
value=single_A100_df,
datatype=COLUMNS_DATATYPES,
headers=list(COLUMNS_MAPPING.values()),
max_rows=None,
visible=False,
)
with gr.TabItem("π₯οΈ 4xA100-80GB Benchmark ποΈ", elem_id="4xA100-benchmark", id=1):
MULTI_A100_TEXT = """<h3>Multi-GPU (4xA100):</h3>
<ul>
<li>Singleton Batch (1)</li>
<li>Thousand Tokens (1000)</li>
<li>Using <a href="https://huggingface.co/docs/accelerate" target="_blank">Accelerate</a>'s Auto Device Map</li>
</ul>"""
gr.HTML(MULTI_A100_TEXT)
multi_A100_df = get_benchmark_df(benchmark="4xA100-80GB")
multi_A100_leaderboard = gr.components.Dataframe(
value=multi_A100_df,
datatype=COLUMNS_DATATYPES,
headers=list(COLUMNS_MAPPING.values()),
elem_id="4xA100-table",
)
# Dummy Leaderboard table for handling the case when the user uses backspace key
multi_A100_for_search = gr.components.Dataframe(
value=multi_A100_df,
datatype=COLUMNS_DATATYPES,
headers=list(COLUMNS_MAPPING.values()),
max_rows=None,
visible=False,
)
# Callbacks
submit_button.click(submit_query,
[single_A100_for_search, multi_A100_for_search, search_bar,
backend_checkboxes, datatype_checkboxes, threshold_slider],
[single_A100_leaderboard, multi_A100_leaderboard])
with gr.Row():
with gr.Accordion("π Citation", open=False):
citation_button = gr.Textbox(
value=CITATION_BUTTON_TEXT,
label=CITATION_BUTTON_LABEL,
elem_id="citation-button",
).style(show_copy_button=True)
dummy = gr.Textbox(visible=False)
demo.load(
change_tab,
dummy,
tabs,
_js=get_window_url_params,
)
# Restart space every hour
scheduler = BackgroundScheduler()
scheduler.add_job(restart_space, "interval", seconds=3600,
args=[LLM_PERF_LEADERBOARD_REPO, OPTIMUM_TOKEN])
scheduler.start()
# Launch demo
demo.queue(concurrency_count=40).launch()
|