TL;DR
This paper introduces Multi-Token Attention (MTA), a novel attention mechanism for LLMs that addresses the limitation of standard attention by conditioning on multiple query and key tokens simultaneously. By employing convolutional operations across queries, keys, and heads, MTA captures richer contextual information, leading to improved performance on language modeling and long-context tasks.
What Problem Does This Paper Address?
Large Language Models (LLMs) heavily rely on the attention mechanism to weigh the importance of different parts of the input context. However, standard multi-head attention computes attention weights based on the similarity between a single query token and a single key token. This "single-token attention" creates a bottleneck, limiting the model's ability to capture nuanced relationships and identify relevant context, especially when multiple pieces of information are needed to pinpoint a specific piece of text. For instance, finding a sentence mentioning both "Alice" and "rabbit" is difficult if attention can only focus on one token at a time.
Methods
The core innovation is Multi-Token Attention (MTA). Instead of relying on pairwise query-key similarity, MTA introduces convolutional operations to aggregate information from multiple query and key vectors. This is achieved through two main components:
- Key-Query Convolution: This operation applies a 2D convolution over the attention logits (pre-softmax) or attention weights (post-softmax). It allows neighboring query and key tokens to influence each other's attention scores, enabling the model to consider a broader context for attention calculation.
- Head Mixing Convolution: This component applies a convolution across groups of attention heads. This allows different heads to share information and learn more complex interactions, further enriching the attention mechanism.
MTA also incorporates group normalization with scalar gating to improve gradient flow and model stability. The authors explore both pre-softmax and post-softmax applications of these convolutions, ultimately favoring the pre-softmax approach for its effectiveness.
Datasets
The paper uses the following datasets:
- SlimPajama: Used for pre-training 880M parameter models on 105B tokens for standard language modeling tasks.
- Motivating Toy Task: A custom dataset designed to highlight the limitations of standard attention and demonstrate MTA's capabilities.
- Long-Context Tasks:
- Needle-In-A-Haystack: Used to evaluate the model's ability to find specific information within long contexts.
- BabiLong: A benchmark for testing reasoning over long documents.
- Standard Benchmarks: BoolQ, PIQA, SIQA, HellaSwag, WinoGrande, ARC (easy and challenge), OpenBookQA, MMLU. These are used for evaluating general language understanding capabilities.
- LAMBADA: Used for evaluating next-word prediction in long contexts.
Key Insights and Ideas
- Beyond Pairwise Similarity: The fundamental insight is that attention shouldn't be limited to single query-key pairs. By allowing tokens to "look" at their neighbors in the attention space (both in terms of position and heads), MTA can capture more complex relationships.
- Convolution as a Context Aggregator: Applying convolutions to attention scores/weights is an effective way to aggregate information from multiple tokens and heads, mimicking how humans might process information by considering surrounding context.
- MTA Solves the "Alice and Rabbit" Problem: The paper illustrates how MTA can naturally handle queries that require information from multiple tokens, unlike standard attention which struggles to combine these signals effectively.
- Performance Gains Across Tasks: MTA demonstrates consistent improvements not only on specialized long-context tasks but also on standard language modeling and general benchmarks, suggesting its broad applicability.
- Minimal Parameter Overhead: MTA achieves significant performance gains with only a marginal increase in parameters, making it an efficient improvement.
Key Results
- Motivating Toy Task: MTA perfectly solves a challenging toy task where standard Transformers struggle, achieving near-zero error rates.
- Large Language Modeling: MTA pre-training on 105B tokens leads to improved validation perplexity and performance on downstream tasks compared to Transformer, DIFF Transformer, and Talking Heads attention baselines, with a parameter increase of only 0.001%.
- Long Context Tasks: MTA shows significant improvements on Needle-In-A-Haystack and BabiLong benchmarks, outperforming baselines by a considerable margin, especially when dealing with lengthy distraction text.
- Standard Benchmarks: MTA-trained models achieve higher average scores on a suite of standard benchmarks, even those not specifically designed for long contexts.
- Finetuning: Finetuning existing models (including Llama 3) with MTA leads to improved perplexity, demonstrating its adaptability.
Limitations and Future Work
- Compatibility with Optimized Kernels: The authors note that MTA is not currently compatible with popular optimized attention kernels, which impacts runtime performance. Optimizing MTA's implementation for efficiency is a key area for future work.
- Exploration of Kernel Patterns: While the paper visualizes MTA's key-query and head kernel patterns, a deeper exploration of their meaning and how they contribute to performance is suggested for future research.
- Further Optimization: The paper mentions that while MTA offers improvements, further optimization of its implementation for faster inference and training is a natural next step.
Summary updated