File size: 8,407 Bytes
810d25e
 
a415f27
 
 
 
810d25e
9e6ac7d
810d25e
a415f27
06f30ec
a415f27
 
fb4d3bf
06f30ec
a415f27
 
 
 
fb4d3bf
a415f27
 
55b103a
 
 
 
a415f27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cef304a
1ef419e
a415f27
 
 
 
0edc22e
 
 
 
 
 
 
cef304a
a415f27
 
 
e6fa278
 
 
a415f27
810d25e
 
 
 
 
7f1ee50
 
 
 
810d25e
a415f27
9e6ac7d
a415f27
 
 
 
9e6ac7d
 
 
 
 
 
 
 
 
 
 
 
 
 
55b103a
9e6ac7d
 
 
 
 
 
 
 
 
 
a415f27
06f30ec
a415f27
 
 
 
e037cf4
a415f27
 
 
 
 
 
 
 
 
 
 
 
 
 
9e6ac7d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a415f27
9e6ac7d
 
 
a415f27
 
 
 
 
 
e6fa278
 
a415f27
 
 
 
 
 
 
9e6ac7d
 
 
 
 
 
 
 
 
 
 
 
a415f27
 
 
 
9e6ac7d
a415f27
 
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
"""A gradio app that renders a static leaderboard. This is used for Hugging Face Space.""" 
import argparse  
import gradio as gr
import numpy as np
import pandas as pd
import gradio as gr
import pandas as pd 
import json 
from constants import BANNER, INTRODUCTION_TEXT, CITATION_TEXT, METRICS_TAB_TEXT, DIR_OUTPUT_REQUESTS  

LAST_UPDATED = "Feb 28th 2024"

css = """
.markdown-text{font-size: 15pt}
.markdown-text-small{font-size: 13pt}
th {
  text-align: center;
}
td {
  font-size: 15px; /* Adjust the font size as needed */
  text-align: center;
}
#od-benchmark-tab-table-button{
    font-size: 15pt;
    font-weight: bold;
}

"""

column_names = {
    "model": "Model",
    "Overall": "All 🎯",    
    "Turn 1": "Turn 1️⃣", 
    "Turn 2": "Turn 2️⃣", 
    }

model_info = {
    "gpt-4": {"hf_name": "https://platform.openai.com/", "pretty_name": "gpt-4"}, 
    "gpt-3.5-turbo": {"hf_name": "https://platform.openai.com/", "pretty_name": "gpt-3.5-turbo"}, 
    "Llama-2-70b-hf": {"hf_name": "meta-llama/Llama-2-70b-hf", "pretty_name": "Llama-2-70B"}, 
    "Llama-2-13b-hf": {"hf_name": "meta-llama/Llama-2-13b-hf", "pretty_name": "Llama-2-13B"}, 
    "Llama-2-7b-hf": {"hf_name": "meta-llama/Llama-2-7b-hf", "pretty_name": "Llama-2-7B"}, 
    "Mixtral-8x7B-v0.1": {"hf_name": "mistralai/Mixtral-8x7B-v0.1", "pretty_name": "Mixtral-8x7B"}, 
    "Mistral-7b-v0.1": {"hf_name": "mistralai/Mistral-7B-v0.1", "pretty_name": "Mistral-7B v0.1"}, 
    # "Mistral-7b-v0.2": {"hf_name": "alpindale/Mistral-7B-v0.2-hf", "pretty_name": "Mistral-7B v0.2"}, 
    "Yi-34B": {"hf_name": "01-ai/Yi-34B", "pretty_name": "Yi-34B"}, 
    "Yi-6B": {"hf_name": "01-ai/Yi-6B", "pretty_name": "Yi-6B"}, 
    "gemma-7b": {"hf_name": "google/gemma-7b", "pretty_name": "Gemma-7B"}, 
    "gemma-2b": {"hf_name": "google/gemma-2b", "pretty_name": "Gemma-2B"}, 
    "phi-2": {"hf_name": "microsoft/phi-2", "pretty_name": "Phi-2 @hf"}, 
    "olmo": {"hf_name": "allenai/OLMo-7B", "pretty_name": "OLMo-7B @hf"},  
    "phi-2-vllm": {"hf_name": "microsoft/phi-2", "pretty_name": "Phi-2 (2.7B)"}, 
    "olmo-7b-vllm": {"hf_name": "allenai/OLMo-7B", "pretty_name": "OLMo-7B"},  
    "falcon-7b": {"hf_name": "microsoft/falcon-7b", "pretty_name": "Falcon-7B"},
    "mpt-7b": {"hf_name": "mosaicml/mpt-7b", "pretty_name": "MPT-7B"},
    "amber": {"hf_name": "LLM360/Amber", "pretty_name": "Amber (7B)"},
    "dbrx": {"hf_name": "databricks/dbrx-base", "pretty_name": "DBRX-base"},
} 


def formatter(x):
    x = round(x, 2)
    return x

def make_clickable_model(model_name, model_info):
    if model_info[model_name]['hf_name'].startswith("http"):
        link = model_info[model_name]['hf_name']
    else:
        link = f"https://huggingface.co/{model_info[model_name]['hf_name']}"
    if model_name.startswith("gpt"):
        return f'<a target="_blank" href="{link}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted; background-color: lightgray;">{model_info[model_name]["pretty_name"]}</a>'
    else:
        return f'<a target="_blank" href="{link}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{model_info[model_name]["pretty_name"]}</a>'


def build_demo(original_df, full_df, TYPES):
    with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
        # gr.HTML(BANNER, elem_id="banner")
        gr.Markdown(INTRODUCTION_TEXT, elem_classes="markdown-text")

        with gr.Tabs(elem_classes="tab-buttons") as tabs:
            with gr.TabItem("πŸ… Leaderboard", elem_id="od-benchmark-tab-table", id=0):
                leaderboard_table = gr.components.Dataframe(
                    value=original_df,
                    datatype=TYPES,
                    height=1000,
                    wrap=False,
                    elem_id="leaderboard-table",
                    interactive=False,
                    visible=True,
                    min_width=60,
                    )

            with gr.TabItem("πŸ‘ URIAL + πŸ€— OpenLLM", elem_id="od-benchmark-tab-table", id=1):
                gr.Markdown("### More results from the awesome πŸ€— [Open LLM Leaderboard](https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard) ", elem_classes="markdown-text")
                leaderboard_table_full = gr.components.Dataframe(
                    value=full_df,
                    datatype=TYPES,
                    height=1000,
                    wrap=False,
                    elem_id="leaderboard-table-full",
                    interactive=False,
                    visible=True,
                    min_width=60,
                    ) 

        gr.Markdown(f"Last updated on **{LAST_UPDATED}**", elem_classes="markdown-text-small")
        
        with gr.Row():
            with gr.Accordion("πŸ“™ Citation", open=False):
                gr.Textbox(
                    value=CITATION_TEXT, lines=18,
                    label="Copy the BibTeX to cite URIAL and MT-Bench",
                    elem_id="citation-button",
                    show_copy_button=True)
                # ).style(show_copy_button=True)

    return demo

if __name__ == "__main__": 

    parser = argparse.ArgumentParser()
    parser.add_argument("--share", action="store_true")
    parser.add_argument("--result_file", help="Path to results table", default="leaderboard_data.jsonl")
    args = parser.parse_args()

    all_model_hf_ids = {v["hf_name"]: k  for k, v in model_info.items()}

    # Load Open LLM Leaderboard 
    with open("open-llm-leaderboard.json") as f:
        open_llm_leaderbaord = json.load(f)
    full_leaderboard = {}
    for item in open_llm_leaderbaord:
        if item["Model"] in all_model_hf_ids:
            # print(item["Model"])
            # print(item["Average \u2b06\ufe0f"])
            full_bench_item = {}
            # full_bench_item["hf_name"] = item["Model"]
            full_bench_item["model_name"] = all_model_hf_ids[item["Model"]]
            tasks = ["HellaSwag", "ARC", "Winogrande", "TruthfulQA", "MMLU", "GSM8K"]
            for task in tasks:
                full_bench_item[task] = item[task]
            full_bench_item["HF_AVG"] = item["Average \u2b06\ufe0f"]
            full_leaderboard[all_model_hf_ids[item["Model"]]] = full_bench_item
    # Load URIAL Leaderboard
    with open("leaderboard_data.jsonl") as f:
        for line in f:
            item = json.loads(line)  
            if item["model"] in full_leaderboard:
                full_leaderboard[item["model"]]["URIAL_AVG"] = item["Overall"]   
 

    # Process the URIAL Benchmark Tab 
    original_df = pd.read_json(args.result_file, lines=True)

    print(original_df.columns)

    for col in original_df.columns:
        if col == "model":
            original_df[col] = original_df[col].apply(lambda x: x.replace(x, make_clickable_model(x, model_info)))
        else: 
            original_df[col] = original_df[col].apply(formatter) # For numerical values
    # Define the first column explicitly, add 'Overall' as the second column, and then append the rest excluding 'Overall'
    new_order = [original_df.columns[0], 'Overall'] + [col for col in original_df.columns if col not in [original_df.columns[0], 'Overall']]
    # Reorder the DataFrame columns using the new order
    reordered_df = original_df[new_order]
    reordered_df.sort_values(by='Overall', inplace=True, ascending=False)
    reordered_df.rename(columns=column_names, inplace=True)

    # Process the Full Benchmark Tab
    full_df = pd.DataFrame(full_leaderboard).T
    full_df = full_df.reset_index()
    full_df.rename(columns={"index": "model"}, inplace=True)
    full_df = full_df[["model",  "URIAL_AVG", "HF_AVG", "HellaSwag", "ARC", "Winogrande", "TruthfulQA", "MMLU", "GSM8K"]]
    full_df.sort_values(by='URIAL_AVG', inplace=True, ascending=False)
    full_df["model"] = full_df["model"].apply(lambda x: make_clickable_model(x, model_info))
    full_df.rename(columns=column_names, inplace=True)
    # apply formatter to numerical columns
    for col in full_df.columns:
        if col not in ["Model"]:
            full_df[col] = full_df[col].apply(formatter) # For numerical values
    # COLS = [c.name for c in fields(AutoEvalColumn)]
    # TYPES = [c.type for c in fields(AutoEvalColumn)]

    TYPES = ["markdown", "number"]
    demo = build_demo(reordered_df, full_df, TYPES)
    demo.launch(share=args.share)