arXiv:2610.21483cs.AIOct 2026

Manuscript Offprint

arXiv:2610.21483

FlashAttention with Statistics: Low-Overhead Attention Features for Compact Hallucination Detectors

Andrei Volodichev, Maksim Savichev, Nikita Sviridov, Artem Yuliy, Dmitry Simakov, Alexey Zaytsev

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Large language models can produce fluent answers that the supplied context does not support. A compact frozen proxy model can detect such answers by reading the context and another model's response, even from a proprietary generator. Attention-based detectors use summary statistics of the proxy's attention weights, but standard pipelines materialize the attention matrix, whose memory grows quadratically with sequence length. We compute these statistics without materializing attention, by accumulation in the FlashAttention pass, sparse lookups after it, or a second tiled pass over the scores, and classify them by this path into nearly free and costlier ones. On an H100, the statistics of five published detectors add 16% to the latency of a Qwen3-8B forward at 2K tokens, falling to 1.4% at 35K, and store 22.5 KiB per response token. On three benchmarks, probes trained on frozen Qwen3 proxies of 0.6B to 8B parameters prove strong detectors: a 4B proxy outperforms the strongest of nine 4–9B LLM judges in F1 on two of the three, the proxies match or outperform specialized grounding checkers of up to 7B parameters, probing each proxy beats prompting it as a judge, and adding attention features significantly improves F1 in half of the 12 benchmark–proxy pairs, never significantly lowering it.

1 Introduction

Contextual hallucination detection asks whether an answer is supported by the supplied information. The detector need not be the model that generated the answer: the generator may expose neither its weights nor its attention, while a separate detector can be much smaller and cheaper. A compact proxy instead reads the context and completed answer and uses its own internal signals to assess context reliance. Prior work has used surrogate probabilities to estimate black-box confidence (Shrivastava et al., 2023), auxiliary models to calibrate generators (Ulmer et al., 2024; Kapoor et al., 2024; Hayes et al.,

Figure

Figure 1: Cost of extracting all implemented attention statistics for hallucination detection in every layer of Qwen3-8B and Qwen3-0.6B using our kernels. Top: model forward-pass latency. Bottom: relative overhead compared with the same forward using standard scaled dot-product attention (SDPA), without statistic extraction.

2026), and hidden states or attention from reader models to detect hallucinations in another model's answers (CH-Wang et al., 2024; Han et al., 2025; Yeh et al., 2026; Singh et al., 2026).

Attention-based detectors need only summary statistics of attention weights, such as prompt mass (Chuang et al., 2024), diagonal or previous-token weights (Sriramanan et al., 2024; Vazhentsev et al., 2026), sink rates (Binkowski et al., 2026), or graph features (Bazarova et al., 2026). Yet standard pipelines materialize the full attention matrix. For a 32-head layer, it occupies about a gigabyte at 4K tokens and tens of gigabytes at 16K–32K, although the detector keeps only a linear number of statistics.

FlashAttention computes exact attention in tiles without storing this matrix (Dao et al., 2022; Dao, 2024). We compute detector statistics 1^{1} during or

1^{1}Code: https://anonymous.4open.science/r/attention-guardrails-0C16

(a) Two stages

(b) One pass: T1 rides along with FlashAttention

Figure

(c) Tiers by extra score work

score from the pass

scored again

stored

more extra work →

T1 fused

row sums Σjpijαg(j,sij)\Sigma_{j}p_{ij}^{\alpha}g(j,s_{ij})

Figure

e.g. entropy, prompt mass,

effective support, max weight

T2 lookup

weights at b fixed positions

Figure

e.g. log⁡pii,pi,i−1,BOSweight\log p_{ii}, p_{i,i-1}, BOS weight

T3 rescore

arbitrary reductions of pijp_{ij}

Figure

e.g. column sums cjc_j,

counts of pij>θp_{ij} > \theta

T4 dense

functions of the whole map

Figure

e.g. MTopDiv, stored maps

Figure 2: Attention with statistics. Blue: standard FlashAttention (Dao et al., 2022; Dao, 2024); green: our additions. (a) We compute statistics for response rows only; prompt rows can go through any production kernel ( §\S2.1). sIJs_{IJ}: scores of query tile I against key tile J. (b) One tile of the pass: the exponentials that FlashAttention already computes also feed the T1 statistics, which are finalized after the last tile; the pass also stores the log-sum-exp (LSE) that T2 and T3 reuse ( §\S2.2). (c) The four tiers, i.e. computation paths of a statistic, ordered by the extra work they need: none (T1, fused), a few positions per row (T2, lookup), a second pass over all scores (T3, rescore), or the whole stored map (T4, dense) ( §\S3).

right after that pass so they inherit its linear memory and most of its speed. We classify attention statistics, including those of published detectors, by how our implementation computes them exactly without the matrix: accumulation inside the pass, a fixed number of post-pass lookups, a second pass over the scores, or dense materialization (Figure 2). Our Triton implementation (Tillet et al., 2019) extends the FlashAttention-2 forward to compute the statistics of five published detectors: Lookback Lens (Chuang et al., 2024), LLM-Check (Sriramanan et al., 2024), RAUQ (Vazhentsev et al., 2026), INTRYGUE (Kuleshova et al., 2026), and SinkProbe (Binkowski et al., 2026). Extracting them from every head and layer adds 16% to a Qwen3-8B forward at 2K tokens and 1.4% at 35K, and stores 22.5 KiB per response token (Figures 1 and 6).

Our contributions are threefold. (i) We develop a taxonomy of attention statistics based on how they can be computed exactly without materializing attention maps, identifying which come almost for free with FlashAttention and which require a second pass. This taxonomy also guides the design of new inexpensive statistics. (ii) We implement these computation paths in Triton kernels and provide an attention backend, which we release publicly, that integrates them into existing model inference pipelines. Experiments evaluate their overhead and detection performance. (iii) We show that frozen Qwen3 proxies (0.6B–8B) can detect hallucinations in larger model's answers across three benchmarks. A 4B proxy outperforms the strongest of nine LLM judges (4B–9B) on two benchmarks, and even the smallest, 0.6B proxy beats it on the third and trails it by at most 0.03 F1 on the other two. Adding attention features significantly improves F1 in 6 of the 12 dataset–proxy pairs and never significantly lowers it, emphasizing the usefulness of attention statistics.

References (58)