Spaces:
Running
Running
adding new plots
Browse files
app.py
CHANGED
@@ -5,6 +5,27 @@ import plotly.express as px
|
|
5 |
import numpy as np
|
6 |
|
7 |
datadir = 'data/emissions/complete'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
model_param_df = pd.read_csv('data/model_parameters.csv', header=0)
|
10 |
model_performance_df = pd.read_csv('data/performance.csv', header=0)
|
@@ -12,17 +33,36 @@ emissions_df = pd.read_csv('data/co2_data.csv',header=0)
|
|
12 |
modalities_df = pd.read_csv('data/modalities_data.csv',header=0)
|
13 |
finetuned_df = emissions_df[~emissions_df['task'].str.contains('zero')]
|
14 |
finetuned_df['task'] = finetuned_df['task'].str.replace('_',' ')
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
fig0 = px.scatter(emissions_df, x="num_params", y="query emissions (g)", color="model", log_x=True, log_y=True)
|
17 |
fig0.update_layout(xaxis={'categoryorder':'mean ascending'})
|
18 |
fig0.update_layout(yaxis_title='Total carbon emitted (g)')
|
19 |
fig0.update_layout(xaxis_title='Number of Parameters')
|
20 |
|
21 |
|
22 |
-
fig1 = px.
|
23 |
fig1.update_layout(xaxis={'categoryorder':'mean ascending'})
|
24 |
fig1.update_layout(yaxis_title='Total energy used (Wh)')
|
25 |
fig1.update_layout(xaxis_title='Task')
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
fig2 = px.scatter(modalities_df, x="num_params", y="query emissions (g)", color="modality",
|
28 |
log_x=True, log_y=True, custom_data=['model','task'])
|
@@ -37,6 +77,32 @@ fig2.update_layout(xaxis_title='Model size (number of parameters)')
|
|
37 |
fig2.update_layout(yaxis_title='Model emissions (g of CO<sub>2</sub>)')
|
38 |
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
demo = gr.Blocks()
|
41 |
|
42 |
with demo:
|
@@ -64,16 +130,35 @@ with demo:
|
|
64 |
gr.Markdown("Image generation is by far the most energy- and carbon-intensive task from the ones studied, and text classification \
|
65 |
is the least.")
|
66 |
gr.Plot(fig1)
|
|
|
67 |
with gr.Column():
|
68 |
gr.Markdown("## Modality comparison (carbon)")
|
69 |
gr.Markdown("### Grouping the models by their modality shows different characteristics:")
|
70 |
gr.Markdown("We can see that tasks involving images (image-to-text, image-to-category) require more energy and emit more carbon\
|
71 |
than ones involving text.")
|
72 |
gr.Plot(fig2)
|
|
|
|
|
|
|
73 |
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
-
|
76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
|
79 |
demo.launch()
|
|
|
5 |
import numpy as np
|
6 |
|
7 |
datadir = 'data/emissions/complete'
|
8 |
+
seq2seq_finetuned = ['sshleifer/distilbart-xsum-12-6', 'sshleifer/distilbart-cnn-12-6', 'sshleifer/distilbart-cnn-6-6',
|
9 |
+
'pszemraj/led-large-book-summary', 'google/pegasus-xsum', 'google/pegasus-large',
|
10 |
+
'google/pegasus-multi_news' ,'facebook/bart-large-cnn', 'ainize/bart-base-cnn']
|
11 |
+
color_discrete_map = {'Task-specific Encoder': '#636EFA', 'Multi-purpose Seq2Seq': '#AB63FA', 'Multi-purpose Decoder': '#00CC96', 'Task-specific Seq2Seq':'#EF553B'}
|
12 |
+
|
13 |
+
def multi_check(mname):
|
14 |
+
if 'flan' in mname:
|
15 |
+
return 'Seq2Seq'
|
16 |
+
elif 'bloomz' in mname:
|
17 |
+
return 'Decoder'
|
18 |
+
|
19 |
+
def encoder_check(mname):
|
20 |
+
if 'flan' in mname:
|
21 |
+
return 'Multi-purpose Seq2Seq'
|
22 |
+
elif mname in seq2seq_finetuned:
|
23 |
+
return 'Task-specific Seq2Seq'
|
24 |
+
elif 'bloomz' in mname:
|
25 |
+
return 'Multi-purpose Decoder'
|
26 |
+
else:
|
27 |
+
return 'Task-specific Encoder'
|
28 |
+
# Data loading
|
29 |
|
30 |
model_param_df = pd.read_csv('data/model_parameters.csv', header=0)
|
31 |
model_performance_df = pd.read_csv('data/performance.csv', header=0)
|
|
|
33 |
modalities_df = pd.read_csv('data/modalities_data.csv',header=0)
|
34 |
finetuned_df = emissions_df[~emissions_df['task'].str.contains('zero')]
|
35 |
finetuned_df['task'] = finetuned_df['task'].str.replace('_',' ')
|
36 |
+
zeroshot_df = emissions_df[emissions_df['task'].str.contains('zero')]
|
37 |
+
zeroshot_df['task'] = zeroshot_df['task'].str.replace('_',' ')
|
38 |
+
zeroshot_df['architecture_type'] = zeroshot_df.apply(lambda x : multi_check(x.model),axis=1)
|
39 |
+
grouped_df = emissions_df.groupby(['model','task']).mean()
|
40 |
+
grouped_df = grouped_df.reset_index()
|
41 |
+
grouped_df = grouped_df.drop('task',axis=1)
|
42 |
+
performance_all = pd.merge(grouped_df, model_performance_df, on='model')
|
43 |
+
performance_all['type']= performance_all.apply(lambda x : encoder_check(x.model),axis=1)
|
44 |
+
performance_all['log_emissions'] = np.log1p(performance_all["query emissions (g)"])
|
45 |
+
sent_df = performance_all[['imdb (acc)','sst2 (acc)','tomatoes (acc)', "query emissions (g)", 'model','type','num_params', 'log_emissions']][performance_all['task'].isin(['sentiment'])]
|
46 |
+
qa_df = performance_all[['sciq (acc)', 'squad (f1)', 'squad_v2 (f1, has answer)', "query emissions (g)", 'model','type','num_params', 'log_emissions']][performance_all['task'].isin(['qa'])]
|
47 |
+
summ_df = performance_all[['samsum (rouge)', 'xsum (rouge)', 'cnn (rouge)', "query emissions (g)", 'model','type', 'num_params','log_emissions']][performance_all['task'].isin(['summarization'])]
|
48 |
+
|
49 |
+
# Figure loading
|
50 |
fig0 = px.scatter(emissions_df, x="num_params", y="query emissions (g)", color="model", log_x=True, log_y=True)
|
51 |
fig0.update_layout(xaxis={'categoryorder':'mean ascending'})
|
52 |
fig0.update_layout(yaxis_title='Total carbon emitted (g)')
|
53 |
fig0.update_layout(xaxis_title='Number of Parameters')
|
54 |
|
55 |
|
56 |
+
fig1 = px.scatter(finetuned_df, x="task", y="query_energy (kWh)", color="model", log_y=True)
|
57 |
fig1.update_layout(xaxis={'categoryorder':'mean ascending'})
|
58 |
fig1.update_layout(yaxis_title='Total energy used (Wh)')
|
59 |
fig1.update_layout(xaxis_title='Task')
|
60 |
+
fig1.update_traces(
|
61 |
+
hovertemplate="<br>".join([
|
62 |
+
"Model: %{customdata[0]}",
|
63 |
+
"Task: %{customdata[1]}",
|
64 |
+
])
|
65 |
+
)
|
66 |
|
67 |
fig2 = px.scatter(modalities_df, x="num_params", y="query emissions (g)", color="modality",
|
68 |
log_x=True, log_y=True, custom_data=['model','task'])
|
|
|
77 |
fig2.update_layout(yaxis_title='Model emissions (g of CO<sub>2</sub>)')
|
78 |
|
79 |
|
80 |
+
fig3 = px.scatter(zeroshot_df, x="model", y="query emissions (g)", color="architecture_type", size='num_params', log_y=True)
|
81 |
+
fig3.update_layout(xaxis={'categoryorder':'mean ascending'})
|
82 |
+
fig3.update_layout(yaxis_title='Model emissions (g of CO<sub>2</sub>)')
|
83 |
+
fig3.update_layout(xaxis_title='Model')
|
84 |
+
|
85 |
+
fig4 = px.scatter(zeroshot_df, x="dataset", y="query emissions (g)", color="model", size='num_params', log_y=True)
|
86 |
+
fig4.update_layout(xaxis={'categoryorder':'mean ascending'})
|
87 |
+
fig4.update_layout(yaxis_title='Model emissions (g of CO<sub>2</sub>)')
|
88 |
+
fig4.update_layout(xaxis_title='Model')
|
89 |
+
|
90 |
+
fig5 = px.scatter(sent_df, y=['imdb (acc)', 'sst2 (acc)', 'tomatoes (acc)'], x="num_params", color="type", color_discrete_map=color_discrete_map,
|
91 |
+
size= "log_emissions", log_x=True, hover_data="model")
|
92 |
+
fig5.update_layout(legend=dict(y=-0.4,x=0.3))
|
93 |
+
fig5.update_layout(yaxis_title='Text Classification Accuracy')
|
94 |
+
|
95 |
+
fig6 = px.scatter(qa_df, y=['sciq (acc)', 'squad (f1)', 'squad_v2 (f1, has answer)'], x="num_params", color="type",
|
96 |
+
size = 'log_emissions', log_x=True, hover_data="model")
|
97 |
+
fig6.update_layout(legend=dict(y=-0.4,x=0.3))
|
98 |
+
fig6.update_layout(yaxis_title='QA accuracy/F1')
|
99 |
+
|
100 |
+
fig7 = px.scatter(summ_df, y=['samsum (rouge)', 'xsum (rouge)', 'cnn (rouge)'], x="num_params", color="type",
|
101 |
+
size = 'log_emissions', log_x=True, hover_data="model")
|
102 |
+
fig7.update_layout(legend=dict(y=-0.4,x=0.3))
|
103 |
+
fig7.update_layout(yaxis_title='Summarization Rouge Score')
|
104 |
+
|
105 |
+
|
106 |
demo = gr.Blocks()
|
107 |
|
108 |
with demo:
|
|
|
130 |
gr.Markdown("Image generation is by far the most energy- and carbon-intensive task from the ones studied, and text classification \
|
131 |
is the least.")
|
132 |
gr.Plot(fig1)
|
133 |
+
with gr.Row():
|
134 |
with gr.Column():
|
135 |
gr.Markdown("## Modality comparison (carbon)")
|
136 |
gr.Markdown("### Grouping the models by their modality shows different characteristics:")
|
137 |
gr.Markdown("We can see that tasks involving images (image-to-text, image-to-category) require more energy and emit more carbon\
|
138 |
than ones involving text.")
|
139 |
gr.Plot(fig2)
|
140 |
+
gr.Markdown("## Multi-task model comparison (carbon)")
|
141 |
+
gr.Markdown("### Looking at the emissions of multi-task models, we can see that decoder-only models tend to emit more carbon compared to sequence-to-sequence ones.")
|
142 |
+
gr.Markdown("### This pattern varies depending on the dataset and task - for summarization datasets (the 3 rightmost ones), the difference between models is less obvious.")
|
143 |
|
144 |
+
with gr.Row():
|
145 |
+
with gr.Column():
|
146 |
+
gr.Plot(fig3)
|
147 |
+
with gr.Column():
|
148 |
+
gr.Plot(fig4)
|
149 |
|
150 |
+
gr.Markdown("## Evaluations (accuracy vs carbon)")
|
151 |
+
gr.Markdown("### Single-task models are, ceteris paribus, less carbon-intensive than multi-task models for all 3 tasks we looked at: ")
|
152 |
+
with gr.Row():
|
153 |
+
with gr.Column():
|
154 |
+
gr.Markdown("### Sentiment Analysis")
|
155 |
+
gr.Plot(fig5)
|
156 |
+
with gr.Column():
|
157 |
+
gr.Markdown("### Question Answering")
|
158 |
+
gr.Plot(fig6)
|
159 |
+
with gr.Column():
|
160 |
+
gr.Markdown("### Summarization")
|
161 |
+
gr.Plot(fig7)
|
162 |
|
163 |
|
164 |
demo.launch()
|