TL;DR
This paper reveals significant redundancy within Transformer-based Large Language Models (LLMs), particularly in attention layers, which can be pruned without substantial performance loss. They introduce "Attention Drop," a training-free method that achieves impressive speedups (e.g., 43.4% for LLaMA-3-70B) with minimal accuracy degradation, offering a practical path towards more efficient LLMs.
What Problem Does This Paper Address?
As Large Language Models (LLMs) based on the Transformer architecture have grown in size and capability, they've also become increasingly computationally expensive and resource-intensive for real-world deployment. While it's known that these models contain some redundancy, the specific nature and extent of this redundancy across different architectural components (like MLP and Attention layers) remain underexplored. This lack of understanding hinders the development of efficient LLMs that can be practically deployed without sacrificing performance. The paper aims to systematically investigate this redundancy to identify which components are most amenable to pruning.
Methods
The core of the paper's methodology is a similarity-based metric to quantify the importance of Transformer modules. They define an "importance score" as $S = 1 - \text{CosineSim}(X, Y)$, where $X$ is the input and $Y$ is the output of a module. Modules with high cosine similarity (i.e., low importance scores) are considered redundant and candidates for pruning.
They apply this metric to three levels:
- Block Drop: Pruning entire Transformer blocks.
- MLP Drop: Pruning Multi-Layer Perceptron (MLP) layers.
- Attention Drop: Pruning attention layers.
Crucially, they treat the MLP layer and its associated LayerNorm as a single unit, and similarly for the Attention layer and its LayerNorm, to ensure a more accurate importance score that accounts for the residual connections. The pruning is performed in a one-shot manner, meaning importance scores are calculated once, and redundant layers are removed simultaneously, avoiding the computational cost of iterative pruning.
Datasets
The paper uses several datasets for different purposes:
- Calibration Datasets: C4 (for pretraining analysis), CodeAlpaca-20k, MathInstruct, and LIMA (for instruction fine-tuning analysis). These are used to measure the importance scores of modules.
- Evaluation Datasets: A suite of tasks including ARC-C, BoolQ, HellaSwag, MMLU, OBQA, PIQA, RTE, and WinoGrande, evaluated using the EleutherAI LM Harness.
- Long Context Benchmark: BANKING77 (for evaluating performance on long sequences).
- Post-training Fine-tuning: Tulu 3 (for fine-tuning compressed models).
Key Insights and Ideas
- Attention Layers are Surprisingly Redundant: Contrary to intuition, a significant portion of attention layers can be pruned without hurting performance. This is a key finding that challenges the perceived indispensability of attention.
- MLP Layers are Crucial: Dropping MLP layers severely degrades performance, indicating they are essential for storing knowledge and distinguishing between tokens.
- Redundancy is Intrinsic: Attention layer redundancy is not just a result of training; it's also evident in randomly initialized models, suggesting it's an inherent property of the architecture.
- Three Factors Drive Attention Redundancy:
- Sparse Attention Patterns: Attention often focuses on a few tokens, leaving others with minimal contribution.
- Over-smoothed Token Embeddings: High similarity between token embeddings limits the impact of attention updates.
- Low Magnitude of Attention Outputs: The outputs of attention layers are often smaller in magnitude compared to MLPs, further constraining their influence.
- Deeper Layers are More Redundant: Across Block, MLP, and Attention modules, deeper layers tend to show lower importance scores and are pruned first.
- One-Shot Pruning is Effective: The simple one-shot approach for calculating importance and pruning is as effective as more complex iterative methods.
Key Results
- LLaMA-3-70B Speedup: Pruning half of the attention layers in LLaMA-3-70B achieved a 43.4% speedup with only a 1.8% drop in performance.
- Mistral-7B Performance: Mistral-7B maintained over 95% of its original performance even after dropping 12 attention layers, achieving a 1.40x speedup with a low $\gamma$ (speedup degradation ratio) of 0.08.
- Joint Layer Drop: Combining Attention and MLP dropping (Joint Layer Drop) further improved efficiency by leveraging redundancy in both components.
- Orthogonal to Quantization: Attention Drop is compatible with quantization techniques like AWQ, maintaining performance gains.
- Impact on Embeddings: Dropping MLP layers caused significant fluctuations and divergence in embeddings, while dropping attention layers maintained high similarity with the original model.
Limitations and Future Work
- Broader Architectures: The authors suggest evaluating their techniques on a wider range of architectures beyond standard Transformers, such as vision transformers and vision-language models.
- Fine-tuning: While their method is training-free, additional fine-tuning (LoRA or full-model) after pruning could potentially restore or even improve performance. They show promising results with fine-tuning on Llama-3.2-3B.
- Integration with Pretraining: Integrating layer dropping into the pretraining phase itself could lead to inherently more compact and efficient models.
- Alternative Mechanisms: Exploring replacements for attention layers that are inherently less redundant could be a future direction.
Summary updated