File size: 10,230 Bytes
460fdc7
 
42e8f64
 
c40907d
2ec9b03
4f8bac4
2ec9b03
 
4f8bac4
2ec9b03
4f8bac4
 
0a8b643
4f8bac4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a8b643
4f8bac4
 
 
 
 
0bcbe4f
78b788d
0a8b643
 
 
 
2af0c24
4f8bac4
4f3cfa8
4f8bac4
 
 
0a8b643
 
 
 
4f8bac4
 
0a8b643
4f8bac4
dae3ac5
0a8b643
 
 
 
 
dae3ac5
0a8b643
e5599c2
f7b4006
0bcbe4f
4f8bac4
0bcbe4f
0a8b643
 
 
 
2af0c24
4f8bac4
 
 
4f3cfa8
 
4f8bac4
 
0a8b643
2af0c24
0a8b643
 
4f8bac4
 
0a8b643
4f8bac4
0bcbe4f
0a8b643
 
 
 
 
0bcbe4f
0a8b643
0bcbe4f
 
 
4f8bac4
0a8b643
2ec9b03
0a8b643
2ec9b03
0a8b643
 
4f8bac4
0a8b643
 
 
 
 
2af0c24
4f8bac4
2ec9b03
 
 
 
 
 
 
 
0a8b643
2ec9b03
0bcbe4f
 
4f8bac4
0a8b643
 
4f8bac4
 
 
0bcbe4f
0a8b643
 
 
 
2af0c24
4f8bac4
2ec9b03
4f8bac4
 
0a8b643
2ec9b03
d4ded0a
4f8bac4
0a8b643
4567668
 
 
 
 
 
 
 
 
 
 
 
f7b4006
7022131
7786ff5
2ec9b03
 
4f8bac4
7786ff5
655d435
2ec9b03
4f8bac4
 
f7b4006
7022131
f7b4006
0a8b643
bb22059
b4c9d86
5966339
4f8bac4
7022131
f7b4006
2dc39dd
b7b78a8
2dc39dd
097117b
4f8bac4
7022131
f7b4006
d4ded0a
b7b78a8
d4ded0a
097117b
4f8bac4
7022131
f7b4006
2dc39dd
3e19f3e
2dc39dd
097117b
4f8bac4
3fe7e68
 
 
172dd94
3fe7e68
172dd94
4f8bac4
3fe7e68
 
 
e513088
3fe7e68
097117b
4f8bac4
 
3fe7e68
 
 
 
097117b
4f8bac4
3fe7e68
 
 
 
 
097117b
4f8bac4
3fe7e68
 
 
 
 
097117b
4f8bac4
7022131
f7b4006
2dc39dd
b7b78a8
2dc39dd
097117b
4f8bac4
296b387
0bcbe4f
e8159e6
0bcbe4f
e8159e6
eb5bbd0
4f8bac4
40e7d39
4f8bac4
 
 
 
 
 
 
0a8b643
 
 
4f8bac4
0a8b643
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
import gradio as gr
import pandas as pd
import plotly.express as px

CITATION_BUTTON_LABEL = "Copy the following snippet to cite these results"
CITATION_BUTTON_TEXT = r"""@misc{aienergyscore-leaderboard,
    author = {Sasha Luccioni and Boris Gamazaychikov and Emma Strubell and Sara Hooker and Yacine Jernite and Carole-Jean Wu and Margaret Mitchell},
    title = {AI Energy Score Leaderboard - February 2025},
    year = {2025},
    publisher = {Hugging Face},
    howpublished = "\url{https://huggingface.co/spaces/AIEnergyScore/Leaderboard}",
}"""

# List of tasks (CSV filenames)
tasks = [
    'asr.csv',
    'object_detection.csv',
    'text_classification.csv',
    'image_captioning.csv',
    'question_answering.csv',
    'text_generation.csv',
    'image_classification.csv',
    'sentence_similarity.csv',
    'image_generation.csv',
    'summarization.csv'
]

def format_stars(score):
    try:
        score_int = int(score)
    except Exception:
        score_int = 0
    return f'<span style="color: #3fa45bff !important; font-size:2em !important;">{"★" * score_int}</span>'

def make_link(mname):
    parts = str(mname).split('/')
    display_name = parts[1] if len(parts) > 1 else mname
    return f'[{display_name}](https://huggingface.co/{mname})'

def get_plots(task):
    df = pd.read_csv('data/energy/' + task)
    if df.columns[0].startswith("Unnamed:"):
        df = df.iloc[:, 1:]
    df['energy_score'] = df['energy_score'].astype(int)
    df['Display Model'] = df['model'].apply(lambda m: m.split('/')[-1])
    
    color_map = {1: "red", 2: "orange", 3: "yellow", 4: "lightgreen", 5: "green"}
    
    fig = px.scatter(
        df,
        x="total_gpu_energy",  # Ensure correct column for x-axis
        y="Display Model",  # Keep model name for y-axis
        color="energy_score",  # Ensure correct column for point color
        custom_data=['energy_score'],
        height=500,
        width=800,
        color_discrete_map=color_map
    )
    fig.update_traces(
        hovertemplate="<br>".join([
            "Model: %{y}",
            "GPU Energy (Wh): %{x}",
            "Energy Score: %{customdata[0]}"
        ])
    )
    fig.update_layout(xaxis_title="GPU Energy (Wh)", yaxis_title="Model")
    return fig

def get_all_plots():
    all_df = pd.DataFrame()
    for task in tasks:
        df = pd.read_csv('data/energy/' + task)
        if df.columns[0].startswith("Unnamed:"):
            df = df.iloc[:, 1:]
        df['energy_score'] = df['energy_score'].astype(int)
        df['Display Model'] = df['model'].apply(lambda m: m.split('/')[-1])
        all_df = pd.concat([all_df, df], ignore_index=True)
    all_df = all_df.drop_duplicates(subset=['model'])
    
    color_map = {1: "red", 2: "orange", 3: "yellow", 4: "lightgreen", 5: "green"}
    
    fig = px.scatter(
        all_df,
        x="total_gpu_energy",  # Ensure correct column for x-axis
        y="Display Model",
        color="energy_score",  # Ensure correct column for point color
        custom_data=['energy_score'],
        height=500,
        width=800,
        color_discrete_map=color_map
    )
    fig.update_traces(
        hovertemplate="<br>".join([
            "Model: %{y}",
            "GPU Energy (Wh): %{x}",
            "Energy Score: %{customdata[0]}"
        ])
    )
    fig.update_layout(xaxis_title="GPU Energy (Wh)", yaxis_title="Model")
    return fig

def get_model_names(task):
    """
    For a given task, load the energy CSV and return a dataframe with the following columns:
      - Model (a markdown link)
      - GPU Energy (Wh) formatted as a string with 4 decimal places
      - Score (a star rating based on energy_score)
    For text_generation.csv only, also add the "Class" column from the CSV.
    The final column order is: Model, GPU Energy (Wh), Score, [Class].
    """
    df = pd.read_csv('data/energy/' + task)
    if df.columns[0].startswith("Unnamed:"):
        df = df.iloc[:, 1:]
    df['energy_score'] = df['energy_score'].astype(int)
    # Format the energy as a string with 4 decimals
    df['GPU Energy (Wh)'] = df['total_gpu_energy'].apply(lambda x: f"{x:.4f}")
    df['Model'] = df['model'].apply(make_link)
    df['Score'] = df['energy_score'].apply(format_stars)
    
    if 'class' in df.columns:
        df['Class'] = df['class']
        df = df[['Model', 'GPU Energy (Wh)', 'Score', 'Class']]
    else:
        df = df[['Model', 'GPU Energy (Wh)', 'Score']]
        
    df = df.sort_values(by='GPU Energy (Wh)')
    return df

def get_all_model_names():
    """
    Combine data from all tasks and return a leaderboard table with:
      - Model, GPU Energy (Wh), Score
    Duplicate models are dropped.
    """
    all_df = pd.DataFrame()
    for task in tasks:
        df = pd.read_csv('data/energy/' + task)
        if df.columns[0].startswith("Unnamed:"):
            df = df.iloc[:, 1:]
        df['energy_score'] = df['energy_score'].astype(int)
        df['GPU Energy (Wh)'] = df['total_gpu_energy'].apply(lambda x: f"{x:.4f}")
        df['Model'] = df['model'].apply(make_link)
        df['Score'] = df['energy_score'].apply(format_stars)
        all_df = pd.concat([all_df, df], ignore_index=True)
    all_df = all_df.drop_duplicates(subset=['model'])
    all_df = all_df.sort_values(by='GPU Energy (Wh)')
    return all_df[['Model', 'GPU Energy (Wh)', 'Score']]

# Build the Gradio interface.
# The css argument below makes all tables (e.g. leaderboard) use a fixed layout with narrower columns.
demo = gr.Blocks(css="""
.gr-dataframe table {
    table-layout: fixed;
    width: 100%;
}
.gr-dataframe th, .gr-dataframe td {
    max-width: 150px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
""")

with demo:
    gr.Markdown(
        """# AI Energy Score Leaderboard
### Welcome to the leaderboard for the [AI Energy Score Project!](https://huggingface.co/AIEnergyScore)
Click through the tasks below to see how different models measure up in terms of energy efficiency."""
    )
    gr.Markdown(
        """Test your own models via the [submission portal](https://huggingface.co/spaces/AIEnergyScore/submission_portal)"""
    )
    
    with gr.Tabs():
        with gr.TabItem("Text Generation 💬"):
            with gr.Row():
                with gr.Column(scale=1.3):
                    plot = gr.Plot(get_plots('text_generation.csv'))
                with gr.Column(scale=1):
                    table = gr.Dataframe(get_model_names('text_generation.csv'), datatype="markdown")
                    
        with gr.TabItem("Image Generation 📷"):
            with gr.Row():
                with gr.Column():
                    plot = gr.Plot(get_plots('image_generation.csv'))
                with gr.Column():
                    table = gr.Dataframe(get_model_names('image_generation.csv'), datatype="markdown")
                    
        with gr.TabItem("Text Classification 🎭"):
            with gr.Row():
                with gr.Column():
                    plot = gr.Plot(get_plots('text_classification.csv'))
                with gr.Column():
                    table = gr.Dataframe(get_model_names('text_classification.csv'), datatype="markdown")
                    
        with gr.TabItem("Image Classification 🖼️"):
            with gr.Row():
                with gr.Column():
                    plot = gr.Plot(get_plots('image_classification.csv'))
                with gr.Column():
                    table = gr.Dataframe(get_model_names('image_classification.csv'), datatype="markdown")
                    
        with gr.TabItem("Image Captioning 📝"):
            with gr.Row():
                with gr.Column():
                    plot = gr.Plot(get_plots('image_captioning.csv'))
                with gr.Column():
                    table = gr.Dataframe(get_model_names('image_captioning.csv'), datatype="markdown")
                    
        with gr.TabItem("Summarization 📃"):
            with gr.Row():
                with gr.Column():
                    plot = gr.Plot(get_plots('summarization.csv'))
                with gr.Column():
                    table = gr.Dataframe(get_model_names('summarization.csv'), datatype="markdown")
                    
        with gr.TabItem("Automatic Speech Recognition 💬"):
            with gr.Row():
                with gr.Column():
                    plot = gr.Plot(get_plots('asr.csv'))
                with gr.Column():
                    table = gr.Dataframe(get_model_names('asr.csv'), datatype="markdown")
                    
        with gr.TabItem("Object Detection 🚘"):
            with gr.Row():
                with gr.Column():
                    plot = gr.Plot(get_plots('object_detection.csv'))
                with gr.Column():
                    table = gr.Dataframe(get_model_names('object_detection.csv'), datatype="markdown")
                    
        with gr.TabItem("Sentence Similarity 📚"):
            with gr.Row():
                with gr.Column():
                    plot = gr.Plot(get_plots('sentence_similarity.csv'))
                with gr.Column():
                    table = gr.Dataframe(get_model_names('sentence_similarity.csv'), datatype="markdown")
                    
        with gr.TabItem("Extractive QA ❔"):
            with gr.Row():
                with gr.Column():
                    plot = gr.Plot(get_plots('question_answering.csv'))
                with gr.Column():
                    table = gr.Dataframe(get_model_names('question_answering.csv'), datatype="markdown")
                    
        with gr.TabItem("All Tasks 💡"):
            with gr.Row():
                with gr.Column():
                    plot = gr.Plot(get_all_plots)
                with gr.Column():
                    table = gr.Dataframe(get_all_model_names, datatype="markdown")
                    
    with gr.Accordion("📙 Citation", open=False):
        citation_button = gr.Textbox(
            value=CITATION_BUTTON_TEXT,
            label=CITATION_BUTTON_LABEL,
            elem_id="citation-button",
            lines=10,
            show_copy_button=True,
        )
    gr.Markdown(
        """Last updated: February 2025"""
    )

demo.launch()