TL;DR
This paper introduces Attention-State Memory (ASM), a training-free approach that eliminates the need to compute attention over long prompt prefixes during inference. By externalizing prefixes into a compact, lookup-based dictionary of precomputed attention states, ASM reduces attention latency by up to 1.8× and cuts memory footprints by 80% while maintaining or exceeding downstream task accuracy.
What Problem Does This Paper Address?
Modern Large Language Model (LLM) applications frequently rely on long conditioning contexts—such as extensive in-context learning (ICL) examples, system instructions, or retrieved documents (RAG). However, keeping these long "prefixes" in the context window introduces two major structural costs:
- Prefix Decay: As the model generates text, its attention becomes diluted across newly generated tokens, causing the guiding influence of the initial prefix to fade.
- Inference Inefficiency: Standard attention computation scales linearly with prefix length. Even with prompt caching, loading massive Key-Value (KV) caches at every decoding step incurs severe memory bandwidth bottlenecks and latency overhead.
Existing solutions fall into two camps, both with significant downsides. Prefix compression methods shorten the prefix but still require the model to attend to it during inference. Prefix internalization methods use gradient-based fine-tuning to bake the prefix into the model's weights, which is computationally expensive and makes updating the prefix highly impractical.
Methods
The authors introduce Attention-State Memory (ASM), a training-free method that replaces inference-time attention over long prefixes with a lightweight dictionary lookup. ASM relies on a mathematical property known as the online-softmax identity, which allows attention over concatenated blocks of tokens to be losslessly decomposed and merged.
The workflow is split into two phases:
1. Offline Calibration Phase
Instead of saving raw KV pairs for the prefix, the authors run a forward pass over a small set of representative calibration queries. They collect the resulting attention outputs over the prefix and use K-means clustering to group similar query vectors into $K$ distinct centroids. These centroids form a per-layer dictionary where each entry maps a representative query to a precomputed attention state.
2. Online Inference Phase
When a user submits a new query, the model does not attend to the prefix tokens at all. Instead, it performs a fast cosine-similarity search to find the closest query centroid in the dictionary. It retrieves the precomputed attention state and mathematically merges it with the query's self-attention over the newly generated tokens. By utilizing hierarchical indexing, this lookup cost scales logarithmically ($O(\log K)$) rather than linearly.
Datasets
The method was evaluated using LLaMA-3.1-8B, LLaMA-3.2-3B, and Qwen3-8B across two primary paradigms:
- ManyICLBench & RuleArena (Reasoning): Evaluated on classification and reasoning subsets including
clinc150,banking77,trec,bbh_geometric_shapes,dialogre,math_counting, andgpqa_cot. - RuleArena (RAG): Tested on the
NBA benchmark, which involves a complex ~20K-token rulebook governing basketball player-trade regulations.
Key Insights and Ideas
- Composability Over Storage: The core "aha!" moment is that if you know how a certain type of query interacts with a prefix, you don't need the prefix's actual tokens or KV cache anymore. The attention state itself is a sufficient statistic.
- Curing Prefix Decay: Because the precomputed prefix attention state is explicitly merged at every step rather than competed against in a massive attention matrix, its influence does not decay as the generation grows longer.
- The Codebook Sweet Spot: Counterintuitively, bigger is not always better. The authors found that accuracy is non-monotonic relative to the number of memory entries ($K$). Performance peaks at intermediate codebook sizes (e.g., $K=4K$), meaning the optimal memory size is a task-specific hyperparameter independent of prefix length.
Key Results
- Latency Speedups: On ManyICLBench, ASM reduces attention latency by 1.36× at an 8K memory budget and achieves up to a 1.8× speedup at 16K entries compared to full-attention in-context learning.
- Memory Efficiency in RAG: On the NBA benchmark, ASM with 4K entries outperformed full-attention RAG while utilizing only 20% of its memory footprint.
Limitations and Future Work
The primary limitation of ASM is its reliance on the assumption that user queries exhibit local structure—meaning they cluster neatly around predictable topics or tasks (like specific intent classification or querying a static rulebook).
If an application encounters severe prefix drift—such as a long, highly erratic, multi-turn casual conversation where query distributions become entirely diffuse—the clustering mechanism begins to degrade. The authors note that exploring alternative, query-dependent retrieval strategies for non-stationary workloads remains an open and promising direction for future research.
Summary updated