Semi-Local Attention (SLA) is a hybrid attention mechanism integrating fixed sliding-window and residual linear streams to capture both local and global contexts.
It efficiently scales with sequence length by reducing computational and memory costs compared to full-attention models.
Kernel optimizations enable SLA to run effectively on modern accelerators, making it practical for large-scale transformer architectures.
Semi-Local Attention (SLA) is a hybrid attention mechanism that integrates a fixed-size sliding-window (local) attention with a residual linear-attention stream designed to capture contextual information from tokens outside the window. Introduced in the context of the RATTENTION model, SLA addresses intrinsic limitations of local-global attention architectures by enabling efficient context aggregation that scales favorably with sequence length, while maintaining or exceeding the accuracy of full-attention models at drastically reduced computational and memory costs (Wang et al., 18 Jun 2025).
Given Q,K,V∈Rn×d (queries, keys, and values), for each position i∈[1,n], compute attention coefficients αi,j for the window j∈[max(1,i−w+1),i]: αi,j=∑k=max(1,i−w+1)iexp(QiKk⊤/d)exp(QiKj⊤/d)
The local attention output: yiswa=j=max(1,i−w+1)∑iαi,jVj
1.2 Residual Linear Attention
A feature map ϕ:Rd→Rd′ satisfying ⟨ϕ(x),ϕ(x′)⟩≈exp(x⊤x′/d) is employed. In practice, ϕ(x)=exp(x) (elementwise), with RMSNorm. The recurrent state St∈Rd′×d is updated sequentially: i∈[1,n]0
At position i∈[1,n]1, the RLA stream reads from i∈[1,n]2: i∈[1,n]3
For i∈[1,n]4, i∈[1,n]5.
1.3 Fusion
Both streams are fused: i∈[1,n]6
i∈[1,n]7 is projected via i∈[1,n]8 before the standard Transformer residual and feed-forward blocks.
2. Layerwise Algorithmic Workflow
A single Transformer layer with SLA operates as follows:
Linear Projection:i∈[1,n]9, αi,j0, αi,j1 for layer input αi,j2.
Iteration (across αi,j3):
Compute sliding-window attention over αi,j4.
Update αi,j5.
Read residual stream αi,j6 (αi,j7 if αi,j8).
Fuse: αi,j9 as above.
Output:j∈[max(1,i−w+1),i]0.
Feed-forward:j∈[max(1,i−w+1),i]1.
Architecturally, RATTENTION interleaves three SLA layers with one full-attention layer.
3. Computational Complexity Analysis
The table below summarizes comparative asymptotic costs, where j∈[max(1,i−w+1),i]2 sequence length, j∈[max(1,i−w+1),i]3 hidden size, j∈[max(1,i−w+1),i]4 window size, j∈[max(1,i−w+1),i]5:
The local part matches SWA cost; the linear part adds αi,j=∑k=max(1,i−w+1)iexp(QiKk⊤/d)exp(QiKj⊤/d)2 extra time and αi,j=∑k=max(1,i−w+1)iexp(QiKk⊤/d)exp(QiKj⊤/d)3 memory.
SLA provides a strict efficiency gain when αi,j=∑k=max(1,i−w+1)iexp(QiKk⊤/d)exp(QiKj⊤/d)4 and αi,j=∑k=max(1,i−w+1)iexp(QiKk⊤/d)exp(QiKj⊤/d)5; αi,j=∑k=max(1,i−w+1)iexp(QiKk⊤/d)exp(QiKj⊤/d)6 is a constant-size recurrent state.
SLA sits between local and global attention, offering a trade-off unattainable by either independently.
4. Kernel and Implementation Considerations
RATTENTION employs two kernel optimizations to ensure SLA’s practicality on accelerators (e.g., TPU, GPU):
“Emergent Mind helps me see which AI papers have caught fire online.”
Philip
Creator, AI Explained on YouTube
Sign up for free to explore the frontiers of research
Discover trending papers, chat with arXiv, and track the latest research shaping the future of science and technology.Discover trending papers, chat with arXiv, and more.