Introduction
Sequence modeling has long been dominated by the Transformer architecture, which relies on the softmax attention mechanism. While highly effective, softmax attention suffers from quadratic computational complexity $O(L^2)$ relative to sequence length $L$, posing a significant bottleneck for long-range dependencies. Recent advancements in Linear Transformers and State Space Models (SSMs) have introduced linear-time alternatives $O(L)$. However, these models have primarily focused on causal (one-way) tasks. Bidirectional modeling—essential for tasks like image classification, DNA analysis, and masked language modeling—has remained fragmented, often relying on inefficient dual-scan approaches.
The LION (LInear attentiON) framework addresses this gap by systematically extending linear attention to bidirectional sequences. LION unifies full attention, bidirectional RNNs, and chunkwise representations into a single framework, enabling training speeds up to 10× faster than existing bidirectional SSMs while matching the accuracy of standard Transformers.
The LION Framework
The core of LION is the generalization of three theoretically equivalent representations for bidirectional modeling. This flexibility allows the model to switch between high-speed parallel training and memory-efficient inference.
1. Full Linear Attention
For maximum training throughput, LION utilizes a parallel matrix multiplication form. Unlike causal models that use a triangular mask, LION employs a bidirectional mask $M$ that incorporates decay properties. This allows the model to capture context from both the past and the future simultaneously.
As shown in the formulation above, the output $Y$ is computed by scaling the element-wise product of the attention matrix $A = QK^\top$ and the mask $M$, then multiplying by the value matrix $V$. The mask $M$ is structured to handle bidirectional dependencies with specific decay factors ($\lambda$), ensuring that distant tokens have a controlled influence on the current representation.
2. Chunkwise Parallel Form
To balance computational speed and memory usage, LION implements a chunkwise parallel representation. This method processes the sequence in discrete blocks (chunks), calculating "intra-chunk" dependencies locally and "inter-chunk" dependencies through a state-passing mechanism.
This representation is particularly effective for high-resolution data. By decomposing the computation into local blocks and a global state, LION avoids the memory explosion typical of standard Transformers while maintaining higher throughput than pure RNNs.
3. Bidirectional RNN
For inference, LION can be cast as a bidirectional Recurrent Neural Network (RNN). This allows for token-by-token processing with constant memory overhead $O(1)$ per step. A critical innovation in LION’s RNN form is a correction term that prevents "double-counting" the current token when merging the forward and backward hidden states, ensuring exact mathematical equivalence with the full attention form.
Experimental Evaluation
The researchers validated LION across a diverse set of benchmarks, comparing it against standard softmax Transformers (like DeiT and BERT) and modern SSMs (like Vision Mamba).
- Computer Vision: On ImageNet-1K, LION-D (fixed decay) and LION-S (selective decay) matched the accuracy of DeiT while offering significantly faster training. LION's linear scaling allowed it to process images at resolutions (e.g., 1248x1248) that would be computationally prohibitive for standard Transformers.
- Natural Language Understanding: In Masked Language Modeling (MLM) on the C4 dataset, a 334M parameter LION model performed on par with BERT-Large. Notably, LION was 3× faster to train, demonstrating its efficiency in large-scale NLP tasks.
- Long-Range Dependencies: On the PathX task from the Long Range Arena (LRA), which involves 16k token sequences, vanilla linear attention often fails. However, LION variants incorporating decay factors and proper initialization (HIPPO) successfully solved the task, highlighting the importance of the framework's flexible decay mechanism.
Key Insights and Future Directions
LION demonstrates that the efficiency of linear attention is not restricted to causal modeling. By providing a unified "recipe" to convert causal linear models into bidirectional ones, LION offers several key advantages:
- Hardware Efficiency: By relying on standard matrix operations rather than custom CUDA kernels, LION achieves superior training speeds on commodity hardware.
- Scalability: The RNN formulation ensures a flat memory profile during inference, enabling the processing of extremely long sequences or high-resolution images.
- The Role of Decay: The success on PathX underscores that learnable or input-dependent decay is crucial for capturing complex long-range patterns in linear models.
Future work includes integrating more complex gating mechanisms and scaling the architecture to multi-billion parameter models to further explore its potential in foundational sequence modeling.
Summary updated