Faster Depth-Adaptive Transformers

Yijin Liu, Fandong Meng, Jie Zhou, Yufeng Chen, Jinan Xu

Abstract

Standard Transformer models are computationally expensive because they apply a uniform number of layers to every token, regardless of its complexity. This paper introduces a novel approach to depth-adaptive Transformers that pre-estimates the required processing depth for each word using statistical measures like Mutual Information (MI) or reconstruction loss. By replacing traditional, high-overhead "halting units" with these pre-calculated estimates, the researchers achieve up to a 7x speedup during inference while maintaining or even improving model accuracy and stability.

The Efficiency Bottleneck in Transformers

Standard Transformer models operate on a "one-size-fits-all" principle: every word in a sentence—from simple stop-words like "the" to highly descriptive keywords like "magnificent"—undergoes the same number of computational passes. This leads to significant wasted computation on "easy" tokens.

Previous attempts to address this used Adaptive Computation Time (ACT), which incorporates a "halting unit" at each layer to decide if a word should stop processing. However, these units are notoriously difficult to train because no ground truth exists for optimal halting points. Furthermore, the computational overhead of the halting units themselves often negates the speed gains they were intended to provide. This research aims to eliminate this bottleneck by determining the required depth before the main model execution begins.

Pre-calculating Computational Depth

The authors propose two primary methods for estimating the "hardness" of a word and assigning it a specific layer depth ($d$) during preprocessing:

  1. Mutual Information (MI) Based Estimation: This method calculates how much information a word provides about the final task label (e.g., sentiment). Words like "terrible" have high MI with a "negative" label and are considered "easy" for the task, requiring fewer layers. Because this is calculated during data preprocessing, it adds zero cost to inference.
  2. Reconstruction Loss Based Estimation: Utilizing a pre-trained Masked Language Model (like BERT), this method measures how easily a word can be predicted from its context. Low reconstruction loss indicates a redundant or simple word that requires less processing. This approach is unsupervised and task-agnostic.

The Adaptive Mechanism

Once a depth $d$ is assigned to a token, the Transformer processes it for exactly $d$ layers. For all subsequent layers up to the maximum depth $N$, the model bypasses heavy computations like self-attention or feed-forward passes, simply copying the token's state upward.

The depth-adaptive mechanism: tokens are processed for a calculated number of layers and then copied to the output.

Performance and Results

The researchers evaluated these methods across 24 text classification datasets, including Amazon-16, Yelp, and DBpedia. The results demonstrate that pre-estimation is not only faster but also more robust than internal halting mechanisms.

  • Speed: The proposed models achieved up to a 7x speedup over a standard 12-layer Transformer. As shown in the performance metrics, the MI and reconstruction-based methods maintain significantly higher throughput as the maximum number of layers increases compared to vanilla Transformers or those using halting units.
  • Accuracy: On the Amazon-16 benchmark, the MI-based approach reached an average accuracy of 90.5%, surpassing both the vanilla Transformer (89.9%) and models using traditional halting units (90.2%).
  • Stability: Unlike previous adaptive methods that were sensitive to random initialization, these pre-estimation techniques proved highly stable across different training runs.
Speed comparison (samples per 10 seconds) between vanilla Transformers, halting units, and the proposed estimation methods.

Conclusion and Future Directions

By moving the decision-making process for computational depth to a preprocessing step, this research removes the overhead and training instability associated with adaptive Transformers. While the current implementation shows massive gains, the authors note that the effective speedup can diminish with very large batch sizes due to hardware scheduling constraints. Future work will focus on developing hardware-aware kernels to maintain these efficiency gains across all processing scales.

Summary updated

BibTeX
@inproceedings{liu2021faster,
  author = {Yijin Liu and Fandong Meng and Jie Zhou and Yufeng Chen and Jinan Xu},
  title = {{Faster Depth-Adaptive Transformers}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2021},
  doi = {10.1609/aaai.v35i15.17584},
}
Figure