Abstract
Standard Transformer attention mechanisms rely on Softmax-normalized weights, which often obscure subtle contextual signals and introduce structural biases like attention sinks. We present RCStat, a statistical framework that analyzes raw attention logits to quantify "Relative Contextualization" (RC). By treating pre-softmax scores as random variables, RCStat enables precise token attribution and efficient KV cache compression—reducing memory usage by up to 80%—without requiring model retraining. Our results across multiple benchmarks demonstrate that RCStat significantly outperforms heuristic-based methods in both generation quality and attribution accuracy.
Introduction
In a standard Transformer, the attention mechanism calculates relevance scores between tokens using a dot product, which is then passed through a Softmax function. While Softmax is necessary for training, it creates a "structural bias" during inference by aggressively sharpening the highest scores and flattening everything else. This leads to two major issues:
- Information Loss: Subtle but meaningful contextual signals are "squashed," making it difficult to identify which tokens truly drive specific outputs.
- Attention Sinks: Softmax often forces the model to allocate disproportionate attention to irrelevant tokens (like the start-of-sentence
<s>token), leading to sub-optimal memory management in the Key-Value (KV) cache.
RCStat addresses these challenges by operating directly in the logit space (pre-softmax) to recover the raw signal.
Methodology: Relative Contextualization
The core of RCStat is the Relative Contextualization (RC) metric, a probabilistic framework that distinguishes between Cross-Contextualization (CC)—how the prompt influences the generation—and Self-Contextualization (SC)—how generated tokens influence each other.
By modeling attention scores as random variables, RC measures how much more a prompt segment influences a generation compared to the generation's own internal influence. To maintain computational efficiency, the authors derive a practical upper bound based on the "Area Under CDFs" (Cumulative Distribution Functions), reducing the complexity from $O(n^3)$ to $O(n \log n)$. This allows for Adaptive Eviction in KV cache compression, where the framework identifies which attention heads are performing the most contextual work and preserves their memory while pruning others.
Evaluation and Key Results
The framework was evaluated using LLaMA-3 (3B and 8B) models across diverse benchmarks, including SQuAD v2.0 (QA), QMSum (summarization), and VERI-GRAN (grounded generation).
KV Cache Compression
RCStat improves generation quality by 15–40% compared to state-of-the-art methods like SnapKV or H2O at high compression ratios. By intelligently selecting heads to prune, it achieves 2–5% higher total compression with minimal quality loss.
Attribution Accuracy
By selecting only the top 2% of attention heads ranked by RC, the framework boosted attribution accuracy by 2–3% on summarization and QA benchmarks. Conversely, using the "worst" heads caused accuracy to plummet, confirming that RC successfully identifies the most informative components of the model.
Task and Layer Insights
- The Middle Layer: The most influential "contextualizing" heads consistently reside in the middle layers of the model.
- Task Complexity: Complex tasks like multi-sentence summarization recruit significantly more high-RC attention heads (up to 9x more) than simpler tasks, suggesting RC can serve as a proxy for task difficulty.
Conclusion and Future Work
RCStat provides a principled, zero-shot upgrade for existing LLM deployments, requiring no retraining or fine-tuning. While it excels at chunk and sentence-level attribution, scaling to extremely fine-grained token-level attribution in overlapping regions remains a challenge. Future research will focus on deriving formal probabilistic guarantees and exploring the use of RC for real-time hallucination detection by measuring how well a model grounds its output in the provided context.
Summary updated