arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2406.15786cs.LGcs.AIcs.CL
收藏

Transformer中什么才是关键?并非所有注意力都不可或缺

What Matters in Transformers? Not All Attention is Needed

University of Maryland, College Park(马里兰大学帕克分校)

Shwai He, Guoheng Sun, Zheyu Shen, Ang Li

AI总结:

本文研究Transformer中注意力层与MLP层的冗余问题,发现大量注意力层可被剪枝且性能损失极小,并提出联合丢弃注意力层和MLP层的方法,在保持性能的同时显著提升推理效率。

摘要:

尽管扩展基于Transformer的大语言模型(LLMs)已在各类任务上展现出良好性能,但这也引入了冗余架构,给实际部署带来了效率挑战。虽然LLMs中的冗余已得到一定认识,但Transformer中不同架构(如MLP层和注意力层)之间冗余的差异性仍未得到充分探索。本文中,我们采用基于相似度的度量方法,考察了Transformer内部不同模块的冗余情况,包括Block、MLP层和注意力层。令人惊讶的是,尽管注意力层在区分Transformer与其他架构方面起着关键作用,我们发现其中很大一部分层表现出过高的相似度,可以在不降低性能的情况下进行剪枝。例如,Llama-2-70B通过剪掉一半的注意力层,实现了48.4%的加速,而性能仅下降2.4%。此外,通过追踪训练过程中的模型检查点,我们观察到注意力层冗余是固有的,并且在各个训练阶段保持一致。另外,我们进一步提出了一种联合丢弃注意力层和MLP层的方法,使我们能够更激进地丢弃更多层。例如,当丢弃31层(注意力层+MLP层)时,Llama-2-13B在MMLU任务上仍能保持90%的性能。我们的工作为未来的网络架构设计提供了有价值的见解。代码已发布在:\url{https://github.com/Shwai-He/LLM-Drop}。

英文摘要:

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}.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑