TL;DR
Fine-tuning large language models (LLMs) is a crucial step in NLP, but its energy and carbon footprint is often overlooked compared to pre-training. This paper provides a comprehensive empirical study of fine-tuning costs across various tasks, datasets, and hardware, revealing that sequence length and token count are key predictors of energy consumption, and offering practical recommendations for more efficient fine-tuning.
What Problem Does This Paper Address?
The "pre-train then fine-tune" paradigm is ubiquitous in Natural Language Processing (NLP). While the immense energy cost of pre-training large language models (LLMs) like BERT has been well-documented, the energy and carbon footprint of the subsequent fine-tuning stage has received less attention. This is problematic because fine-tuning is performed far more frequently and by a much larger community of researchers and practitioners than pre-training. Without a clear understanding of fine-tuning's impact, efforts to make NLP more sustainable will be incomplete. This paper aims to fill this gap by systematically quantifying the energy and carbon costs associated with fine-tuning BERT-base models across a range of common NLP tasks and datasets.
Methods
The researchers conducted a detailed empirical study to measure the energy consumption and carbon emissions of fine-tuning BERT-base models. They employed a multi-faceted approach:
- Hardware Diversity: Experiments were run on two distinct hardware platforms: an NVIDIA A100 machine and an NVIDIA RTX 8000 machine, each with four GPUs. This allowed them to assess the impact of hardware on energy usage.
- Measurement Calibration: They used the CodeCarbon software library for programmatic energy tracking, but crucially, they calibrated these readings with physical energy meters connected directly to the wall. This addresses potential inaccuracies in software-based estimations and accounts for power loss.
- Task and Dataset Variation: Fine-tuning was performed on a diverse set of common NLP tasks, including Natural Language Inference (NLI), Sentiment Analysis, Question Answering (QA), and Named Entity Recognition (NER). Datasets varied in size (from 6K to 400K examples) and sequence length characteristics.
- Pre-training Baseline: To contextualize fine-tuning costs, they also pre-trained BERT-base models from scratch on the same hardware, providing a direct comparison point.
- Distillation Study: They investigated the energy savings offered by DistilBERT, a distilled version of BERT, by comparing its fine-tuning energy consumption to that of the original BERT-base model.
Datasets
The study utilized several standard NLP datasets for fine-tuning:
- Wiki+Books: Used for pre-training BERT.
- RTE (Recognizing Textual Entailment): A Natural Language Inference dataset.
- MNLI (Multi-Genre Natural Language Inference): Another Natural Language Inference dataset.
- SQuAD v1 & v2 (Stanford Question Answering Dataset): Question Answering datasets.
- IMDB: A sentiment analysis dataset.
- SST2 (Stanford Sentiment Treebank v2): A sentiment analysis dataset.
- CoNLL 2003 & CoNLL 2012: Named Entity Recognition datasets.
The paper does not introduce new benchmarks but rather uses existing datasets to provide a comprehensive analysis of fine-tuning costs.
Key Insights and Ideas
- Fine-tuning is not trivial: While a single pre-training run is more energy-intensive than a single fine-tuning run, the sheer frequency of fine-tuning across the NLP community makes its cumulative energy and carbon footprint significant and worthy of study.
- Token count is a strong predictor: The total number of tokens processed during fine-tuning (including padded tokens) is a highly reliable indicator of energy consumption, more so than just the number of examples or optimization steps.
- Sequence length matters significantly: Longer sequences in fine-tuning tasks lead to substantially higher energy consumption, a factor that is often dynamically handled through padding.
- Hardware impacts efficiency: The RTX 8000 GPU machine showed higher energy consumption compared to the A100 GPU, likely due to differences in hardware architecture and energy overhead.
- Distillation offers substantial savings: Fine-tuning DistilBERT requires significantly less energy (around 50% less) than fine-tuning the original BERT-base model, making it a compelling option for reducing environmental impact.
- Multi-GPU fine-tuning can be efficient: While naive multi-GPU fine-tuning might not always yield benefits, optimizing batch size and learning rate for multiple GPUs can lead to significant reductions in both time and energy, especially for tasks with longer sequences.
Key Results
- Pre-training vs. Fine-tuning Scale: Pre-training BERT was found to be equivalent to anywhere from 400 (MNLI) to 45,000 (RTE) fine-tuning runs, highlighting the vast difference in scale for a single pre-training event.
- Energy Savings with DistilBERT: Fine-tuning DistilBERT consumed approximately 50% less energy than fine-tuning BERT-base on the same tasks. The authors estimate that the upfront cost of distillation can be amortized within 86 fine-tuning runs for MNLI-like tasks or 47k for RTE-like tasks.
- Predictive Power of Tokens: The study demonstrated a strong linear correlation between the total number of tokens seen and energy consumed, particularly on the RTX 8000 machine.
- Inference vs. Fine-tuning: Fine-tuning energy usage varied more widely across datasets and tasks compared to inference energy usage, which was more consistently related to sequence lengths.
- Multi-GPU Efficiency: When batch size and learning rate were optimized, multi-GPU fine-tuning on 4 GPUs often resulted in similar or lower energy costs and significantly reduced training times compared to single-GPU fine-tuning, especially for tasks with longer sequences.
Limitations and Future Work
The authors acknowledge several limitations:
- Task Scope: The study focused on specific token classification, sequence classification, and question answering tasks using BERT-base and DistilBERT-base models. Extrapolations to much larger models, different architectures (e.g., RoBERTa), or other task types like summarization are not directly supported by this work.
- Hardware Environment: The experiments were conducted on on-premises hardware, which is typical for academic settings. The energy profiles for fine-tuning on large-scale public cloud infrastructure or specialized hardware like TPUs might differ.
- Future Work: The authors suggest expanding the study to include more tasks and architectures. They also emphasize the importance of further research into fine-tuning on cloud platforms and with specialized hardware. They also note that while their work provides a procedure for measuring energy, practitioners should ideally measure on their own hardware to get the most accurate estimates.
Summary updated