File size: 11,793 Bytes
cf7e82a
 
f1df503
 
c4a74cb
 
 
b3b2e6b
cf7e82a
 
 
 
 
c050e6e
 
cf7e82a
 
c050e6e
cf7e82a
 
 
c050e6e
cf7e82a
 
c050e6e
 
 
cf7e82a
 
 
 
c050e6e
cf7e82a
 
 
 
c050e6e
 
7776235
4b73981
245fe03
c050e6e
 
 
7776235
c050e6e
7776235
c050e6e
 
cf7e82a
 
7776235
cf7e82a
 
200e56a
c4a74cb
 
7776235
 
 
 
 
 
 
 
c91973c
 
 
 
200e56a
 
 
 
 
7776235
 
 
 
 
 
 
 
c91973c
 
 
 
c4a74cb
 
cf7e82a
 
 
 
 
 
584c000
cf7e82a
 
 
245fe03
 
7776235
245fe03
cf7e82a
 
 
c050e6e
 
7776235
f1df503
cf7e82a
eec2308
c050e6e
7776235
eec2308
7776235
cf7e82a
 
 
eec2308
c050e6e
cf7e82a
 
 
 
 
 
eec2308
c050e6e
 
cf7e82a
c050e6e
cf7e82a
f1df503
c050e6e
cf7e82a
7776235
cf7e82a
7776235
 
 
 
 
 
 
 
 
 
245fe03
7776235
 
200e56a
245fe03
7776235
 
 
 
200e56a
c050e6e
 
7776235
c050e6e
 
eec2308
c050e6e
 
 
 
 
 
 
eec2308
c050e6e
 
 
 
 
 
 
eec2308
c050e6e
 
 
 
 
 
 
 
7776235
 
 
 
 
 
 
 
 
 
 
 
 
 
c050e6e
89c9ca7
c4a74cb
7776235
 
 
 
 
 
 
 
c4a74cb
c050e6e
cf7e82a
7776235
 
245fe03
7776235
89c9ca7
c050e6e
 
7776235
 
245fe03
7776235
c050e6e
7776235
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c050e6e
7776235
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c050e6e
7776235
 
 
 
c050e6e
 
7776235
 
 
f1df503
cf7e82a
c4a74cb
 
 
 
f1df503
cf7e82a
f1df503
cf7e82a
584c000
cf7e82a
7776235
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
import os
import json
import gradio as gr
import pandas as pd
from about_content import about_markdown  # Import the about page content
from submission_content import submission_markdown  # Import the submission page content
import plotly.express as px
import plotly
# Helper function to load data from JSON files
def load_data(data_dir):
    data = []
    for file_name in os.listdir(data_dir):
        if file_name.endswith(".json"):
            # Extract stage, method, model, and dataset from the file name
            stage, method, model, dataset = file_name.replace(".json", "").split("_")
            with open(os.path.join(data_dir, file_name), "r") as f:
                entry = json.load(f)
                entry.update({"Method": method, "Model": model, "Dataset": dataset, "Stage": stage})
                data.append(entry)
    return pd.DataFrame(data)

def filter_and_display(selected_columns, model_types, datasets, stage):
    filtered = data.copy()

    # Filter by stage
    filtered = filtered[filtered["Stage"] == stage]

    # Filter by model types
    if model_types:
        filtered = filtered[filtered["Model"].isin(model_types)]

    # Filter by datasets
    if datasets:
        filtered = filtered[filtered["Dataset"].isin(datasets)]
    
    if not filtered.empty:
        # Adjust aggregation based on stage
        if stage == "decode":
            filtered = filtered.groupby(["Method", "Model", "Dataset"], as_index=False).agg({
                "Throughput (token/s)": "mean",
                "Quality": "mean",
                "Link": "first"
            })
        else:
            filtered = filtered.groupby(["Method", "Model", "Dataset"], as_index=False).agg({
                "Quality": "mean",
                "TTFT (s)": "mean",
                "Link": "first"
            })

    # Select columns to display
    display_columns = ["Method", "Model", "Dataset"] + [col for col in selected_columns if col in filtered.columns]
    return filtered[display_columns] if not filtered.empty else pd.DataFrame(columns=display_columns)

def create_prefill_visualization(filtered_data):
    if filtered_data.empty:
        return None
    fig = px.scatter(
        filtered_data, 
        x='TTFT (s)', 
        y='Quality', 
        color='Method', 
        hover_data=['Model', 'Dataset'],
        title='Prefill Stage: Quality vs TTFT (s) by Method'
    )
    fig.update_layout(
        yaxis=dict(range=[0, 100]),  # Set y-axis (Quality) range from 0 to 1
        xaxis=dict(range=[0, None])  # Set x-axis (TTFT (s)) to start from 0
    )
    return fig

def create_decode_visualization(filtered_data):
    if filtered_data.empty:
        return None
    fig = px.scatter(
        filtered_data, 
        x='Throughput (token/s)', 
        y='Quality', 
        color='Method', 
        hover_data=['Model', 'Dataset'],
        title='Decode Stage: Quality vs Throughput by Method'
    )
    fig.update_layout(
        yaxis=dict(range=[0, 100]),  # Set y-axis (Quality) range from 0 to 1
        xaxis=dict(range=[0, None])  # Set x-axis (Throughput (token/s)) to start from 0
    )
    return fig

# Load the data from the /data folder
data_dir = "data"
data = load_data(data_dir)

# Gradio app UI and functionality
def create_gradio_app():

    with gr.Blocks() as app:
        with gr.Row():
            gr.Markdown(
                """# KV Cache Benchmark
### Demo leaderboard  
This demo leaderboard allows users to explore and compare different KV cache implementations across various models and datasets. It provides interactive filtering options and real-time updates of benchmark results, including visualization of Quality and TTFT (s) metrics.
""")
        
        with gr.Tabs():
            with gr.TabItem("KV Cache Benchmark"):
                # Prefill-stage selection
                with gr.Row():
                    gr.Markdown("## Prefill-Stage KV Cache Compression")
                with gr.Row():
                    with gr.Column():
                        gr.Markdown("#### Select Columns to Display")
                        prefill_columns_to_display = gr.CheckboxGroup(
                            choices=["Quality", "TTFT (s)", "Link"],
                            label="Columns",
                            value=["Quality", "TTFT (s)"]
                        )

                    with gr.Column():
                        gr.Markdown("#### Model Types")
                        prefill_model_types = gr.CheckboxGroup(
                            choices=list(data["Model"].unique()),
                            label="Model Types",
                            value=list(data["Model"].unique())  # Default to all models
                        )

                    with gr.Column():
                        gr.Markdown("#### Datasets")
                        prefill_datasets = gr.CheckboxGroup(
                            choices=list(data[data["Stage"] == "prefill"]["Dataset"].unique()),
                            label="Datasets",
                            value=list(data[data["Stage"] == "prefill"]["Dataset"].unique())  # Default to all datasets for prefill
                        )

                # Prefill-stage compression results
                with gr.Row():
                    gr.Markdown("## Results")
                
                # Initialize the Prefill Dataframe with default data
                prefill_default = filter_and_display(
                    ["Quality", "TTFT (s)"], 
                    list(data["Model"].unique()), 
                    list(data[data["Stage"] == "prefill"]["Dataset"].unique()), 
                    "prefill"
                )
                prefill_results = gr.Dataframe(
                    value=prefill_default
                )

                # Prefill-stage visualization (Static initially)
                
                with gr.Row():
                    gr.Markdown("### Prefill-stage Visualization")
                with gr.Row():
                    prefill_plot = gr.Plot(
                        value=create_prefill_visualization(prefill_default)
                    )

                # Decode-stage selection
                with gr.Row():
                    gr.Markdown("## Decode-Stage KV Cache Compression")
                with gr.Row():
                    with gr.Column():
                        gr.Markdown("#### Select Columns to Display")
                        decode_columns_to_display = gr.CheckboxGroup(
                            choices=["Throughput (token/s)", "Quality", "Link"],
                            label="Columns",
                            value=["Throughput (token/s)", "Quality"]
                        )

                    with gr.Column():
                        gr.Markdown("#### Model Types")
                        decode_model_types = gr.CheckboxGroup(
                            choices=list(data["Model"].unique()),
                            label="Model Types",
                            value=list(data["Model"].unique())  # Default to all models
                        )

                    with gr.Column():
                        gr.Markdown("#### Datasets")
                        decode_datasets = gr.CheckboxGroup(
                            choices=list(data[data["Stage"] == "decode"]["Dataset"].unique()),
                            label="Datasets",
                            value=list(data[data["Stage"] == "decode"]["Dataset"].unique())  # Default to all datasets for decode
                        )

                # Decode-stage compression results
                with gr.Row():
                    gr.Markdown("## Results")

                # Initialize the Decode Dataframe with default data
                decode_default = filter_and_display(
                    ["Throughput (token/s)", "Quality"], 
                    list(data["Model"].unique()), 
                    list(data[data["Stage"] == "decode"]["Dataset"].unique()), 
                    "decode"
                )
                decode_results = gr.Dataframe(
                    value=decode_default
                )

                # Decode-stage visualization (Static initially)
                

                with gr.Row():
                    gr.Markdown("### Decode-Stage Visualization")
                with gr.Row():
                    decode_plot = gr.Plot(
                        value=create_decode_visualization(decode_default)
                    )

                # AUTO-UPDATE FUNCTIONS:
                # (We only update the DataFrame, NOT the Plot)

                def auto_update_prefill(selected_columns, model_types, datasets):
                    if not model_types or not datasets:
                        # Return an empty DataFrame if no selection is made
                        return pd.DataFrame(columns=["Method", "Model"] + selected_columns)
                    filtered_data = filter_and_display(selected_columns, model_types, datasets, "prefill")
                    return filtered_data

                def auto_update_decode(selected_columns, model_types, datasets):
                    if not model_types or not datasets:
                        # Return an empty DataFrame if no selection is made
                        return pd.DataFrame(columns=["Method", "Model"] + selected_columns)
                    filtered_data = filter_and_display(selected_columns, model_types, datasets, "decode")
                    return filtered_data

                # Only update the tables when filters change
                prefill_columns_to_display.change(
                    auto_update_prefill, 
                    inputs=[prefill_columns_to_display, prefill_model_types, prefill_datasets], 
                    outputs=[prefill_results]
                )
                prefill_model_types.change(
                    auto_update_prefill, 
                    inputs=[prefill_columns_to_display, prefill_model_types, prefill_datasets], 
                    outputs=[prefill_results]
                )
                prefill_datasets.change(
                    auto_update_prefill, 
                    inputs=[prefill_columns_to_display, prefill_model_types, prefill_datasets], 
                    outputs=[prefill_results]
                )

                decode_columns_to_display.change(
                    auto_update_decode, 
                    inputs=[decode_columns_to_display, decode_model_types, decode_datasets], 
                    outputs=[decode_results]
                )
                decode_model_types.change(
                    auto_update_decode, 
                    inputs=[decode_columns_to_display, decode_model_types, decode_datasets], 
                    outputs=[decode_results]
                )
                decode_datasets.change(
                    auto_update_decode, 
                    inputs=[decode_columns_to_display, decode_model_types, decode_datasets], 
                    outputs=[decode_results]
                )

                # Reload button to restart the whole website
                def reload_website():
                    # This function will trigger a page reload using JavaScript
                    return gr.JS("window.location.reload();")

                reload_button = gr.Button("Reload Data")
                reload_button.click(
                    reload_website
                )

            with gr.TabItem("About"):
                gr.Markdown(about_markdown)  # Use the imported about page content

            with gr.TabItem("Submission Instructions"):
                gr.Markdown(submission_markdown)  # Use the imported submission page content

    return app

if __name__ == "__main__":

    app = create_gradio_app()
    app.launch()