DeeBERT: Dynamic Early Exiting for Accelerating BERT Inference

Ji Xin, Raphael Tang, Jaejun Lee, Yaoliang Yu, Jimmy Lin

Introduction

Large-scale pre-trained language models like BERT and RoBERTa have set new benchmarks across natural language processing (NLP) tasks. However, their deployment in real-time applications or on resource-constrained hardware (e.g., mobile devices) is often hindered by significant computational costs and slow inference times. While static compression techniques like distillation and pruning offer some relief, they result in fixed-size models that cannot adapt to the varying complexity of individual inputs.

DeeBERT addresses this by introducing a dynamic early exiting strategy. The core insight is that not every input requires the full depth of a 12-layer transformer; "easy" samples should be able to exit the model early, saving time and energy without sacrificing performance.

The DeeBERT Architecture

DeeBERT modifies the standard BERT architecture by inserting a classification layer, or "off-ramp," after each transformer layer. This allows the model to make a prediction and potentially terminate processing at any intermediate stage.

Schematic of DeeBERT architecture featuring intermediate classification layers (off-ramps) that allow for dynamic early exiting based on prediction confidence.

Inference Logic and Entropy

During inference, a sample passes through a transformer layer and into the subsequent off-ramp. The off-ramp calculates a probability distribution for the labels. DeeBERT then measures the entropy of this distribution to quantify the model's uncertainty.

  • High Confidence: If the entropy is below a predefined threshold $S$, the model exits and returns the result immediately.
  • Low Confidence: If the entropy exceeds $S$, the sample proceeds to the next transformer layer for further processing.

Two-Stage Fine-Tuning

To maintain the high quality of the final output while enabling intermediate layers to classify accurately, the authors employ a two-stage training process:

  1. Standard Fine-Tuning: The entire model and the final classification layer are trained on the specific downstream task.
  2. Off-Ramp Training: The transformer layers and the final classification layer are frozen. Only the new intermediate off-ramps are trained. This ensures the "gold standard" performance of the full model is preserved while the early layers learn to classify samples independently.

Performance and Efficiency

The researchers evaluated DeeBERT using BERT-base and RoBERTa-base across six GLUE benchmark datasets, including SST-2, MRPC, QQP, QNLI, RTE, and MNLI.

Key Results

  • Speed vs. Quality: DeeBERT consistently achieved approximately 40% savings in inference time with a performance degradation of less than 0.5%.
  • Comparison to DistilBERT: DeeBERT often outperformed static models like DistilBERT. On the SST-2 dataset, for instance, DeeBERT provided better accuracy while offering comparable or superior time savings.
  • Wall-clock Validation: The authors demonstrated that "Expected Saving" (the fraction of layers skipped) correlates linearly with actual measured wall-clock time on GPU hardware.
The trade-off between model accuracy and runtime savings on the SST-2 dataset for BERT and RoBERTa.

Analysis of Model Behavior

DeeBERT reveals interesting internal dynamics within pre-trained models. The authors found that RoBERTa and BERT exhibit different redundancy patterns. In RoBERTa, the initial layers often contribute very little to accuracy, followed by a sharp performance jump. In contrast, BERT’s performance tends to improve more linearly across layers.

Furthermore, DeeBERT offers significant operational flexibility. A single trained model can be adjusted for different latency requirements (e.g., high-throughput servers vs. low-power mobile devices) simply by tuning the entropy threshold $S$, eliminating the need to train multiple models for different environments.

Conclusion and Future Work

DeeBERT provides a robust framework for accelerating BERT inference through input-adaptive computation. While the current two-stage training approach is effective, future research may explore more balanced learning methods between intermediate and final layers. Additionally, extending dynamic early exiting beyond classification to tasks like sequence labeling or text generation remains a promising avenue for further optimization.

Summary updated

BibTeX
@inproceedings{xin2020deebert,
  author = {Ji Xin and Raphael Tang and Jaejun Lee and Yaoliang Yu and Jimmy Lin},
  title = {{DeeBERT: Dynamic Early Exiting for Accelerating BERT Inference}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2020},
  doi = {10.18653/v1/2020.acl-main.204},
}
Figure