[论文解读] What Matters in Transformers? Not All Attention is Needed
该论文提出一种基于相似度的度量方法,用于识别并剪枝Transformer中的冗余注意力与MLP层,揭示了在Llama-3-70B模型中,高达50%的注意力层可被移除而性能无任何下降。作者提出联合层剪枝(Joint Layer Drop),同时移除低重要性的注意力层与MLP层,实现更高的剪枝率与更高的效率,且不损失准确性。
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}.
研究动机与目标
- 研究不同Transformer组件(模块、MLP层、注意力层)中冗余程度的差异。
- 应对因模型规模扩展导致的结构冗余所引发的大语言模型(LLMs)高部署成本问题。
- 提出一种基于相似度的度量方法,通过测量模型模块的输入输出相似度来量化冗余程度。
- 探索在不降低模型性能的前提下,剪除整个层(尤其是注意力层)的可行性。
- 提出联合层剪枝(Joint Layer Drop),联合优化注意力层与MLP层的剪除,以提升效率与性能。
提出的方法
- 引入一种基于相似度的度量方法,通过计算每个模块输入与输出激活之间的余弦相似度,识别冗余组件。
- 应用模块剪枝(Block Drop)、注意力剪枝(Attention Drop)与MLP剪枝(MLP Drop)来评估剪除整个模块或单个层对模型性能的影响。
- 基于相似度度量得出的重要性分数对层进行排序并剪枝,优先移除输入输出相似度最高的层。
- 提出联合层剪枝(Joint Layer Drop),将注意力层与MLP层的重要性分数合并,共同剪除得分最低的模块。
- 使用小型且多样化的数据集校准剪枝过程,以确保在不同数据分布与样本规模下具有鲁棒性。
- 在多个大语言模型(如Llama-2、Llama-3)与基准测试集(如GSM8K、HumanEval)上评估性能,以验证方法的泛化性与有效性。
实验结果
研究问题
- RQ1Transformer中的注意力层在多大程度上是冗余的?能否在不造成性能下降的前提下进行剪枝?
- RQ2在标准Transformer架构中,MLP层与注意力层的冗余程度有何差异?
- RQ3与单独剪枝相比,联合剪枝注意力层与MLP层是否能同时提升剪枝率与模型性能?
- RQ4所提出的剪枝方法在不同模型尺寸与数据集上是否具有鲁棒性?
- RQ5模块级别的冗余性分析为未来高效Transformer架构设计提供了哪些洞见?
主要发现
- 在Llama-3-70B中,高达50%的注意力层可被剪枝,平均性能仅下降0.1%,表明注意力机制存在极端冗余。
- Block Drop与MLP Drop即使在低剪枝比例下(例如剪除20%的模块)也会导致显著性能下降,凸显其结构重要性。
- 在Llama-2-70B中,剪除80个注意力层中的32个(即40%剪枝)后,性能保持相近,平均性能仅下降0.1%。
- 联合层剪枝优于单独的注意力剪枝与MLP剪枝,实现了更高的剪枝率与更优的性能表现,尤其在深层模型中优势明显。
- 更大的模型(如Llama-2-70B)对MLP层剪枝更具鲁棒性,当剪除8个MLP层时,性能仅下降0.6%。
- 基于相似度的度量方法能有效识别冗余模块,且其结果对校准数据集大小与类型的变动具有强鲁棒性。
阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。