Search arXiv⌕ Search

arXiv subjects

Yaoye Wang

Publications and source records attributed to Yaoye Wang.

3 recordsLinked to original sources

HeadMem: Turning an LLM's Retrieval Heads into a Compact Memory for Later Question

Documents, codebases and agent histories are read long before their questions arrive and are then queried many times. Their memory may serve any later question. Compressing the KV cache before the questions keeps this memory small but loses the evidence. Storing the full cache keeps the evidence but costs gigabytes per document, and dense retrievers bring an embedding model and an index of their own. We show that the LLM already contains a retriever that keeps the memory small and still finds the evidence. Its retrieval heads, detected once per model, find the evidence even when they read the question alone. They are token-matching heads, and masking them hurts the model's own long-context reading far more than masking random heads. \ours{} stores only the compressed keys of these heads, using $290\times$ less memory than the KV cache of Llama-3.1-8B. For each question, the heads' own softmax selects the tokens the model re-reads. It needs no training, no model besides the LLM and no pass over the context per question. On multi-question RULER-style contexts, \ours{} alone beats four KV compression methods by a wide margin. Because it only proposes tokens to re-read, it combines readily with the memories already in use. On Llama-3.1-8B it can share the token budget of a KV cache compressed by StreamingLLM or SnapKV and keep over 90\% of its full-budget score at every length. Fused with BM25 or a dense retriever, it beats BM25 and reranked dense RAG at 128k tokens on both this model and Qwen2.5-7B. \ours{} also works when question and evidence share no words, on long chat histories and beyond the model's context window.

cs.AI↗

S$^3$-Attention:Attention-Aligned Endogenous Retrieval for Memory-Bounded Long-Context Inference

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.

cs.CL↗

Unlocking the Address Book: Dissecting the Sparse Semantic Structure of LLM Key-Value Caches via Sparse Autoencoders

The Key-Value (KV) cache is the primary memory bottleneck in long-context Large Language Models, yet it is typically treated as an opaque numerical tensor. In this work, we propose \textbf{STA-Attention}, a framework that utilizes Top-K Sparse Autoencoders (SAEs) to decompose the KV cache into interpretable ``semantic atoms.'' Unlike standard $L_1$-regularized SAEs, our Top-K approach eliminates shrinkage bias, preserving the precise dot-product geometry required for attention. Our analysis uncovers a fundamental \textbf{Key-Value Asymmetry}: while Key vectors serve as highly sparse routers dominated by a ``Semantic Elbow,'' deep Value vectors carry dense content payloads requiring a larger budget. Based on this structure, we introduce a Dual-Budget Strategy that selectively preserves the most informative semantic components while filtering representational noise. Experiments on Yi-6B, Mistral-7B, Qwen2.5-32B, and others show that our semantic reconstructions maintain perplexity and zero-shot performance comparable to the original models, effectively bridging the gap between mechanistic interpretability and faithful attention modeling.

cs.LG↗