Selective-Attention-Study v0.1.0 · results

Selective Attention, trained with no position encoding at 16K

Selective Attention (Leviathan, Kalman and Matias, ICLR 2025) lets each query subtract from its attention logits how strongly earlier queries already selected each key. The paper trained it with learned position embeddings and measured it inside its training context. We trained it the way our DilutionAttention models were trained, at 209 million parameters and a 16K context with no position encoding, and found that it retrieves planted keywords out to 128K tokens — eight times its training context — on all three seeds, with in-context loss level with dilution attention. Training it at that scale needed a fused kernel, which this release provides.

8×

training context, retrieval held

0.99–1.00 to 128K, all three seeds

3.059

validation loss, mean of 3 seeds

dilution 3.056 · softmax + RoPE 3.083

0

parameters added to attention

the operator is parameter-free

½

softmax's training throughput

36K vs 72K tokens/s at 16K

Every model is a 24-layer, 209-million-parameter decoder trained at a 16K context on 4.19 billion FineWeb-Edu tokens (Chinchilla-matched) with the DilutionAttention harness, data and schedule unchanged. The softmax and dilution results are the published DilutionAttention runs; the Selective Attention models are new, three seeds. Only the attention operator, its position encoding and the seed differ.

Why this study

While reviewing related work for DilutionAttention we found that Selective Attention has the same shape: both subtract from each attention logit a term built from what earlier queries did with the same key. In small experiments at a 2K context it behaved much like dilution with no position signal at all, which made it worth testing at the scale where the dilution results were measured.

The paper's listing builds the full attention matrix, which does not fit a 24-layer model at 16K tokens. We wrote fused Triton kernels — forward and full backward, tested against the paper's listing — that compute the same operator without it. With those it trains at about dilution's speed on the unchanged DilutionAttention harness, so its results sit directly beside the published runs.

The operator

Head 0 decides how strongly each query "selects" each earlier key; the running total of those selections is subtracted from every head's logits for later queries. No parameters are added.

L_h[i, j] = q_h[i] . k_h[j] / sqrt(d)               # every head h, keys j <= i
S[i, j]   = relu(L_0[i, j])   for 1 <= j < i       # head 0 selects; not <BOS>, not self
F[i, j]   = sum over r < i of S[r, j]               # selection by strictly earlier queries
A_h       = causal_softmax(L_h - F);   out_h = A_h @ v_h

Dilution attention has the same form, softmax(L − F), with a different history F: the log of the softmax demand each key has accumulated, per head. The two differ in what is accumulated, how it is subtracted and whose history is used, and those differences show up in the long-document results below.

Retrieval past the trained context

A keyword is planted at varying depths in haystacks from 3.8K to 512K tokens. Everything to the right of the vertical rule is longer than any sequence the models saw in training. Each row is one trained model.

Retrieval past the trained contextHeatmap of keyword-retrieval accuracy by haystack length for 209M models trained at 16K. All three Selective Attention seeds retrieve 0.99 to 1.00 out to 128K, then 0.87 to 1.00 at 256K and 0.20 to 0.97 at 512K depending on the seed. Dilution holds 0.91 to 1.00 to 128K. Softmax with RoPE falls to chance by 32K.Keyword retrieval by haystack length · 209M parameters, trained at 16Kshare of planted keywords retrieved · chance is 0.14 · every seed shownin contextpast the trained context · no fine-tuning3.8K16K32K2×64K4×128K8×256K16×512K32×Selective Attention + BOS, no position encodingseed 13371.001.001.001.001.001.000.97seed 23571.001.001.001.001.000.870.40seed 73311.001.001.001.000.990.890.20Dilution, no position encoding (published)seed 13371.001.000.960.990.960.63–seed 23571.001.001.001.000.910.79–Softmax + RoPE (published control)seed 13371.000.790.140.14–––seed 23570.970.640.140.14–––
Likelihood-scored retrieval: eight candidate keywords, one disqualified by a control prior, so chance is 1/7 ≈ 0.14; 20 depth placements in context, 10 past it. Models without position encoding run unmodified; the RoPE models are shown unscaled (NTK scaling extends them somewhat, see the DilutionAttention results). Past 256K every model depends on its seed. – not evaluated.

Harder retrieval: natural text and distractors

The standard test repeats one paragraph, so a model can pass by spotting the only sentence that breaks the pattern. Two harder conditions: the haystack is real book text, and three similar facts about other keys are planted beside the target.

Retrieval in natural text · 209M, trained at 16KRange chart of retrieval in natural PG-19 text. Inside 16K the position-free operators retrieve 0.73 to 1.00. Past 16K Selective Attention declines to 0.30 to 0.83 at 128K depending on the seed, dilution to 0.67, and softmax with RoPE is at chance from 32K.Retrieval in natural text · 209M, trained at 16Kplanted keyword in PG-19 book text · bars: range over seeds · dots: one seed · chance 0.140.000.250.500.751.004K16K32K · 2×64K · 4×128K · 8×haystack length (tokens)Dilution0.67Selective + BOS0.30–0.83Softmax + RoPE0.11–0.16
Natural text: contiguous slices of six PG-19 books, 70 scored placements per cell (about ±0.06). The RoPE models use NTK scaling past 16K. Inside 16K, two of the three Selective Attention seeds and dilution retrieve 0.96–1.00 in natural text, evenly at every depth (seed 7331 is already at 0.73 at 16K), while softmax with RoPE favours facts near the end of the input.

Past the training length natural text costs Selective Attention retrieval, with a wide spread between seeds, and it loses facts in the middle of the input first. With three distractors, every operator scores 0.24–0.46 inside 16K and most misses are a distractor's keyword: the models find the planted facts but often attach the wrong one to the key. The position-free operators hold that level to 128K; softmax with RoPE falls toward chance.

A practical lesson: train with a BOS token

Selective Attention exempts position 0 from selection because the paper assumes it holds a beginning-of-sequence token. Windows cut from a token stream start mid-document, and without a BOS token two of our three models could not retrieve a fact placed in the very first sentence of their input (2/7 and 1/7 placements), at every length, while every other depth was retrieved. Putting a BOS token at the start of every training window brought those two seeds to 7/7 and 6/7 at no measurable cost in loss. The failure did not appear in our 2K-context experiments, so a short screen may not catch it.

Long documents: tolerated, not used

The same models read 29 PG-19 books to 128K tokens, out of domain for a model trained on educational web pages. Loss is averaged over each range of positions.

Loss along 29 PG-19 books, out to 128K tokens · 209M, trained at 16KRange chart of loss by position on PG-19 books. Selective Attention is at or below every reference in every range, about 3.43 to 3.58 nats. Dilution stays near 3.55 to 3.61. Past 16K softmax with RoPE and NTK scaling rises to 5.34 to 5.54 and the alt6 hybrid to 3.98 to 4.21.Loss along 29 PG-19 books, out to 128K tokens · 209M, trained at 16Knats per token by position in the book · lower is better · bars: range over seeds3.54.04.55.05.58–16K16–32K32–64K64–128Kposition in the book (range, tokens)Softmax + RoPE, NTK5.34–5.54Alt6 hybrid, NTK3.98–4.21Dilution3.61Selective + BOS3.54–3.58
Selective Attention is at or below every reference model in every range to 128K, by a clear margin past 16K, where softmax with RoPE and the alt6 hybrid climb. Past 128K its loss rises (0.13–0.29 nats above its in-window value by 256–512K) while dilution's stays nearly flat.

A flat curve shows that a model tolerates long input, not that it uses it. Scoring the same tokens with the whole book and with only a 16K rolling window, Selective Attention gains a little from text one to two windows back and is hurt by text more than four windows back, by up to 0.29 nats at 16–32×; dilution is about neutral to 131K and hurt about a third as much. Its lower loss on these books is in-window quality. Trained on to twice the tokens, its long-book loss climbs well above dilution's, which stays flat.

Selective vs dilution

The two operators share a form, softmax(L − F), and differ only in the history F: Selective Attention subtracts a linear running sum of head 0's selections, shared by every head; dilution subtracts the log of each head's own accumulated softmax demand. Trained identically, they split the axes.

Selective Attention against dilution attentionSide-by-side comparison at 209M parameters trained at 16K. Validation loss is tied. Selective Attention is better on in-window loss on long books, on standard retrieval at 128K and 256K, and on kernel cost. Dilution does not need a BOS token, keeps long-book loss flat past 128K and after further training, and is harmed about a third as much by distant text. Telling similar facts apart is tied; natural-text retrieval past the context is unclear.Selective Attention vs dilution attention · 209M, trained at 16K, no position encodingSelective + BOSDilutionEdgeValidation loss, 16K, 1×3.059 · 3 seeds3.056 · 2 seedstieLoss on long books, 8–32K3.43–3.523.55–3.58selectiveNeeds a BOS tokenyes · 2 of 3 seeds blindnodilutionRetrieval at 8× (128K)0.99–1.00 · 3 seeds0.91–0.96 · 2 seedsselectiveRetrieval at 16× (256K)0.87–1.000.63–0.79selectiveNatural-text retrieval at 8×0.30–0.83 · seed-dependent0.67 · 1 seedunclearTelling similar facts apart0.24–0.46 bandsame bandtieLong-book loss past 128Krises 0.13–0.29nearly flatdilutionLong books after 2× training+0.5 nats by 128–256Kflat (within 0.05)dilutionHarm from text 16–32× backup to +0.29 natsabout a third of thatdilutionAttention layer at 16K27.7 ms · half the memory30.5 msselective
Selective Attention: three seeds with BOS; dilution: the two published seeds (one seed where marked). Validation loss on a common 2.1M-token slice; long-book loss on 29 PG-19 books at 8–32K (with only a 16K window it is still about 0.1 nats better, so this is in-window quality); retrieval on the standard test; harm from distant text from the 16K rolling-window control on 16 books to 512K (one dilution seed). Kernel time: one attention layer, forward and backward, batch 2.

Where Selective Attention is ahead: it retrieves further on the standard test (all three seeds at 0.99–1.00 to 128K), models book text better inside its window by about 0.1 nats, and its kernel is slightly faster with half the memory. Validation loss on the training distribution is a tie.

Where dilution is ahead: stability. It needs no BOS token; its long-book loss stays flat to 32× its training length, at 1× and after twice the training, where Selective Attention's rises; and distant text harms it about a third as much. Its natural-text retrieval declines more gently on the one seed we evaluated, but the selective seeds spread so widely that this is not settled.

A plausible reading, not yet tested causally: Selective Attention's history grows linearly with the number of earlier queries and is shared by every head, so its suppression keeps strengthening with length and with training; dilution's log of demand grows slowly and is kept per head.

What it costs

One attention layer, forward and backward at 16K, takes 27.7 ms with the selective kernel against 30.5 ms for the dilution kernel and 9.4 ms for flash softmax attention: 2.9× softmax's time, 0.91× dilution's, with half dilution's memory. For the whole model a 16K training step runs at about 36K tokens/s against 72K for softmax with RoPE, so at equal wall clock softmax sees about twice the tokens; every comparison here is at equal tokens. Cached decoding is written in PyTorch, not as a kernel.

What this does not establish

One model size, one corpus and one context length, with three seeds of Selective Attention and two of each reference. The retrieval tests are synthetic — one planted keyword, in repeated text or in natural text with distractors — and how far retrieval reaches past 16K varies by seed.

Retrieval scores overstate long-context ability: neither position-free operator uses distant natural text to predict better, and Selective Attention's long-document loss degrades further with more training. Why its extrapolation varies between seeds and erodes with training is not resolved; damping the history term at evaluation time made things worse. The Forgetting Transformer and stick-breaking attention also train without position encoding and were not run at this scale. This is an independent implementation, not affiliated with or endorsed by the paper's authors.

Everything behind these results

The release ships the fused Triton kernels with exact gradients and the plain reference they are tested against, the training and evaluation code, the configurations, metrics and data provenance of every run, every result file behind these charts, and the investigation scripts. It is research code published as-is, released under the Apache-2.0 license.