[Paper Review] Magic Pyramid: Accelerating Inference with Early Exiting and Token Pruning
Magic Pyramid (MP) accelerates BERT inference by synergistically combining token pruning and early exiting, reducing computation across both width and depth. It achieves up to 11.95x speedup with less than 0.5% accuracy drop, outperforming state-of-the-art methods by up to 2.13x in speedup while maintaining robust performance across diverse input lengths.
Pre-training and then fine-tuning large language models is commonly used to achieve state-of-the-art performance in natural language processing (NLP) tasks. However, most pre-trained models suffer from low inference speed. Deploying such large models to applications with latency constraints is challenging. In this work, we focus on accelerating the inference via conditional computations. To achieve this, we propose a novel idea, Magic Pyramid (MP), to reduce both width-wise and depth-wise computation via token pruning and early exiting for Transformer-based models, particularly BERT. The former manages to save the computation via removing non-salient tokens, while the latter can fulfill the computation reduction by terminating the inference early before reaching the final layer, if the exiting condition is met. Our empirical studies demonstrate that compared to previous state of arts, MP is not only able to achieve a speed-adjustable inference but also to surpass token pruning and early exiting by reducing up to 70% giga floating point operations (GFLOPs) with less than 0.5% accuracy drop. Token pruning and early exiting express distinctive preferences to sequences with different lengths. However, MP is capable of achieving an average of 8.06x speedup on two popular text classification tasks, regardless of the sizes of the inputs.
Motivation & Objective
- To address the challenge of high inference latency in large pre-trained models like BERT, especially under real-time production constraints.
- To overcome the limitations of existing methods—token pruning (effective for long sequences) and early exiting (effective for short sequences)—which perform poorly at opposite ends of the sequence length spectrum.
- To develop a unified framework that synergistically combines token pruning and early exiting for consistent, speed-adjustable inference across variable input lengths.
- To maintain high accuracy while achieving significant computational reduction, particularly in low-latency, high-throughput deployment environments.
Proposed method
- MP integrates token pruning and early exiting into a single, hierarchical inference pipeline, where pruning reduces width-wise computation and early exiting reduces depth-wise computation.
- The model uses a learnable thresholding mechanism to identify and remove non-salient tokens at each layer, based on attention score uncertainty.
- A sub-classifier is attached at each transformer block, enabling early prediction if confidence exceeds a dynamic threshold τ, which is tuned during training.
- The method employs a temperature scaling and loss weighting (λ) to balance the trade-off between accuracy and speed during joint optimization of pruning and early exiting.
- The training process jointly optimizes for accuracy, GFLOPs, and early exit probability, using a multi-task loss function that includes knowledge distillation and uncertainty regularization.
- The framework is applied end-to-end to BERT-based models, with inference dynamically adapting to input length by pruning tokens and exiting early when conditions are met.
Experimental results
Research questions
- RQ1Can token pruning and early exiting be effectively combined to achieve consistent inference acceleration across diverse input lengths?
- RQ2Does the synergy between width-wise (pruning) and depth-wise (early exiting) computation reduction lead to superior speedup compared to individual methods?
- RQ3Can the combined approach maintain high accuracy while achieving significant computational savings, especially in low-latency production settings?
- RQ4How does the performance of the proposed method vary across different sequence lengths and NLP tasks?
Key findings
- MP achieves up to 11.95x speedup on the AG News and Yelp datasets, significantly outperforming FastBERT (early exiting) and LTP (token pruning) across all sequence length groups.
- On average, MP delivers an 8.06x speedup across two text classification tasks, regardless of input length, demonstrating consistent performance across diverse inputs.
- MP reduces GFLOPs by up to 70% compared to BERT, with less than 0.5% accuracy drop, surpassing both LTP and FastBERT in efficiency-accuracy trade-off.
- For long sequences (>70 tokens), MP achieves 8.25x speedup on Yelp and 11.95x on AG News, outperforming FastBERT’s 6.18x and 8.84x, respectively.
- With τ = 0.8, MP achieves 11.95x speedup on AG News and 10.10x on Yelp, demonstrating strong scalability under aggressive early exit thresholds.
- MP maintains or slightly improves accuracy compared to BERT (e.g., 94.3% on AG News) while reducing GFLOPs to 1.8 (4.95x speedup), outperforming FastBERT’s 2.3 GFLOPs (3.97x speedup).
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.