Ark (Part-1)

Not Every Token Deserves Softmax

Ark Series  —  Part 1: Not Every Token Deserves Softmax  |  Part 2: Results →  |  Part 3: Kernels and Systems →

🚢 An ark can’t carry everything through the flood, so it has to choose what comes aboard. A language model reading a long context faces its own flood of tokens: caching every one makes memory grow with the context, while compressing all of them into a fixed-size state blurs the details it may later need to recall.

Attention Routing Kernels (Ark) take the ark’s approach. Ark is a new attention layer that decides, token by token, what to retain exactly in a KV cache and what to compress into a recurrent state. Across 400M–2B parameters it is competitive with Transformers and hybrid models while storing a fraction of their memory, and it decodes 3.35× faster than FlashAttention from a 64K-token prompt (2B models, batch 8, one H100).

How Much Attention Do We Need?

Recurrent models fold each token into a fixed-size state, so they run in linear time with constant memory, yet they still trail Transformers on recall. The go-to fix today is the hybrid: interleave a few softmax attention layers among many recurrent ones. Recent large-scale releases such as Kimi K3, Qwen3.8-Flash-Next and NVIDIA Nemotron 3 are all built this way.

Why does a little attention go so far? Recurrent models fall furthest behind on tasks that hinge on retrieval, finding and reusing something given earlier in the prompt. Looking inside the models showed why: both Transformers and recurrent models implement retrieval with the same two-step circuit, termed gather-and-aggregate (G&A). It lives in only a few heads, and recurrent models run it less sharply; swapping even one of them for attention brings the recurrent model closer to the Transformer. That is what the attention layers of a hybrid provide.

But hybrids keep far more exact memory than retrieval needs: every attention layer caches every token, at a ratio set by hand. Retrieval-aware distillation (RAD) shows how far this can go: keeping attention in only the 2% of heads that run G&A recovers over 95% of the teacher on retrieval-heavy tasks. But every head RAD keeps as attention still caches every token, even though retrieval needs only a few, and which few depends on the input. The last step is to choose per token, and to learn that choice during training.

Can a single layer learn, token by token, what to cache and what to compress into its recurrent state?

We think this is where next-generation architectures should go: not a stack of separate attention and recurrent layers, but one kind of layer that holds both memories and learns the pattern of what to compress. In effect, the network learns its own architecture, placing each KV group anywhere between attention and recurrence. Its KV cache grows only with the tokens worth remembering exactly, next to a compact state that absorbs everything else. That is what we built Ark for.

Two Kernels, Two Memories

Every autoregressive sequence model has to decide how the current token reads the past. Write the queries, keys and values as \(q_t, k_t, v_t\). Causal attention is a weighted average over past values, and the weights come from a similarity kernel:

\[o_t = \frac{\sum_{j=1}^t \mathrm{sim}(q_t, k_j)\, v_j}{\sum_{j=1}^t \mathrm{sim}(q_t, k_j)}.\]

Choosing the kernel decides much more than the weights. It decides what the model has to remember.

The exponential kernel needs a KV cache

Softmax attention uses the exponential kernel \(\mathrm{sim}(q,k)=\exp(q^\top k)\) (with \(1/\sqrt{d_k}\) absorbed into \(q\)). This kernel does not factorize: there is no finite feature map that turns \(\exp(q^\top k)\) into an inner product. To evaluate the sum for every new query, the model has to keep every past key and value around. That is the KV cache. It grows linearly with context, and its size dominates long-context inference memory.

The linear kernel folds into a state

Linear attention uses a kernel that does factorize, \(\mathrm{sim}(q,k)=\phi(q)^\top\phi(k)\), with a non-negative feature map \(\phi\). Then the sums can be accumulated ahead of time:

\[o_t = \frac{\phi(q_t)^\top S_t}{\phi(q_t)^\top z_t}, \qquad S_t = \sum_{j\le t}\phi(k_j)\,v_j^\top \in \mathbb{R}^{d_k\times d_v},\quad z_t = \sum_{j\le t}\phi(k_j).\]

The whole history lives in a fixed-size recurrent state \((S_t, z_t)\). It is cheap to carry, but individual tokens are blended together and cannot be recovered exactly. That is why recurrent models struggle with recall.

One shared notion of position

So far, both kernels compare only content; neither knows how far back a key is. Transformers usually inject position through positional embeddings, and today’s standard choice is rotary embeddings (RoPE), which rotate queries and keys by position-dependent angles so that each score depends on the relative distance. That suits the exponential kernel, but Ark needs one positional scheme that works for both kernels, and RoPE is awkward for the linear one: once the non-negative features \(\phi(q),\phi(k)\) are rotated, a score can turn negative and the normalizing sum can even hit zero. A cleaner option is temporal decay, which works for both kernels and is what the Forgetting Transformer (FoX) uses in softmax attention. A forget gate \(f_u\in(0,1)\), which doubles as a positional encoding (see our post On the Legacy of Linear Transformers in Positional Embeddings), multiplies every score by

\[f_{j:t} = \prod_{u=j+1}^{t} f_u ,\]

and for the linear kernel this keeps the recurrence: \(S_t = f_t S_{t-1} + \phi(k_t)v_t^\top\). Because the same decay applies to both kernels, a token’s positional weight does not depend on which memory it ends up in. This will matter a lot when we route.

Attention Routing Kernels

Ark chooses the kernel separately for each entry: one token, in one KV group, of one layer. An entry assigned to the exponential (softmax) kernel is retained in the KV cache. An entry assigned to the linear kernel is compressed into the recurrent state. We use this pair of words, and these two colors, for the two kinds of entries throughout the series. Every query reads both memories.

One router, two memories

The choice is made by a learned router \(r:\mathcal X\to\lbrace 0,1\rbrace\) that looks at the token’s representation \(x_j\). This is the layer’s hidden state at that position, so it already mixes in the tokens before it; what the router cannot see is the queries that will come later. With \(r(x_j)=1\) the entry is retained: it stays in the KV cache and is read through the exponential (softmax) kernel. With \(r(x_j)=0\) it is compressed: it goes into the recurrent state and is read through the linear kernel. The router commits when a token is written, without ever seeing the queries that will later look it up. In return, routing stays causal, and at decode time each new token goes straight into one memory and stays there.

Formally, let \(R(t)=\lbrace j\le t : r(x_j)=1\rbrace\) be the retained set. Splitting the decayed attention sum by routing decision gives a linear part over the compressed entries and a softmax part over the retained ones:

\[o_t = \frac{\textcolor{#D9730D}{\phi(q_t)^\top S_t} \;+\; \textcolor{#2E6DB4}{\sum_{j\in R(t)} \exp(q_t^\top k_j)\,f_{j:t}\,v_j}} {\textcolor{#D9730D}{\phi(q_t)^\top z_t} \;+\; \textcolor{#2E6DB4}{\sum_{j\in R(t)} \exp(q_t^\top k_j)\,f_{j:t}}},\]

where the recurrent state now only accumulates the entries assigned to the linear kernel:

\[{S_t = f_t S_{t-1} + (1-r(x_t))\,\phi(k_t)v_t^\top, \qquad z_t = f_t z_{t-1} + (1-r(x_t))\,\phi(k_t).}\]

The output combines a cheap linear (recurrent) part with an expressive softmax part over the retained set, under one shared normalizer: unlike in a hybrid, the two kernels compete for the same attention mass inside a single layer. So a query reads from the cache and the state in proportion to their summed scores, with their magnitudes on one scale. When the query finds a strong match in the cache, the cache scores dominate; when it doesn’t, the state scores do. And since both parts share the decay \(f_{j:t}\), a token fades with distance at the same rate whichever memory holds it; routing only changes how its content is matched against a query.

Why decide at write time, and not per query? Sparse-attention methods such as NSA and DeepSeek Sparse Attention pick, for every query, which past tokens to read. With context length \(L\) and \(K \ll L\) selected tokens, each query’s attention costs \(O(K)\) instead of \(O(L)\), so a full sequence costs \(O(LK)\) rather than \(O(L^2)\) (DSA still runs a lightweight indexer over all \(L\) tokens to make the choice). That is flexible and saves compute, but every token has to stay in the KV cache in case a later query selects it, so the cache still holds \(O(L)\) entries: sparse readout reduces computation, not the linearly growing memory. Ark makes one fixed, causal and cheap decision per token, once, and a compressed token never enters the cache at all. The cache grows only with the retained set \(R(t)\), about a tenth of the tokens at our budget, while everything else lives in a fixed-size state. That is what actually cuts memory.

Why does the router decide from \(x_j\) alone? Deciding from the current hidden state keeps decoding simple: one decision when a token arrives, no lookahead and no revisiting. The flip side is that a token whose importance only becomes clear later, once a query shows what matters, cannot be recovered exactly after it is compressed. A router that can revisit its decisions, or a budget that adapts to the input, is the natural next step; we come back to it at the end of Part 3.

Routing splits the attention matrix in two

The router decides once, from \(x_j\), so once an entry picks a kernel, every later query in that KV group reads it through that kernel. In the score matrix, routing colors whole columns. Here is the readout for five tokens with routing \(r=[1,0,1,0,0]\): tokens 1 and 3 are retained and read through the exponential kernel, and the rest are compressed and read through the linear kernel.

Because routing colors whole columns, the readout splits exactly into two smaller problems. Gather the blue columns and you get a packed problem: every query attends only to the retained keys \(k_1, k_3\), so the score matrix shrinks from \(5\times 5\) to \(5\times 2\) and only \(v_1, v_3\) need to sit in the KV cache. The orange columns form a recurrent problem: a causal linear-attention readout over \(k_2, k_4, k_5\), which never has to be materialized because it folds into the state \((S_t, z_t)\). The readout above is exactly the sum of the two (decay and the shared normalizer are left out for clarity):

The two parts meet only in the shared normalizer, so each can run on its own kernel: exponential attention over the packed retained entries, and a linear recurrence over everything else. This split is what makes Ark cheap, and Part 3 shows how each side is implemented.

Two familiar models are special cases. With \(r\equiv 1\), everything is retained and Ark is softmax attention with a forget gate (FoX). With \(r\equiv 0\), everything is compressed and Ark is decayed linear attention. Ark lives in between and lets the data decide where.

The Ark Block

Building an Ark model is simple: unlike a hybrid, it stacks a single type of layer, an Ark block followed by a gated MLP, each wrapped in an RMSNorm and a residual connection. The router decides where memory goes, so there is no layer ratio to tune.

Inside the block, the input is projected into a router score, a decay gate, values, and queries and keys. The router sends each token either to the KV cache, read through the exponential kernel, or into the recurrent state, read through the linear kernel, and every query reads both under one shared normalizer. The output then goes through an RMSNorm, a swish gate and the output projection.

The two kernels share their base query and key projections, but the best key for exact retrieval is not the best input to the linear kernel’s feature map, here \(\phi(x)=1+\mathrm{elu}(x)\), so the linear kernel adds small low-rank adapters (QK LoRA) on top. Each kernel also RMS-normalizes its own queries and keys so their scores stay comparable in the shared normalizer. There is no short convolution: it hurt recall in our ablations.

Teaching the Router

The router has a hard job: it must decide whether a token will need exact recall before the query that needs it arrives. We give it that signal with two simple losses. The first uses full softmax attention as a teacher: a token should stay in the KV cache if reading it through the linear kernel would noticeably change the attention distribution that the softmax kernel would have produced. We only need to check this on a handful of randomly sampled queries per sequence, so it is cheap. The second is a budget: on its own, the teacher would happily keep everything, so we ask each sequence to compress at least 90% of its entries. The budget only says how much to compress, pooled over all layers and KV groups, never where, so the router is free to spend its cache wherever retrieval needs it.

These losses train only the router; the rest of the model is trained by the usual language-modeling loss.

Deep dive: the two router losses

The router is a linear score per layer \(\ell\) and KV group \(g\), thresholded at \(\tau\):

\[\tilde r_{\ell g}(x_t) = \sigma\!\left(W_R^{(\ell,g)} x_t\right), \qquad r_{\ell g}(x_t) = \mathbf 1\!\left[\tilde r_{\ell g}(x_t) > \tau\right], \qquad \mathcal L_{\text{router}} = \lambda_{\text{approx}}\mathcal L_{\text{approx}} + \lambda_{\text{budget}}\mathcal L_{\text{budget}} .\]

Approximation loss (the softmax teacher). For a query \(t\), define the branch-normalized distributions

\[\textcolor{#2E6DB4}{P^{\exp}_{tj} = \frac{\exp(q_t^\top k_j)f_{j:t}}{\sum_{u\le t}\exp(q_t^\top k_u)f_{u:t}}}, \qquad \textcolor{#D9730D}{P^{\text{lin}}_{tj} = \frac{\phi(q_t)^\top\phi(k_j)f_{j:t}}{\sum_{u\le t}\phi(q_t)^\top\phi(k_u)f_{u:t}}} .\]

The hard decision is not differentiable, so we mix the two with the router score and renormalize, \(\widetilde P_t \propto \textcolor{#2E6DB4}{\tilde r_j P^{\exp}_{tj}} + \textcolor{#D9730D}{(1-\tilde r_j)P^{\text{lin}}_{tj}}\), and compare it to the teacher on a small set \(\mathcal Q\) of uniformly sampled queries:

\[\mathcal L_{\text{approx}} = \frac{1}{|\mathcal Q|}\sum_{t\in\mathcal Q}\mathrm{KL}\!\left(\textcolor{#2E6DB4}{P^{\exp}_t} \,\big\|\, \widetilde P_t\right).\]

This is an unbiased estimate of the average over all queries. We use \(\lvert\mathcal Q\rvert = 10\); Part 2 shows that even a single sampled query per sequence is enough.

Budget loss. With a target linear fraction \(\textcolor{#D9730D}{c^{\ast}_{\text{lin}}}=0.9\) and the realized fraction \(\textcolor{#D9730D}{\bar c_{\text{lin},b}}\) of sequence \(b\), pooled over all its layers, KV groups and positions, we penalize only a shortfall:

\[\mathcal L_{\text{budget}} = \frac{1}{B}\sum_{b=1}^{B}\max\!\left(\textcolor{#D9730D}{c^{\ast}_{\text{lin}}} - \textcolor{#D9730D}{\bar c_{\text{lin},b}},\, 0\right)^2 .\]

The forward pass uses the hard indicator with a straight-through estimator. The weight \(\lambda_{\text{budget}}\) adapts online, growing while a batch compresses too little and shrinking once it compresses enough, The budget applies only during training: at inference nothing caps the cache, so retention varies with the input and from one KV group to another. In the example in Part 2, one KV group retains about 13% of tokens.

What Comes Next