Learned Token Pruning for Transformers

Sehoon Kim, Sheng Shen, David Thorsley, Amir Gholami, Woosuk Kwon, Joseph Hassoun, Kurt Keutzer

TL;DR

Learned Token Pruning (LTP) is a novel method that speeds up Transformer models by adaptively removing "unimportant" tokens as they pass through the network. By learning a specific attention-score threshold for each layer during training, LTP achieves a 2.1x reduction in FLOPs and up to a 2.0x throughput improvement on standard CPUs and GPUs with less than a 1% drop in accuracy.

What Problem Does This Paper Address?

Transformer-based models like BERT and RoBERTa have revolutionized NLP, but they come with a massive computational tax: the self-attention mechanism scales quadratically ($O(n^2)$) with the input sequence length. This makes them expensive to deploy in real-time environments, especially for long documents.

Existing "token pruning" methods—which try to drop less useful words or tokens mid-calculation—suffer from two main flaws:

  1. Static Budgets: Many methods prune every sentence to the same fixed length. This is inefficient because a complex sentence might need 50 tokens to understand, while a simple one might only need 5.
  2. Computational Overhead: Methods that choose the "top-$k$" most important tokens often rely on sorting operations that are surprisingly slow on standard hardware (CPUs/GPUs) without specialized accelerators.

Methods

The authors introduce Learned Token Pruning (LTP), which shifts the strategy from "keep the top $k$ tokens" to "keep every token above a certain importance threshold."

Key Technical Innovations:

  • Importance Scoring: LTP calculates a token's importance by looking at the attention it receives from other tokens. If no one is "looking" at a token across the multi-head attention layers, it’s likely safe to prune.
  • The "Soft Mask" Trick: Thresholding is normally a discrete, non-differentiable operation (you either keep a token or you don't), which makes it impossible to train using standard gradient descent. The authors solve this by using a differentiable soft binarized mask (a sigmoid function with a temperature parameter). This allows the model to "learn" the optimal threshold ($\theta$) for each layer during training.
  • Three-Step Training:
    1. Soft Pruning: Train the model weights and the thresholds simultaneously using the soft mask and an $L_1$ regularization term to encourage pruning.
  • Binarization: Lock the learned thresholds.
  • Hard Pruning: Fine-tune the model weights with the fixed thresholds to recover any lost accuracy.

Datasets

The researchers evaluated LTP on two major benchmarks:

  • GLUE (General Language Understanding Evaluation): Including tasks like MNLI (inference), QQP (paraphrase), QNLI (question-answering), SST-2 (sentiment), and others.
  • SQuAD 2.0 (Stanford Question Answering Dataset): A challenging reading comprehension task where the model must also decide if a question is unanswerable based on the text.

Key Insights and Ideas

  • Thresholding > Top-k: On an Intel Haswell CPU, the authors found that the simple comparison required for thresholding is up to 33.4x faster than the top-k sorting operation for long sequences (1024 tokens). This makes LTP much easier to deploy on "commodity" hardware.
  • Robustness to Length: Because LTP uses a threshold rather than a fixed length, it is much more robust when the evaluation data has different sentence lengths than the training data. Static methods (like LAT) often "over-prune" long sentences in the wild, leading to massive accuracy drops (up to 16.4% in some tests), whereas LTP adapts gracefully.
  • Layer-wise Specialization: The model naturally learns to be more aggressive in later layers. By the time an input reaches the final layers, the model has often condensed the information into just a few "essential" tokens.

Key Results

  • Efficiency: LTP achieves a 2.1x FLOPs reduction with less than 1% accuracy degradation across GLUE tasks.
  • Real-world Speed: This translates to a 1.9x throughput increase on NVIDIA V100 GPUs and a 2.0x increase on Intel CPUs.
  • SOTA Performance: LTP consistently outperformed prior state-of-the-art methods (like SpAtten and LAT), providing roughly 2.5% higher accuracy at the same computational budget.
  • Compatibility: The authors demonstrated that LTP can be combined with 8-bit quantization (INT8) and Knowledge Distillation to achieve a 10x reduction in Bit Operations (BOPs) with less than 2% accuracy loss.

Limitations and Future Work

  • Training Complexity: While inference is faster, the three-step training process (soft pruning followed by hard fine-tuning) adds complexity and time to the model development cycle.
  • Attention-Only Metric: The importance score is derived solely from attention probabilities. While effective, it’s possible that some tokens are important for reasons not fully captured by the attention map alone.
  • Task Specificity: The thresholds are learned per task. A model pruned for sentiment analysis might not have the correct thresholds for question answering, requiring re-training for different downstream applications.

Overall, LTP represents a significant step toward making Transformers "hardware-aware" and adaptive, moving away from rigid architectures toward models that spend more effort on harder inputs and less on easier ones.

Summary updated

BibTeX
@inproceedings{kim2022learned,
  author = {Sehoon Kim and Sheng Shen and David Thorsley and Amir Gholami and Woosuk Kwon and Joseph Hassoun and Kurt Keutzer},
  title = {{Learned Token Pruning for Transformers}},
  booktitle = {ACM SIGKDD Conference on Knowledge Discovery and Data Mining},
  year = {2022},
  doi = {10.1145/3534678.3539260},
}
Figure