[Paper Review] S$^3$-Attention:Attention-Aligned Endogenous Retrieval for Memory-Bounded Long-Context Inference
The paper proposes S3-Attention, an endogenous retrieval framework that converts long-context inference into a streaming, attention-aligned process using Top-k Sparse Autoencoders to build a CPU-based inverted index, achieving constant GPU memory while retaining near-full-context performance. A Hybrid variant combines endogenous signals with BM25 for robustness.
Large language models are increasingly applied to multi-document and long-form inputs, yet long-context inference remains memory- and noise-inefficient. Key-value (KV) caching scales linearly with context length, while external retrieval methods often return lexically similar but causally irrelevant passages. We present S3-Attention, a memory-first inference-time framework that treats long-context processing as attention-aligned endogenous retrieval. S3-Attention decodes transient key and query projections into top-k sparse feature identifiers using lightweight sparse autoencoders, and constructs a CPU-based inverted index mapping features to token positions or spans during a single streaming scan. This design allows the KV cache to be discarded entirely and bounds GPU memory usage by the scan chunk size. At generation time, feature co-activation is used to retrieve compact evidence spans, optionally fused with BM25 for exact lexical matching. Under a unified LongBench evaluation protocol with fixed prompting, decoding, and matched token budgets, S3-Hybrid closely matches full-context inference across multiple model families and improves robustness in several information-dense settings. We also report an engineering limitation of the current prototype, which incurs higher wall-clock latency than optimized full-KV baselines, motivating future kernel-level optimization.
Motivation & Objective
- Motivate memory-efficient long-context inference without the semantic mismatch of external retrievers.
- Develop an endogenous retrieval mechanism aligned with the model’s internal reasoning signals.
- Achieve O(1) GPU memory during prefill by streaming semantic indexing and discarding the KV cache.
- Propose S3-Hybrid by fusing endogenous signals with BM25 to enhance robustness.
- Demonstrate near-lossless performance across model families on LongBench.
Proposed method
- Transform dense internal Key/Query projections into discrete sparse semantic features via Top-k Sparse Autoencoders (SAEs).
- During streaming prefill, encode key projections into sparse feature IDs and build a CPU-based inverted index to discard the GPU KV cache (O(1) GPU memory).
- Query projections are decoded with the same SAE to obtain the model’s search intent and retrieve spans via feature co-activation.
- Compute semantic density scores using feature co-activation with the query, weighted by IDF to emphasize rare concepts, followed by smoothing and non-maximum suppression to select semantic-rich spans.
- Optionally fuse endogenous signals with BM25 lexical signals and a bias to form the final compressed context for generation (M_final = M_S3 ∪ M_BM25 ∪ M_Bias).
- Evaluate using LongBench across multiple models (Llama-3.1, Mistral, Qwen2) and compare against FullKV, RAG, and KV-cache compression baselines.

Experimental results
Research questions
- RQ1Can endogenous attention-aligned signals be discretized into a lightweight, searchable memory for long-context inference?
- RQ2Does an SAE-based sparse feature representation preserve causal evidence while reducing GPU memory usage?
- RQ3Can endogenous retrieval be competitive with RAG while maintaining constant GPU memory and avoiding external indexes?
- RQ4Does fusing endogenous signals with lexical retrieval (BM25) improve robustness across tasks?
- RQ5What is the information-theoretic trade-off between fluency and evidence fidelity when using S3-Attention?
Key findings
- S3-Hybrid retains 99.4% of full-context performance on Llama-3-8B (25.01 vs. 24.87) and over 99% on Qwen2-7B in a unified evaluation setup.
- Endogenous retrieval via SAE-based features yields higher signal-to-noise than exogenous RAG on information-dense tasks and demonstrates a denoising effect in some settings.
- Across LongBench, S3-Hybrid achieves near-lossless fidelity with O(1) GPU memory, outperforming or matching strong exogenous baselines in several scenarios.
- Layer-wise ablations show deeper semantic layers improve performance on reasoning tasks, with multi-layer fusion generally offering robustness across tasks.
- Information-theoretic analysis on HotpotQA indicates S3-Hybrid achieves favorable recall and lower KL divergence, placing it on the Pareto frontier for fluency vs. utility.

Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.