{"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/unveiling-and-harnessing-hidden-attention","title":"Unveiling and Harnessing Hidden Attention Sinks: Enhancing Large Language Models without Training through Attention Calibration","arxiv_id":"2406.15765","date":"2024-06-22","proceeding":null,"authors":["Zhongzhi Yu","Zheng Wang","Yonggan Fu","Huihong Shi","Khalid Shaikh","Yingyan Celine Lin"],"abstract":"Attention is a fundamental component behind the remarkable achievements of large language models (LLMs). However, our current understanding of the attention mechanism, especially regarding how attention distributions are established, remains limited. Inspired by recent studies that explore the presence of attention sink in the initial token, which receives disproportionately large attention scores despite their lack of semantic importance, this work delves deeper into this phenomenon. We aim to provide a more profound understanding of the existence of attention sinks within LLMs and to uncover ways to enhance the achievable accuracy of LLMs by directly optimizing the attention distributions, without the need for weight finetuning. Specifically, this work begins with comprehensive visualizations of the attention distributions in LLMs during inference across various inputs and tasks. Based on these visualizations, to the best of our knowledge, we are the first to discover that (1) attention sinks occur not only at the start of sequences but also within later tokens of the input, and (2) not all attention sinks have a positive impact on the achievable accuracy of LLMs. Building upon our findings, we propose a training-free Attention Calibration Technique (ACT) that automatically optimizes the attention distributions on the fly during inference in an input-adaptive manner. Extensive experiments validate that ACT consistently enhances the accuracy of various LLMs across different applications. Specifically, ACT achieves an average improvement of up to 7.30% in accuracy across different datasets when applied to Llama-30B. Our code is available at https://github.com/GATECH-EIC/ACT.","url_abs":"https://arxiv.org/abs/2406.15765v1","url_pdf":"https://arxiv.org/pdf/2406.15765v1.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":"unveiling-and-harnessing-hidden-attention","repo_url":"https://github.com/gatech-eic/act","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":0,"framework":"pytorch","reach":{"status":"ok"}}],"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":{"syntology_url":"https://syntology.ai/paper/2406.15765","atlas_url":"https://app.syntology.ai/?focus=2406.15765","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2406.15765"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-25T09:33:49+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/gatech-eic/act","reach":{"status":"ok"}}],"summary":{"ran_fixture":2,"ran":2,"ran_draft_wrong":1,"unverified":8},"by_repo_kind":{"official":{"samples":13,"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":13,"samples":[{"code_sha256_prefix":"30d7eec482ebf6b1","entry":"repeat_kv","repo":"gatech-eic/act","repo_kind":"official","path":"models/modelling_llama.py","file_url":"https://github.com/gatech-eic/act/blob/HEAD/models/modelling_llama.py","link_basis":"harvester_set","language":"python","status":"ran_fixture","verification_level":2,"contract_check":"RAISES","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"30d7eec482ebf6b1"}},{"code_sha256_prefix":"d61c483a3c2b3156","entry":"apply_rotary_pos_emb","repo":"gatech-eic/act","repo_kind":"official","path":"models/modelling_llama.py","file_url":"https://github.com/gatech-eic/act/blob/HEAD/models/modelling_llama.py","link_basis":"harvester_set","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":"invariant","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"d61c483a3c2b3156"}},{"code_sha256_prefix":"22be0f0263f68218","entry":"atten_process_cal","repo":"gatech-eic/act","repo_kind":"official","path":"models/llama_modelling_aug.py","file_url":"https://github.com/gatech-eic/act/blob/HEAD/models/llama_modelling_aug.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"22be0f0263f68218"}},{"code_sha256_prefix":"fb732786766c9170","entry":"form_choices","repo":"gatech-eic/act","repo_kind":"official","path":"utils/data_utils.py","file_url":"https://github.com/gatech-eic/act/blob/HEAD/utils/data_utils.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"fb732786766c9170"}},{"code_sha256_prefix":"b99eea6376d1e212","entry":"rotate_half","repo":"gatech-eic/act","repo_kind":"official","path":"models/modelling_llama.py","file_url":"https://github.com/gatech-eic/act/blob/HEAD/models/modelling_llama.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"b99eea6376d1e212"}},{"code_sha256_prefix":"81cfc398d4db8c00","entry":"atten_aug_forward_eval_llama","repo":"gatech-eic/act","repo_kind":"official","path":"models/llama_modelling_aug.py","file_url":"https://github.com/gatech-eic/act/blob/HEAD/models/llama_modelling_aug.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"81cfc398d4db8c00"}},{"code_sha256_prefix":"8ec16c9a57666186","entry":"atten_aug_forward_eval_mistral","repo":"gatech-eic/act","repo_kind":"official","path":"models/mistral_modelling_aug.py","file_url":"https://github.com/gatech-eic/act/blob/HEAD/models/mistral_modelling_aug.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"8ec16c9a57666186"}},{"code_sha256_prefix":"4491e28ac0c62c55","entry":"atten_aug_forward_llama","repo":"gatech-eic/act","repo_kind":"official","path":"mt-bench/gen_model_answer.py","file_url":"https://github.com/gatech-eic/act/blob/HEAD/mt-bench/gen_model_answer.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"4491e28ac0c62c55"}},{"code_sha256_prefix":"9766c8d6378000f2","entry":"atten_process","repo":"gatech-eic/act","repo_kind":"official","path":"mt-bench/gen_model_answer.py","file_url":"https://github.com/gatech-eic/act/blob/HEAD/mt-bench/gen_model_answer.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"9766c8d6378000f2"}},{"code_sha256_prefix":"d20d6b485da65eef","entry":"atten_process_eval","repo":"gatech-eic/act","repo_kind":"official","path":"models/llama_modelling_aug.py","file_url":"https://github.com/gatech-eic/act/blob/HEAD/models/llama_modelling_aug.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"d20d6b485da65eef"}},{"code_sha256_prefix":"936d7a36c6e12df6","entry":"atten_process_eval","repo":"gatech-eic/act","repo_kind":"official","path":"models/mistral_modelling_aug.py","file_url":"https://github.com/gatech-eic/act/blob/HEAD/models/mistral_modelling_aug.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"936d7a36c6e12df6"}},{"code_sha256_prefix":"5d8307adf1e23d57","entry":"get_classification_dataset","repo":"gatech-eic/act","repo_kind":"official","path":"utils/data_utils.py","file_url":"https://github.com/gatech-eic/act/blob/HEAD/utils/data_utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"5d8307adf1e23d57"}},{"code_sha256_prefix":"1bea206b322ec46d","entry":"get_multiple_choice_dataset","repo":"gatech-eic/act","repo_kind":"official","path":"utils/data_utils.py","file_url":"https://github.com/gatech-eic/act/blob/HEAD/utils/data_utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"1bea206b322ec46d"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}