AdapLeR: Speeding up Inference by Adaptive Length Reduction

Ali Modarressi, Hosein Mohebbi, Mohammad Taher Pilehvar

Abstract

Large-scale pre-trained language models like BERT have revolutionized NLP, but their computational "tax" is high. We present AdapLeR (Adaptive Length Reduction), a novel approach that speeds up BERT inference by dynamically pruning "unimportant" tokens as they pass through the model's layers. By training lightweight "Contribution Predictors" based on gradient saliency, the method achieves up to a 22x speedup on classification tasks with minimal impact on accuracy.

Introduction

Standard efficiency techniques like distillation or quantization are typically static: they apply the same amount of computation to every input, regardless of complexity. While some dynamic methods focus on "early exiting" (reducing the number of layers), AdapLeR targets the sequence length. Because the self-attention mechanism in Transformers has a quadratic complexity $O(n^2)$ relative to the number of tokens, reducing the sequence length mid-flight offers a massive opportunity for speedup, especially for long-form text.

Methods

AdapLeR introduces three key components to enable effective mid-inference sequence reduction:

  1. Contribution Predictors (CP): A small Multi-Layer Perceptron (MLP) is attached to each encoder layer to predict a "contribution score" for every token. Tokens falling below a threshold $\delta^\ell$ are dropped in subsequent layers.
  2. Saliency-based Supervision: Rather than relying on noisy attention weights, AdapLeR uses gradient-based saliency ($gradient \times input$). A fine-tuned teacher model provides these scores to train the CPs via KL-divergence.
  3. Soft-removal Function: To maintain differentiability during training, a "soft-removal" function gradually masks out less important tokens, allowing the model to adapt its internal representations to the shrinking sequence length.
  4. [CLS] Amplification: The model is incentivized to pool information into the [CLS] token while discarding redundant background tokens.
Overview of the AdapLeR architecture, where Contribution Predictors (CP) determine which tokens to prune between encoder layers.

Experimental Results

The model was evaluated on eight diverse text classification benchmarks, including sentiment analysis (SST-2, IMDB), NLI (MNLI, QNLI), and topic classification (DBpedia, AG’s News).

Efficiency vs. Accuracy

AdapLeR achieved a 22.23x speedup on DBpedia and a 17.10x speedup on AG’s News while maintaining accuracies within 0.4% and 1.9% of the full BERT base model, respectively. On shorter sequences like SST-2, it achieved a 1.49x speedup with 92.3% accuracy (compared to BERT's 92.7%).

Accuracy vs. Speedup trade-offs for AdapLeR compared to TR and PoWER baselines on SST-2 and HateXplain datasets.

Rationale Alignment

Using the ERASER benchmark, the authors compared the tokens selected by AdapLeR against human-annotated "rationales." AdapLeR's token selection had a significantly lower False Positive Rate compared to attention-based methods, meaning it naturally learns to focus on sentiment-carrying adjectives or task-critical nouns without explicit supervision.

Key Insights and Limitations

  • Saliency > Attention: Training on gradients identifies tokens that actually influence the final prediction, leading to better performance-speedup trade-offs than previous methods like PoWER-BERT.
  • Task-Specific Redundancy: In topic classification, the model can often identify categories using just a few key tokens, allowing it to discard over 90% of the sequence early on.
  • Limitations: The current method is optimized for classification where a single [CLS] token represents the sequence. It is not yet adapted for tasks like Question Answering or Sequence Labeling. Additionally, implementing these dynamic shifts efficiently in high-throughput batched environments remains a hardware engineering challenge.

Summary updated

BibTeX
@inproceedings{modarressi2022adapler,
  author = {Ali Modarressi and Hosein Mohebbi and Mohammad Taher Pilehvar},
  title = {{AdapLeR: Speeding up Inference by Adaptive Length Reduction}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2022},
  url = {https://openreview.net/forum?id=BclsD7QCC3},
}
Figure