[Paper Review] What Matters in Transformers? Not All Attention is Needed
This paper proposes a similarity-based metric to identify and prune redundant attention and MLP layers in Transformers, revealing that up to 50% of attention layers in Llama-3-70B can be removed with no performance drop. The authors introduce Joint Layer Drop, which simultaneously removes low-importance attention and MLP layers, achieving higher pruning ratios and improved efficiency without sacrificing accuracy.
While scaling Transformer-based large language models (LLMs) has demonstrated promising performance across various tasks, it also introduces redundant architectures, posing efficiency challenges for real-world deployment. Despite some recognition of redundancy in LLMs, the variability of redundancy across different architectures in transformers, such as MLP and Attention layers, is under-explored. In this work, we investigate redundancy across different modules within Transformers, including Blocks, MLP, and Attention layers, using a similarity-based metric. Surprisingly, despite the critical role of attention layers in distinguishing transformers from other architectures, we found that a large portion of these layers exhibit excessively high similarity and can be pruned without degrading performance. For instance, Llama-2-70B achieved a 48.4\% speedup with only a 2.4\% performance drop by pruning half of the attention layers. Furthermore, by tracing model checkpoints throughout the training process, we observed that attention layer redundancy is inherent and consistent across training stages. Additionally, we further propose a method that jointly drops Attention and MLP layers, allowing us to more aggressively drop additional layers. For instance, when dropping 31 layers (Attention + MLP), Llama-2-13B still retains 90\% of the performance on the MMLU task. Our work provides valuable insights for future network architecture design. The code is released at: \url{https://github.com/Shwai-He/LLM-Drop}.
Motivation & Objective
- Investigate the varying levels of redundancy across different Transformer components: Blocks, MLP layers, and Attention layers.
- Address the challenge of high deployment costs in large language models (LLMs) due to structural redundancy from scaling.
- Develop a similarity-based metric to quantify redundancy by measuring input-output similarity in model modules.
- Explore the feasibility of dropping entire layers (especially attention layers) without degrading model performance.
- Propose Joint Layer Drop to jointly optimize attention and MLP layer removal for improved efficiency and performance.
Proposed method
- Introduce a similarity-based metric that computes cosine similarity between input and output activations of each module to identify redundant components.
- Apply Block Drop, Attention Drop, and MLP Drop to evaluate the impact of removing entire blocks or individual layers on model performance.
- Use importance scores derived from similarity metrics to rank and prune layers, prioritizing those with highest input-output similarity.
- Propose Joint Layer Drop, which concatenates importance scores from both attention and MLP layers and drops the lowest-scoring modules together.
- Calibrate the pruning process using a small, diverse dataset to ensure robustness across different data distributions and sample sizes.
- Evaluate performance across multiple LLMs (e.g., Llama-2, Llama-3) and benchmarks (e.g., GSM8K, HumanEval) to validate generalization and effectiveness.
Experimental results
Research questions
- RQ1To what extent are attention layers in Transformers redundant, and can they be pruned without performance degradation?
- RQ2How does the redundancy vary between MLP layers and attention layers in standard Transformer architectures?
- RQ3Can joint pruning of attention and MLP layers improve both pruning ratio and model performance compared to individual pruning?
- RQ4How robust is the proposed pruning method across different model sizes and datasets?
- RQ5What insights does module-level redundancy analysis provide for future efficient Transformer architecture design?
Key findings
- Up to 50% of attention layers in Llama-3-70B can be pruned with only a 0.1% average performance drop, indicating extreme redundancy in attention mechanisms.
- Block Drop and MLP Drop cause significant performance degradation even at low pruning ratios (e.g., 20% drop in accuracy when removing 20% of blocks), highlighting their structural importance.
- Llama-2-70B maintains comparable performance after removing 32 out of 80 attention layers (40% pruning), with only a 0.1% average performance drop.
- Joint Layer Drop outperforms both Attention Drop and MLP Drop individually, achieving higher pruning ratios and better performance, especially in deeper models.
- Larger models like Llama-2-70B are more robust to MLP layer removal than smaller models, with only 0.6% performance drop when 8 MLP layers are dropped.
- The similarity-based metric effectively identifies redundant modules, and its results are resilient to variations in calibration dataset size and type.
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.