Several recent detectors catch a language model making things up by reading its internal computations instead of its output text. They check, for example, whether the attention heads that copy from a retrieved document actually fired, or whether late layers overwrote that evidence with memorized priors. Every one of these detectors was built and calibrated on a single reference implementation, usually a HuggingFace model running "eager" attention, which computes and stores every attention probability. Real deployments migrate the same weights into different runtimes: lower precision, fused attention kernels such as FlashAttention that never materialize the attention matrix, and serving engines like vLLM. Migration between deep-learning frameworks is known to introduce subtle numerical drift and silent interface changes. Nobody has asked what that drift does to detectors whose inputs are exactly those internal numbers.
This note proposes a migration study plus a concrete fix. First, we measure how much mechanistic hallucination detectors degrade, both in ranking quality and in calibration, when a model moves from its reference runtime to production runtimes, and which kinds of signal break. Second, we define a small "migration contract": a minimal set of tensors that every runtime can expose. We then show that attention-based hallucination features can be recomputed exactly from that set for a handful of selected heads, so a detector carries over to a fused-kernel runtime without falling back to slow eager attention. The deliverable is a measured answer to whether these detectors are deployable, and a way to make them so where they are not.
Why this gap, and why not the obvious one
The obvious combination of these three directions is a unified intermediate representation that lets a hallucination intervention be written once and run on any transformer. Here "intermediate representation" means a framework-neutral description of the model's computation graph. This builds on the pivot-format idea of Daoudi et al., which reduces N-to-N framework translation to N-to-pivot. It also builds on nnterp, which already standardizes module access across 21 transformer families.
We think that idea is mostly engineering, and largely solved at the access level. nnterp gives uniform names. Re-finding copying heads per model is cheap, as the needle-in-a-haystack probe in DeCoRe shows. A reviewer would reasonably say "just rerun the probe."
What nnterp explicitly cannot do is the harder, more scientific problem. It cannot track attention weights under FlashAttention, because the fused kernel bypasses the intermediate tensors. It also documents that upstream library updates (HuggingFace v4.54) silently change return types. Separately, A First Look at Bugs in LLM Inference Engines documents that serving engines themselves have structural bugs. The question we target is therefore not "can we name the heads everywhere" but "do the detector's numbers mean the same thing after migration, and can we still compute them at all."
The detectors we study each depend on a different part of the internals:
- ReDeEP combines two scores in a logistic regression. The first, an external-context score, measures how much copying heads move context tokens into the model's running hidden state. The second, a parametric-knowledge score, uses the logit lens (projecting intermediate hidden states into vocabulary space) to measure how much feed-forward layers shift the output distribution.
- CHARM runs a graph neural network over token-to-token attention edges from all layers.
- RHD uses only layerwise logit-lens divergence.
These dependencies motivate the study. ReDeEP and CHARM consume attention probabilities, which fused kernels hide. RHD and ReDeEP's parametric score consume only hidden states between layers, which every runtime can expose. The detectors therefore span the range from "should migrate easily" to "cannot run as written." That spread lets us test a specific hypothesis: hidden-state signals survive migration after recalibration, while attention signals do not survive without help.
Core Claim
We make two claims.
The first is empirical. Applying a mechanistic hallucination detector, unchanged, to a migrated runtime produces two kinds of failure. Numerical drift from bf16 arithmetic and kernel reordering shifts detector scores enough to break the reference decision threshold, even when ranking quality (AUROC, the area under the ROC curve) is roughly preserved. Attention-based features cannot be produced at all under fused kernels.
The second is methodological. The attention features these detectors actually use are low-dimensional summaries, mostly "how much attention mass does head h place on the retrieved context." Such a summary can be reconstructed exactly from a migration contract consisting of three things:
- the hidden state at layer boundaries;
- the query and key vectors of a small selected set of heads;
- the per-row softmax normalizer, i.e. the log-sum-exp of attention scores, which FlashAttention already computes and saves for its backward pass.
For a selected head with query $q_t$ at generated position $t$, keys $k_j$, head dimension $d$, and per-row log-sum-exp $L_t$, the attention mass on the retrieved-context positions $C$ is
$$ m_t^{(h)} = \sum_{j \in C} \exp\!\left(\frac{q_t \cdot k_j}{\sqrt{d}} - L_t\right). $$
This equals the eager-attention quantity up to floating-point error.
The cost depends on whether the runtime exposes $L_t$. If it does, computing $m_t^{(h)}$ costs one pass over the context keys for each selected head. If it does not, as may be the case in vLLM's paged attention, $L_t$ must be recomputed for each selected head, which costs one pass over all keys. Either way, the extra cost scales with the number of selected heads times sequence length. It does not scale with all heads in all layers, which is what eager attention pays. If ReDeEP's copying heads and DeCoRe's retrieval heads number in the tens, this should keep overhead small. Measuring that overhead is one of the decisive checks.
Research Program
Migration matrix. We fix model weights and build four runtimes for each model:
- HuggingFace eager attention in fp32, the reference;
- HuggingFace scaled-dot-product attention in bf16;
- FlashAttention-2 in bf16;
- vLLM.
A fifth condition crosses a HuggingFace version boundary, the v4.54 change nnterp flagged, to test silent interface breakage. Models are LLaMA-2-7B (where ReDeEP and CHARM report numbers), Mistral-7B-instruct (CHARM), and one reasoning model from the RHD study. All internal access goes through nnterp's standardized accessors so that differences come from numerics, not from naming. Where a runtime exposes no hooks, we teacher-force the same response tokens through it and read the contract tensors. This keeps the text identical across runtimes and isolates internal-signal drift from generation drift.
Drift audit. For identical inputs and outputs, we measure the following:
- per-layer hidden-state divergence;
- the rank correlation of each detector's per-example scores between reference and target runtime;
- the AUROC change;
- the F1 change at the reference-calibrated threshold.
The last is the deployment-relevant number, since a detector ships with a threshold.
Contract implementation. We implement exact attention-mass recomputation for selected heads in each runtime: reading $L_t$ from FlashAttention where it is exposed, and recomputing it for selected heads otherwise. We then rebuild ReDeEP's context score, a Lookback-style context-attention ratio, and a sparsified CHARM graph from contract tensors only.
CHARM is the stress case. It needs edges from all heads, but it reports that pruning low-attention edges removes up to 98% of edges with little accuracy loss. We test whether restricting edges to response-to-context attention in a selected subset of heads keeps most of its accuracy.
Signal-family analysis. We group features into hidden-state-only features (logit-lens divergence, activation probes) and attention-derived features. We report which group is migration-stable, which tells practitioners what to build detectors from in the first place.
Baselines
The do-nothing reference is each detector trained and thresholded on the eager fp32 reference, then applied unchanged to the migrated runtime. Where attention probabilities are unavailable, the reference falls back to the detector's hidden-state features alone. This baseline measures the cost of ignoring migration. It is run on exactly the same teacher-forced RAGTruth responses as every other condition.
The strongest existing method on our main benchmark is ReDeEP. It reports a chunk-level AUC of 0.7458 on RAGTruth with LLaMA-2-7B, against 0.7290 for RAGAS and 0.5844 for SelfCheckGPT. It is the strongest competitor because it is the best reported mechanistic detector on RAG hallucination and it depends on both attention and hidden-state signals. We first reproduce it on the eager reference. We count the proposal as beating the migration problem when the contract-based ReDeEP on FlashAttention and vLLM comes within 0.005 AUC of our reproduced reference, and recovers reference-threshold F1 without retraining.
On Natural Questions, the comparison point is CHARM at 74.8% AUROC, against activation probes at 73.0% and the best attention heuristic at 71.9%. On ReTruthQA math, it is RHD at 0.7978 AUC.
A re-tune baseline retrains the logistic regression and recalibrates thresholds on the target runtime, using the same labeled training split and the same tuning budget as the reference. This tells us whether the contract adds anything beyond recalibration.
An eager-fallback baseline routes monitored requests through eager attention to obtain true attention probabilities. It is matched on hardware and batch size, and reported in throughput and peak memory as well as AUROC.
The key ablation replaces exact recomputation with a cheap proxy that needs no queries or keys: the norm of each selected head's output vector. This isolates whether exactness matters or whether any head-level magnitude signal suffices.
Why not just…?
Why not just retrain the detector on each new runtime? For hidden-state-only detectors this may be the whole answer, and we will report it as such. If recalibrated RHD or logit-lens features recover reference AUROC on every runtime, the drift half of the problem reduces to "always recalibrate." Retraining cannot help an attention-based detector on a runtime that never produces attention probabilities, however. Retraining also needs labeled data generated through each runtime and repeated after every library update. Given nnterp's report of silent return-type changes, that is the condition under which teams would not notice they needed it. The re-tune baseline settles the first point directly.
Why not just use eager attention when you want to monitor? This is a real threat for short contexts at 7B scale, where eager attention's memory cost may be tolerable. Its overhead grows with context length and covers every head in every layer. Our recomputation touches only a few selected heads. We will report the crossover context length at which eager fallback becomes unaffordable. If no such crossover appears within RAGTruth-scale contexts, the contract's value is limited to longer-context deployments, and we will say so.
Why not just drop attention features and use hidden-state probes, which migrate trivially? This is the most serious alternative. On Natural Questions, CHARM reports activation probes at 73.0% against 74.8% for its attention graph, a small gap. On Math the gap is 78.1% versus 81.7%. ReDeEP's finding that in 65–77% of hallucinations attention did reach the right context, only to be overridden later, cuts both ways. It suggests attention signals carry information hidden-state signals lack, but also that the decisive event happens in the feed-forward layers. Our signal-family analysis tests this head-on. If hidden-state-only detectors match the contract-based detectors after migration, the recommendation becomes "build detectors from hidden states," which is still a useful, falsifiable outcome of the study.
Why not just ask a strong external model to check outputs? Such a judge is unaffected by migration, but RAGTruth reports that prompted GPT-4 reaches only 63.4% response-level F1 and 28.3% span-level F1, against 78.7% and 52.7% for a fine-tuned detector. RHD's authors also note that judges are fooled by fluent reasoning. We include no judge baseline beyond these reported numbers.
Proposed Experiments
The primary experiment runs ReDeEP, a Lookback-style context-attention detector, and sparsified CHARM on RAGTruth's question-answering, data-to-text, and summarization splits. It covers the full migration matrix with LLaMA-2-7B and Mistral-7B, and reports AUROC, reference-threshold F1, score rank correlation, tokens per second, and peak memory. It is repeated on Natural Questions for CHARM. RHD is run on ReTruthQA as the hidden-state-only control.
There are three decisive checks:
- Exactness. Contract-recomputed attention mass must match eager-attention mass to within bf16 tolerance on selected heads. Without this, the method claim fails.
- Drift. The do-nothing reference must lose measurable reference-threshold F1 on at least the bf16 fused-kernel runtimes. If it does not, the migration problem is smaller than claimed and the paper becomes a negative result.
- Overhead. Contract-based detection on FlashAttention must beat eager fallback on throughput at equal AUROC.
A secondary check generates fresh responses natively in each runtime rather than teacher-forcing. This tests whether generation drift changes the hallucination labels themselves, which would bound how much any internal-signal fix can recover.
References
- Towards Migrating Neural Network Implementations
- nnterp: A Standardized Interface for Mechanistic Interpretability of Transformers
- DeCoRe: Decoding by Contrasting Retrieval Heads to Mitigate Hallucinations
- A First Look at Bugs in LLM Inference Engines
- ReDeEP: Detecting Hallucination in Retrieval-Augmented Generation via Mechanistic Interpretability
- Neural Message-Passing on Attention Graphs for Hallucination Detection
- Mechanistic Detection and Mitigation of Hallucination in Large Reasoning Models
- RAGTruth: A Hallucination Corpus for Developing Trustworthy Retrieval-Augmented Language Models