# CO2 Emissions and the 🤗 Hub: Leading the Charge

huggingface.co · Sasha Luccioni, Zachary Mueller, Nate Raw · Apr 22, 2022

**Type:** Tutorial

## Summary

Training and deploying machine learning models produces greenhouse gas emissions determined by infrastructure runtime, hardware type, and energy grid carbon intensity. Hugging Face introduced mechanisms to measure, report, and filter models based on their carbon footprint to improve ecological transparency. Using the huggingface\_hub library, practitioners can query HfApi.list\_models with an emissions\_thresholds parameter to filter models by maximum or minimum carbon emissions measured in grams. In addition, installing the codecarbon package enables the Transformers Trainer to automatically attach CodeCarbonCallback and log training emissions to an emissions.csv file. Users can then publish these measured values directly into model card metadata under co2\_eq\_emissions for public tracking.

## Context

Training and deploying machine learning models emits carbon dioxide due to the energy consumed by computing hardware, including GPUs and storage. Total emissions depend on runtime, hardware type, and the carbon intensity of the energy source, creating a need for standardized tracking, reporting, and model selection mechanisms.

## Approach / What changed

The huggingface\_hub library introduces an emissions\_thresholds parameter in HfApi.list\_models to search models within specific carbon gram limits. Additionally, integrating the codecarbon library with the Transformers Trainer activates CodeCarbonCallback to write training emissions into an emissions.csv file, which can then be documented in the model card metadata under co2\_eq\_emissions.

## Takeaways

- The huggingface\_hub HfApi.list\_models method supports an emissions\_thresholds parameter to search models based on minimum or maximum carbon emission gram ranges.
- Installing codecarbon allows the Transformers Trainer to automatically load CodeCarbonCallback and track emissions during training.
- Emissions data logged during training runs is written to an emissions.csv file and can be published in model cards under the co2\_eq\_emissions metadata field.

**Tags:** [Machine Learning](https://yomu.fyi/topic/machine-learning), [Open Source](https://yomu.fyi/topic/open-source), [Python](https://yomu.fyi/topic/python)

[Read original post](https://huggingface.co/blog/carbon-emissions-on-the-hub)
