EBERT: Efficient BERT Inference with Dynamic Structured Pruning

Zejian Liu, Fanrong Li, Gang Li, Jian Cheng

Introduction

Large-scale Transformer models like BERT have set new benchmarks in NLP but come with significant computational and memory costs. This overhead complicates deployment on edge devices and in low-latency environments. Existing efficiency solutions typically involve static pruning or adaptive inference (early exiting). Static pruning is often too rigid, potentially removing components critical for a minority of inputs. Early exiting, while dynamic, can be overly aggressive by skipping entire layers, which often degrades accuracy for complex queries.

EBERT (Efficient BERT) addresses these challenges by introducing dynamic structured pruning. Instead of permanent removal or coarse layer-skipping, EBERT decides which specific attention heads and feed-forward channels to activate for each individual input.

Methodology: The Predictor Branch

EBERT augments the standard BERT architecture with a lightweight Predictor Branch. In each Transformer block, two small predictors are inserted: one for the Multi-Head Attention (MHA) layer and one for the Feed-Forward Network (FFN).

The EBERT architecture integrates lightweight predictors into each Transformer block to enable dynamic structured pruning.

These predictors are tiny Multi-Layer Perceptrons (MLPs) that analyze the [CLS] token representation. For every input sentence, they output a binary mask. A value of '0' indicates that the corresponding attention head or FFN channel should be skipped, effectively pruning the model's internal structure on the fly. This structured approach is hardware-friendly, allowing standard GPUs to skip large matrix multiplications entirely.

The training process follows a three-stage pipeline:

  1. Fine-tuning: Standard task-specific fine-tuning of the base BERT model.
  2. Joint Training: Training both BERT and the Predictors using the Gumbel-Softmax trick to handle discrete pruning decisions differentiably. A specialized loss function enforces a target FLOPs budget.
  3. Re-training: Freezing the predictors and fine-tuning the BERT branch again to adapt weights to the dynamic sparsity patterns.

Key Results and Insights

The authors evaluated EBERT on the GLUE benchmark (MNLI, QQP, QNLI, SST-2) and SQuAD (v1.1 and v2.0).

Efficiency and Accuracy

EBERT consistently outperformed static pruning and early-exit baselines. For instance, on the QQP task, EBERT achieved a 50% reduction in FLOPs with only a 0.6% drop in accuracy. On SQuAD v2.0, EBERT improved Exact Match (EM) and F1 scores by over 3% compared to other dynamic baselines at similar FLOPs levels.

Gumbel-Softmax vs. Top-k

A critical finding was the superiority of the Gumbel-Softmax approach over a "Top-k" baseline. While Top-k always prunes a fixed number of components, EBERT's learned predictors allow the model to adjust the pruning rate based on sample difficulty.

Comparison of Gumbel-Softmax and Top-k pruning strategies on the MNLI dataset, showing EBERT's superior accuracy-efficiency trade-off.

The Role of the [CLS] Token

The research demonstrates that the [CLS] token contains sufficient information to guide pruning decisions. Because the predictors are so small, their overhead is negligible—typically less than 1% of total FLOPs. This confirms that dynamic, input-dependent importance is a viable path for model acceleration.

Conclusion

EBERT provides a robust framework for making BERT faster without sacrificing significant accuracy. By leveraging the [CLS] token for dynamic structured pruning, it achieves substantial FLOPs reductions that translate to real-world speedups. Future work may focus on stabilizing performance for smaller datasets and further optimizing hardware kernels to maximize the benefits of structured sparsity.

Summary updated

BibTeX
@inproceedings{liu2021ebert,
  author = {Zejian Liu and Fanrong Li and Gang Li and Jian Cheng},
  title = {{EBERT: Efficient BERT Inference with Dynamic Structured Pruning}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2021},
  doi = {10.18653/v1/2021.findings-acl.425},
}
Figure