Study · April 2026

Tap-In V7: Stacking Memory at Eval Time

A 36M-parameter LM under Parameter Golf rules can't see past its 2,048-token attention window. Tap-In V6 reads the lost prefix via contiguous n-gram matches. Tap-In V7 extends V6's recipe along two new axes — multi-candidate vote distributions over gap-pattern skip-grams, plus token-class hybrid keys. Together V7 lowers BPB by pre-TTT, validated across two seeds within . The load-bearing principle: orthogonal match criteria stack additively; same-axis variants cannibalize.


The recipe V6 set, V7 extends.

At each scored position , both versions build a small probability distribution from the lost prefix and convex-mix it with the model's output. Four steps. Same contract on both sides: causal, normalized, per-document, built only from already-scored tokens.

#
Step
Tap-In V6
Tap-In V7 (this post)
1
Build a key
longest contiguous suffix of
tokens at fixed gap offsets, packed via bit-shift
2
Look up in lost prefix
find any with matching contiguous suffix
find any with matching gap-offset hash
3
Read out (cont, count)
longest match → single best continuation
top- vote-weighted distribution
4
Convex mix into

Every is normalized. Every is in . The mix preserves by construction. All four conditions of Issue #1017 hold. V7 changes two of the four steps. Step 1: V6 matches contiguous suffixes; V7 matches tokens at fixed gap offsets packed into a hash — (1, 2, 3), (1, 2, 3, 4), (1, 3, 5),(1, 2). Different keys see different historical positions, and V7 runs all four matchers in parallel and stacks the mixes. Step 3: V6 picks the longest single match and mixes a Dirac on its continuation; V7 reads out a top- vote distribution and mixes the whole distribution. The first change unlocks compositional gain across gap variants; the second uses the entire vote shape instead of throwing it away.

The recipe on one real position.

A position from FineWeb val. The document is some legal text about “registry,” with the phrase registry.jockey appearing several times earlier — all before the model's 2,048-token window. Below is the position itself, what every V7 gap pattern sees, and what the mix does to the model's top-5.

Case 1Δ -10.28 nats
…regarding the electronic transmission of data. 6 no re-distribution of registry.j[ockey]
✓ matcher said ockey (4/4 patterns)

The model put ockey at logp −12.4, outside its top-5 (top guess: son). V7's gap-(1,2,3) hash over the last three tokens hit 6 historical positions, every one followed by ockey. The mix moves ockey to logp −2.11 — new rank 3.

ockey-12-10-8-6-4-20-2.11-12.40
patterns(1, 2, 3)(1, 2, 3, 4)(1, 3, 5)(1, 2)
earlier in doc…use for registry.jockey… → ockey…or using registry.jockey… → ockey…or using registry.jockey… → ockey
pattern details
(1, 2, 3) bucket=6, uniq=1, q₁=1.00 → ockey@1.00
(1, 2, 3, 4) bucket=6, uniq=1, q₁=1.00 → ockey@1.00
(1, 3, 5) bucket=6, uniq=1, q₁=1.00 → ockey@1.00
(1, 2) bucket=13, uniq=4, q₁=0.44 → ockey@0.44, ␣@0.25, .@0.25

What each step of the recipe is doing here:

  1. 1. Build a key. V7 with gap (1, 2, 3) reads the tokens at — ["j", "registry.", "."] — and packs them into one integer hash via bit-shift. Pure causal, target token never read.
  2. 2. Look up. One pass over the lost prefix has built a table mapping each gap-offset hash to all observed continuations. This key has 6 hits; every one was followed by ockey.
  3. 3. Read out. Top- vote: 100% mass on ockey, so is a Dirac on ockey. Confidence-scaling sets .
  4. 4. Mix. . Log-prob shifts from to . Ten nats of cross-entropy disappear because the matcher remembered what the model couldn't see.

Three other patterns ((1,2,3,4), (1,3,5), (1,2)) fire on the same position with their own keys. They each contribute a smaller, redundant push toward ockey. The cumulative shift is what shows in the case card above.

Why different keys stack.

Different gap patterns see different historical positions. If their fire sets overlapped completely, adding a second pattern would do nothing. We add four patterns one at a time and watch the marginal:

-0.000557(1, 2, 3)-0.000679+ (1, 2, 3, 4)-0.000744+ (1, 3, 5)-0.000841+ (1, 2)-0.000865+ (1, 3, 5, 7)0.0000-0.0002-0.0004-0.0006-0.0008-0.0010Δ BPB (cumulative, pre-TTT)Stack depth (pattern added at each step)
Cumulative (pre-TTT, seed 42) as gap patterns are added. Each new pattern adds at least on top of the previous stack. Saturation only starts at depth 5.

Two things to notice. First, the marginals don't collapse: every added pattern brings new fires the earlier patterns missed. Second, the depth-4 contribution comes from gap (1, 2) — whose stand-alone delta is weaker than gap (1, 2, 3) at depth 1. Patterns aren't ranked by solo strength; they're ranked by the complement they bring to the running stack.

Two more positions: composition and failure.

A second case where stacking mattered visibly: Supreme Court justices named in order. Two narrow patterns are confident; two wider ones are noisy. Mass adds because their confidences correlate negatively.

Case 2Δ -5.64 nats
…joint opinion of stewart, powell, and [steven]
✓ matcher said steven (3/4 patterns)

Model's top guess was j (probably the start of “Justice”), with the target steven at logp −8.17. The two narrow patterns (1,2,3,4) and (1,3,5) each had a bucket of just 2, both followed by steven. The wider (1,2) bucket of 72 votes was diluted by irrelevant continuations and didn't even put steven in its top-3. Narrower keys are higher precision; wider keys are broader nets. Stacked together they push steven to logp −2.52.

steven-12-10-8-6-4-20-2.52-8.17
patterns(1, 2, 3)(1, 2, 3, 4)(1, 3, 5)(1, 2)
earlier in doc…stewart, powell, and stevens… → steven…powell, and stevens, jj… → steven
pattern details
(1, 2, 3) bucket=11, uniq=9, q₁=0.23 → steven@0.23, i@0.23, ken@0.08
(1, 2, 3, 4) bucket=2, uniq=1, q₁=1.00 → steven@1.00
(1, 3, 5) bucket=2, uniq=1, q₁=1.00 → steven@1.00
(1, 2) bucket=72, uniq=20, q₁=0.30 → g@0.30, south@0.12, justice@0.11

And the worst position across all 26,369 fires — where V7 is wrong with high confidence:

Case 3Δ +0.16 nats
…habitats need to be protected. — ks god declared the creation ‘good’[␣]
✗ matcher said including (4/4 patterns)→ target was ␣

Earlier in the document, the phrase “good intentions including X” appeared a few times. Every V7 gap pattern confidently votes for including with . But here the sentence ends differently and the target is whitespace. V7 wastes of mass on a wrong continuation, costing 0.16 nats. The hurt ceiling is structural — — so the matcher can't blow up.

␣-12-10-8-6-4-20-1.41-1.25
patterns(1, 2, 3)(1, 2, 3, 4)(1, 3, 5)(1, 2)
earlier in doc…created good intentions including… → including…of all good intentions including… → including
pattern details
(1, 2, 3) bucket=3, uniq=1, q₁=1.00 → including@1.00
(1, 2, 3, 4) bucket=3, uniq=1, q₁=1.00 → including@1.00
(1, 3, 5) bucket=3, uniq=1, q₁=1.00 → including@1.00
(1, 2) bucket=4, uniq=1, q₁=1.00 → including@1.00

V7's second axis: token-class hybrid keys.

Gap patterns vary which positions the key reads. V7 has a second matcher that turns a different knob: what each slot in the key actually holds. The gap matcher's slots are exact token IDs (13 bits each, full 8,192-vocab). What if some slots were token classes instead — small buckets of similar tokens?

Build a hybrid key with exact slots (anchor positions) plus 5-bit token-class slots (context). Call it r9h_E_C — V7's second matcher family. Exact slots demand specific tokens; class slots generalize across tokens of the same class. The recipe's steps stay identical — only step 1 changes.

A 30-chunk screen across the grid (single-rule alone, then stacked on V7's gap stack):

(E, C)
solo Δ BPB
+ V7 gap-stack Δ BPB
(1, 2)
-0.000449
-0.000821
(1, 3)
-0.000467
-0.000832
(2, 2)
-0.000707
-0.000912
(2, 3)
-0.000644
-0.000891
(2, 4)
-0.000567
—
(2, 5)
-0.000500
-0.000849
(3, 1)
-0.000627
—
(3, 2)
-0.000568
-0.000864
(3, 3)
-0.000501
-0.000847
(4, 1)
-0.000488
—
(4, 2)
-0.000444
-0.000849

r9h_2_2 wins both columns. We validated it on full val across two seeds:

configuration
seed 42
seed 314
range
r9h_2_2 alone
-0.000729
-0.000734
5e-6
V7 gap stack alone
-0.000841
-0.000847
6e-6
V7 full (gap + r9h_2_2)
-0.001046
-0.001051
5e-6

The mean is , range under . That's a 24% bump over V7's gap stack alone — from one new matcher operating on a different axis of the recipe.

The two-axis structure has a sharper rule than the gap-only stacking did. Same-axis variants cannibalize: the V7 gap stack + r9h_2_2 plus r9h_2_3 (both share context depth) is barely better than the gap stack + r9h_2_2 alone. Diagonal pairs stack: the gap stack + r9h_2_2 + r9h_3_1 (anchor depth 2 then 3, context 2 then 1) is the best three-rule combo we've seen on the screen substrate. Moves along the diagonal of the grid compose; moves on the same row or column don't. The choice of “what fills the key” is a grid, not a list.

Why a 79% loss rate still helps in aggregate.

Most fires hurt slightly. A long left tail helps a lot. The aggregate is dominated by the tail.

helped (5,497)hurt (20,872)2-1293-8168-4184-2233-1807-0.51,450-0.12,560-0.016,221014,2740.013770.11101001,00010,000Fires (log scale)Per-fire CE delta (nats; left = helped, right = hurt)
Per-fire CE delta (log scale). 21% of fires lower CE; 79% raise it slightly. The negative tail reaches −10 nats; the positive ceiling is +0.16 nats. The matcher cannot blow up because the worst it can do is move of mass — capped at 4% — onto a wrong continuation.

The asymmetry is structural. The hurt ceiling is set by . The help floor isn't bounded the same way: when the lost prefix repeats verbatim, the matcher can route up to of mass onto a token the model missed entirely. V7 is a small cheap bet with bounded downside and an unbounded right tail.

The asymmetry is also exploitable. Most of the 79% hurt mass is on positions where the model was already confident-correct; the matcher fires anyway and wastes a few percent on a wrong continuation. Gating by model uncertainty — only firing when the negative log-prob of the target exceeds some threshold (e.g. ) — filters those out. Combined with a higher on what remains, this is what production tuning does: trade quantity of fires for quality per fire, then crank on the survivors.

Aside: how we measured all of this on CPUs.

Live inference on the 25M-token val set takes a 4×H100 hour per rule variant. We tried over a hundred variants. The trick is to dump logits once, then re-mix from cache:

research
GPU forward → cache (W,T,V) bf16 → CPU mix → CE → Δ BPB
one time, ~ $5 thousands of variants, ~ $0.05 each
submission
GPU forward → CPU C++ matcher → GPU scatter_add_ → CE → BPB
live, end-to-end on 8×H100 within 600 s

Logits at the same input tokens are deterministic, so caching them and replaying thousands of mixers is mathematically equivalent to live inference within bf16 precision (about BPB). Every in this post is measured against the same cache; any constant offset from bf16 chunking cancels in the difference.

The submission doesn't use a cache. Its eval_val_sliding_tapinpath runs model.forward_logits live on GPU, calls the tapin_match_v8_gapped C++ matcher on CPU (one thread per window batch via ThreadPoolExecutor), and mixes via scatter_add_ on GPU. End-to-end inside the 600 s eval budget. The cache is a research optimization, not a submission shortcut — and it's why we could iterate on a hundred match-criterion variants for less than the cost of one full re-eval.

Why the recipe stays causal.

With and , then . Sequential application of rules is convex combinations stacked, each preserving normalization on its own — no joint calibration, no shared parameter, no order-dependence. The strict-prefix property is structural: the lookup table is built from tokens[doc_start : window_start]only, which is strictly earlier than the model's window. There is no path by which a matcher reads the target at scoring time.

Implementation note: the production GPU kernel uses (target's vote share) rather than (top-1's share) to keep the tilt scalar — the kernel only needs target stats, not the full vote vector. The two are equal when target is the top-1 candidate; when target is in the bucket but not top-1, the deployed kernel uses a slightly softer mix. Both are convex and preserve normalization.

Why the matcher is C++.

Both of V7's matchers (gap-pattern and hybrid-key) run inside tapin_cpp.py, JIT-compiled via torch.utils.cpp_extension.load_inline() at import time. The hot path is integer-only: pack a few prefix tokens into a hash key, look up the bucket of historical continuations, accumulate votes, return the top-K. Every step is array indexing and bit-shifts — the kind of work where Python overhead dominates by 100× or more.

The same matcher in pure NumPy takes ~14 s per evaluated window across 25M val tokens. In C++ it takes ~0.04 s. Three things make that gap:

  • GIL-free hot loop. A py::gil_scoped_releaseat the top of the matching function lets every window run independently. A ThreadPoolExecutor on the Python side fans out windows across CPU cores. With 16 cores on a Modal CPU instance the matcher saturates the bandwidth of the token array.
  • Zero allocation on the hot path. A thread_local Scratch struct holds pre-sized head[V], tail[V], fwd[wlen]linked-list arrays plus the candidate-vote scratch. First call grows them; subsequent calls reuse. No malloc in the matching loop, no GC, no Python objects.
  • Linked-list-of-occurrences for O(matches) iteration. For each token , head[t] is the first index where it occurred in the lost prefix; fwd[i] chains to the next. Iterating the chain is an walk — no scan over the whole prefix.

The matcher emits a flat array of fires (positions, tokens, is_cross, match_lengths, vote_counts). Python wraps it as a numpy view with zero copy. The downstream GPU mix reads it directly via torch.from_numpy.

~250 LOC of C++ per matcher. -O3 -march=native -ffast-math -funroll-loops at compile, sub-second JIT on a warm cache. The submission path runs the same C++ inside the post-TTT sliding-eval loop on 8×H100; matcher cost lives entirely on the CPU side and overlaps with GPU compute via streams.

Research baseline (defaults used throughout this post):

TAPIN_V7_ENABLED=1
TAPIN_V7_GAP_PATTERNS="1,2,3|1,2,3,4|1,3,5|1,2"
TAPIN_V7_GAP_W_BASES="0.04,0.04,0.04,0.04"
TAPIN_V7_HYBRID="2_2" # 2 exact + 2 class slots

Production config (tuning along the named axes):

TAPIN_V7_ENABLED=1
TAPIN_V7_GAP_PATTERNS="1,2,3|1,2,3,4|1,3,5|1,2|2,3,4|1,2,4|1,2,5|1,4,5|1,2,3,5"
TAPIN_V7_GAP_W_BASES="0.20,0.20,0.20,0.20,0.20,0.20,0.20,0.20,0.20"
TAPIN_V7_HYBRID="3,3|2,2|2,3|3,2"
TAPIN_V7_HYBRID_W=0.20
TAPIN_V7_ENTROPY_MIN=1.0 # gate by uncertainty
TAPIN_V7_MIN_LOST=64

Five tunings, all named in this post: more gap patterns (9 vs 4), more hybrid specs along the diagonal (4 vs 1), higher (0.20 vs 0.04), shorter (64 vs 128), and entropy gating. Together these push the booster well past the baseline numbers reported here on the deployment substrate (post-TTT, full val). The recipe's remaining headroom is real.