Abstract
Large Language Models (LLMs) are traditionally limited by the quadratic computational complexity of self-attention, making long-context processing computationally expensive. While Sliding Window Attention (SWA) offers a linear-time alternative, its direct application often leads to performance collapse due to the "attention sink" phenomenon. This paper introduces SWAT (Sliding Window Attention Training), a modified Transformer architecture designed from the ground up for efficient long-context handling. By replacing softmax with sigmoid attention and utilizing balanced linear biases, SWAT enables effective layer-by-layer information compression. Our results show that SWAT outperforms state-of-the-art linear recurrent models on commonsense reasoning while maintaining linear inference complexity.
The Problem: Attention Sinks and Performance Collapse
Standard LLMs rely on the softmax function, which forces attention weights to be sparse. This often leads to "attention sinks," where the model disproportionately focuses on initial tokens to serve as numerical anchors.
When a sliding window is applied during inference to a model not trained for it, these critical initial tokens are eventually evicted from the window. This causes the attention distribution to collapse, leading to a catastrophic loss of coherence and performance.
As shown in Figure 6, standard models like Mistral-7B-v0.1 exhibit a sharp increase in perplexity as the evaluation length exceeds the fixed window size, rendering them ineffective for long-document processing without specialized training.
The SWAT Architecture
To overcome these limitations, SWAT introduces three fundamental changes to the Transformer block, designed to facilitate continuous information flow even as tokens are evicted from the local window.
1. Sigmoid Attention
SWAT replaces the traditional softmax activation with a sigmoid function. Unlike softmax, which forces tokens to compete for a fixed probability mass, sigmoid evaluates each token independently. This prevents "winner-takes-all" sparsity and allows the model to maintain dense attention weights. These dense weights enable token embeddings to act as high-capacity memory states, carrying historical information forward through the network.
2. Balanced ALiBi and RoPE
To manage the dense representations created by sigmoid attention, SWAT uses a bidirectional version of Attention with Linear Biases (ALiBi). By using both negative slopes (to focus on recent context) and positive slopes (to preserve historical context), the model can effectively differentiate between tokens. Additionally, Rotary Position Embeddings (RoPE) are included to provide explicit positional signals, ensuring training stability.
3. Training with SWA
Unlike methods that apply sliding windows only at inference, SWAT is trained with SWA from the start. This forces the network to learn how to compress and pass information from "invisible" (evicted) tokens up through the layers. As illustrated in Figure 1, the effective receptive field grows linearly with the number of layers, allowing the model to "remember" context far beyond its immediate window.
Experimental Results
SWAT was evaluated against several state-of-the-art linear and recurrent architectures, including Mamba, RetNet, and Titans.
- Commonsense Reasoning: At the 340M parameter scale, SWAT achieved an average accuracy of 46.88% across eight benchmarks (including HellaSwag and ARC), surpassing Mamba (43.59%) and Titans (46.17%).
- Scaling and Stability: At 760M parameters, the model's performance improved to 51.85%, demonstrating robust scaling behavior.
- Length Extrapolation: SWAT models maintained low perplexity on sequences up to 16,384 tokens, even when trained on much shorter contexts. This contrasts sharply with vanilla Transformers, which degrade rapidly beyond their training length.
Conclusion and Future Work
SWAT demonstrates that the core Transformer architecture can be adapted for linear-time long-context processing without moving to entirely new paradigms. By addressing the softmax-induced attention sink problem, SWAT provides a path toward highly efficient LLMs capable of processing virtually infinite context. Future research will focus on adaptive window sizes and integrating explicit retrieval mechanisms to further enhance the model's ability to handle ultra-long sequences without information decay.
Summary updated