GRAIL & GRAIL-SC: Geometric Riemannian Anti-Echo and Self-Contrastive Decoding for Long-Horizon LLM Prose
1. Introduction
Long-horizon prose from instruction-tuned language models reads as mechanically uniform even at high parameter counts. Probing sparse Mixture-of-Experts (Inkling-2-Mini, 30B/128 experts), hybrid linear-attention MoE (Qwen3.6-35B-A3B, 256 experts), and dense transformers (Gemma-4-12B-it, Meta-Llama-3.1-8B-Instruct, Qwen3-4B, SmolLM2-1.7B), we identify four decoding-accessible statistical distortions alongside deeper representational constraints:
- The
min_pTruncation Barrier: Canonical published books cross $5.0$ nats of surprisal ($-\log P(y_t \mid y_{<t}) > 5$) on $18.3\%$ of tokens (roughly once every $5.4$ tokens). UnderT = 0.8, min_p = 0.05, the cutoff caps candidate surprisal near $4.6$ nats, reducing $>5$-nat frequency to $0.0\%\text{–}0.5\%$. - Subword vs. Word-Boundary Conflation: Removing truncation (
T = 1.0, top_p = 1.0) restores the rare-token tail while applying the same dispersion to mid-word BPE continuations as to word starts, producing spelling artifacts (algoritm), glued words (Thegarageis), and hyphen-break glitches. - Excessive Autoregressive Self-Echo: Autoregressive attention repeats its own content words and 5-character morphological stems (
layer,layers,layering) $2.15\times$ more often than published prose over a lagged $16\text{–}60$-word window ($+1.977$ vs. $+0.921$ nats PMI; $0.8858$ zero-training ROC-AUC). - Final-Layer Chat Tail Collapse & Nominalization Drift: Post-trained chat models concentrate probability on Latinate nominalizations (
manifestation,oscillation,operational,paradigm) and discourse signposts (Furthermore,Ultimately), while final layers under chat templates collapse $>5$-nat mass $50\times\text{–}107\times$ relative to document continuation.
GRAIL and GRAIL-SC address these four distortions in logit space using only the model's next-token logits $z_t \in \mathbb{R}^{|V|}$, its tokenizer vocabulary, and (optionally) its own $L_2$-normalized unembedding matrix $W_{\text{norm}} \in \mathbb{R}^{|V| \times d}$, requiring 0 MB extra weights and 0 model hooks.
2. Preliminaries: Fisher-Rao Geometry on the Top-$K$ Simplex
Let $z \in \mathbb{R}^K$ denote the top-$K$ plausible next-token logits ($K = 96$) with softmax distribution $p_i = \exp(z_i) / \sum_j \exp(z_j)$. Perturbing $z \mapsto z + \delta$ induces an exponential-family shift whose second-order Kullback–Leibler divergence is governed by the Fisher-Rao Riemannian inner product:
Additive logit penalties sum linearly across heuristics (repetition penalty, contrastive delta, stylistic bias), causing runaway KL spikes on uncertain tokens and grammar breakage on forced tokens. Given a list of raw steering signals $\{(d^{(m)}, w_m)\}_{m=1}^M$, Riemannian Gram-Schmidt Composition centers each vector $\tilde{d}^{(m)} = d^{(m)} - \mathbb{E}_p[d^{(m)}]$, orthogonalizes it under $g_p$ against prior basis vectors $\{b^{(1)}, \dots, b^{(r)}\}$:
forms $\Delta = \sum_m w_m u^{(m)}$, and radially projects $\Delta$ into an explicit KL trust region of budget $\kappa = \texttt{kl\_budget}$:
Solving the orthogonalization in $M \times M$ Gram-matrix space ($M \le 8$) avoids inner-loop synchronization on GPU. Two properties follow directly:
- Syntactic Protection: On a syntactically forced token ($p_0 \to 1$), $\operatorname{Var}_p(u) \to 0$, so Fisher-centered perturbations vanish naturally without corrupting grammar.
- Exact Non-Interference: Writing $z'$ back strictly over the top-$K$ indices (
z_mod[cand_ids] = cand_vals) leaves the remaining $|V| - K$ tail logits unclipped and preserves upstream $-\infty$ masks withoutNaN.
3. Single-Stream GRAIL
3.1 Subword vs. Word-Boundary Tail Split & Far-Tail Floor
For every vocabulary entry, we precompute a boolean word-start mask $\mathcal{W}$ (leading space, newline, tab, or non-alphanumeric character) and an alphabetic-join mask $\mathcal{A}$. At step $t$, let $m_{\text{ws}} = \sum_{i \in \mathcal{W}} p_i$ over top-$K$.
- Mid-word continuation ($\text{argmax}(z) \notin \mathcal{W} \land m_{\text{ws}} < 0.20$): clamp tightly with $\texttt{min\_p} = 0.02$ at $T = 0.72$ and ban newline tokens. No anti-echo, contrastive, or temperature boosts fire inside a word.
- Word boundary (all other steps): skip
min_pand mask strictly below a far-tail floor $\max(z_{\text{mod}}) - \texttt{tail\_floor\_nats}$ (9.5nats, $p < 7.5 \times 10^{-5}\, p_{\max}$). This retains the entire $5\text{–}9$ nat human rare-word band while blocking extreme outlier glitch tokens, lifting blind cross-family judge Coherence by $+2.0$ to $+2.5$ points ($6.0 \to 8.0\text{–}8.5 / 10$). When the previous token ended with an alphabetic character and $m_{\text{ws}} \ge 0.45$, low-probability alphabetic joins ($p < 0.025$) are damped by $-8.0$ logits to prevent glued words (Thegarageis).
Exact Byte-Level BPE Vocabulary Decoding. GPT-2, Qwen, Llama, and Inkling tokenizers serialize non-ASCII UTF-8 bytes as shifted Latin codepoints in U+0100..U+0143 (for example, "—" as "âĢĶ", Arabic "بين" as "بÙĬÙĨ"). Naive Unicode scans over tok.get_vocab() miss $100\%$ of non-Latin and em-dash tokens on these models. Decoding every vocabulary piece through the exact inverse GPT-2 byte table once at initialization ($\approx 0.4\text{ s}$) masks 43,547 non-Latin and 249 em-dash tokens on Qwen3 (60,860 / 17 on Inkling-2), keeping foreign-script leaks at zero (NL = 0).
3.2 Split-Scale Morphological Stem & Opener Anti-Echo
Let $W_{\text{norm}} \in \mathbb{R}^{|V| \times d}$ be the $L_2$-normalized output embedding matrix (projected via Johnson–Lindenstrauss to $d = 128$ in FP16, requiring 63.6 MB for a 248k vocabulary, $32\times$ smaller than FP32) and $Q_{\text{prompt}} \in \mathbb{R}^{d \times r}$ an orthonormal SVD basis of non-function prompt content tokens. For every non-function generated token $y_t$:
- Slow document EMA ($\tau_{\text{slow}} \approx 125\text{–}250$ tok, decay $0.992$): projected orthogonal to the prompt subspace, $u_{\text{slow}}^{\perp} = u_{\text{slow}} - Q_{\text{prompt}} Q_{\text{prompt}}^\top u_{\text{slow}}$, preventing thematic drift away from the prompt while repelling long-range paraphrase.
- Fast local EMA ($\tau_{\text{fast}} \approx 15$ tok, decay $0.88$) + 64-token 5-character morphological stem log-frequency damper (
-log(1 + count(stem5))) + lagged stale-echo damper (lag window $[-320, -10]$): left unprojected so even prompt nouns cannot loop verbatim within a paragraph. - Syntactic-Opener Anti-Echo (
anti_syntax_echo) & Semantic Velocity: Fisher-Rao damping of repeated sentence-opener grammatical classes (Determiner, Pronoun, Subordinator, Preposition, Adverb) over a $5$-sentence window, plus optional repulsion of the previous sentence's $Q_{\text{prompt}}$-orthogonal mean embedding at sentence starts (sent_tok_pos <= 6).
All vectors are composed inside riemann_compose under kl_budget.
3.3 Rolling 64-Token Surprisal Thermostat
Tracking a rolling $64$-token window of raw base surprisals $\bar{s}_t$ and rare-token fraction $\bar{r}_{5,t} = \frac{1}{64}\sum \mathbf{1}[s > 5]$:
- Lower bound (flat RLHF valley escape): When $\bar{s}_t < 2.15$, word-boundary temperature rises smoothly:
Because intra-word steps stay locked at $T = 0.72$, lifting $T_{\text{eff}}$ up to $1.20$ rescues flat technical stretches without spelling errors.
- Upper bound (drift ceiling): When $\bar{s}_t > 2.68$ and $\texttt{hot\_temp\_cool} > 0$, temperature cools softly:
and damps perturbation gain thermo_gain, holding long essays inside the human surprisal band without truncating the tail.
3.4 Prompt-Exempt Anti-Nominalization & Structural Habit Masks
Comparing 12 pre-2020 human technical essays ($99.5\%$ Mesmer-9B human at $1{,}000$ words) against stock Gemma-4-12B-it ($0.0\%$) showed zero overlap in Latinate nominalization density ($1.1\%\text{–}3.1\%$ vs. $4.0\%\text{–}8.6\%$) and mean word length ($4.25\text{–}4.85$ vs. $5.06\text{–}5.63$). When anti_nominalization > 0, GRAIL adds a $-1.0$ Fisher-Rao tangent vector on plausible ($p_{\text{raw}} \ge 5 \times 10^{-4} p_{\max}$) word-start tokens matching an RLHF-filler lexicon or ^[a-z]{5,}(tion|sion|ment|ity|ance|ence|ization|izing|ism|ality|ational|ological)$ ($\ge 9$ chars), exempting every 5-character stem present in the prompt so domain terms (quantization, compaction) are untouched.
Stateful word-start masks apply deterministic pre-Riemann guards outside quotation marks (quote parity disables lexical penalties inside quoted speech):
- Anti-antithesis pivot guard (
anti_antithesis): Tracks clause-level negation state and damps contrastive hedges (merely,just,simplyat-2.0), semicolon/em-dash pivots (-2.6), comma pivots (-2.2), and semicolons/dashes inside negated clauses (-1.1). Removing "pink-elephant" negative prompt rules (explicitly instructing the model not to write"is not X; it is Y") further reduced opening antithesis hits from3to0onQwen3.6-35B-A3B. - Colon/semicolon cooldown (
colon_semi_cooldown_steps = 28): Forensic comparison of stockQwen3.6Mesmerwins ($\ge 40\%$, $n = 9$) against losses ($< 5\%$, $n = 38$) showed $2.3\times$ lower colon/semicolon density in wins; enforcing a 28-token cooldown removes over-punctuated list cadences. - EOS, reasoning-tag, and byline guards:
min_tokens_before_eosprevents premature termination on long prompts,REASONING_CONTROL_TOKENSbans<think>/<thought>leaks in cross-frame mode, andanti_byline_openerblocks blog-byline openers (By ...,Author: ...,Published ...).
3.5 Adaptive Cliff-Flip, PhaVE-XTC, Opening Forks & Sentence-Aligned SMC
- Adaptive Cliff-Flip & Varentropy-Gated
PhaVE-XTC: Gently flattens narrow bimodal top-6 peaks and firesPhaVE-XTConly when varentropy $V \ge 1.35$ and entropy $H \ge 0.90$. Underadaptive_cliff_xtc = True, both activate strictly inside flat valleys ($\bar{r}_5 < 13.5\%$ or $\bar{s} < 2.35$). - Batched Opening Forks & Front-Loaded Beam Decay (
Fast-SMC): On-demand batchedB = kforks at Sentence 1 (e.g.,3 × 28tokens,max_p_forks = 0) use<0.5 msbit-exact KV/DeltaNet cache rewind to escape bistable opening valleys.GrailSMCSamplerextends native.merge()/.filter()cache resampling toB = 4parallel trajectories with sentence-boundary resampling and optional front-loaded beam decay (beam_collapse_at = 100).
4. Self-Contrastive GRAIL-SC, Tiny-Draft Sparse Contrast & Systems Architecture
4.1 Cross-Frame, In-Turn & Anchor-Refreshed GRAIL-SC
When RLHF typicality dominates single-stream logits, GRAIL-SC runs two synchronized streams of identical weights (0 MB extra parameters):
- Cross-Frame (
build_cross_frame_prompts, base-capable instruct models such asQwen3.6andQwen3): $P_+(y_t \mid x_{\text{doc}}, y_{<t})$ continues a role-free document header while $P_-(y_t \mid x_{\text{chat}}, y_{<t})$ runs the aligned chat/textbook framing (neg_style = "chat_textbook") over the identical generated history $y_{<t}$. - In-Turn Contrast (
build_inturn_contrast_prompts, strictly chat-turn models such asGemma-4-12B-itandMeta-Llama-3.1-8B-Instruct): Both streams stay inside the native chat turn, contrasting a direct literary/technical persona against a textbook-explainer persona.
At each word boundary, GRAIL-SC computes top-96 Jensen–Shannon divergence $D_{\text{JS}}(P_+^{(\tau)} \| P_-^{(\tau)})$ at probe_temp = 1.25 (preventing sharp RLHF peaks from zeroing the gate when $H(P_+) < 0.95$) and scales the clamped log-likelihood ratio:
To prevent contrast dilution over long passages, Anchor-Refresh (neg_refresh_window = 96) periodically re-prefills only the negative stream at paragraph boundaries with [neg_prompt + last_96_tokens], lifting late-essay log-likelihood ratio $3.1\times$ on average ($0.206 \to 0.642$) and $10.7\times$ on long systems essays (0.136 → 1.458). An optional Opening Alpha Surge (opening_alpha_boost = 0.45 over the first 28 tokens) sharpens Sentence-1 escape.
4.2 Asymmetric Plausibility Gate (boost_min_p = 0.015)
In contrastive decoding, suppressing clichés ($d_{\text{RLHF}} < 0$) and boosting alternative tokens ($d_{\text{RLHF}} > 0$) carry asymmetric risk: suppressing an overconfident chat cliché is safe across the support, whereas boosting an improbable token from the far tail can inject syntax glitches. Restricting positive contrastive boosts to tokens with sufficient target probability while leaving cliché suppression and the unclipped tail unrestricted yields the Asymmetric Plausibility Gate:
With boost_min_p = 0.015, positive contrastive shifts land strictly on plausible target tokens, stabilizing multi-seed coherence without clipping rare-word selection.
4.3 Zero-Sync Syntax-Gated Sparse Tiny-Draft Contrast
Running a full B = 2 pass on a 35B model cuts throughput by ~16%. Sparse Tiny-Draft Contrast (make_draft_sc_stepper in MLX; generate_draft_sc in PyTorch) replaces the same-size negative stream with a tiny same-family drafter (e.g., Qwen3-0.6B-4bit, ~350 MB, cross-tokenizer aligned by text prefix) and skips draft forward passes on syntactically forced continuations (sparse_draft = True, max_skip_chunk = 2, skipping 35.8% of draft passes with zero extra GPU syncs). Paired with Qwen3.6-35B-A3B, this reaches 51.6 ± 1.0 tok/s no-fork and 39.2 tok/s with a 3 × 28 S1 fork.
4.4 Production Serving: 1-Sync MLX, Top-K-First PyTorch MPS, Multi-Turn, Speculative Verification & Native C++17 llama.cpp
- 1-Sync Pure-GPU MLX Engine: Replacing per-token Python loops with GPU ring-buffer broadcasts (
[96, 64]and[96, 310]int32 masks), branchless subword/word-start selection, and an@mx.compilefinalizer collapsesGRAIL,GRAIL-SC, andGrailSMCSamplerto 1 Metalmx.evalper token, reaching40.2 tok/svs.40.5 tok/sbaremin_p(99.3%native speed,0.18 ms/tokoverhead). - Top-K-First PyTorch MPS Optimization: Precomputing one
_static_biastensor, moving dynamic masks onto thek = 96slice, caching(z, lse_base), vectorizingPhaVE-XTCon GPU, storingJL-128lm_normin FP16, and solving Fisher-Rao in $M \times M$ Gram space lowers Apple MPS (V = 151,936) latency from5.15 → 3.19 ms/tok(-38.1%) forGrailLogitsProcessorand5.84 → 3.70 ms/tok(-36.6%) forGrailSCLogitsProcessor. - Multi-Turn & Exact Speculative / MTP Verification:
reset_turn()/reset_turn_state()clears per-turn sentence/quote/antithesis state while keeping long-horizon stem and embedding anti-echo memory across assistant turns.verify_draft_batch()implements exact Leviathan-et-al. rejection sampling sequentially through GRAIL's stateful logit transform over[K + 1, V]target batches, advancing internal state only for accepted tokens and sampling the exact residual bonus token on rejection (live-verified4/4acceptance onQwen3.6-35B-A3B). - Native C++17
llama.cpp:examples/llamacpp_grail_sampler.hppimplementsllama_sampler_init_grail(vocab, params)as a standalone zero-warning C++17 header (clang++ -std=c++17 -Wall -Wextra -Werror) against upstreamllama.h.
5. Experimental Setup
We evaluate across four calibrated open-weight detector architectures spanning four model families: Mesmer-9B (Qwen3.5-9B, $1.0000$ ROC-AUC on our calibration set), Desklib (DeBERTa-v3-large, $0.9784$ AUC), TMR-RoBERTa (hard-negative-mined RoBERTa, whitespace-normalized, $0.9353$ AUC), and ModernBERT (RAID+MAGE, whitespace-normalized, $0.9129$ AUC), alongside Slop purity ($1.000$ = zero cliché hits), morphological Stem Echo, nominalization rate (nom%), antithesis count (anti), non-Latin leak count (NL), blind cross-family $1\text{–}10$ ratings (Accuracy / Coherence / Naturalness), position-balanced blind A/B preference tests, an 80-question verifiable math & factual QA harness, and live Pangram 4.1 checks on $1{,}000+$-word essays.
6. Results
6.1 Multi-Domain Generalization on Stock Qwen3.6-35B-A3B (12 Prompts)
Evaluated on unmodified Qwen3.6-35B-A3B across 12 diverse prompts (3 systems engineering, 3 physical science, 3 literary observation, 3 essays; 8 unseen; 380 tokens each), judged blindly by Gemma-4-12B-it:
Sampler (Qwen3.6-35B-A3B, 12 Prompts) |
Speed | Mesmer Mean / Med (>=50%, Peak) |
Desklib AI% (<=20%) |
TMR AI% | ModernBERT AI% | Stem Echo | Anti (12) | Judge Acc / Coh / Nat | Blind A/B vs. min_p |
|---|---|---|---|---|---|---|---|---|---|
min_p (T=0.8, min_p=0.05) |
48.2 tok/s | 0.0% / 0.0% (0/12, 0.0%) | 100.0% (0/12) | 97.7% | 86.7% | 0.325 | 5 | 7.6 / 8.9 / 5.5 | baseline |
Fast-SMC (B=4 -> B=1 at 100t) |
36.3 tok/s | 0.6% / 0.2% (0/12, 2.1%) | 52.8% (5/12) | 71.0% | 49.0% | 0.192 | 2 | 8.1 / 8.4 / 5.8 | 7W–5L |
Fast-SC-SMC (B=6 -> B=2 at 100t) |
28.9 tok/s | 29.3% / 5.6% (3/12, 99.6%) | 44.9% (6/12) | 64.5% | 21.8% | 0.177 | 2 | 7.6 / 7.2 / 6.5 | 7W–5L |
Cross-Frame GRAIL-SC (B=2, no fork) |
35.2 tok/s | 47.0% / 35.6% (6/12, 99.4%) | 53.9% (4/12) | 59.0% | 32.7% | 0.197 | 0 | 7.1 / 7.2 / 6.3 | 8W–3L–1T |
Cross-Frame GRAIL-SC + Fork (B=2 + B=8) |
29.1 tok/s | 33.0% / 0.2% (4/12, 96.0%) | 61.5% (3/12) | 66.8% | 30.7% | 0.185 | 0 | 8.4 / 8.2 / 7.2 | 8W–4L |
Dual-Failure + Surge + Fork (chat_textbook) |
31.0 tok/s | 35.7% / 2.6% (4/12, 99.9%) | 42.5% (5/12) | 59.5% | 29.4% | 0.212 | 1 | 8.6 / 8.3 / 8.2 | 9W–3L |
Dual-Failure + S1-Only Fork (s1=40) |
28.1 tok/s | 33.1% / 0.3% (4/12, 99.9%) | 40.0% (6/12) | 60.7% | 13.8% | 0.226 | 2 | 8.5 / 8.0 / 7.8 | 9W–3L |
Tiny-Draft + Plausibility (3-seed, n=36) |
51.6 ± 1.0 | 45.0 ± 2.9% (17/36, 99.9%) | 55.0 ± 9.8% | 49.2 ± 6.0% | 33.4 ± 3.6% | 0.232 | 0 (1/36) | 7.3 / 7.1 / 7.2 | 7W–5L |
Tiny-Draft + Plausibility + S1 Fork (3×28) |
39.2 tok/s | 28.7% / 1.5% (3/12, 99.7%) | 39.2% (5/12) | 58.3% | 39.4% | 0.185 | 0 | 9.2 / 9.2 / 7.1 | 10W–2L |
Sparse Draft-Contrast (4B, n=12) |
23.7 tok/s | 45.7% / 40.6% (6/12, 98.3%) | 47.3% (6/12) | 54.5% | 20.2% | 0.193 | 0 | 6.9 / 6.9 / 6.6 | 6W–5L–1T |
Tiny-Draft + Plausibility + S1 Fork (3 × 28, max_p_forks = 0, 39.2 tok/s) sets the Pareto frontier on Qwen3.6-35B-A3B: 10W–2L (83.3%) blind A/B wins over min_p, 9.2 / 9.2 / 7.1 blind ratings (beating min_p on Accuracy, Coherence, and Naturalness simultaneously), lowest 12-prompt Desklib (39.2%), 0.185 stem echo, and 0/12 antithesis. Over 3 seeds (n = 36), Tiny-Draft + Plausibility holds 51.6 ± 1.0 tok/s, 45.0 ± 2.9% Mesmer-9B human, 0.232 ± 0.017 stem echo, and zero short/byline runs (min 137–229w).
6.2 Three-Family Chat Validation (Gemma-4-12B-it & Meta-Llama-3.1-8B-Instruct)
Strictly chat-turn checkpoints fail to reliably continue bare document headers even under min_p (collapsing to 1–2 words or thought loops on 3/8 prompts on Gemma-4-12B-it). Running In-Turn GRAIL-SC (build_inturn_contrast_prompts) inside the native chat turn resolves this across both model families (Gemma-4-12B-it judged blindly by Qwen3.6-35B-A3B; Meta-Llama-3.1-8B-Instruct judged blindly by Gemma-4-12B-it):
| Model & Sampler (Native Chat Turn) | Speed | Avg Words | Desklib AI% | TMR AI% | ModernBERT AI% | Stem Echo | Antithesis | Judge Acc / Coh / Nat | Blind A/B vs. min_p |
|---|---|---|---|---|---|---|---|---|---|
Gemma-4-12B-it (min_p, n=8) |
44.0 tok/s | 264 | 99.8% | 96.5% | 96.4% | 0.250 | 2 | 8.6 / 8.6 / 8.0 | baseline |
Gemma-4-12B-it (In-Turn GRAIL-SC, B=2) |
35.0 tok/s | 308 | 60.9% | 49.7% | 37.1% | 0.144 | 3 | 8.8 / 8.2 / 9.0 | 7W–1L |
Gemma-4-12B-it (In-Turn GRAIL-SC + Fork) |
29.4 tok/s | 308 | 68.1% | 53.8% | 33.7% | 0.167 | 4 | 8.9 / 9.0 / 8.9 | 7W–1L |
Llama-3.1-8B-Instruct (min_p, n=12) |
78.0 tok/s | 298 | 100.0% | 96.1% | 98.7% | 0.296 | 0 | 9.2 / 9.2 / 7.4 | baseline |
Llama-3.1-8B-Instruct (In-Turn GRAIL-SC, B=2) |
53.5 tok/s | 303 | 60.5% | 57.4% | 22.5% | 0.133 | 0 | 7.7 / 6.6 / 6.5 | 8W–4L |
6.3 Throughput & Memory (Apple Silicon MLX & PyTorch MPS)
Mode (Apple Silicon MLX, JL-128 63.6–67.1 MB) |
Qwen3.6-35B (MoE) |
Gemma-4-12B (Dense) |
Artaud (Inkling-2) |
Notes |
|---|---|---|---|---|
min_p (T=0.8, min_p=0.05) |
40.5 tok/s (100%) | 42.4 tok/s (100%) | 51.3 tok/s | Bare mlx-lm baseline |
Standard GRAIL (single-stream) |
40.2 tok/s (99.3%) | 36.0 tok/s (84.9%) | 54.0 tok/s | 0.18 ms/tok on Qwen3.6; 3.19 ms/tok on PyTorch MPS (V=151k) |
GRAIL (+ batched B=4 opening fork) |
33.5 tok/s (82.7%) | 31.8 tok/s (75.0%) | — | Native B=1 KV cache; merges only at forks |
GRAIL-SC (batched B=2) |
33.9 tok/s (83.7%) | 32.0 tok/s (75.5%) | — | Dual stream in one pass; 3.70 ms/tok on PyTorch MPS |
Tiny-Draft Sparse Contrast (35B + 0.6B) |
51.6 ± 1.0 tok/s | — | — | Zero-sync syntax-gated skipping; 39.2 tok/s with 3×28 S1 fork |
Fast-SMC (B=4 -> B=1 at 100 tok) |
36.3 tok/s | — | — | +77% faster than full-length B=4 SMC |
GRAIL-SMC (full-length B=4) |
20.5 tok/s (50.6%) | 24.1 tok/s (56.8%) | — | 4 parallel trajectories |
GRAIL-SC-SMC (full-length K=3, B=6) |
18.6 tok/s (45.9%) | 17.1 tok/s (40.3%) | — | 3 dual-contrastive trajectories (6 streams) |
6.4 Head-to-Head vs. Published Baselines (Stock Qwen3.6-35B-A3B)
Mean across 4 raw-document prompts (2 technical, 2 literary) on identical stock Qwen3.6-35B-A3B weights, judged blindly by Gemma-4-12B-it:
| Sampler (Identical Stock Weights) | Speed | Mesmer P(H) Mean (Peak) | Desklib AI% | TMR AI% | ModernBERT AI% | Tail >5 nats | Stem Echo | Anti (4) | Judge Acc / Coh / Nat |
|---|---|---|---|---|---|---|---|---|---|
min_p (Nguyen et al. 2024) |
41.3 tok/s | 0.0% (0.0%) | 99.5% | 71.3% | 74.7% | 0.0% | 0.284 | 3 | 9.0 / 10.0 / 8.5 |
top_p (Holtzman et al. 2020) |
42.6 tok/s | 0.0% (0.0%) | 99.7% | 95.2% | 75.2% | 1.2% | 0.348 | 2 | 9.5 / 9.5 / 9.2 |
DRY (Repetition Penalty) |
41.1 tok/s | 0.0% (0.0%) | 94.3% | 71.6% | 50.4% | 0.0% | 0.309 | 3 | 7.5 / 9.2 / 7.8 |
Typical (Meister et al. 2023) |
40.8 tok/s | 3.5% (14.0%) | 62.8% | 58.6% | 74.7% | 4.1% | 0.283 | 0 | 9.0 / 9.8 / 8.5 |
XTC (Standalone) |
41.1 tok/s | 17.0% (67.9%) | 80.8% | 74.7% | 74.3% | 6.7% | 0.239 | 0 | 7.8 / 8.8 / 7.8 |
Eta (Hewitt et al. 2022) |
40.6 tok/s | 18.9% (70.8%) | 73.6% | 65.5% | 3.3% | 12.7% | 0.242 | 0 | 8.0 / 9.0 / 8.8 |
GRAIL-SC (Batched B=2, Anchor) |
33.9 tok/s | 14.9% (55.1%) | 17.6% | 28.0% | 1.8% | 15.2% | 0.288 | 0 | 7.5 / 8.5 / 7.8 |
GRAIL-SMC (Sentence-Aligned B=4) |
20.5 tok/s | 29.3% (89.6%) | 62.4% | 76.4% | 74.1% | 14.6% | 0.238 | 0 | 8.0 / 8.0 / 7.8 |
GRAIL-SC-SMC (Sentence-Aligned K=3, B=6) |
18.6 tok/s | 24.8% (98.8%) | 25.7% | 41.5% | 2.7% | 11.8% | 0.201 | 0 | 8.0 / 8.5 / 8.0 |
On the 589-word chat systems essay (chat_btrees_long), GRAIL-SC-SMC scored blind judge 9 / 10 / 9 while sweeping Desklib 2.4% / TMR 1.5% / ModernBERT 2.2% / Stem Echo 0.137 / anti = 0; on lit_boredom (328w), it hit 98.8% Mesmer-9B human, 1.5% Desklib, 5.1% ModernBERT, and Judge 9 / 9 / 9.
6.5 Zero-Regression Verifiable QA Parity (80 Questions)
Comparing default GRAIL (GrailConfig.goldilocks()) against min_p (T = 0.8, min_p = 0.05) across 40 multi-step math problems and 40 verifiable factual QA questions scored by an exact-match parser:
| Model (40 Math + 40 Factual QA) | Sampler | Total Correct | Accuracy | Factual Slice |
|---|---|---|---|---|
Qwen3.6-35B-A3B |
min_p |
29 / 40 | 72.5% | 19 / 20 |
Qwen3.6-35B-A3B |
GRAIL (goldilocks) |
30 / 40 | 75.0% | 19 / 20 |
Meta-Llama-3.1-8B-Instruct |
min_p |
34 / 40 | 85.0% | 19 / 20 |
Meta-Llama-3.1-8B-Instruct |
GRAIL (goldilocks) |
33 / 40 | 82.5% | 19 / 20 |
| Combined (80 Questions) | GRAIL vs. min_p |
63 / 80 vs. 63 / 80 | 78.8% (Exact Parity) | 38 / 40 (95.0%) |
6.6 Cross-Architecture Stock Validation, Clean Chat Sweep & Ablations
Across 138 raw-document essays on four stock architectures (Qwen3-4B, SmolLM2-1.7B, Inkling-2-Mini, Qwen3.6-35B-A3B), GRAIL and GRAIL-SC cut Desklib AI scores by $50\text{–}79$ percentage points (99.8% → 35.9% on Qwen3-4B, 99.9% → 23.2% on SmolLM2-1.7B, 73.0% → 22.4% on Inkling-2-Mini, 99.5% → 20.5% on Qwen3.6-35B-A3B) and cut morphological stem echo by $30\%\text{–}56\%$.
In clean chat mode (enable_thinking = False), single-stream GRAIL reduced Qwen3.6-35B-A3B Desklib from 95.2% → 45.1%, TMR from 35.7% → 3.4%, and ModernBERT from 98.8% → 3.8% (GRAIL-SC: 24.3% / 2.9% / 3.9%, sweeping 798-word B-trees to 4.3% / 1.6% / 1.4%), and reduced Gemma-4-12B-it from 97.2% / 65.6% / 98.7% to 57.3% / 32.7% / 37.3% (nom% 5.1% → 3.0%, Stem Echo 0.250 → 0.139).
A 56-essay leave-one-out ablation established that Subword Split ($13\times$ Mesmer drop when removed on Artaud), Stem Anti-Echo ($8\times$ Mesmer drop, $+27\%\text{–}41\%$ stem echo), and Opening Forks ($+14.2\text{ pp}$ Desklib on Qwen3-4B) are universally load-bearing. Cliff-Flip + PhaVE-XTC showed a phase split: removing it hurts collapsed stock RLHF (+16.4 pp Desklib on Qwen3-4B), while gating it off on expressive prose (Artaud, $>5$-nat mass $\ge 15\%$) lifts Mesmer $2.9\times$ ($7.9\% \to 22.8\%$), motivating adaptive_cliff_xtc = True.
In our 24-essay thermostat sweep on Artaud, GrailConfig.goldilocks() (flat_temp_boost = 0.20, hot_temp_cool = 0.12, kl_budget = 0.24) reached 4/4 Slop = 1.000, 4/4 anti = 0, Desklib = 0.7%, TMR = 1.9%, technical ModernBERT = 1.6%, and peak Mesmer = 97.2% human (963w). Negative findings: aggressive flat_temp_boost = 0.32 and forced short-sentence injection (bursty_cadence) collapsed Mesmer from $54.9\% \to 1.7\%\text{–}1.9\%$ and were excluded.
6.7 Fine-Tuned Weights: Artaud + GRAIL & Long-Horizon Verification (1,000+ Words)
When paired with stylistically fine-tuned weights (Artaud, trained from Inkling-2-Mini) whose distribution retains rare syntax and vocabulary, single-stream GRAIL eliminates self-echo at 54.0 tok/s and clears all four detectors simultaneously:
Transcript (Artaud, Fine-Tuned Inkling-2-Mini) |
Sampler | Words | Speed | Mesmer Human | Desklib AI% | TMR AI% | ModernBERT AI% | Stem Echo |
|---|---|---|---|---|---|---|---|---|
| On Keeping Old Notebooks | min_p (T=0.8, min_p=0.05) |
477 | 51.2 tok/s | 0.0% | 77.2% | 97.8% | 98.7% | 0.322 |
| On Keeping Old Notebooks | Standard GRAIL |
450 | 54.0 tok/s | 28.2% | 13.2% | 11.4% | 1.4% | 0.114 |
| The Geometry of Self-Echo | min_p (T=0.8, min_p=0.05) |
457 | 51.4 tok/s | 0.0% | 99.8% | 56.2% | 99.0% | 0.328 |
| The Geometry of Self-Echo | Standard GRAIL |
348 | 54.0 tok/s | 0.0% | 0.7% | 1.7% | 1.5% | 0.222 |
| Airport Lounges (Long-Form) | Standard GRAIL |
807 | 23.6 tok/s* | 96.5% | 0.2% | 1.7% | 2.9% | 0.103 |
*Measured prior to the single-sync MLX kernel rewrite; single-stream GRAIL on Artaud runs at 54.0 tok/s under v0.14.0.
On $1{,}000+$-word runs past Pangram 4.1's high-accuracy threshold, Artaud + GRAIL scored 100% HUMAN on live Pangram 4.1 (1,098w: Mesmer 47.3% / Desklib 0.1% / TMR 1.4% / ModernBERT 1.6% / Slop 1.000) and 96% HUMAN on 1,075w (91.9% Mesmer human).
6.8 Cross-Family Mechanistic Diagnostics: Final-Layer Tail Collapse & Clause-Start Wave
- Cross-Family Final-Layer Tail Collapse: Projecting intermediate hidden states through
norm + lm_headconfirms the same mechanism across two unrelated families:Qwen3-4B-Instruct(36 layers): Through Layer 32 ($89\%$ depth), chat mode holds $H = 2.74$ and $13.89\%$ $>5$-nat mass (vs. $8.58\%$ for document mode). Across layers $32 \to 35$, chat entropy drops $18\times$ ($2.74 \to 0.15$) and $>5$-nat mass drops $50\times$ ($13.89\% \to 0.28\%$ vs. $16.26\%$ in document mode).Gemma-4-12B-it(48 layers): Through Layer 46 ($98\%$ depth), chat mode holds $H = 2.861$ and $18.17\%$ $>5$-nat mass. Inside Layer 47 alone, chat-RLHF crushes $>5$-nat mass $107\times$ down to $0.17\%$ ($H = 0.718$, $63\times$ below document mode's $10.69\%$).- Negative Controls (KV Masking & Residual Damping): Zeroing
<|im_start|>assistant/<|turn>modelKV entries after prefill left chatMesmerat $0.0\%$ on bothQwen3.6(DeltaNet + attention) andGemma-4(pure attention). Bluntly damping the final-layer residual delta ($h_{L-3} + 0.65(h_L - h_{L-3})$) droppedGemma-4TMRto $2.4\%$ andModernBERTto $1.7\%$, yet verbatim inspection exposed multilingual token leakage ("sistema'buffer... bloques... velocidad... struttura... leitura"). Similarly, subtracting the top final-layer SVD shift direction ($85.8\%$ variance onQwen3.6) lifted token-0 chat tail from $4.2\% \to 13.3\%$ while leaving chatMesmerat $0.0\%$. These controls confirm that the final layer couples RLHF peak-sharpening with language alignment and establish logit-space contrastive subtraction (GRAIL-SC) as the clean zero-hook intervention.
- Clause-Position Surprisal Wave: Pre-2020 human technical essays ($n = 8$) exhibit a $+0.97$-nat surprisal peak at clause starts (
3.69at positions0–2vs.2.72mid-clause). StockGRAIL-SCmatches human mean ($2.92$ vs. $2.88$), std ($3.16$ vs. $3.10$), and $>5$-nat share ($22.6\%$ vs. $22.2\%$) within $1.1\%$, whilemin_pstays $\approx 0.8\text{–}1.0$ nats too flat across all clause positions.
7. Limitations: The Radon–Nikodym Support-Collapse Boundary
Pure logit-space sampling has a sharp mathematical boundary:
- Chat-Role Support Collapse: Even exact token-level Bayesian inversion guided directly by
Mesmer-9Bacross $192$ forks in $184$ words left an untuned chat model at $0.0\%$ human because chat-role conditioning drives human-syntax support near zero ($0 \times \infty = 0$). In clean chat mode on stockQwen3.6andGemma-4, GRAIL sweeps encoder detectors and wins blind preference (7W–1L/8W–4L), whileMesmer-9Bremains near $0\%$ until chat-role framing is stripped (Cross-FrameGRAIL-SC$\to 47.0\%$ mean across 12 domains onQwen3.6). - 2026 Synthetic Pretraining Saturation: Prompting a raw, zero-RLHF 2026 base model (
gemma-4-12B) on a systems topic spontaneously produced "In this blog post, we'll explore... Conclusion... FAQ Section" ($0.0\%$Mesmer, $99.6\%$Desklib). Once synthetic 2023–2026 explainers saturate pretraining itself, no zero-weight reweighting of the support can synthesize absent pre-2020 prose distributions; full four-detector clearance on technical essays then requires weight-level restoration (Artaud), which single-streamGRAILamplifies cleanly at54.0 tok/s. - Multi-Stream Compute Tradeoffs: Single-stream
GRAILruns at $40.2\text{ tok/s}$ ($99.3\%$ ofmin_p,0.18 ms/tokon MLX;3.19 ms/tokon PyTorch MPS), andTiny-Draft Sparse Contrastruns at $51.6\text{ tok/s}$ ($39.2\text{ tok/s}$ with3 × 28S1 fork). Full-lengthB = 4GRAIL-SMC($20.5\text{ tok/s}$) andK = 3, B = 6GRAIL-SC-SMC($18.6\text{ tok/s}$) remain bandwidth-bound on 256-expert MoE models, makingFast-SMC(36.3 tok/s) andTiny-Draft + S1 Fork(39.2 tok/s) the practical production operating points.
8. Conclusion
Separating intra-word spelling from word-start tail selection, bounding geometric anti-echo inside a Fisher-Rao KL ball, and subtracting aligned chat priors under an asymmetric plausibility gate resolves long-horizon repetition and tail collapse at 0.18 ms/tok single-stream overhead (99.3% native min_p throughput) with exact 63/80 QA parity. The Radon–Nikodym support-collapse boundary characterizes what logit-space sampling can recover on stock weights and where fine-tuned weights (such as Artaud) unlock full four-detector clearance. The grail-sampler package is MIT-licensed with a single numpy core dependency, lazy PyTorch and MLX backends, multi-turn reset_turn(), exact speculative verify_draft_batch(), the grail-demo CLI, and tested adapters for HuggingFace, MLX, oMLX, vLLM, SGLang, and native C++17 llama.cpp.
References
- Amari, S. (2016). Information Geometry and Its Applications. Springer.
- Hewitt, J., Manning, C. D., & Liang, P. (2022). Truncation Sampling as Language Model Desmoothing. Findings of EMNLP.
- Holtzman, A., Buys, J., Du, L., Forbes, M., & Choi, Y. (2020). The Curious Case of Neural Text Degeneration. ICLR.
- Leviathan, Y., Kalman, M., & Matias, Y. (2023). Fast Inference from Transformers via Speculative Decoding. ICML.
- Li, X. L., Holtzman, A., Fried, D., Liang, P., Eisner, J., Hashimoto, T., Zettlemoyer, L., & Lewis, M. (2023). Contrastive Decoding: Open-ended Text Generation as Optimization. ACL.
- Meister, C., Pimentel, T., Wiher, G., & Cotterell, R. (2023). Locally Typical Sampling. TACL.
- Nguyen, M., Baker, A., Neo, C., Roush, A., Kirsch, A., & Shwartz-Ziv, R. (2024). Turning Up the Heat: Min-p Sampling for Creative and Coherent LLM Outputs. arXiv:2407.01082.
- O'Brien, S., & Lewis, M. (2023). Contrastive Decoding Improves Reasoning in Large Language Models. arXiv:2309.09117.
- Shi, W., Han, X., Lewis, M., Tsvetkov, Y., Zettlemoyer, L., & Yih, W. (2024). Trusting Your Evidence: Hallucinate Less with Context-Aware Decoding. NAACL.