about
What Matters in Transformers? Not All Attention Is Needed (arxiv.org)
4 points by Anon84 on Oct 25, 2024 | hide | past | pdf | discuss on HN

In plain words: They measured how alike each layer's output is inside big language models and found many attention layers do the same job, so they can be deleted. Deleting half of them in a 70-billion-parameter model made it 48.4% faster while losing only 2.4% of its performance.

Abstract · What Matters in Transformers? Not All Attention is Needed

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

Shwai He, Guoheng Sun, Zheyu Shen, Ang Li
arXiv:2406.15786 · cs.LG, cs.AI, cs.CL · submitted Jun 22, 2024 · updated Oct 17, 2024
abstract · pdf · html · 15 pages, 13 figures, 6 tables

add comment on HN
Also discussed: Oct 2024 (3 points, 0 comments)