Abstract
Taipan is a hybrid language model architecture that combines the linear efficiency of Mamba-2 with "Selective Attention Layers" (SALs). By dynamically choosing only the most critical tokens to process with softmax attention, Taipan achieves Transformer-level retrieval performance while maintaining the low latency and constant memory scaling of State Space Models, even at context lengths of up to 1 million tokens.
Introduction: The Long-Context Challenge
The "long-context" problem remains a primary hurdle in Natural Language Processing. Standard Transformers rely on self-attention, which suffers from quadratic computational cost ($O(L^2)$) and linear memory growth for the KV cache. This makes processing very long documents prohibitively expensive.
Recent State Space Models (SSMs) like Mamba offer a promising alternative with linear scaling ($O(L)$) and constant memory usage during inference. However, SSMs are "Markovian"—they compress the entire history into a fixed-size hidden state. This compression leads to information loss, causing SSMs to struggle with "needle-in-a-haystack" retrieval tasks or complex, non-local dependencies that Transformers handle with ease. Taipan bridges this gap, creating a model as efficient as an SSM but as expressive as a Transformer.
Methods: Selective Attention Layers
Taipan introduces a hybrid approach that intersperses Mamba-2 blocks with Selective Attention Layers (SALs). The core innovation lies in how these SALs operate to maintain efficiency without sacrificing the high-fidelity retrieval of attention mechanisms.
The SAL Pipeline
- Gating Network: For every token, a lightweight gating network uses a Gumbel-Softmax trick to decide whether that token is "important" enough to require attention.
- Feature Refinement: Tokens selected for attention undergo a refinement step (using a SwiGLU-like structure) to filter out noise and sharpen their representations.
- Selective Softmax Attention: Only the selected tokens are passed through a Softmax Attention module. To maintain efficiency, Taipan utilizes Sliding Window Attention (SWA) with a window size of 2048.
- Attention Budgeting: To prevent the model from attending to every token, a budget constraint loss forces the model to select only a predefined fraction of tokens (e.g., 15%) for attention.
- Positional Embedding Removal: Removing positional embeddings from the attention module significantly improved the model's ability to extrapolate to context lengths far beyond its training window.
Experimental Setup
The models (scaled at 190M, 450M, and 1.3B parameters) were pre-trained on a diverse 300-billion-token corpus including mathematics (MetaMathQA), web/code (Fineweb-Edu, Starcoderdata), and general knowledge (Wikipedia). Evaluation focused on standard zero-shot benchmarks and specialized retrieval tasks (SWDE, FDA, SQuAD) designed to test long-range memory.
Key Results and Insights
Performance and Retrieval
The 1.3B Taipan model outperformed both Mamba-2 and Transformer++ baselines on zero-shot tasks, averaging 53.3% accuracy. In memory-intensive tasks like structured information extraction, Taipan significantly outperformed pure SSMs, proving that the selective attention mechanism successfully addresses the "SSM retrieval gap."
Extreme Context Extrapolation
While trained on 4,096-token sequences, Taipan maintained stable perplexity and high accuracy on sequences up to 1 million tokens. As shown in the performance metrics, Taipan avoids the "Out of Memory" (OOM) errors and perplexity spikes that plague Transformers and other hybrid models at scale.
Efficiency and Synergy
Taipan demonstrated significantly lower latency and better scaling than Transformers or Jamba as generation length increased. This is driven by the "Not All Tokens are Equal" hypothesis: most tokens can be handled by the compressed memory of an SSM, while only a small subset of "anchor" tokens requires the high-fidelity access provided by attention. By enforcing a strict attention budget, the model learns to be highly strategic about its memory allocation.
Limitations and Future Work
While 1.3B parameters provide a strong proof-of-concept, the model has not yet been tested at the "frontier" scale (7B+ parameters). Additionally, the current implementation of the gating mechanism could be further optimized at the kernel level (e.g., via specialized CUDA kernels) to improve speed. Finally, performance remains sensitive to the attention budget, suggesting a delicate balance between efficiency and expressivity that may vary by task.
Summary updated