update: added model/provider in expert mode + fixed visuals
Browse files- app.py +1 -1
- src/__pycache__/calculator.cpython-312.pyc +0 -0
- src/__pycache__/content.cpython-312.pyc +0 -0
- src/__pycache__/expert.cpython-312.pyc +0 -0
- src/__pycache__/models.cpython-312.pyc +0 -0
- src/__pycache__/token_estimator.cpython-312.pyc +0 -0
- src/__pycache__/utils.cpython-312.pyc +0 -0
- src/calculator.py +1 -3
- src/content.py +10 -1
- src/expert.py +64 -37
- src/models.py +4 -2
- src/utils.py +7 -50
app.py
CHANGED
@@ -55,7 +55,7 @@ with tab_method:
|
|
55 |
|
56 |
with tab_about:
|
57 |
|
58 |
-
st.
|
59 |
|
60 |
with st.expander('📚 Citation'):
|
61 |
st.html(CITATION_LABEL)
|
|
|
55 |
|
56 |
with tab_about:
|
57 |
|
58 |
+
st.markdown(ABOUT_TEXT, unsafe_allow_html=True)
|
59 |
|
60 |
with st.expander('📚 Citation'):
|
61 |
st.html(CITATION_LABEL)
|
src/__pycache__/calculator.cpython-312.pyc
CHANGED
Binary files a/src/__pycache__/calculator.cpython-312.pyc and b/src/__pycache__/calculator.cpython-312.pyc differ
|
|
src/__pycache__/content.cpython-312.pyc
CHANGED
Binary files a/src/__pycache__/content.cpython-312.pyc and b/src/__pycache__/content.cpython-312.pyc differ
|
|
src/__pycache__/expert.cpython-312.pyc
CHANGED
Binary files a/src/__pycache__/expert.cpython-312.pyc and b/src/__pycache__/expert.cpython-312.pyc differ
|
|
src/__pycache__/models.cpython-312.pyc
CHANGED
Binary files a/src/__pycache__/models.cpython-312.pyc and b/src/__pycache__/models.cpython-312.pyc differ
|
|
src/__pycache__/token_estimator.cpython-312.pyc
CHANGED
Binary files a/src/__pycache__/token_estimator.cpython-312.pyc and b/src/__pycache__/token_estimator.cpython-312.pyc differ
|
|
src/__pycache__/utils.cpython-312.pyc
CHANGED
Binary files a/src/__pycache__/utils.cpython-312.pyc and b/src/__pycache__/utils.cpython-312.pyc differ
|
|
src/calculator.py
CHANGED
@@ -1,12 +1,10 @@
|
|
1 |
import streamlit as st
|
2 |
-
import pandas as pd
|
3 |
|
4 |
from ecologits.tracers.utils import llm_impacts
|
5 |
from src.impacts import get_impacts, display_impacts, display_equivalent
|
6 |
from src.utils import format_impacts
|
7 |
from src.content import WARNING_CLOSED_SOURCE, WARNING_MULTI_MODAL, WARNING_BOTH
|
8 |
-
from src.models import load_models
|
9 |
-
from src.constants import MAIN_MODELS
|
10 |
|
11 |
from src.constants import PROMPTS
|
12 |
|
|
|
1 |
import streamlit as st
|
|
|
2 |
|
3 |
from ecologits.tracers.utils import llm_impacts
|
4 |
from src.impacts import get_impacts, display_impacts, display_equivalent
|
5 |
from src.utils import format_impacts
|
6 |
from src.content import WARNING_CLOSED_SOURCE, WARNING_MULTI_MODAL, WARNING_BOTH
|
7 |
+
from src.models import load_models
|
|
|
8 |
|
9 |
from src.constants import PROMPTS
|
10 |
|
src/content.py
CHANGED
@@ -4,13 +4,18 @@ HERO_TEXT = """
|
|
4 |
<img style="max-height: 80px" alt="EcoLogits" src="https://raw.githubusercontent.com/genai-impact/ecologits/main/docs/assets/logo_light.png">
|
5 |
</a>
|
6 |
</div>
|
7 |
-
<h1 align="center">🧮 EcoLogits Calculator</h1>
|
8 |
<div align="center">
|
9 |
<p style="max-width: 500px; text-align: center">
|
10 |
<i><b>EcoLogits</b> is a python library that tracks the <b>energy consumption</b> and <b>environmental
|
11 |
footprint</b> of using <b>generative AI</b> models through APIs.</i>
|
12 |
</p>
|
13 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
<br>
|
15 |
"""
|
16 |
|
@@ -111,12 +116,14 @@ EcoLogits is focused on estimating the environmental impacts of generative AI (o
|
|
111 |
providers (such as OpenAI, Anthropic, Cloud APIs...)** whereas CodeCarbon is more general tool to measure energy
|
112 |
consumption and estimate GHG emissions measurement. If you deploy LLMs locally we encourage you to use CodeCarbon to
|
113 |
get real numbers of your energy consumption.
|
|
|
114 |
## 🤗 Contributing
|
115 |
We are eager to get feedback from the community, don't hesitate to engage the discussion with us on this
|
116 |
[GitHub thread](https://github.com/genai-impact/ecologits/discussions/45) or message us on
|
117 |
[LinkedIn](https://www.linkedin.com/company/genai-impact/).
|
118 |
We also welcome any open-source contributions on 🌱 **[EcoLogits](https://github.com/genai-impact/ecologits)** or on
|
119 |
🧮 **EcoLogits Calculator**.
|
|
|
120 |
## ⚖️ License
|
121 |
<p xmlns:cc="http://creativecommons.org/ns#" >
|
122 |
This work is licensed under
|
@@ -127,12 +134,14 @@ We also welcome any open-source contributions on 🌱 **[EcoLogits](https://gith
|
|
127 |
<img style="display:inline-block;height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/by.svg?ref=chooser-v1" alt="">
|
128 |
<img style="display:inline-block;height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/sa.svg?ref=chooser-v1" alt="">
|
129 |
</p>
|
|
|
130 |
## 🙌 Acknowledgement
|
131 |
We thank [Data For Good](https://dataforgood.fr/) and [Boavizta](https://boavizta.org/en) for supporting the
|
132 |
development of this project. Their contributions of tools, best practices, and expertise in environmental impact
|
133 |
assessment have been invaluable.
|
134 |
We also extend our gratitude to the open-source contributions of 🤗 [Hugging Face](huggingface.com) on the LLM-Perf
|
135 |
Leaderboard.
|
|
|
136 |
## 🤝 Contact
|
137 |
For general question on the project, please use the [GitHub thread](https://github.com/genai-impact/ecologits/discussions/45).
|
138 |
Otherwise use our contact form on [genai-impact.org/contact](https://genai-impact.org/contact/).
|
|
|
4 |
<img style="max-height: 80px" alt="EcoLogits" src="https://raw.githubusercontent.com/genai-impact/ecologits/main/docs/assets/logo_light.png">
|
5 |
</a>
|
6 |
</div>
|
|
|
7 |
<div align="center">
|
8 |
<p style="max-width: 500px; text-align: center">
|
9 |
<i><b>EcoLogits</b> is a python library that tracks the <b>energy consumption</b> and <b>environmental
|
10 |
footprint</b> of using <b>generative AI</b> models through APIs.</i>
|
11 |
</p>
|
12 |
</div>
|
13 |
+
<h1 align="center">🧮 EcoLogits Calculator</h1>
|
14 |
+
<div align="center">
|
15 |
+
<p style="max-width: 500px; text-align: center">
|
16 |
+
<i>allows a broader access to <b>EcoLogits</b> through a visual application.</i>
|
17 |
+
</p>
|
18 |
+
</div>
|
19 |
<br>
|
20 |
"""
|
21 |
|
|
|
116 |
providers (such as OpenAI, Anthropic, Cloud APIs...)** whereas CodeCarbon is more general tool to measure energy
|
117 |
consumption and estimate GHG emissions measurement. If you deploy LLMs locally we encourage you to use CodeCarbon to
|
118 |
get real numbers of your energy consumption.
|
119 |
+
|
120 |
## 🤗 Contributing
|
121 |
We are eager to get feedback from the community, don't hesitate to engage the discussion with us on this
|
122 |
[GitHub thread](https://github.com/genai-impact/ecologits/discussions/45) or message us on
|
123 |
[LinkedIn](https://www.linkedin.com/company/genai-impact/).
|
124 |
We also welcome any open-source contributions on 🌱 **[EcoLogits](https://github.com/genai-impact/ecologits)** or on
|
125 |
🧮 **EcoLogits Calculator**.
|
126 |
+
|
127 |
## ⚖️ License
|
128 |
<p xmlns:cc="http://creativecommons.org/ns#" >
|
129 |
This work is licensed under
|
|
|
134 |
<img style="display:inline-block;height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/by.svg?ref=chooser-v1" alt="">
|
135 |
<img style="display:inline-block;height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/sa.svg?ref=chooser-v1" alt="">
|
136 |
</p>
|
137 |
+
|
138 |
## 🙌 Acknowledgement
|
139 |
We thank [Data For Good](https://dataforgood.fr/) and [Boavizta](https://boavizta.org/en) for supporting the
|
140 |
development of this project. Their contributions of tools, best practices, and expertise in environmental impact
|
141 |
assessment have been invaluable.
|
142 |
We also extend our gratitude to the open-source contributions of 🤗 [Hugging Face](huggingface.com) on the LLM-Perf
|
143 |
Leaderboard.
|
144 |
+
|
145 |
## 🤝 Contact
|
146 |
For general question on the project, please use the [GitHub thread](https://github.com/genai-impact/ecologits/discussions/45).
|
147 |
Otherwise use our contact form on [genai-impact.org/contact](https://genai-impact.org/contact/).
|
src/expert.py
CHANGED
@@ -1,12 +1,11 @@
|
|
1 |
import streamlit as st
|
2 |
-
import pandas as pd
|
3 |
from ecologits.impacts.llm import compute_llm_impacts
|
4 |
|
5 |
-
from src.utils import format_impacts, average_range_impacts
|
6 |
from src.impacts import display_impacts
|
7 |
-
#from src.constants import PROVIDERS, MODELS
|
8 |
from src.electricity_mix import COUNTRY_CODES, find_electricity_mix, dataframe_electricity_mix
|
9 |
-
from
|
|
|
10 |
|
11 |
import plotly.express as px
|
12 |
|
@@ -21,35 +20,56 @@ def expert_mode():
|
|
21 |
|
22 |
########## Model info ##########
|
23 |
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
########## Model parameters ##########
|
39 |
|
40 |
col11, col22, col33 = st.columns(3)
|
41 |
|
42 |
with col11:
|
43 |
-
|
44 |
-
# st.write(models.find_model(provider, model))
|
45 |
-
# st.write(model_active_params_fn(provider, model, 45))
|
46 |
-
active_params = st.number_input('Active parameters (B)', 0, None, 45)
|
47 |
|
48 |
with col22:
|
49 |
-
total_params = st.number_input('Total parameters (B)', 0, None,
|
50 |
|
51 |
with col33:
|
52 |
-
output_tokens = st.number_input('Output completion tokens',
|
53 |
|
54 |
########## Electricity mix ##########
|
55 |
|
@@ -89,15 +109,16 @@ def expert_mode():
|
|
89 |
st.markdown('The usage impacts account for the electricity consumption of the model while the embodied impacts account for resource extraction (e.g., minerals and metals), manufacturing, and transportation of the hardware.')
|
90 |
|
91 |
col_ghg_comparison, col_adpe_comparison, col_pe_comparison = st.columns(3)
|
92 |
-
|
93 |
with col_ghg_comparison:
|
|
|
94 |
fig_gwp = px.pie(
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
fig_gwp.update_layout(showlegend=False, title_x=0.5)
|
102 |
|
103 |
st.plotly_chart(fig_gwp)
|
@@ -107,11 +128,10 @@ def expert_mode():
|
|
107 |
values = [average_range_impacts(usage.adpe.value), average_range_impacts(embodied.adpe.value)],
|
108 |
names = ['usage', 'embodied'],
|
109 |
title = 'Abiotic depletion',
|
110 |
-
color_discrete_sequence=["#
|
111 |
width = 100)
|
112 |
fig_adpe.update_layout(
|
113 |
-
showlegend=
|
114 |
-
legend=dict(yanchor="bottom", x = 0.35, y = -0.1),
|
115 |
title_x=0.5)
|
116 |
|
117 |
st.plotly_chart(fig_adpe)
|
@@ -121,7 +141,7 @@ def expert_mode():
|
|
121 |
values = [average_range_impacts(usage.pe.value), average_range_impacts(embodied.pe.value)],
|
122 |
names = ['usage', 'embodied'],
|
123 |
title = 'Primary energy',
|
124 |
-
color_discrete_sequence=["#
|
125 |
width = 100)
|
126 |
fig_pe.update_layout(showlegend=False, title_x=0.5)
|
127 |
|
@@ -139,16 +159,23 @@ def expert_mode():
|
|
139 |
|
140 |
try:
|
141 |
|
142 |
-
|
143 |
|
144 |
impact_type = st.selectbox(
|
145 |
label='Select an impact type to compare',
|
146 |
-
options=[x for x in
|
147 |
index=1)
|
148 |
|
149 |
-
|
150 |
-
|
151 |
-
fig_2 = px.bar(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
st.plotly_chart(fig_2)
|
153 |
|
154 |
except:
|
|
|
1 |
import streamlit as st
|
|
|
2 |
from ecologits.impacts.llm import compute_llm_impacts
|
3 |
|
4 |
+
from src.utils import format_impacts, average_range_impacts
|
5 |
from src.impacts import display_impacts
|
|
|
6 |
from src.electricity_mix import COUNTRY_CODES, find_electricity_mix, dataframe_electricity_mix
|
7 |
+
from src.models import load_models
|
8 |
+
from src.constants import PROMPTS
|
9 |
|
10 |
import plotly.express as px
|
11 |
|
|
|
20 |
|
21 |
########## Model info ##########
|
22 |
|
23 |
+
col1, col2, col3 = st.columns(3)
|
24 |
+
|
25 |
+
df = load_models(filter_main=True)
|
26 |
+
|
27 |
+
with col1:
|
28 |
+
provider_exp = st.selectbox(
|
29 |
+
label = 'Provider',
|
30 |
+
options = [x for x in df['provider_clean'].unique()],
|
31 |
+
index = 7,
|
32 |
+
key = 1
|
33 |
+
)
|
34 |
|
35 |
+
with col2:
|
36 |
+
model_exp = st.selectbox(
|
37 |
+
label = 'Model',
|
38 |
+
options = [x for x in df['name_clean'].unique() if x in df[df['provider_clean'] == provider_exp]['name_clean'].unique()],
|
39 |
+
key = 2
|
40 |
+
)
|
41 |
+
|
42 |
+
with col3:
|
43 |
+
output_tokens_exp = st.selectbox(
|
44 |
+
label = 'Example prompt',
|
45 |
+
options = [x[0] for x in PROMPTS],
|
46 |
+
key = 3
|
47 |
+
)
|
48 |
|
49 |
+
df_filtered = df[(df['provider_clean'] == provider_exp) & (df['name_clean'] == model_exp)]
|
50 |
+
|
51 |
+
try:
|
52 |
+
total_params = int(df_filtered['total_parameters'].iloc[0])
|
53 |
+
except:
|
54 |
+
total_params = int((df_filtered['total_parameters'].values[0]['min'] + df_filtered['total_parameters'].values[0]['max'])/2)
|
55 |
+
|
56 |
+
try:
|
57 |
+
active_params = int(df_filtered['active_parameters'].iloc[0])
|
58 |
+
except:
|
59 |
+
active_params = int((df_filtered['active_parameters'].values[0]['min'] + df_filtered['active_parameters'].values[0]['max'])/2)
|
60 |
|
61 |
########## Model parameters ##########
|
62 |
|
63 |
col11, col22, col33 = st.columns(3)
|
64 |
|
65 |
with col11:
|
66 |
+
active_params = st.number_input('Active parameters (B)', 0, None, active_params)
|
|
|
|
|
|
|
67 |
|
68 |
with col22:
|
69 |
+
total_params = st.number_input('Total parameters (B)', 0, None, total_params)
|
70 |
|
71 |
with col33:
|
72 |
+
output_tokens = st.number_input('Output completion tokens', [x[1] for x in PROMPTS if x[0] == output_tokens_exp][0])
|
73 |
|
74 |
########## Electricity mix ##########
|
75 |
|
|
|
109 |
st.markdown('The usage impacts account for the electricity consumption of the model while the embodied impacts account for resource extraction (e.g., minerals and metals), manufacturing, and transportation of the hardware.')
|
110 |
|
111 |
col_ghg_comparison, col_adpe_comparison, col_pe_comparison = st.columns(3)
|
112 |
+
|
113 |
with col_ghg_comparison:
|
114 |
+
|
115 |
fig_gwp = px.pie(
|
116 |
+
values = [average_range_impacts(usage.gwp.value), average_range_impacts(embodied.gwp.value)],
|
117 |
+
names = ['usage', 'embodied'],
|
118 |
+
title = 'GHG emissions',
|
119 |
+
color_discrete_sequence=["#00BF63", "#0B3B36"],
|
120 |
+
width = 100
|
121 |
+
)
|
122 |
fig_gwp.update_layout(showlegend=False, title_x=0.5)
|
123 |
|
124 |
st.plotly_chart(fig_gwp)
|
|
|
128 |
values = [average_range_impacts(usage.adpe.value), average_range_impacts(embodied.adpe.value)],
|
129 |
names = ['usage', 'embodied'],
|
130 |
title = 'Abiotic depletion',
|
131 |
+
color_discrete_sequence=["#0B3B36","#00BF63"],
|
132 |
width = 100)
|
133 |
fig_adpe.update_layout(
|
134 |
+
showlegend=False,
|
|
|
135 |
title_x=0.5)
|
136 |
|
137 |
st.plotly_chart(fig_adpe)
|
|
|
141 |
values = [average_range_impacts(usage.pe.value), average_range_impacts(embodied.pe.value)],
|
142 |
names = ['usage', 'embodied'],
|
143 |
title = 'Primary energy',
|
144 |
+
color_discrete_sequence=["#00BF63", "#0B3B36"],
|
145 |
width = 100)
|
146 |
fig_pe.update_layout(showlegend=False, title_x=0.5)
|
147 |
|
|
|
159 |
|
160 |
try:
|
161 |
|
162 |
+
df_comp = dataframe_electricity_mix(countries_to_compare)
|
163 |
|
164 |
impact_type = st.selectbox(
|
165 |
label='Select an impact type to compare',
|
166 |
+
options=[x for x in df_comp.columns if x!='country'],
|
167 |
index=1)
|
168 |
|
169 |
+
df_comp.sort_values(by = impact_type, inplace = True)
|
170 |
+
|
171 |
+
fig_2 = px.bar(
|
172 |
+
df_comp,
|
173 |
+
x = df_comp.index,
|
174 |
+
y = impact_type,
|
175 |
+
text = impact_type,
|
176 |
+
color = impact_type
|
177 |
+
)
|
178 |
+
|
179 |
st.plotly_chart(fig_2)
|
180 |
|
181 |
except:
|
src/models.py
CHANGED
@@ -32,6 +32,8 @@ def clean_models_data(df, with_filter = True):
|
|
32 |
|
33 |
df['architecture_type'] = df['architecture'].apply(lambda x: x['type'])
|
34 |
df['architecture_parameters'] = df['architecture'].apply(lambda x: x['parameters'])
|
|
|
|
|
35 |
|
36 |
df['warnings'] = df['warnings'].apply(lambda x: ', '.join(x) if x else None).fillna('none')
|
37 |
df['warning_arch'] = df['warnings'].apply(lambda x: 'model-arch-not-released' in x)
|
@@ -39,8 +41,8 @@ def clean_models_data(df, with_filter = True):
|
|
39 |
|
40 |
if with_filter == True:
|
41 |
df = df[df['name'].isin(models_to_keep)]
|
42 |
-
|
43 |
-
return df[['provider', 'provider_clean', 'name', 'name_clean', 'architecture_type', 'architecture_parameters', 'warning_arch', 'warning_multi_modal']]
|
44 |
|
45 |
@st.cache_data
|
46 |
def load_models(filter_main = True):
|
|
|
32 |
|
33 |
df['architecture_type'] = df['architecture'].apply(lambda x: x['type'])
|
34 |
df['architecture_parameters'] = df['architecture'].apply(lambda x: x['parameters'])
|
35 |
+
df['total_parameters'] = df['architecture_parameters'].apply(lambda x: x['total'] if isinstance(x, dict) and 'total' in x.keys() else x)
|
36 |
+
df['active_parameters'] = df['architecture_parameters'].apply(lambda x: x['active'] if isinstance(x, dict) and 'active' in x.keys() else x)
|
37 |
|
38 |
df['warnings'] = df['warnings'].apply(lambda x: ', '.join(x) if x else None).fillna('none')
|
39 |
df['warning_arch'] = df['warnings'].apply(lambda x: 'model-arch-not-released' in x)
|
|
|
41 |
|
42 |
if with_filter == True:
|
43 |
df = df[df['name'].isin(models_to_keep)]
|
44 |
+
|
45 |
+
return df[['provider', 'provider_clean', 'name', 'name_clean', 'architecture_type', 'architecture_parameters', 'total_parameters', 'active_parameters', 'warning_arch', 'warning_multi_modal']]
|
46 |
|
47 |
@st.cache_data
|
48 |
def load_models(filter_main = True):
|
src/utils.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
from dataclasses import dataclass
|
2 |
from enum import Enum
|
3 |
|
4 |
-
import pandas as pd
|
5 |
from ecologits.model_repository import models
|
6 |
from ecologits.impacts.modeling import Impacts, Energy, GWP, ADPe, PE
|
7 |
#from ecologits.tracers.utils import llm_impacts
|
@@ -91,12 +90,6 @@ IRELAND_POPULATION_MILLION = 5
|
|
91 |
# From https://impactco2.fr/outils/comparateur?value=1&comparisons=&equivalent=avion-pny
|
92 |
AIRPLANE_PARIS_NYC_GWP_EQ = q("177000 kgCO2eq")
|
93 |
|
94 |
-
def filter_models(provider, list_models):
|
95 |
-
|
96 |
-
model = 1
|
97 |
-
|
98 |
-
return model
|
99 |
-
|
100 |
#####################################################################################
|
101 |
### IMPACTS FORMATING
|
102 |
#####################################################################################
|
@@ -146,8 +139,12 @@ def format_impacts(impacts: Impacts) -> QImpacts:
|
|
146 |
def split_impacts_u_e(impacts: Impacts) -> QImpacts:
|
147 |
return impacts.usage, impacts.embodied
|
148 |
|
149 |
-
def average_range_impacts(
|
150 |
-
|
|
|
|
|
|
|
|
|
151 |
|
152 |
def format_impacts_expert(impacts: Impacts, display_range: bool) -> QImpacts:
|
153 |
|
@@ -219,44 +216,4 @@ def format_energy_eq_electricity_consumption_ireland(energy: Quantity) -> Quanti
|
|
219 |
def format_gwp_eq_airplane_paris_nyc(gwp: Quantity) -> Quantity:
|
220 |
gwp_eq = gwp * ONE_PERCENT_WORLD_POPULATION * DAYS_IN_YEAR
|
221 |
gwp_eq = gwp_eq.to("kgCO2eq")
|
222 |
-
return gwp_eq / AIRPLANE_PARIS_NYC_GWP_EQ
|
223 |
-
|
224 |
-
#####################################################################################
|
225 |
-
### MODELS PARAMETERS
|
226 |
-
#####################################################################################
|
227 |
-
|
228 |
-
def model_active_params_fn(provider_name: str, model_name: str, n_param: float):
|
229 |
-
if model_name == 'CUSTOM':
|
230 |
-
return n_param
|
231 |
-
else:
|
232 |
-
model = models.find_model(provider=provider_name, model_name=model_name)
|
233 |
-
|
234 |
-
if model.architecture == 'moe':
|
235 |
-
try:
|
236 |
-
return model.architecture.parameters.active.max
|
237 |
-
except:
|
238 |
-
try:
|
239 |
-
return model.architecture.parameters.active
|
240 |
-
except:
|
241 |
-
return model.architecture.parameters
|
242 |
-
elif model.architecture == 'dense':
|
243 |
-
try: #dense with range
|
244 |
-
return model.architecture.parameters.max
|
245 |
-
except: #dense without range
|
246 |
-
return model.architecture.parameters
|
247 |
-
|
248 |
-
def model_total_params_fn(provider_name: str, model_name: str, n_param: float):
|
249 |
-
if model_name == 'CUSTOM':
|
250 |
-
return n_param
|
251 |
-
provider, model_name = model_name.split('/', 1)
|
252 |
-
model = models.find_model(provider=provider, model_name=model_name)
|
253 |
-
try: #moe
|
254 |
-
return model.architecture.parameters.total.max
|
255 |
-
except:
|
256 |
-
try: #dense with range
|
257 |
-
return model.architecture.parameters.max
|
258 |
-
except: #dense without range
|
259 |
-
try:
|
260 |
-
return model.architecture.parameters.total
|
261 |
-
except:
|
262 |
-
return model.architecture.parameters
|
|
|
1 |
from dataclasses import dataclass
|
2 |
from enum import Enum
|
3 |
|
|
|
4 |
from ecologits.model_repository import models
|
5 |
from ecologits.impacts.modeling import Impacts, Energy, GWP, ADPe, PE
|
6 |
#from ecologits.tracers.utils import llm_impacts
|
|
|
90 |
# From https://impactco2.fr/outils/comparateur?value=1&comparisons=&equivalent=avion-pny
|
91 |
AIRPLANE_PARIS_NYC_GWP_EQ = q("177000 kgCO2eq")
|
92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
#####################################################################################
|
94 |
### IMPACTS FORMATING
|
95 |
#####################################################################################
|
|
|
139 |
def split_impacts_u_e(impacts: Impacts) -> QImpacts:
|
140 |
return impacts.usage, impacts.embodied
|
141 |
|
142 |
+
def average_range_impacts(x):
|
143 |
+
|
144 |
+
if isinstance(x, float):
|
145 |
+
return x
|
146 |
+
else:
|
147 |
+
return (x.max + x.min)/2
|
148 |
|
149 |
def format_impacts_expert(impacts: Impacts, display_range: bool) -> QImpacts:
|
150 |
|
|
|
216 |
def format_gwp_eq_airplane_paris_nyc(gwp: Quantity) -> Quantity:
|
217 |
gwp_eq = gwp * ONE_PERCENT_WORLD_POPULATION * DAYS_IN_YEAR
|
218 |
gwp_eq = gwp_eq.to("kgCO2eq")
|
219 |
+
return gwp_eq / AIRPLANE_PARIS_NYC_GWP_EQ####################################################################################### MODELS PARAMETER####################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|