{"url":"/method/global-sub-sampled-attention","slug":"global-sub-sampled-attention","name":"Global Sub-Sampled Attention","full_name":"Global Sub-Sampled Attention","full_name_withheld":false,"description_markdown":"**Global Sub-Sampled Attention**, or **GSA**, is a local [attention mechanism](https://paperswithcode.com/methods/category/attention-mechanisms-1) used in the [Twins-SVT](https://paperswithcode.com/method/twins-svt) architecture. \r\n\r\nA single representative is used to summarize the key information for each of $m \\times n$ subwindows and the representative is used to communicate with other sub-windows (serving as the key in self-attention), which can reduce the cost to $\\mathcal{O}(m n H W d)=\\mathcal{O}\\left(\\frac{H^{2} W^{2} d}{k\\_{1} k\\_{2}}\\right)$. This is essentially equivalent to using the sub-sampled feature maps as the key in attention operations, and thus it is termed global sub-sampled attention (GSA). \r\n\r\nIf we alternatively use the [LSA](https://paperswithcode.com/method/locally-grouped-self-attention) and GSA like [separable convolutions](https://paperswithcode.com/method/depthwise-separable-convolution) (depth-wise + point-wise). The total computation cost is $\\mathcal{O}\\left(\\frac{H^{2} W^{2} d}{k\\_{1} k\\_{2}}+k\\_{1} k\\_{2} H W d\\right) .$ We have:\r\n\r\n$$\\frac{H^{2} W^{2} d}{k\\_{1} k\\_{2}}+k_{1} k_{2} H W d \\geq 2 H W d \\sqrt{H W} $$ \r\n\r\nThe minimum is obtained when $k\\_{1} \\cdot k\\_{2}=\\sqrt{H W}$. Note that $H=W=224$ is popular in classification. Without loss of generality, square sub-windows are used, i.e., $k\\_{1}=k\\_{2}$. Therefore, $k\\_{1}=k\\_{2}=15$ is close to the global minimum for $H=W=224$. However, the network is designed to include several stages with variable resolutions. Stage 1 has feature maps of $56 \\times 56$, the minimum is obtained when $k\\_{1}=k\\_{2}=\\sqrt{56} \\approx 7$. Theoretically, we can calibrate optimal $k\\_{1}$ and $k\\_{2}$ for each of the stages. For simplicity, $k\\_{1}=k\\_{2}=7$ is used everywhere. As for stages with lower resolutions, the summarizing window-size of GSA is controlled to avoid too small amount of generated keys. Specifically, the sizes of 4,2 and 1 are used for the last three stages respectively.","description_state":"present","introduced_year":null,"introduced_by":{"title":"Twins: Revisiting the Design of Spatial Attention in Vision Transformers","paper":"/paper/twins-revisiting-spatial-attention-design-in","first_author":"Xiangxiang Chu","n_authors":8,"url_abs":null,"archive_paper_url":"https://paperswithcode.com/paper/twins-revisiting-spatial-attention-design-in"},"source":{"url":"https://arxiv.org/abs/2104.13840v4","title":"Twins: Revisiting the Design of Spatial Attention in Vision Transformers","url_on_a_paper_host":true},"code_snippet_url":null,"code_snippet_url_on_a_code_host":false,"categories":[{"area":"General","area_id":"general","collection":"Attention Mechanisms","url":"/methods/category/attention-mechanisms","pwc_aliases":["attention-mechanisms-1"]}],"n_papers_tagged":2,"archive_num_papers":2,"papers_newest_first":[{"paper":null,"title":"Logically at Factify 2: A Multi-Modal Fact Checking System Based on Evidence Retrieval techniques and Transformer Encoder Architecture","date":"2023-01-09","arxiv_id":"2301.03127","n_code_links":0,"syntology":null},{"paper":"/paper/twins-revisiting-spatial-attention-design-in","title":"Twins: Revisiting the Design of Spatial Attention in Vision Transformers","date":"2021-04-28","arxiv_id":"2104.13840","n_code_links":9,"syntology":{"ran":0,"of":2,"unverified":2,"pointer_only":2}}],"papers_shown":2,"tasks":[{"task":null,"name":"Avg","papers":1},{"task":"/task/benchmarking","name":"Benchmarking","papers":1},{"task":"/task/fact-checking","name":"Fact Checking","papers":1},{"task":"/task/fact-verification","name":"Fact Verification","papers":1},{"task":"/task/image-classification","name":"Image Classification","papers":1},{"task":"/task/retrieval","name":"Retrieval","papers":1},{"task":"/task/semantic-segmentation","name":"Semantic Segmentation","papers":1}],"tasks_shown":7,"n_tasks":7,"usage_by_year":[{"year":"2021","papers":1},{"year":"2023","papers":1}],"row_source":"methods_table","archive":{"source":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","archive_url":"https://paperswithcode.com/method/global-sub-sampled-attention"},"syntology_read_at":"2026-09-24T18:15:14+00:00"}