{"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/sema-a-scalable-and-efficient-mamba-like","title":"SEMA: a Scalable and Efficient Mamba like Attention via Token Localization and Averaging","arxiv_id":"2506.08297","date":"2025-06-10","proceeding":null,"authors":["Nhat Thanh Tran","Fanghui Xue","Shuai Zhang","Jiancheng Lyu","Yunling Zheng","Yingyong Qi","Jack Xin"],"abstract":"Attention is the critical component of a transformer. Yet the quadratic computational complexity of vanilla full attention in the input size and the inability of its linear attention variant to focus have been challenges for computer vision tasks. We provide a mathematical definition of generalized attention and formulate both vanilla softmax attention and linear attention within the general framework. We prove that generalized attention disperses, that is, as the number of keys tends to infinity, the query assigns equal weights to all keys. Motivated by the dispersion property and recent development of Mamba form of attention, we design Scalable and Efficient Mamba like Attention (SEMA) which utilizes token localization to avoid dispersion and maintain focusing, complemented by theoretically consistent arithmetic averaging to capture global aspect of attention. We support our approach on Imagenet-1k where classification results show that SEMA is a scalable and effective alternative beyond linear attention, outperforming recent vision Mamba models on increasingly larger scales of images at similar model parameter sizes.","url_abs":"https://arxiv.org/abs/2506.08297v1","url_pdf":"https://arxiv.org/pdf/2506.08297v1.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":[],"tasks":[{"task_slug":"mamba","task_name":"Mamba"}],"methods":[{"method_slug":"attention","method_name":"Attention"},{"method_slug":"focus","method_name":"Focus"},{"method_slug":"mamba","method_name":"Mamba"},{"method_slug":"softmax","method_name":"Softmax"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/2506.08297","atlas_url":"https://app.syntology.ai/?focus=2506.08297","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2506.08297"}},"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":"deterministic:regex_extraction","url":"https://github.com/nhatthanhtran/SEMA","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"ran":1,"ran_violates":2,"ran_honours":1,"unverified":9},"by_repo_kind":{"found_in_text":{"samples":13,"ran":4,"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":"f07bf3d46feead4c","entry":"broadcat","repo":"nhatthanhtran/SEMA","repo_kind":"found_in_text","path":"models/rope.py","file_url":"https://github.com/nhatthanhtran/SEMA/blob/HEAD/models/rope.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":false,"mcp_get_code":{"code_sha256":"f07bf3d46feead4c"}},{"code_sha256_prefix":"60fff7c3c400d7ff","entry":"default","repo":"nhatthanhtran/SEMA","repo_kind":"found_in_text","path":"models/rope.py","file_url":"https://github.com/nhatthanhtran/SEMA/blob/HEAD/models/rope.py","link_basis":"harvester_set","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":"well_formed","behaviour_fingerprint":true,"licence":"MIT","inline_ok":false,"mcp_get_code":{"code_sha256":"60fff7c3c400d7ff"}},{"code_sha256_prefix":"aa5486a3650902d8","entry":"exists","repo":"nhatthanhtran/SEMA","repo_kind":"found_in_text","path":"models/rope.py","file_url":"https://github.com/nhatthanhtran/SEMA/blob/HEAD/models/rope.py","link_basis":"harvester_set","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"MIT","inline_ok":false,"mcp_get_code":{"code_sha256":"aa5486a3650902d8"}},{"code_sha256_prefix":"eec1e7cba51d5e8e","entry":"get_grad_norm","repo":"nhatthanhtran/SEMA","repo_kind":"found_in_text","path":"utils.py","file_url":"https://github.com/nhatthanhtran/SEMA/blob/HEAD/utils.py","link_basis":"harvester_set","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":"well_formed","behaviour_fingerprint":false,"licence":"MIT","inline_ok":false,"mcp_get_code":{"code_sha256":"eec1e7cba51d5e8e"}},{"code_sha256_prefix":"0c32459bef92ff8c","entry":"auto_resume_helper","repo":"nhatthanhtran/SEMA","repo_kind":"found_in_text","path":"utils.py","file_url":"https://github.com/nhatthanhtran/SEMA/blob/HEAD/utils.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":false,"mcp_get_code":{"code_sha256":"0c32459bef92ff8c"}},{"code_sha256_prefix":"f0da8448e76e4d0e","entry":"build_model","repo":"nhatthanhtran/SEMA","repo_kind":"found_in_text","path":"models/build.py","file_url":"https://github.com/nhatthanhtran/SEMA/blob/HEAD/models/build.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":false,"mcp_get_code":{"code_sha256":"f0da8448e76e4d0e"}},{"code_sha256_prefix":"fcf2d41dd445a70b","entry":"build_optimizer","repo":"nhatthanhtran/SEMA","repo_kind":"found_in_text","path":"optimizer.py","file_url":"https://github.com/nhatthanhtran/SEMA/blob/HEAD/optimizer.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":false,"mcp_get_code":{"code_sha256":"fcf2d41dd445a70b"}},{"code_sha256_prefix":"07e8b4b487c0abb6","entry":"build_scheduler","repo":"nhatthanhtran/SEMA","repo_kind":"found_in_text","path":"lr_scheduler.py","file_url":"https://github.com/nhatthanhtran/SEMA/blob/HEAD/lr_scheduler.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":false,"mcp_get_code":{"code_sha256":"07e8b4b487c0abb6"}},{"code_sha256_prefix":"b0a5beb34716d5a6","entry":"check_keywords_in_name","repo":"nhatthanhtran/SEMA","repo_kind":"found_in_text","path":"optimizer.py","file_url":"https://github.com/nhatthanhtran/SEMA/blob/HEAD/optimizer.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":false,"mcp_get_code":{"code_sha256":"b0a5beb34716d5a6"}},{"code_sha256_prefix":"82e52feafbf040bb","entry":"create_logger","repo":"nhatthanhtran/SEMA","repo_kind":"found_in_text","path":"logger.py","file_url":"https://github.com/nhatthanhtran/SEMA/blob/HEAD/logger.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":false,"mcp_get_code":{"code_sha256":"82e52feafbf040bb"}},{"code_sha256_prefix":"20681a9065c0a731","entry":"get_config","repo":"nhatthanhtran/SEMA","repo_kind":"found_in_text","path":"config.py","file_url":"https://github.com/nhatthanhtran/SEMA/blob/HEAD/config.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":false,"mcp_get_code":{"code_sha256":"20681a9065c0a731"}},{"code_sha256_prefix":"26a01685ebc8f358","entry":"load_checkpoint","repo":"nhatthanhtran/SEMA","repo_kind":"found_in_text","path":"utils.py","file_url":"https://github.com/nhatthanhtran/SEMA/blob/HEAD/utils.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":false,"mcp_get_code":{"code_sha256":"26a01685ebc8f358"}},{"code_sha256_prefix":"104af48a94364f24","entry":"set_weight_decay_and_lr","repo":"nhatthanhtran/SEMA","repo_kind":"found_in_text","path":"optimizer.py","file_url":"https://github.com/nhatthanhtran/SEMA/blob/HEAD/optimizer.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":false,"mcp_get_code":{"code_sha256":"104af48a94364f24"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}