The standard self-attention mechanism fundamentally changed how neural networks process sequential and spatial data. By computing pairwise interactions between every single element in an input, Transformers capture long-range dependencies without the inductive biases of local receptive fields found in convolutional networks.
However, this global expressivity comes at a steep price. The computational and memory complexity of standard multi-head self-attention scales quadratically ($O(N^2)$) with the number of input tokens $N$. In computer vision, where an image is typically divided into a grid of patches, this quadratic bottleneck severely limits the network's ability to process high-resolution images, multi-dimensional medical data, or long video sequences.
To understand why this bottleneck occurs and how modern architectures bypass it, we can look at the core mathematical operation of attention and the diverse strategies researchers have developed to linearize or sparsify it.
The Root of the Problem: Full Matrix Scaling
In a standard Vision Transformer (ViT), an image of resolution $H \times W$ is split into patches of size $P \times P$, resulting in $N = (H \cdot W) / P^2$ tokens. The attention matrix is computed as:
$$\text{Attention}(Q, K, V) = \text{softmax}\left(\frac{QK^T}{\sqrt{d_k}}\right)V$$
Here, $Q$ (Queries) and $K$ (Keys) both have dimensions $N \times d_k$. The product $QK^T$ yields an $N \times N$ matrix representing the affinity between every patch and every other patch.
Standard Attention:
[ Queries ] [ Keys^T ] [ Attention Matrix ]
(N x d_k) * (d_k x N) = (N x N) -> Requires O(N^2) compute/memory
If we double the resolution of an image (e.g., moving from $224 \times 224$ to $448 \times 448$), the number of tokens $N$ quadruples. Consequently, the size of the attention matrix increases by a factor of $16$. As noted by Sucheng Ren et al. in SG-Former and Rajat Koner et al. in LookupViT, this scaling behavior makes processing high-resolution imagery prohibitively expensive for standard architectures, particularly on resource-constrained edge devices.
To break this bottleneck, researchers have converged on four primary paradigms: Token Sparsification, Mathematical Linearization, Localized Windowing, and Linear State Space Models.
Strategy 1: Token Sparsification and Dynamic Reallocation
The most intuitive way to reduce $O(N^2)$ complexity is to make $N$ smaller. Not all regions of an image contain equal amounts of information; a uniform grid allocates the same computational budget to a blank background as it does to a complex foreground object.
Dynamic Significance Mapping
Instead of treating all patches equally, architectures can dynamically allocate tokens based on visual salience. For instance, SG-Former introduces an evolving token reallocation strategy. It computes a "significance map" to identify regions of interest, preserving a high density of tokens for detailed foreground objects while aggregating background patches into fewer, coarser tokens. Similarly, Not All Tokens Are Equal proposes TCFormer, which abandons rigid grids entirely in favor of dynamic, semantic-based token clustering to focus computation on critical regions like human faces or hands.
Information Compression and Early Pruning
Another approach is to compress the token space before performing heavy global attention. The authors of LookupViT achieve this by compressing high-resolution visual data into a tiny set of "compressed tokens" for global processing, while maintaining the original high-resolution tokens in a lightweight "lookup" stream.
Furthermore, token redundancy often increases in the deeper layers of a network. In Large Vision-Language Models (LVLMs), Liang Chen et al. demonstrate in An Image is Worth 1/2 Tokens After Layer 2 that deeper layers largely ignore a significant portion of visual tokens. By implementing a plug-and-play pruning method (FastV) that discards redundant visual tokens after the early layers, they slash computational costs by up to 45% with virtually no loss in performance. A systematic evaluation of these strategies in Which Tokens to Use? confirms that even straightforward Top-K token pruning serves as a highly resilient baseline for accelerating inference.
Strategy 2: Linearizing Attention via Matrix Associativity
If we can eliminate the non-linear $\text{softmax}$ function between $Q$ and $K^T$, we can leverage the associative property of matrix multiplication to change the order of operations.
$$\text{Linear Attention: } (Q K^T) V \rightarrow Q (K^T V)$$
Computing $K^T V$ first results in a matrix of size $d_k \times d_v$. Multiplying $Q$ by this intermediate matrix takes $O(N \cdot d_k \cdot d_v)$ time, which scales linearly with the sequence length $N$.
Linear Attention (Associative Property):
[ Queries ] ( [ Keys^T ] [ Values ] ) = [ Queries ] [ Intermediate ] = [ Output ]
(N x d_k) (d_k x N) (N x d_v) (N x d_k) (d_k x d_v) (N x d_v)
---------------------------------------------
Matrix size depends on channel dimension,
scaling linearly with token count N.
Softmax Approximations
The challenge lies in approximating the expressivity of the softmax function without actually computing the $N \times N$ matrix. In QT-ViT, the authors achieve this by approximating the standard softmax function using a quadratic Taylor expansion. By utilizing a mathematical "self-multiplication" trick to simplify the resulting Kronecker products, they preserve the high accuracy of second-order approximations while maintaining strict $O(N)$ linear scaling.
Alternatively, Lu Chi et al. bypass pairwise dot-products entirely in Non-Local Neural Networks With Grouped Bilinear Attentional Transforms by replacing standard attention with data-adaptive matrix multiplications ($Y = PXQ$), significantly lowering computational overhead for large-scale visual tasks.
Strategy 3: Localized Windowing and Structured Sparsity
Instead of allowing every token to attend to every other token globally, architectures can restrict the receptive field to local neighborhoods or structured sparse patterns, relying on hierarchical stacking to propagate information globally.
Shifted Windows and Channel Attention
A prominent example of this paradigm is found in TransDeepLab, which adapts the Swin Transformer's hierarchical, shifted-window attention mechanism for medical image segmentation. By bounding attention within local windows, the computational complexity scales linearly with image resolution while still allowing cross-window communication in subsequent layers. For autoregressive tasks like image compression, A. Burakhan Koyuncu et al. introduce Spatio-Channel Window Attention in Efficient Contextformer, optimizing context modeling by constraining attention to localized spatial and channel dimensions.
Log-Linear and Multiscale Hierarchies
For generative tasks like diffusion models, where long sequence lengths are common, standard attention becomes a massive bottleneck. To address this, Zeqi Xiao et al. propose Log-linear Sparse Attention (LLSA) in Trainable Log-linear Sparse Attention for Efficient Diffusion Transformers. LLSA uses a hierarchical selection process and a coarse-to-fine token enrichment strategy to reduce computational and memory complexity from $O(N^2)$ to $O(N \log N)$, enabling efficient high-resolution image and video generation.
Strategy 4: Replacing Attention with Linear State Space Models
A radical alternative to modifying the attention mechanism is replacing it entirely with architectures designed from the ground up to scale linearly. State Space Models (SSMs), such as Mamba, model sequences through continuous-time state equations that can be computed efficiently during training via parallelizable scans, and during inference as linear-time recurrences.
Multi-Directional 2D Scanning
Because SSMs are inherently 1D causal sequence models, adapting them to 2D visual data requires flattening the image grid into a sequence. To capture spatial context without quadratic costs, Yuan Shi et al. utilize an "Omni Selective Scan" mechanism in VmambaIR, which scans image tokens across six distinct directions to capture comprehensive long-range dependencies with linear complexity.
Visual State Space Model (SSM) Scanning:
[P1][P2][P3] Raster Scan: P1 -> P2 -> P3 -> P4 -> P5 -> P6
[P4][P5][P6] --->
[P7][P8][P9] Fractal Scan: Preserves 2D proximity by following space-filling curves
(e.g., Hilbert curves) to maintain local context in 1D.
To further optimize this process, Yuheng Shi introduces a "hierarchy within a hierarchy" in Multi-Scale VMamba, running 2D scans at multiple scales to eliminate spatial redundancy. To prevent the "forgetting" behavior typical of 1D scans on flattened images, Haoke Xiao et al. introduce FractalMamba in Boosting Vision State Space Model with Fractal Scanning. By utilizing fractal (Hilbert) scanning curves, the model flattens 2D images while preserving spatial proximity and structural integrity far better than traditional raster scans, offering a true linear-time alternative to high-resolution visual attention.