Introduction
The rapid advancement of Large Language Models (LLMs) has revolutionized natural language processing, but at a significant computational cost. As models grow in size, inference latency becomes a bottleneck for real-time applications. Early Exiting (EE) has emerged as a promising solution, allowing models to terminate computation at intermediate layers for simpler inputs. However, traditional EE methods suffer from a fundamental "Training-Inference Inconsistency." This paper introduces ConsistentEE, a novel framework presented at AAAI-24 that addresses this gap through reinforcement learning and hardness-guided optimization.
The Challenge: Training-Inference Inconsistency
Standard early-exiting approaches typically employ a "strict" training objective where every internal classifier is forced to predict every training sample correctly. This approach ignores the varying difficulty of inputs and the limited capacity of shallower layers. In practice, during inference, only the specific layer where the model exits needs to be accurate. Forcing shallow layers to master complex samples they cannot realistically handle leads to suboptimal performance and inefficient computation.
Methodology: ConsistentEE
ConsistentEE reformulates early exiting as a reinforcement learning (RL) problem to bridge the gap between training and deployment.
1. Policy Network and RL Formulation
At each Transformer layer, ConsistentEE introduces a lightweight Policy Network. This network analyzes the current hidden state to decide whether to "Exit" and provide a prediction or "Continue" to the next layer. This dynamic decision-making process allows the model to adapt its computational effort to the specific needs of each input.
2. Training Consistency
Unlike traditional methods, ConsistentEE ensures that during training, only the internal classifier at the layer chosen by the policy network incurs a loss. This "consistent" objective allows each layer to specialize in the samples it is best equipped to handle, mimicking the actual behavior of the model during inference.
3. Hardness-Guided Reward and the Memorized Layer
To guide the RL agent, the authors introduce the Memorized Layer ($M$) metric. $M$ is defined as the first layer where a sample is correctly classified and remains so through all subsequent layers. This serves as an objective measure of an instance's "hardness" relative to the model architecture.
The RL agent is trained with a reward function that balances accuracy and speed, dynamically adjusted by $M$:
- Easy samples (low $M$): The reward prioritizes speed, encouraging early exits.
- Hard samples (high $M$): The reward prioritizes accuracy, encouraging deeper processing.
Key Results
ConsistentEE was evaluated on the GLUE benchmark using BERT-Base and on generation tasks using LLaMA-7b/13b.
- Efficiency and Accuracy: On GLUE, ConsistentEE achieved a 1.52x speedup with no degradation in accuracy compared to the full BERT-Base model.
- Superiority over Baselines: As shown in the figures above, ConsistentEE consistently outperforms established EE methods like PABEE and BERxiT, particularly on challenging datasets like RTE. It maintains higher accuracy even at aggressive speedup ratios.
- Scalability to LLMs: When applied to LLaMA models for generation tasks, ConsistentEE outperformed state-of-the-art methods like CALM, demonstrating its effectiveness across different model architectures and task types.
Discussion and Insights
The success of ConsistentEE highlights that specialization is more effective than uniformity in multi-exit architectures. By allowing shallow layers to "relax" and focus on easy samples, the overall system becomes more robust. Furthermore, the "Memorized Layer" provides a more nuanced understanding of sample hardness than simple loss values, enabling more intelligent resource allocation.
While the method introduces some training overhead—specifically the need for an initial pass to calculate $M$—and requires careful RL hyperparameter tuning, its ability to significantly accelerate inference without sacrificing intelligence makes it a powerful tool for deploying large-scale language models in resource-constrained environments.
Conclusion
ConsistentEE effectively resolves the training-inference mismatch in early-exiting models. By combining a consistent training objective with a hardness-guided reinforcement learning policy, it enables LLMs to intelligently manage their computational budget, paving the way for faster and more efficient AI applications.
Summary updated