Introduction
Large-scale pre-trained language models, particularly BERT, have set new benchmarks across various Natural Language Processing (NLP) tasks. However, their massive parameter counts and high computational requirements pose significant challenges for deployment in latency-sensitive or resource-constrained environments. While dynamic early exiting has emerged as a popular solution—allowing models to terminate inference early if confidence is high—it suffers from a fundamental inefficiency: the model must still sequentially process every layer preceding the exit point.
SmartBERT addresses this limitation by introducing a dual-strategy approach that combines dynamic early exiting with adaptive layer skipping. This allows the model to not only stop early but also bypass redundant intermediate layers, significantly reducing the total FLOPs required for inference.
Proposed Architecture and Methodology
SmartBERT augments the standard BERT architecture with two lightweight components at each layer: a skipping gate ($G^i$) and an exiting operator (classifier).
Adaptive Layer Skipping
The skipping gate is a binary decision module that evaluates the input representation to determine if the current Transformer block is necessary for the final prediction. If the gate decides to skip, the input is passed directly to the next layer via a residual-like connection, avoiding the heavy self-attention and feed-forward computations of that block.
Two-Stage Training Process
To maintain stability and performance, SmartBERT employs a specialized two-stage training pipeline:
- Stage 1: The skipping gates are trained alongside the fine-tuning of the BERT backbone. To bridge the gap between continuous training probabilities and discrete inference decisions, a "hard weight" mechanism is used.
- Stage 2: The backbone and gates are frozen while the intermediate classifiers are trained. This stage incorporates Cross-Layer Contrastive Learning (CCL), which encourages semantic consistency across layers, making early representations more robust for classification.
Cross-Layer Contrastive Learning (CCL)
CCL is a critical component for enhancing the accuracy of early exits. By forcing the model to maintain consistent token representations across consecutive layers, the intermediate classifiers can produce results that more closely approximate the final layer's output. This stability is essential for the model to make reliable "exit or not" decisions early in the stack.
Experimental Evaluation
The researchers evaluated SmartBERT on the GLUE (General Language Understanding Evaluation) benchmark, covering tasks ranging from sentiment analysis (SST-2) to natural language inference (MNLI, QNLI).
Key Results
SmartBERT demonstrates a superior Pareto frontier between accuracy and computational cost compared to existing state-of-the-art methods like DeeBERT and FastBERT.
- Efficiency Gains: SmartBERT achieves a 2-3x reduction in FLOPs with negligible loss in accuracy.
- Robustness on Hard Tasks: On complex datasets where entropy-based early exiting often fails (e.g., RTE), layer skipping becomes the primary driver of efficiency, saving up to 70% of computation.
- Minimal Overhead: The additional gates and classifiers are extremely lightweight, representing a tiny fraction of the computational cost of a single Transformer layer.
Conclusion
SmartBERT represents a significant advancement in dynamic model acceleration. By integrating layer skipping with early exiting, it effectively eliminates redundant computations that traditional early-exit models are forced to perform. The combination of two-stage training, hard-weight mechanisms, and cross-layer contrastive learning ensures that these efficiency gains do not come at the cost of model performance. Future work may explore extending this mechanism to larger architectures like RoBERTa or combining it with complementary techniques such as weight pruning and quantization.
Summary updated