{"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/why-do-llms-attend-to-the-first-token","title":"Why do LLMs attend to the first token?","arxiv_id":"2504.02732","date":"2025-04-03","proceeding":null,"authors":["Federico Barbero","Álvaro Arroyo","Xiangming Gu","Christos Perivolaropoulos","Michael Bronstein","Petar Veličković","Razvan Pascanu"],"abstract":"Large Language Models (LLMs) tend to attend heavily to the first token in the sequence -- creating a so-called attention sink. Many works have studied this phenomenon in detail, proposing various ways to either leverage or alleviate it. Attention sinks have been connected to quantisation difficulties, security issues, and streaming attention. Yet, while many works have provided conditions in which they occur or not, a critical question remains shallowly answered: Why do LLMs learn such patterns and how are they being used? In this work, we argue theoretically and empirically that this mechanism provides a method for LLMs to avoid over-mixing, connecting this to existing lines of work that study mathematically how information propagates in Transformers. We conduct experiments to validate our theoretical intuitions and show how choices such as context length, depth, and data packing influence the sink behaviour. We hope that this study provides a new practical perspective on why attention sinks are useful in LLMs, leading to a better understanding of the attention patterns that form during training.","url_abs":"https://arxiv.org/abs/2504.02732v3","url_pdf":"https://arxiv.org/pdf/2504.02732v3.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":"why-do-llms-attend-to-the-first-token","repo_url":"https://github.com/zzmtsvv/ad-gta","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"Apache-2.0"}}],"tasks":[],"methods":[{"method_slug":"attention","method_name":"Attention"},{"method_slug":"attention-sinks","method_name":"Attention Sinks"},{"method_slug":"softmax","method_name":"Softmax"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2504.02732","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2504.02732"}},"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/zzmtsvv/ad-gta","reach":{"status":"ok","spdx":"Apache-2.0"}}],"summary":{"unverified":7},"by_repo_kind":{"listed":{"samples":7,"ran":0,"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":"07a98c0df7ee4019","entry":"all_goals","repo":"zzmtsvv/ad-gta","repo_kind":"listed","path":"src/envs/dark_room.py","file_url":"https://github.com/zzmtsvv/ad-gta/blob/HEAD/src/envs/dark_room.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":"07a98c0df7ee4019"}},{"code_sha256_prefix":"e7bb8ed4a55e86fb","entry":"apply_rotary_emb","repo":"zzmtsvv/ad-gta","repo_kind":"listed","path":"src/nn/memeff_rope_fn.py","file_url":"https://github.com/zzmtsvv/ad-gta/blob/HEAD/src/nn/memeff_rope_fn.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":"e7bb8ed4a55e86fb"}},{"code_sha256_prefix":"e8f6d785640a6346","entry":"apply_rotary_pos_emb","repo":"zzmtsvv/ad-gta","repo_kind":"listed","path":"src/nn/memeff_rope_fn.py","file_url":"https://github.com/zzmtsvv/ad-gta/blob/HEAD/src/nn/memeff_rope_fn.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":"e8f6d785640a6346"}},{"code_sha256_prefix":"6d739483013ff314","entry":"get_alibi_relative_positions","repo":"zzmtsvv/ad-gta","repo_kind":"listed","path":"src/nn/attention_sink.py","file_url":"https://github.com/zzmtsvv/ad-gta/blob/HEAD/src/nn/attention_sink.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":"6d739483013ff314"}},{"code_sha256_prefix":"664be17da66a5906","entry":"get_alibi_slopes","repo":"zzmtsvv/ad-gta","repo_kind":"listed","path":"src/nn/attention_sink.py","file_url":"https://github.com/zzmtsvv/ad-gta/blob/HEAD/src/nn/attention_sink.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":"664be17da66a5906"}},{"code_sha256_prefix":"d03c5ab466edb014","entry":"rotate_half","repo":"zzmtsvv/ad-gta","repo_kind":"listed","path":"src/nn/memeff_rope_fn.py","file_url":"https://github.com/zzmtsvv/ad-gta/blob/HEAD/src/nn/memeff_rope_fn.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":"d03c5ab466edb014"}},{"code_sha256_prefix":"4bdf0edd73ee697d","entry":"train_test_goals","repo":"zzmtsvv/ad-gta","repo_kind":"listed","path":"src/envs/dark_room.py","file_url":"https://github.com/zzmtsvv/ad-gta/blob/HEAD/src/envs/dark_room.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":"4bdf0edd73ee697d"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}