{"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/soft-softmax-free-transformer-with-linear","title":"SOFT: Softmax-free Transformer with Linear Complexity","arxiv_id":"2110.11945","date":"2021-10-22","proceeding":"NeurIPS 2021 12","authors":["Jiachen Lu","Jinghan Yao","Junge Zhang","Xiatian Zhu","Hang Xu","Weiguo Gao","Chunjing Xu","Tao Xiang","Li Zhang"],"abstract":"Vision transformers (ViTs) have pushed the state-of-the-art for various visual recognition tasks by patch-wise image tokenization followed by self-attention. However, the employment of self-attention modules results in a quadratic complexity in both computation and memory usage. Various attempts on approximating the self-attention computation with linear complexity have been made in Natural Language Processing. However, an in-depth analysis in this work shows that they are either theoretically flawed or empirically ineffective for visual recognition. We further identify that their limitations are rooted in keeping the softmax self-attention during approximations. Specifically, conventional self-attention is computed by normalizing the scaled dot-product between token feature vectors. Keeping this softmax operation challenges any subsequent linearization efforts. Based on this insight, for the first time, a softmax-free transformer or SOFT is proposed. To remove softmax in self-attention, Gaussian kernel function is used to replace the dot-product similarity without further normalization. This enables a full self-attention matrix to be approximated via a low-rank matrix decomposition. The robustness of the approximation is achieved by calculating its Moore-Penrose inverse using a Newton-Raphson method. Extensive experiments on ImageNet show that our SOFT significantly improves the computational efficiency of existing ViT variants. Crucially, with a linear complexity, much longer token sequences are permitted in SOFT, resulting in superior trade-off between accuracy and complexity.","url_abs":"https://arxiv.org/abs/2110.11945v3","url_pdf":"https://arxiv.org/pdf/2110.11945v3.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":"soft-softmax-free-transformer-with-linear","repo_url":"https://github.com/fudan-zvg/soft","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}},{"paper_slug":"soft-softmax-free-transformer-with-linear","repo_url":"https://github.com/fudan-zvg/SOFT_MindSpore_Ascend","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":0,"framework":"mindspore","reach":{"status":"ok","spdx":"MIT"}}],"tasks":[{"task_slug":"computational-efficiency","task_name":"Computational Efficiency"}],"methods":[{"method_slug":"softmax","method_name":"Softmax"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2110.11945","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2110.11945"}},"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/fudan-zvg/soft","reach":{"status":"ok","spdx":"MIT"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/fudan-zvg/SOFT_MindSpore_Ascend","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"unverified":8},"by_repo_kind":{"listed":{"samples":8,"ran":0,"repositories":2}},"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":"8765fe83bed1a28f","entry":"get_logger","repo":"fudan-zvg/SOFT_MindSpore_Ascend","repo_kind":"listed","path":"src/logging.py","file_url":"https://github.com/fudan-zvg/SOFT_MindSpore_Ascend/blob/HEAD/src/logging.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"8765fe83bed1a28f"}},{"code_sha256_prefix":"d2729f1965abbac9","entry":"get_lr","repo":"fudan-zvg/SOFT_MindSpore_Ascend","repo_kind":"listed","path":"src/lr_generator.py","file_url":"https://github.com/fudan-zvg/SOFT_MindSpore_Ascend/blob/HEAD/src/lr_generator.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"d2729f1965abbac9"}},{"code_sha256_prefix":"570957a19fabf30c","entry":"inverse_kernel","repo":"fudan-zvg/soft","repo_kind":"listed","path":"SOFT/kernel/inverse.py","file_url":"https://github.com/fudan-zvg/soft/blob/HEAD/SOFT/kernel/inverse.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"570957a19fabf30c"}},{"code_sha256_prefix":"9da7260d717664f9","entry":"linear_warmup_lr","repo":"fudan-zvg/SOFT_MindSpore_Ascend","repo_kind":"listed","path":"src/lr_generator.py","file_url":"https://github.com/fudan-zvg/SOFT_MindSpore_Ascend/blob/HEAD/src/lr_generator.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"9da7260d717664f9"}},{"code_sha256_prefix":"345f9159d30a4489","entry":"load_function","repo":"fudan-zvg/SOFT_MindSpore_Ascend","repo_kind":"listed","path":"models/softmax_free_vision_transformer.py","file_url":"https://github.com/fudan-zvg/SOFT_MindSpore_Ascend/blob/HEAD/models/softmax_free_vision_transformer.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"345f9159d30a4489"}},{"code_sha256_prefix":"b232f14510419084","entry":"newton_inv","repo":"fudan-zvg/soft","repo_kind":"listed","path":"SOFT/kernel/inverse.py","file_url":"https://github.com/fudan-zvg/soft/blob/HEAD/SOFT/kernel/inverse.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"b232f14510419084"}},{"code_sha256_prefix":"1e2ac61b7dd7512d","entry":"newton_inverse_kernel","repo":"fudan-zvg/soft","repo_kind":"listed","path":"SOFT/kernel/inverse.py","file_url":"https://github.com/fudan-zvg/soft/blob/HEAD/SOFT/kernel/inverse.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"1e2ac61b7dd7512d"}},{"code_sha256_prefix":"a93cab73f1f99c67","entry":"subtraction_gaussian_kernel_torch","repo":"fudan-zvg/soft","repo_kind":"listed","path":"models/softmax_free_transformer.py","file_url":"https://github.com/fudan-zvg/soft/blob/HEAD/models/softmax_free_transformer.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"a93cab73f1f99c67"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}