CO2æåºéãšð€ããïŒãªãŒãã£ã³ã°ã»ã¶ã»ãã£ãŒãž
'CO2æåºéãšããïŒãªãŒãã£ã³ã°ã»ã¶ã»ãã£ãŒãž'
CO2æåºéãšã¯äœã§ããããªãéèŠãªã®ãïŒ
æ°åå€åã¯ç§ãã¡ãçŽé¢ããŠããæ倧ã®èª²é¡ã®äžã€ã§ãããäºé žåççŽ ïŒCO2ïŒãªã©ã®æž©å®€å¹æã¬ã¹ã®æåºåæžã¯ãã®åé¡ã«åãçµãäžã§éèŠãªåœ¹å²ãæãããŸãã
æ©æ¢°åŠç¿ã¢ãã«ã®ãã¬ãŒãã³ã°ãšãããã€ã¡ã³ãã«ã¯ãã³ã³ãã¥ãŒãã£ã³ã°ã€ã³ãã©ã¹ãã©ã¯ãã£ã®ãšãã«ã®ãŒäœ¿çšã«ããCO2ãæåºãããŸããGPUããã¹ãã¬ãŒãžãŸã§ããã¹ãŠãæ©èœããããã«ãšãã«ã®ãŒãå¿ èŠãšãããã®éçšã§CO2ãæåºããŸãã
åçïŒæè¿ã®Transformerã¢ãã«ãšãã®CO2æåºé
CO2ã®æåºéã¯ãå®è¡æéã䜿çšãããããŒããŠã§ã¢ããšãã«ã®ãŒæºã®ççŽ å¯åºŠãªã©ãããŸããŸãªèŠçŽ ã«äŸåããŸãã
以äžã«èª¬æããããŒã«ã䜿çšããããšã§ãèªèº«ã®æåºéã远跡ããã³å ±åããããšãã§ããŸãïŒããã¯ç§ãã¡ã®ãã£ãŒã«ãå šäœã®éææ§ãåäžãããããã«éèŠã§ãïŒïŒãŸããã¢ãã«ãéžæããéã«ã¯ãã®CO2æåºéã«åºã¥ããŠéžæããããšãã§ããŸãã
Transformersã䜿çšããŠèªåçã«èªåã®CO2æåºéãèšç®ããæ¹æ³
å§ããåã«ãã·ã¹ãã ã«ææ°ããŒãžã§ã³ã®huggingface_hub
ã©ã€ãã©ãªãã€ã³ã¹ããŒã«ãããŠããªãå Žåã¯ã以äžãå®è¡ããŠãã ããïŒ
pip install huggingface_hub -U
Hugging Face Hubã䜿çšããŠäœççŽ æåºã¢ãã«ãèŠã€ããæ¹æ³
ã¢ãã«ãããã«ã¢ããããŒããããããšãèæ
®ããŠããšã³æèãæã£ãŠããäžã®ã¢ãã«ãæ€çŽ¢ããæ¹æ³ã¯ãããŸããïŒããã«ã¯ãhuggingface_hub
ã©ã€ãã©ãªã«æ°ããç¹å¥ãªãã©ã¡ãŒã¿emissions_threshold
ããããŸããæå°ãŸãã¯æ倧ã®ã°ã©ã æ°ãæå®ããã ãã§ããã®ç¯å²å
ã«å«ãŸãããã¹ãŠã®ã¢ãã«ãæ€çŽ¢ãããŸãã
ããšãã°ãæ倧100ã°ã©ã ã§äœæããããã¹ãŠã®ã¢ãã«ãæ€çŽ¢ã§ããŸãïŒ
from huggingface_hub import HfApi
api = HfApi()
models = api.list_models(emissions_thresholds=(None, 100), cardData=True)
len(models)
>>> 191
ããªãå€ããããŸããïŒããã«ããããã¬ãŒãã³ã°äžã«éåžžã®ããå°ãªãççŽ ãæŸåºããå°åã¢ãã«ãèŠã€ããã®ã«ã圹ç«ã¡ãŸãã
ãããã«è¿ãã§èŠãŠã¿ããšãããããç§ãã¡ã®éŸå€ã«åã£ãŠããããšãããããŸãïŒ
model = models[0]
print(f'ã¢ãã«åïŒ{model.modelId}\nãã¬ãŒãã³ã°äžã«çºçããCO2ïŒ{model.cardData["co2_eq_emissions"]}')
>>> ã¢ãã«åïŒesiebomajeremiah/autonlp-email-classification-657119381
ãã¬ãŒãã³ã°äžã«çºçããCO2ïŒ3.516233232503715
åæ§ã«ãæå°å€ãæ€çŽ¢ããŠããã¬ãŒãã³ã°äžã«å€ãã®CO2ãæåºããéåžžã«å€§ããªã¢ãã«ãèŠã€ããããšãã§ããŸãïŒ
models = api.list_models(emissions_thresholds=(500, None), cardData=True)
len(models)
>>> 10
ããŠããããã®ãã¡ã®1ã€ãã©ãã ãCO2ãæåºããããèŠãŠã¿ãŸãããïŒ
model = models[0]
print(f'ã¢ãã«åïŒ{model.modelId}\nãã¬ãŒãã³ã°äžã«çºçããCO2ïŒ{model.cardData["co2_eq_emissions"]}')
>>> ã¢ãã«åïŒMaltehb/aelaectra-danish-electra-small-cased
ãã¬ãŒãã³ã°äžã«çºçããCO2ïŒ4009.5
ããã¯ããããã®CO2ã§ãïŒ
ã芧ã®ããã«ããããæ°è¡ã®ã³ãŒãã§ç°å¢ã«é æ ®ãã䜿çšãããã¢ãã«ãçŽ æ©ãè©äŸ¡ããããšãã§ããŸãïŒ
Transformersã䜿çšããŠççŽ æåºéãå ±åããæ¹æ³
transformers
ã䜿çšããŠããå Žåãcodecarbon
ã®çµ±åã«ãããççŽ æåºéãèªåçã«è¿œè·¡ããã³å ±åããããšãã§ããŸãããã·ã³ã«codecarbon
ãã€ã³ã¹ããŒã«ããŠããå ŽåãTrainer
ãªããžã§ã¯ãã¯ãã¬ãŒãã³ã°äžã«CodeCarbonCallback
ãèªåçã«è¿œå ãããã¬ãŒãã³ã°äžã«ççŽ æåºããŒã¿ãä¿åããŸãã
ãããã£ãŠã次ã®ãããªãã®ãå®è¡ãããš…
from datasets import load_dataset
from transformers import AutoModelForSequenceClassification, AutoTokenizer, Trainer, TrainingArguments
â
ds = load_dataset("imdb")
model = AutoModelForSequenceClassification.from_pretrained("bert-base-cased", num_labels=2)
tokenizer = AutoTokenizer.from_pretrained("bert-base-cased")
â
def tokenize_function(examples):
return tokenizer(examples["text"], padding="max_length", truncation=True)
â
â
small_train_dataset = ds["train"].shuffle(seed=42).select(range(1000)).map(tokenize_function, batched=True)
small_eval_dataset = ds["test"].shuffle(seed=42).select(range(1000)).map(tokenize_function, batched=True)
â
â
training_args = TrainingArguments(
"codecarbon-text-classification",
num_train_epochs=4,
push_to_hub=True
)
â
trainer = Trainer(
model=model,
args=training_args,
train_dataset=small_train_dataset,
eval_dataset=small_eval_dataset,
)
â
trainer.train()
…codecarbon-text-classification
ãã£ã¬ã¯ããªå
ã« emissions.csv
ãšããååã®ãã¡ã€ã«ãäœæãããŸãããã®ãã¡ã€ã«ã¯ãç°ãªããã¬ãŒãã³ã°å®è¡éã®ççŽ æåºéã远跡ããŸãããããŠãæºåãã§ããããæçµã¢ãã«ããã¬ãŒãã³ã°ããããã«äœ¿çšããå®è¡ã®ççŽ æåºéãååŸããã¢ãã«ã«ãŒãã«å«ããããšãã§ããŸããð
ã¢ãã«ã«ãŒãã®äžéšã«ãã®ããŒã¿ãå«ãŸããäŸã¯ä»¥äžã®éãã§ãïŒ
co2_eq_emissions
ã®ã¡ã¿ããŒã¿åœ¢åŒã®è©³çŽ°ã«ã€ããŠã¯ãããã®ããã¥ã¡ã³ããåç
§ããŠãã ããã
ãããªãåèæç®
- Rolnick et al. (2019) – Tackling Climate Change with Machine Learning
- Strubell et al. (2019) – Energy and Policy Considerations for Deep Learning in NLP
- Schwartz et al. (2020) – Green AI
We will continue to update VoAGI; if you have any questions or suggestions, please contact us!
Was this article helpful?
93 out of 132 found this helpful
Related articles
- Hugging Faceãããžãfastaiãããæè¿ããŸã
- æé©ãªãã€ãã©ã€ã³ãšãã©ã³ã¹ãã©ãŒããŒãã€ãã©ã€ã³ã«ããé«éæšè«
- Gradio 3.0 ããªãªãŒã¹ãããŸããïŒ
- ãã®ã³ã°ãã§ã€ã¹ãã§ããŒã·ããããã°ã©ã ã®çºè¡š
- ã»ã³ãã¬ãã«ã¹ãå°é家å éããã°ã©ã ã掻çšããŠã圌ãã®MLããŒãããããå éããæ¹æ³
- ãã«ãªã¯ãšã¹ããšãã£ã¹ã«ãã·ã§ã³ã®çŽ¹ä» ð¥³
- GraphcoreãšHugging FaceããIPU察å¿ã®æ°ãããã©ã³ã¹ãã©ãŒããŒã®ã©ã€ã³ã¢ãããçºè¡š