{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/what-matters-in-transformers-not-all","title":"What Matters in Transformers? Not All Attention is Needed","arxiv_id":"2406.15786","date":"2024-06-22","proceeding":null,"authors":["Shwai He","Guoheng Sun","Zheyu Shen","Ang Li"],"abstract":"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}.","url_abs":"https://arxiv.org/abs/2406.15786v6","url_pdf":"https://arxiv.org/pdf/2406.15786v6.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"what-matters-in-transformers-not-all","repo_url":"https://github.com/case-lab-umd/llm-drop","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"Apache-2.0"}},{"paper_slug":"what-matters-in-transformers-not-all","repo_url":"https://github.com/shwai-he/llm-drop","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"Apache-2.0"}}],"tasks":[{"task_slug":"all","task_name":"All"},{"task_slug":"mmlu","task_name":"MMLU"}],"methods":[{"method_slug":"attention","method_name":"Attention"},{"method_slug":"pruning","method_name":"Pruning"},{"method_slug":"softmax","method_name":"Softmax"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2406.15786","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2406.15786"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/case-lab-umd/llm-drop","reach":{"status":"ok","spdx":"Apache-2.0"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/shwai-he/llm-drop","reach":{"status":"ok","spdx":"Apache-2.0"}}],"summary":{"ran":5,"unverified":5},"by_repo_kind":{"official":{"samples":10,"ran":5,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":0,"samples":[{"code_sha256_prefix":"5995c2562cfcbc33","entry":"count_parameters","repo":"case-lab-umd/llm-drop","repo_kind":"official","path":"src/llmtuner/extras/misc.py","file_url":"https://github.com/case-lab-umd/llm-drop/blob/HEAD/src/llmtuner/extras/misc.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"5995c2562cfcbc33"}},{"code_sha256_prefix":"e52f261bfb32b88e","entry":"generate_torch","repo":"case-lab-umd/llm-drop","repo_kind":"official","path":"src/benchmark_speed.py","file_url":"https://github.com/case-lab-umd/llm-drop/blob/HEAD/src/benchmark_speed.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"e52f261bfb32b88e"}},{"code_sha256_prefix":"4049a2f89b11dd2f","entry":"get_logger","repo":"case-lab-umd/llm-drop","repo_kind":"official","path":"src/llmtuner/extras/logging.py","file_url":"https://github.com/case-lab-umd/llm-drop/blob/HEAD/src/llmtuner/extras/logging.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"4049a2f89b11dd2f"}},{"code_sha256_prefix":"02c5c966e64fd4a4","entry":"max_with_tolerance","repo":"case-lab-umd/llm-drop","repo_kind":"official","path":"src/llmtuner/compression/prune/block_drop.py","file_url":"https://github.com/case-lab-umd/llm-drop/blob/HEAD/src/llmtuner/compression/prune/block_drop.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"02c5c966e64fd4a4"}},{"code_sha256_prefix":"70c7f6d657ef0a9e","entry":"smooth","repo":"case-lab-umd/llm-drop","repo_kind":"official","path":"src/llmtuner/extras/ploting.py","file_url":"https://github.com/case-lab-umd/llm-drop/blob/HEAD/src/llmtuner/extras/ploting.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"70c7f6d657ef0a9e"}},{"code_sha256_prefix":"9885027831acc7a5","entry":"discrete_layer_dropping","repo":"case-lab-umd/llm-drop","repo_kind":"official","path":"src/llmtuner/compression/prune/layer_drop.py","file_url":"https://github.com/case-lab-umd/llm-drop/blob/HEAD/src/llmtuner/compression/prune/layer_drop.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"9885027831acc7a5"}},{"code_sha256_prefix":"e8a9f68f74108b49","entry":"get_block_similarities","repo":"case-lab-umd/llm-drop","repo_kind":"official","path":"src/llmtuner/compression/prune/block_drop.py","file_url":"https://github.com/case-lab-umd/llm-drop/blob/HEAD/src/llmtuner/compression/prune/block_drop.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"e8a9f68f74108b49"}},{"code_sha256_prefix":"a5ceec399132f3c7","entry":"get_block_similarities_consecutive","repo":"case-lab-umd/llm-drop","repo_kind":"official","path":"src/llmtuner/compression/prune/block_drop.py","file_url":"https://github.com/case-lab-umd/llm-drop/blob/HEAD/src/llmtuner/compression/prune/block_drop.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"a5ceec399132f3c7"}},{"code_sha256_prefix":"3ff4456dbf47be57","entry":"get_layer_similarities","repo":"case-lab-umd/llm-drop","repo_kind":"official","path":"src/llmtuner/compression/prune/layer_drop.py","file_url":"https://github.com/case-lab-umd/llm-drop/blob/HEAD/src/llmtuner/compression/prune/layer_drop.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"3ff4456dbf47be57"}},{"code_sha256_prefix":"0ace211ff2e7d07f","entry":"infer_optim_dtype","repo":"case-lab-umd/llm-drop","repo_kind":"official","path":"src/llmtuner/extras/misc.py","file_url":"https://github.com/case-lab-umd/llm-drop/blob/HEAD/src/llmtuner/extras/misc.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"0ace211ff2e7d07f"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}