{"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/ecoformer-energy-saving-attention-with-linear","title":"EcoFormer: Energy-Saving Attention with Linear Complexity","arxiv_id":"2209.09004","date":"2022-09-19","proceeding":null,"authors":["Jing Liu","Zizheng Pan","Haoyu He","Jianfei Cai","Bohan Zhuang"],"abstract":"Transformer is a transformative framework that models sequential data and has achieved remarkable performance on a wide range of tasks, but with high computational and energy cost. To improve its efficiency, a popular choice is to compress the models via binarization which constrains the floating-point values into binary ones to save resource consumption owing to cheap bitwise operations significantly. However, existing binarization methods only aim at minimizing the information loss for the input distribution statistically, while ignoring the pairwise similarity modeling at the core of the attention. To this end, we propose a new binarization paradigm customized to high-dimensional softmax attention via kernelized hashing, called EcoFormer, to map the original queries and keys into low-dimensional binary codes in Hamming space. The kernelized hash functions are learned to match the ground-truth similarity relations extracted from the attention map in a self-supervised way. Based on the equivalence between the inner product of binary codes and the Hamming distance as well as the associative property of matrix multiplication, we can approximate the attention in linear complexity by expressing it as a dot-product of binary codes. Moreover, the compact binary representations of queries and keys enable us to replace most of the expensive multiply-accumulate operations in attention with simple accumulations to save considerable on-chip energy footprint on edge devices. Extensive experiments on both vision and language tasks show that EcoFormer consistently achieves comparable performance with standard attentions while consuming much fewer resources. For example, based on PVTv2-B0 and ImageNet-1K, Ecoformer achieves a 73% on-chip energy footprint reduction with only a 0.33% performance drop compared to the standard attention. Code is available at https://github.com/ziplab/EcoFormer.","url_abs":"https://arxiv.org/abs/2209.09004v3","url_pdf":"https://arxiv.org/pdf/2209.09004v3.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":"ecoformer-energy-saving-attention-with-linear","repo_url":"https://github.com/ziplab/ecoformer","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"Apache-2.0"}}],"tasks":[{"task_slug":"binarization","task_name":"Binarization"}],"methods":[{"method_slug":"softmax","method_name":"Softmax"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/2209.09004","atlas_url":"https://app.syntology.ai/?focus=2209.09004","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2209.09004"}},"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/ziplab/EcoFormer","reach":{"status":"ok","spdx":"Apache-2.0"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/ziplab/ecoformer","reach":{"status":"ok","spdx":"Apache-2.0"}}],"summary":{"ran":3,"unverified":2},"by_repo_kind":{"official":{"samples":5,"ran":3,"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":"90e0b9db0ae2a681","entry":"li_sra_flops","repo":"ziplab/EcoFormer","repo_kind":"official","path":"pvt/get_flops.py","file_url":"https://github.com/ziplab/EcoFormer/blob/HEAD/pvt/get_flops.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"90e0b9db0ae2a681"}},{"code_sha256_prefix":"8c49841910af653a","entry":"msa_flops","repo":"ziplab/EcoFormer","repo_kind":"official","path":"pvt/get_energy.py","file_url":"https://github.com/ziplab/EcoFormer/blob/HEAD/pvt/get_energy.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"8c49841910af653a"}},{"code_sha256_prefix":"5eb28a11cf629463","entry":"sra_flops","repo":"ziplab/EcoFormer","repo_kind":"official","path":"pvt/get_flops.py","file_url":"https://github.com/ziplab/EcoFormer/blob/HEAD/pvt/get_flops.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"5eb28a11cf629463"}},{"code_sha256_prefix":"b1ff741b34908d33","entry":"build_transform","repo":"ziplab/EcoFormer","repo_kind":"official","path":"pvt/datasets.py","file_url":"https://github.com/ziplab/EcoFormer/blob/HEAD/pvt/datasets.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":"b1ff741b34908d33"}},{"code_sha256_prefix":"4bfb487391e32597","entry":"get_flops","repo":"ziplab/EcoFormer","repo_kind":"official","path":"pvt/get_flops.py","file_url":"https://github.com/ziplab/EcoFormer/blob/HEAD/pvt/get_flops.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":"4bfb487391e32597"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}