File size: 5,834 Bytes
2fcb72a
 
 
aa8b4d6
2fcb72a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aa8b4d6
2fcb72a
 
 
 
 
 
 
 
aa8b4d6
2fcb72a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aa8b4d6
2fcb72a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from typing import List

import gradio as gr
import pandas as pd

from src.leaderboard import get_leaderboard_df
from src.llm_perf import get_llm_perf_df
# from attention_implementations import get_attn_decode_fig, get_attn_prefill_fig
# from custom_kernels import get_kernel_decode_fig, get_kernel_prefill_fig


def create_control_panel(
    machine: str,
    backends: List[str],
    hardware_provider: str,
    hardware_type: str,
):
    # controls
    machine_value = gr.State(value=machine)
    backends_value = gr.State(value=backends)
    hardware_type_value = gr.State(value=hardware_type)

    if hardware_provider == "ARM":
        backends = ["llama_cpp"]
        quantizations = ["Q8_0", "Q4_K_M", "Q4_0_4_4"]
    else:
        raise ValueError(f"Unknown hardware provider: {hardware_provider}")

    with gr.Accordion("Control Panel", open=False, elem_id="control-panel"):
        with gr.Row():
            with gr.Column(scale=2, variant="panel"):
                memory_slider = gr.Slider(
                    label="Model Size (GB)",
                    info="🎚️ Slide to maximum Model Size",
                    minimum=0,
                    maximum=16,
                    value=16,
                    elem_id="memory-slider",
                )
            with gr.Column(scale=1, variant="panel"):
                quantization_checkboxes = gr.CheckboxGroup(
                    label="Quantizations",
                    choices=quantizations,
                    value=quantizations,
                    info="β˜‘οΈ Select the quantization schemes",
                    elem_id="quantization-checkboxes",
                    elem_classes="boxed-option",
                )
        with gr.Row():
            filter_button = gr.Button(
                value="Filter πŸš€",
                elem_id="filter-button",
                elem_classes="boxed-option",
            )

    return (
        filter_button,
        machine_value,
        backends_value,
        hardware_type_value,
        memory_slider,
        quantization_checkboxes,
    )

def filter_rows_fn(
    machine,
    backends,
    hardware_type,
    # inputs
    memory,
    quantizations,
    # interactive
    columns,
    search,
):
    llm_perf_df = get_llm_perf_df(
        machine=machine, backends=backends, hardware_type=hardware_type
    )
    # print(attentions)
    # print(llm_perf_df["Attention πŸ‘οΈ"].unique())
    filtered_llm_perf_df = llm_perf_df[
        llm_perf_df["Model"].str.contains(search, case=False)
        & llm_perf_df["Quantization"].isin(quantizations)
        & llm_perf_df["Model Size (GB)"] <= memory
    ]
    selected_filtered_llm_perf_df = select_columns_fn(
        machine, backends, hardware_type, columns, search, filtered_llm_perf_df
    )
    # filtered_bt_prefill_fig = get_bt_prefill_fig(filtered_df)
    # filtered_bt_decode_fig = get_bt_decode_fig(filtered_df)
    # filtered_fa2_prefill_fig = get_fa2_prefill_fig(filtered_df)
    # filtered_fa2_decode_fig = get_fa2_decode_fig(filtered_df)
    # filtered_quant_prefill_fig = get_quant_prefill_fig(filtered_df)
    # filtered_quant_decode_fig = get_quant_decode_fig(filtered_df)

    return [
        selected_filtered_llm_perf_df,
        # filtered_bt_prefill_fig,
        # filtered_bt_decode_fig,
        # filtered_fa2_prefill_fig,
        # filtered_fa2_decode_fig,
        # filtered_quant_prefill_fig,
        # filtered_quant_decode_fig,
    ]


def create_control_callback(
    # button
    filter_button,
    # fixed
    machine_value,
    backends_value,
    hardware_type_value,
    # inputs
    memory_slider,
    quantization_checkboxes,
    # interactive
    columns_checkboxes,
    search_bar,
    # outputs
    leaderboard_table,
    # attn_prefill_plot,
    # attn_decode_plot,
    # fa2_prefill_plot,
    # fa2_decode_plot,
    # quant_prefill_plot,
    # quant_decode_plot,
):
    filter_button.click(
        fn=filter_rows_fn,
        inputs=[
            # fixed
            machine_value,
            backends_value,
            hardware_type_value,
            # inputs
            memory_slider,
            quantization_checkboxes,
            # interactive
            columns_checkboxes,
            search_bar,
        ],
        outputs=[
            leaderboard_table,
            # attn_prefill_plot,
            # attn_decode_plot,
            # fa2_prefill_plot,
            # fa2_decode_plot,
            # quant_prefill_plot,
            # quant_decode_plot,
        ],
    )


def select_columns_fn(
    machine, backends, hardware_type, columns, search, llm_perf_df=None
):
    if llm_perf_df is None:
        llm_perf_df = get_llm_perf_df(
            machine=machine,
            backends=backends,
            hardware_type=hardware_type,
        )

    selected_leaderboard_df = get_leaderboard_df(llm_perf_df)
    selected_leaderboard_df = selected_leaderboard_df[
        selected_leaderboard_df["Model"].str.contains(search, case=False)
    ]
    selected_leaderboard_df = selected_leaderboard_df[columns]

    return selected_leaderboard_df


def create_select_callback(
    # fixed
    machine_value,
    backends_value,
    hardware_type_value,
    # interactive
    columns_checkboxes,
    search_bar,
    # outputs
    leaderboard_table,
):
    columns_checkboxes.change(
        fn=select_columns_fn,
        inputs=[
            machine_value,
            backends_value,
            hardware_type_value,
            columns_checkboxes,
            search_bar,
        ],
        outputs=[leaderboard_table],
    )
    search_bar.change(
        fn=select_columns_fn,
        inputs=[
            machine_value,
            backends_value,
            hardware_type_value,
            columns_checkboxes,
            search_bar,
        ],
        outputs=[leaderboard_table],
    )