Spaces:
Running
Running
File size: 13,054 Bytes
c8763bd 134a499 c8763bd 4cfc121 134a499 c8763bd 134a499 699b4cd 0f1bf97 c382b2a 134a499 483e3a1 0f1bf97 c8763bd 134a499 d262fb3 134a499 a894537 134a499 3d7033f 134a499 dcfabfb 6db5c25 3d7033f 3c37eb3 3d7033f 134a499 cdf41e7 dcfabfb 134a499 a894537 134a499 0321f62 a894537 0f1bf97 134a499 ad86e2e 223c247 0321f62 06b3632 3d7033f efc3d5b 3d7033f 134a499 3d7033f c8763bd 3d7033f 0321f62 3d7033f cdf41e7 c5c2773 cdf41e7 bc255c5 aa1afc2 134a499 3d7033f 134a499 bf397e6 0321f62 134a499 0321f62 134a499 6203f23 134a499 5490c7c b3a1bf0 e89d633 b3a1bf0 134a499 43b85eb 3d7033f 43b85eb 3d7033f 43b85eb e89d633 c8763bd d19e350 8541989 134a499 f3dc796 8e8c463 8541989 3d7033f 134a499 b3a1bf0 8e8c463 5236273 8e8c463 5aba478 0f1bf97 8e8c463 134a499 3d7033f 134a499 8985298 d3abea5 5643bcb 0f1bf97 134a499 0f1bf97 8e8c463 97058d0 c4dcfe7 3d7033f c4dcfe7 0321f62 134a499 97058d0 134a499 c1efc37 134a499 3d7033f 134a499 b3a1bf0 d19e350 b3a1bf0 8e8c463 c8763bd 8e8c463 c8763bd 8e8c463 5721994 c8763bd 4b40065 134a499 4b40065 134a499 a29a8d2 134a499 4b40065 134a499 4b40065 134a499 4b40065 134a499 4b40065 0321f62 134a499 0321f62 4b40065 0321f62 c1efc37 0321f62 c1efc37 16a8bbd 3d7033f 16a8bbd c1efc37 16a8bbd c1efc37 0321f62 c1efc37 0321f62 c1efc37 0321f62 c1efc37 3d7033f 0321f62 3d7033f 0321f62 c1efc37 699b4cd c1efc37 699b4cd 0321f62 134a499 4b40065 3d7033f 4b40065 134a499 4b40065 134a499 d19e350 134a499 d19e350 29e37fd |
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 |
import os
import gradio as gr
import pandas as pd
import plotly.express as px
from huggingface_hub.file_download import hf_hub_download
from src.utils import process_model_name, process_model_arch
from src.assets.css_html_js import custom_css
from src.assets.text_content import (
TITLE,
ABOUT_TEXT,
INTRODUCTION_TEXT,
EXAMPLE_CONFIG_TEXT,
CITATION_BUTTON_LABEL,
CITATION_BUTTON_TEXT,
)
HF_TOKEN = os.environ.get("HF_TOKEN", None)
LLM_PERF_DATASET_REPO = "optimum/llm-perf-dataset"
MACHINE_TO_HARDWARE = {"hf-dgx-01": "A100-80GB π₯οΈ"}
ALL_COLUMNS_MAPPING = {
"Model": "Model π€",
"Arch": "Arch ποΈ",
"Size": "Params (B) π",
# deployment settings
"backend.name": "Backend π",
"backend.torch_dtype": "Dtype π₯",
"optimization": "Optimization π οΈ",
"quantization": "Quantization ποΈ",
# measurements
"Score": "Open LLM Score (%) β¬οΈ",
"decode.throughput(tokens/s)": "Decode Throughput (tokens/s) β¬οΈ",
"generate.throughput(tokens/s)": "E2E Throughput (tokens/s) β¬οΈ",
"forward.latency(s)": "Prefill Latency (s) β¬οΈ",
"generate.latency(s)": "E2E Latency (s) β¬οΈ",
"generate.max_memory_allocated(MB)": "Allocated Memory (MB) β¬οΈ",
"generate.max_memory_reserved(MB)": "Reserved Memory (MB) β¬οΈ",
"generate.max_memory_used(MB)": "Used Memory (MB) β¬οΈ",
"generate.energy_consumption(tokens/kWh)": "Energy (tokens/kWh) β¬οΈ",
}
SORTING_COLUMN = ["Score", "generate.throughput(tokens/s)"]
SORTING_ASCENDING = [False, True]
ALL_COLUMNS_DATATYPES = [
# open llm
"markdown",
"markdown",
"number",
# deployment settings
"str",
"str",
"str",
"str",
# measurements
"number",
"number",
"number",
"number",
"number",
"number",
"number",
"number",
"number",
"number",
]
# download data
hf_hub_download(
repo_id="optimum/llm-perf-dataset",
filename="open-llm.csv",
local_dir="dataset",
repo_type="dataset",
token=HF_TOKEN,
)
OPEN_LLM = pd.read_csv("dataset/open-llm.csv")
MACHINE_TO_DATAFRAME = {}
for machine in MACHINE_TO_HARDWARE:
hf_hub_download(
repo_id="optimum/llm-perf-dataset",
filename=f"{machine}/full-report.csv",
local_dir="dataset",
repo_type="dataset",
token=HF_TOKEN,
)
MACHINE_TO_DATAFRAME[machine] = pd.read_csv(f"dataset/{machine}/full-report.csv")
def get_benchmark_df(machine="hf-dgx-01"):
# merge on model
llm_perf = MACHINE_TO_DATAFRAME[machine].copy()
merged_df = OPEN_LLM.merge(llm_perf, left_on="Model", right_on="model")
# transpose energy consumption
merged_df["generate.energy_consumption(tokens/kWh)"] = (
1 / merged_df["generate.energy_consumption(kWh/token)"].fillna(1)
).astype(int)
# fix nan values
merged_df.loc[
merged_df["generate.energy_consumption(tokens/kWh)"] == 1,
"generate.energy_consumption(tokens/kWh)",
] = pd.NA
# add optimization column
merged_df["optimization"] = merged_df[
["backend.to_bettertransformer", "backend.use_flash_attention_2"]
].apply(
lambda x: "BetterTransformer"
if x["backend.to_bettertransformer"]
else ("FlashAttentionV2" if x["backend.use_flash_attention_2"] else "None"),
axis=1,
)
# add quantization scheme
merged_df["quantization"] = merged_df["backend.quantization_scheme"].apply(
lambda x: "BnB.4bit" if x == "bnb" else ("GPTQ.4bit" if x == "gptq" else "None")
)
# add decode throughput
merged_df["decode.throughput(tokens/s)"] = (
1000 / (merged_df["generate.latency(s)"] - merged_df["forward.latency(s)"])
).round(2)
# sort by metric
merged_df.sort_values(by=SORTING_COLUMN, ascending=SORTING_ASCENDING, inplace=True)
# filter columns
merged_df = merged_df[list(ALL_COLUMNS_MAPPING.keys())]
# rename columns
merged_df.rename(columns=ALL_COLUMNS_MAPPING, inplace=True)
return merged_df
def get_benchmark_table(bench_df):
copy_df = bench_df.copy()
# transform
copy_df["Model π€"] = copy_df["Model π€"].apply(process_model_name)
copy_df["Arch ποΈ"] = copy_df["Arch ποΈ"].apply(process_model_arch)
# process quantization
copy_df["Open LLM Score (%) β¬οΈ"] = copy_df.apply(
lambda x: f"{x['Open LLM Score (%) β¬οΈ']}**"
if x["Quantization ποΈ"] in ["BnB.4bit", "GPTQ.4bit"]
else x["Open LLM Score (%) β¬οΈ"],
axis=1,
)
return copy_df
def get_benchmark_chart(bench_df):
copy_df = bench_df.copy()
# transform
copy_df["Arch ποΈ"] = copy_df["Arch ποΈ"].apply(process_model_arch)
# plot
fig = px.scatter(
copy_df,
y="Open LLM Score (%) β¬οΈ",
x="E2E Latency (s) β¬οΈ",
size="Allocated Memory (MB) β¬οΈ",
color="Arch ποΈ",
custom_data=list(ALL_COLUMNS_MAPPING.values()),
color_discrete_sequence=px.colors.qualitative.Light24,
)
fig.update_layout(
title={
"text": "Latency vs. Score vs. Memory",
"y": 0.95,
"x": 0.5,
"xanchor": "center",
"yanchor": "top",
},
xaxis_title="Per 1000 Tokens Latency (s)",
yaxis_title="Open LLM Score (%)",
legend_title="LLM Architecture",
width=1200,
height=600,
)
fig.update_traces(
hovertemplate="<br>".join(
[
f"<b>{column}:</b> %{{customdata[{i}]}}"
for i, column in enumerate(ALL_COLUMNS_MAPPING.values())
]
)
)
return fig
def filter_query(
text,
backends,
datatypes,
optimizations,
quantizations,
score,
memory,
machine,
):
raw_df = get_benchmark_df(machine=machine)
filtered_df = raw_df[
raw_df["Model π€"].str.contains(text, case=False)
& raw_df["Backend π"].isin(backends)
& raw_df["Dtype π₯"].isin(datatypes)
& raw_df["Optimization π οΈ"].isin(optimizations)
& raw_df["Quantization ποΈ"].isin(quantizations)
& (raw_df["Open LLM Score (%) β¬οΈ"] >= score)
& (raw_df["Allocated Memory (MB) β¬οΈ"] <= memory)
]
filtered_table = get_benchmark_table(filtered_df)
filtered_chart = get_benchmark_chart(filtered_df)
return filtered_table, filtered_chart
# Demo interface
demo = gr.Blocks(css=custom_css)
with demo:
# leaderboard title
gr.HTML(TITLE)
# introduction text
gr.Markdown(INTRODUCTION_TEXT, elem_classes="descriptive-text")
with gr.Tabs(elem_classes="leaderboard-tabs"):
machine_placeholders = {}
machine_tables = {}
machine_plots = {}
####################### HARDWARE TABS #######################
for i, (machine, hardware) in enumerate(MACHINE_TO_HARDWARE.items()):
# dummy placeholder of the machine name
machine_placeholders[machine] = gr.Textbox(value=machine, visible=False)
with gr.TabItem(hardware, id=i):
with gr.Tabs(elem_classes="machine-tabs"):
# placeholder for full dataframe
machine_df = get_benchmark_df(machine=machine)
with gr.TabItem("Leaderboard π
", id=0):
gr.HTML(
"π Scroll to the right π for additional columns.",
elem_id="descriptive-text",
)
# Original leaderboard table
machine_tables[machine] = gr.components.Dataframe(
value=get_benchmark_table(machine_df),
headers=list(ALL_COLUMNS_MAPPING.values()),
datatype=ALL_COLUMNS_DATATYPES,
elem_id="machine-table",
)
with gr.TabItem("Plot π", id=1):
gr.HTML(
"π Hover over the points π for additional information.",
elem_id="descriptive-text",
)
# Original leaderboard plot
machine_plots[machine] = gr.components.Plot(
value=get_benchmark_chart(machine_df),
elem_id="machine-plot",
show_label=False,
)
###################### CONTROL PANEL #######################
with gr.TabItem("Control Panel ποΈ", id=2):
gr.HTML(
"Use this control panel to filter the leaderboard's table and plot.", # noqa: E501
elem_id="descriptive-text",
)
with gr.Row():
with gr.Column():
search_bar = gr.Textbox(
label="Model π€",
info="π Search for a model name",
elem_id="search-bar",
)
with gr.Row():
with gr.Column(scale=1):
score_slider = gr.Slider(
label="Open LLM Score (%) π",
info="ποΈ Slide to minimum Open LLM score",
value=0,
elem_id="threshold-slider",
)
with gr.Column(scale=1):
memory_slider = gr.Slider(
label="Peak Memory (MB) π",
info="ποΈ Slide to maximum Peak Memory",
minimum=0,
maximum=80 * 1024,
value=80 * 1024,
elem_id="memory-slider",
)
with gr.Column(scale=1):
backend_checkboxes = gr.CheckboxGroup(
label="Backends π",
choices=["pytorch", "onnxruntime"],
value=["pytorch", "onnxruntime"],
info="βοΈ Select the backends",
elem_id="backend-checkboxes",
)
with gr.Row():
with gr.Column(scale=1):
datatype_checkboxes = gr.CheckboxGroup(
label="Load Dtypes π₯",
choices=["float32", "float16"],
value=["float32", "float16"],
info="βοΈ Select the load dtypes",
elem_id="dtype-checkboxes",
)
with gr.Column(scale=1):
optimization_checkboxes = gr.CheckboxGroup(
label="Optimizations π οΈ",
choices=["None", "BetterTransformer", "FlashAttentionV2"],
value=["None", "BetterTransformer", "FlashAttentionV2"],
info="βοΈ Select the optimization",
elem_id="optimization-checkboxes",
)
with gr.Column(scale=1):
quantization_checkboxes = gr.CheckboxGroup(
label="Quantizations ποΈ",
choices=["None", "BnB.4bit", "GPTQ.4bit"],
value=["None", "BnB.4bit", "GPTQ.4bit"],
info="βοΈ Select the quantization schemes",
elem_id="quantization-checkboxes",
)
with gr.Row():
filter_button = gr.Button(
value="Filter π",
elem_id="filter-button",
)
for machine in MACHINE_TO_HARDWARE:
filter_button.click(
filter_query,
[
search_bar,
backend_checkboxes,
datatype_checkboxes,
optimization_checkboxes,
quantization_checkboxes,
score_slider,
memory_slider,
machine_placeholders[machine],
],
[machine_tables[machine], machine_plots[machine]],
)
####################### ABOUT TAB #######################
with gr.TabItem("About π", id=3):
gr.HTML(ABOUT_TEXT, elem_classes="descriptive-text")
gr.Markdown(EXAMPLE_CONFIG_TEXT, elem_classes="descriptive-text")
####################### CITATION #######################
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",
show_copy_button=True,
)
# Launch demo
demo.queue().launch()
|