TR-BERT: Dynamic Token Reduction for Accelerating BERT Inference

Deming Ye, Yankai Lin, Yufei Huang, Maosong Sun

Abstract

TR-BERT introduces a dynamic token reduction strategy to accelerate BERT inference by selectively dropping unimportant tokens as they pass through the model's layers. By employing reinforcement learning to determine token importance for specific tasks, TR-BERT achieves 2–5x speedups with minimal performance loss. The approach proves particularly effective for long-text reasoning, where it can outperform vanilla BERT by efficiently managing sequence length and focusing computation on task-critical information.

Introduction

Pre-trained language models (PLMs) such as BERT have significantly advanced NLP but impose a heavy computational burden during inference. The primary bottleneck is the self-attention mechanism, which scales quadratically ($O(n^2)$) with sequence length. Existing acceleration techniques often rely on layer-wise pruning, which skips entire layers regardless of the input's specific needs. However, not all tokens require the same depth of processing; for instance, function words like "the" are often sufficiently encoded in early layers, whereas task-specific keywords require deeper analysis to capture their full meaning.

Methodology

TR-BERT treats inference as a multi-step token selection process, as illustrated in Figure 1.

Overview of the TR-BERT architecture showing dynamic token reduction via policy networks at specific layers.

Dynamic Token Selection

At designated "reduction layers" (e.g., after layer 2 and layer 6), a lightweight Policy Network evaluates the hidden states of all tokens to decide whether to Select (retain for subsequent layers) or Skip (terminate computation) each token. This allows the model to progressively reduce the sequence length $n$, leading to substantial FLOP reductions compared to standard layer-wise skipping.

Reinforcement Learning and Training

Because token importance lacks explicit ground truth, the authors utilize the REINFORCE algorithm. The reward function is designed to balance predictive accuracy (log-likelihood) with computational efficiency (a penalty based on the number of selected tokens). To stabilize training, a three-stage pipeline is employed:

  1. Standard Fine-tuning: Initializing the base BERT model on the target task.
  2. Imitation Learning: Warming up the policy network using a "Residual Strategy" heuristic that identifies tokens with the greatest impact on the final loss.
  3. Joint Fine-tuning: Optimizing the entire system using both task-specific objectives and RL rewards, supplemented by Knowledge Distillation from an unpruned teacher model to maintain high performance.

Experimental Results

The model was evaluated across 11 NLP benchmarks, including SQuAD 2.0, HotpotQA, and Yelp.F, with a focus on both standard and long-text datasets.

Performance comparison (F1/Accuracy) vs. FLOPs speedup across multiple datasets, comparing TR-BERT with baselines like DynaBERT and DistilBERT.

Efficiency and Accuracy

As shown in Figure 5, TR-BERT consistently achieves a 2–5x speedup in FLOPs while maintaining competitive performance. Notably, it outperforms other popular acceleration methods such as DistilBERT, PoWER-BERT, and DynaBERT. For example, on SQuAD 2.0, TR-BERT provides a +1.8 F1 improvement over DynaBERT at a similar speedup level.

Long-Context Performance

On long-document tasks like WikiHop (up to 1,024 tokens), TR-BERT achieves a 4.65x speedup compared to long-sequence BERT variants with negligible accuracy loss. By reducing sequence length dynamically, TR-BERT can process longer contexts faster than standard BERT handles truncated 512-token inputs, leading to superior performance on complex reasoning tasks.

Discussion and Conclusion

TR-BERT validates the "well-encoded" hypothesis: BERT captures syntactic information in lower layers and task-specific semantics in higher layers. By "exiting" tokens once their contribution is complete, the model naturally learns to drop function words early while retaining sentiment-bearing or question-relevant keywords. While the current three-step training process is complex, the results demonstrate that token-level granularity is far more effective for acceleration than layer-level pruning. Future work may involve integrating token reduction directly into the pre-training phase or developing more flexible architectures that allow the model to decide both when and what to prune.

Summary updated

BibTeX
@inproceedings{ye2021tr,
  author = {Deming Ye and Yankai Lin and Yufei Huang and Maosong Sun},
  title = {{TR-BERT: Dynamic Token Reduction for Accelerating BERT Inference}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2021},
  doi = {10.18653/v1/2021.naacl-main.463},
}
Figure