{"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/bridging-the-divide-reconsidering-softmax-and","title":"Bridging the Divide: Reconsidering Softmax and Linear Attention","arxiv_id":"2412.06590","date":"2024-12-09","proceeding":null,"authors":["Dongchen Han","Yifan Pu","Zhuofan Xia","Yizeng Han","Xuran Pan","Xiu Li","Jiwen Lu","Shiji Song","Gao Huang"],"abstract":"Widely adopted in modern Vision Transformer designs, Softmax attention can effectively capture long-range visual information; however, it incurs excessive computational cost when dealing with high-resolution inputs. In contrast, linear attention naturally enjoys linear complexity and has great potential to scale up to higher-resolution images. Nonetheless, the unsatisfactory performance of linear attention greatly limits its practical application in various scenarios. In this paper, we take a step forward to close the gap between the linear and Softmax attention with novel theoretical analyses, which demystify the core factors behind the performance deviations. Specifically, we present two key perspectives to understand and alleviate the limitations of linear attention: the injective property and the local modeling ability. Firstly, we prove that linear attention is not injective, which is prone to assign identical attention weights to different query vectors, thus adding to severe semantic confusion since different queries correspond to the same outputs. Secondly, we confirm that effective local modeling is essential for the success of Softmax attention, in which linear attention falls short. The aforementioned two fundamental differences significantly contribute to the disparities between these two attention paradigms, which is demonstrated by our substantial empirical validation in the paper. In addition, more experiment results indicate that linear attention, as long as endowed with these two properties, can outperform Softmax attention across various tasks while maintaining lower computation complexity. Code is available at https://github.com/LeapLabTHU/InLine.","url_abs":"https://arxiv.org/abs/2412.06590v1","url_pdf":"https://arxiv.org/pdf/2412.06590v1.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":"bridging-the-divide-reconsidering-softmax-and","repo_url":"https://github.com/leaplabthu/inline","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok"}}],"tasks":[],"methods":[{"method_slug":"absolute-position-encodings","method_name":"Absolute Position Encodings"},{"method_slug":"adam","method_name":"Adam"},{"method_slug":"attention","method_name":"Attention"},{"method_slug":"bpe","method_name":"BPE"},{"method_slug":"dense-connections","method_name":"Dense Connections"},{"method_slug":"dropout","method_name":"Dropout"},{"method_slug":"label-smoothing","method_name":"Label Smoothing"},{"method_slug":"layer-normalization","method_name":"Layer Normalization"},{"method_slug":"linear-layer","method_name":"Linear Layer"},{"method_slug":"multi-head-attention","method_name":"Multi-Head Attention"},{"method_slug":"position-wise-feed-forward-layer","method_name":"Position-Wise Feed-Forward Layer"},{"method_slug":"residual-connection","method_name":"Residual Connection"},{"method_slug":"softmax","method_name":"Softmax"},{"method_slug":"transformer","method_name":"Transformer"},{"method_slug":"vision-transformer","method_name":"Vision Transformer"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/2412.06590","atlas_url":"https://app.syntology.ai/?focus=2412.06590","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2412.06590"}},"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/leaplabthu/inline","reach":{"status":"ok"}}],"summary":{"ran_fixture":2,"ran_honours":1,"ran_draft_wrong":2,"unverified":17},"by_repo_kind":{"official":{"samples":22,"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":22,"samples":[{"code_sha256_prefix":"144d10b49baeb8a6","entry":"window_partition","repo":"leaplabthu/inline","repo_kind":"official","path":"models/inline_swin.py","file_url":"https://github.com/leaplabthu/inline/blob/HEAD/models/inline_swin.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":"144d10b49baeb8a6"}},{"code_sha256_prefix":"eec1e7cba51d5e8e","entry":"get_grad_norm","repo":"leaplabthu/inline","repo_kind":"official","path":"utils.py","file_url":"https://github.com/leaplabthu/inline/blob/HEAD/utils.py","link_basis":"plan_row","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":"well_formed","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"eec1e7cba51d5e8e"}},{"code_sha256_prefix":"39b18f062e0cc6d9","entry":"img2windows","repo":"leaplabthu/inline","repo_kind":"official","path":"models/inline_cswin.py","file_url":"https://github.com/leaplabthu/inline/blob/HEAD/models/inline_cswin.py","link_basis":"plan_row","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":"39b18f062e0cc6d9"}},{"code_sha256_prefix":"61bf152e6a42a184","entry":"window_reverse","repo":"leaplabthu/inline","repo_kind":"official","path":"models/inline_swin.py","file_url":"https://github.com/leaplabthu/inline/blob/HEAD/models/inline_swin.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"61bf152e6a42a184"}},{"code_sha256_prefix":"ab01fbfe58c75b08","entry":"windows2img","repo":"leaplabthu/inline","repo_kind":"official","path":"models/inline_cswin.py","file_url":"https://github.com/leaplabthu/inline/blob/HEAD/models/inline_cswin.py","link_basis":"plan_row","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"ab01fbfe58c75b08"}},{"code_sha256_prefix":"0c32459bef92ff8c","entry":"auto_resume_helper","repo":"leaplabthu/inline","repo_kind":"official","path":"utils.py","file_url":"https://github.com/leaplabthu/inline/blob/HEAD/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":"0c32459bef92ff8c"}},{"code_sha256_prefix":"aad933b3b81ff1a5","entry":"build_model","repo":"leaplabthu/inline","repo_kind":"official","path":"models/build.py","file_url":"https://github.com/leaplabthu/inline/blob/HEAD/models/build.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":"aad933b3b81ff1a5"}},{"code_sha256_prefix":"fcf2d41dd445a70b","entry":"build_optimizer","repo":"leaplabthu/inline","repo_kind":"official","path":"optimizer.py","file_url":"https://github.com/leaplabthu/inline/blob/HEAD/optimizer.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":"fcf2d41dd445a70b"}},{"code_sha256_prefix":"07e8b4b487c0abb6","entry":"build_scheduler","repo":"leaplabthu/inline","repo_kind":"official","path":"lr_scheduler.py","file_url":"https://github.com/leaplabthu/inline/blob/HEAD/lr_scheduler.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":"07e8b4b487c0abb6"}},{"code_sha256_prefix":"b0a5beb34716d5a6","entry":"check_keywords_in_name","repo":"leaplabthu/inline","repo_kind":"official","path":"optimizer.py","file_url":"https://github.com/leaplabthu/inline/blob/HEAD/optimizer.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":"b0a5beb34716d5a6"}},{"code_sha256_prefix":"5dac11fdc41c896b","entry":"checkpoint_filter_fn","repo":"leaplabthu/inline","repo_kind":"official","path":"models/inline_deit.py","file_url":"https://github.com/leaplabthu/inline/blob/HEAD/models/inline_deit.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":"5dac11fdc41c896b"}},{"code_sha256_prefix":"82e52feafbf040bb","entry":"create_logger","repo":"leaplabthu/inline","repo_kind":"official","path":"logger.py","file_url":"https://github.com/leaplabthu/inline/blob/HEAD/logger.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":"82e52feafbf040bb"}},{"code_sha256_prefix":"99a5631eaaa3bf92","entry":"exp_kernel","repo":"leaplabthu/inline","repo_kind":"official","path":"models/inline_swin.py","file_url":"https://github.com/leaplabthu/inline/blob/HEAD/models/inline_swin.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":"99a5631eaaa3bf92"}},{"code_sha256_prefix":"20681a9065c0a731","entry":"get_config","repo":"leaplabthu/inline","repo_kind":"official","path":"config.py","file_url":"https://github.com/leaplabthu/inline/blob/HEAD/config.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":"20681a9065c0a731"}},{"code_sha256_prefix":"66116ff15364aa78","entry":"inline_cswin_tiny","repo":"leaplabthu/inline","repo_kind":"official","path":"models/inline_cswin.py","file_url":"https://github.com/leaplabthu/inline/blob/HEAD/models/inline_cswin.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":"66116ff15364aa78"}},{"code_sha256_prefix":"08374cb9905d8cf6","entry":"inline_pvt_medium","repo":"leaplabthu/inline","repo_kind":"official","path":"models/inline_pvt.py","file_url":"https://github.com/leaplabthu/inline/blob/HEAD/models/inline_pvt.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":"08374cb9905d8cf6"}},{"code_sha256_prefix":"ad181339ef9d5474","entry":"inline_pvt_small","repo":"leaplabthu/inline","repo_kind":"official","path":"models/inline_pvt.py","file_url":"https://github.com/leaplabthu/inline/blob/HEAD/models/inline_pvt.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":"ad181339ef9d5474"}},{"code_sha256_prefix":"65a492aded74a41e","entry":"inline_pvt_tiny","repo":"leaplabthu/inline","repo_kind":"official","path":"models/inline_pvt.py","file_url":"https://github.com/leaplabthu/inline/blob/HEAD/models/inline_pvt.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":"65a492aded74a41e"}},{"code_sha256_prefix":"7e0715dc48712749","entry":"load_checkpoint","repo":"leaplabthu/inline","repo_kind":"official","path":"utils.py","file_url":"https://github.com/leaplabthu/inline/blob/HEAD/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":"7e0715dc48712749"}},{"code_sha256_prefix":"26a01685ebc8f358","entry":"load_checkpoint","repo":"leaplabthu/inline","repo_kind":"official","path":"utils_ema.py","file_url":"https://github.com/leaplabthu/inline/blob/HEAD/utils_ema.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":"26a01685ebc8f358"}},{"code_sha256_prefix":"1dbef2d4da4ee10f","entry":"resize_pos_embed","repo":"leaplabthu/inline","repo_kind":"official","path":"models/inline_deit.py","file_url":"https://github.com/leaplabthu/inline/blob/HEAD/models/inline_deit.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":"1dbef2d4da4ee10f"}},{"code_sha256_prefix":"104af48a94364f24","entry":"set_weight_decay_and_lr","repo":"leaplabthu/inline","repo_kind":"official","path":"optimizer.py","file_url":"https://github.com/leaplabthu/inline/blob/HEAD/optimizer.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":"104af48a94364f24"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}