Loading…
CO2 Emissions and the 🤗 Hub: Leading the Charge
Sasha Luccioni, Zachary Mueller, Nate Raw
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.
Related reading
huggingface.co ·
Supercharged Searching on the 🤗 Hub
Programmatically searching the Hugging Face Hub previously required navigating web browser widgets or enduring trial and error to guess exact query string formats. The huggingface_hub library solves this issue by introducing helper utilities such as ModelSearchArguments, DatasetSearchArguments, and ModelFilter alongside HfApi. These namespace helpers translate accessible Python attributes into the formatted parameters expected by the backend API, covering datasets, tasks, and libraries. For complex queries across multiple tasks, frameworks, and datasets, developers can combine criteria inside ModelFilter instances and retrieve matching model metadata via api.list_models. Under the hood, the library uses AttributeDictionary, a data structure inspired by fastcore that enables nested tab-completion while supporting standard dictionary key indexing for special characters.
Zachary Muellerhuggingface.co ·
Machine Learning Experts - Sasha Luccioni
Research scientist Sasha Luccioni discusses her work on evaluating the environmental, societal, and ethical impacts of machine learning models. Her research includes measuring and reducing artificial intelligence emissions through initiatives such as CodeCarbon, regional grid selection, and the BigScience carbon footprint working group. BigScience aims to make large language models transparent by curating multilingual datasets, assessing manufacturing and compute costs, and analyzing participant workloads. Luccioni also emphasizes expanding model evaluation criteria beyond standard accuracy metrics to encompass efficiency, emissions, and subset-level fairness across demographics and data features. Overall, these efforts aim to democratize artificial intelligence and encourage deliberate trade-offs between model performance and computational resource demands.