Paper · Open models · Version v1
Not Every Token Deserves Softmax
First published: arXiv, . Original
Copyright the authors. Licensed under Creative Commons Attribution 4.0 International.
This page holds the text of the paper, converted to HTML; figures may be left out.
Softmax and linear attention sit at opposite ends of a memory tradeoff because they compare tokens with different kernels. The former uses an exponential kernel and caches every token, growing memory linearly with length; the latter uses a linear kernel, which factorizes so that the past compresses into a fixed-size recurrent state, at the cost of limited recall. In both cases the kernel is fixed, so neither adapts computation or memory to the input. We introduce Attention Routing Kernels (Ark), an architecture that chooses the kernel separately for each token, in every layer and KV group. A learned router sends each token to exactly one of two memories: tokens that need the exponential kernel stay in a KV cache, and the rest are folded into a fixed-size recurrent state. Every query reads both memories. The routing split governs cost: training combines a linear-time recurrent pass with pairwise attention over retained keys, while inference carries a fixed-size recurrent state plus the retained entries in the KV cache. Across 400M--2B parameters, Ark is competitive with Transformers and with hybrids that interleave softmax- and linear-attention layers, while storing about 90% and 25--53% less memory, respectively. Ark's smaller memory thus speeds up long-context decoding: at 64K, the 2B model is $1.8\times$ faster than a GLA hybrid and $3.8\times$ faster than FlashAttention-4. Code is available at https://github.com/goombalab/ark.
Abstract
Softmax and linear attention sit at opposite ends of a memory tradeoff because they compare tokens with different kernels. The former uses an exponential kernel and caches every token, growing memory linearly with length; the latter uses a linear kernel, which factorizes so that the past compresses into a fixed-size recurrent state, at the cost of limited recall. In both cases the kernel is fixed, so neither adapts computation or memory to the input. We introduce Attention Routing Kernels (Ark), an architecture that chooses the kernel separately for each token, in every layer and KV group. A learned router sends each token to exactly one of two memories: tokens that need the exponential kernel stay in a KV cache, and the rest are folded into a fixed-size recurrent state. Every query reads both memories. The routing split governs cost: training combines a linear-time recurrent pass with pairwise attention over retained keys, while inference carries a fixed-size recurrent state plus the retained entries in the KV cache. Across 400M–2B parameters, Ark is competitive with Transformers and with hybrids that interleave softmax- and linear-attention layers, while storing about 90% and 25–53% less memory, respectively. Ark’s smaller memory thus speeds up long-context decoding: at 64K, the 2B model is faster than a GLA hybrid and faster than FlashAttention-4. Code is available at https://github.com/goombalab/ark.
1 Introduction
Autoregressive language models differ in how the current token reads past context, and that choice is set by the similarity kernel. Transformers (Vaswani et al., 2023) compare each query to every past key through an exponential (softmax) kernel; because this kernel does not factorize, they must cache the entire history and pay quadratic training cost. Linear-attention and state-space models (SSMs) (Katharopoulos et al., 2020; Gu and Dao, 2024) use interactions that factorize, so the past folds into a fixed-size recurrent state that is cheap to carry but cannot recover any single token exactly. Hybrids (Kimi Team et al., 2025; Blakeman et al., 2025) interleave the two, but the split is coarse: each layer is fixed in advance as attention or recurrent, and every attention layer still caches every token, so memory still grows with sequence length.
This coarseness is at odds with how Transformers actually retrieve. Bick et al. (2025c) show that although retrieval depends on exact attention, it runs through only a handful of heads, and within those heads only a few tokens are recalled. The capability that separates attention from recurrence is therefore concentrated in a few heads and, within them, a small set of tokens, rather than spread across whole layers as a per-layer split assumes. The choice between the KV cache and the recurrent state should thus be made per token, not per layer.
We introduce Attention Routing Kernels (Ark), which replaces the per-layer split with a learned per-token router. For each token and KV group in each layer, the router decides how future queries will read that token: either it is kept in the KV cache and read through the exponential kernel, or it is folded into a recurrent state and read through the linear kernel (Figure 1). Every query reads both memories. The router sees only the token’s own representation, before any future query arrives, so it must predict which entries will need exact recall. We train it to preserve the full decayed softmax attention distribution while meeting a compression target.
Because the router sets the allocation, Ark needs no hand-tuned layer ratio. Every layer is the same Ark block, and the amount of KV-cache memory can vary across layers, KV groups, and inputs. The router learns to retain the entries whose exact recall the linear kernel cannot provide, so KV-cache memory concentrates where retrieval needs it. Training and inference costs then scale with the number of retained entries: exponential attention runs only over them, and decoding stores a fixed-size recurrent state plus those entries.
Across 400M–2B parameters, Ark is competitive with strong Gated Linear Attention (GLA) and Gated DeltaNet (GDN) hybrids (Yang et al., 2023; Yang et al., 2024a) while storing 25–53% fewer elements and decoding faster at long context: at 64K, the 2B model is faster than a GLA hybrid and faster than FlashAttention-4 (Zadouri et al., 2026). These results support learned per-entry allocation as a way to preserve the accuracy of Transformers and hybrids while reducing memory and accelerating long-context decoding.
Contributions.
We make the following contributions.
Per-entry kernel routing (§3). We introduce Ark, whose block chooses the exponential or linear kernel separately for each token in each KV group of each layer. Because the router sets the allocation, a single homogeneous block replaces hand-tuned layer ratios, and KV-cache memory can vary across layers, KV groups, and inputs. We train the router to distill the full decayed softmax distribution from a few sampled queries, with a per-sequence compression target pooled across layers and KV groups.
Efficient computation (§4). Once routing is fixed, the two branches run independently: exponential attention over packed retained entries, and a log-space chunkwise linear pass with retained entries masked out. Training and inference costs then scale with the number of retained entries, and decoding carries a fixed-size recurrent state plus those entries.
Empirical validation (§5). Across 400M–2B parameters, Ark is competitive with Transformers and hybrids on language modeling and recall, and outperforms training-free KV eviction at equal memory. It stores about a tenth of a Transformer’s memory and 25–53% less than hybrids, and thus decodes substantially faster: at 64K context, it is faster than a GLA hybrid and faster than FlashAttention-4.
Ablations and analysis (§6–§7). Ablations identify how to design the linear branch to complement the exponential branch (query–key LoRA adapters, normalizations, feature maps, and convolutions). They also show that a single sampled query per sequence suffices to train the router, which recalls better than allocations that ignore content, even when they get up to more KV memory. Analysis of the trained model shows that Ark handles commonsense tasks with its recurrent state alone but retrieves through a few entries in the KV cache: moving only the answer tokens to the recurrent state cuts the 400M model’s mean recall accuracy about sixfold.
\underbrace{\begin{pmatrix}{\color[rgb]{0.1797,0.4258,0.707}\exp\left(q_{1}^{\top}k_{1}\right)}&0&0&0&0\\ {\color[rgb]{0.1797,0.4258,0.707}\exp\left(q_{2}^{\top}k_{1}\right)}&{\color[rgb]{0.85,0.425,0}\phi\left(q_{2}\right)^{\top}\mkern-5.0mu\phi\left(k_{2}\right)}&0&0&0\\ {\color[rgb]{0.1797,0.4258,0.707}\exp\left(q_{3}^{\top}k_{1}\right)}&{\color[rgb]{0.85,0.425,0}\phi\left(q_{3}\right)^{\top}\mkern-5.0mu\phi\left(k_{2}\right)}&{\color[rgb]{0.1797,0.4258,0.707}\exp\left(q_{3}^{\top}k_{3}\right)}&0&0\\ {\color[rgb]{0.1797,0.4258,0.707}\exp\left(q_{4}^{\top}k_{1}\right)}&{\color[rgb]{0.85,0.425,0}\phi\left(q_{4}\right)^{\top}\mkern-5.0mu\phi\left(k_{2}\right)}&{\color[rgb]{0.1797,0.4258,0.707}\exp\left(q_{4}^{\top}k_{3}\right)}&{\color[rgb]{0.85,0.425,0}\phi\left(q_{4}\right)^{\top}\mkern-5.0mu\phi\left(k_{4}\right)}&0\\ {\color[rgb]{0.1797,0.4258,0.707}\exp\left(q_{5}^{\top}k_{1}\right)}&{\color[rgb]{0.85,0.425,0}\phi\left(q_{5}\right)^{\top}\mkern-5.0mu\phi\left(k_{2}\right)}&{\color[rgb]{0.1797,0.4258,0.707}\exp\left(q_{5}^{\top}k_{3}\right)}&{\color[rgb]{0.85,0.425,0}\phi\left(q_{5}\right)^{\top}\mkern-5.0mu\phi\left(k_{4}\right)}&{\color[rgb]{0.85,0.425,0}\phi\left(q_{5}\right)^{\top}\mkern-5.0mu\phi\left(k_{5}\right)}\end{pmatrix}\cdot\begin{pmatrix}v_{1}^{\top}\\ v_{2}^{\top}\\ v_{3}^{\top}\\ v_{4}^{\top}\\ v_{5}^{\top}\end{pmatrix}}_{\text{\large Full QKV}}
(a) Routed readout
(b) Routing over time
Figure 1: Ark routes each token to one of two memories. (a) The routed readout for five tokens with routing : retained keys are scored with the exponential kernel (blue), compressed keys with the linear kernel (orange); decay and normalization are suppressed. (b) The same five tokens over time: the router retains a token in the KV cache (blue) or compresses it into the recurrent state (orange). Every output reads both memories.
2 Background
We review the two kernels that Ark routes between, the decay mechanism they share, and the cost of computing each.
2.1 Causal Attention
Let be a sequence of token embeddings. Queries , keys , and values are learned projections of , with denoting their -th rows, written as column vectors. Causal attention computes the output at position as
o_{t}=\frac{\sum_{j=1}^{t}\mathop{\mathrm{sim}}\left(q_{t},k_{j}\right)\,v_{j}}{\sum_{j=1}^{t}\mathop{\mathrm{sim}}\left(q_{t},k_{j}\right)}.
We assume throughout that similarity scores are non-negative and that the denominator is nonzero. The choice of kernel \mathop{\mathrm{sim}}\left(\cdot,\cdot\right) gives rise to two broad families:
Softmax Attention (Vaswani et al., 2023). Softmax Attention uses the strictly positive exponential dot-product kernel
\mathop{\mathrm{sim}}_{\mathrm{exp}}\left(q_{t},k_{j}\right)\coloneqq\exp\!\left(\frac{q_{t}^{\top}k_{j}}{\sqrt{d_{k}}}\right),which gives
From here on, we absorb into the queries used by the exponential kernel and write
\mathop{\mathrm{sim}}_{\mathrm{exp}}\left(q_{t},k_{j}\right)=\exp(q_{t}^{\top}k_{j}). To evaluate this sum at every step, softmax attention stores the keys and values of all past tokens in a KV cache. The cache grows linearly with context length and dominates long-context inference memory.Linear Attention (Katharopoulos et al., 2020). Linear attention avoids a growing KV cache by using a kernel that factorizes through a feature map:
\mathop{\mathrm{sim}}_{\mathrm{lin}}\left(q_{t},k_{j}\right)\coloneqq\phi(q_{t})^{\top}\phi(k_{j}),where is an elementwise non-negative feature map. We call this the linear kernel, since it is an inner product in feature space. In Ark, linear-kernel scores are likewise scaled by ; we absorb this factor into . We use a strictly positive map (or add a small positive constant) to keep the denominator nonzero. The normalized output is
where and are recurrent states. We keep this normalized form; many recent linear-attention models drop the denominator (Yang et al., 2023; Dao and Gu, 2024). Because the kernel factorizes, the entire history is summarized by the fixed-size recurrent states and , which are updated incrementally: and . This is the property softmax attention lacks: the exponential kernel has no exact finite-dimensional feature map over unrestricted real inputs, so it cannot be summarized this way; the resulting recall limitations are discussed in Section 8.
Heads and KV groups.
Both kernels run in parallel over query heads. With grouped-query attention (Ainslie et al., 2023), these heads share key–value heads: each KV group holds one set of keys and values, which its query heads all read, and hence one KV cache (softmax attention), one recurrent state (linear attention), or, in Ark, one of each. The equations in this section describe a single query head and its KV group, and memory is counted per KV group.
Temporal Decay.
A causal mask restricts a query to past keys but does not encode their distance. Transformers commonly encode position with RoPE (Su et al., 2021), which rotates queries and keys before their dot product. However, RoPE does not combine cleanly with normalized linear attention: rotating the non-negative features can produce negative scores, so the denominator is no longer guaranteed positive. Temporal decay instead multiplies each similarity score by a cumulative forget factor. Because it applies equally to both kernels, it gives the two branches of Ark one shared positional mechanism (Section 3).
For forget gates , decayed causal attention is
o_{t}=\frac{\sum_{j=1}^{t}\mathop{\mathrm{sim}}\left(q_{t},k_{j}\right)\,f_{j:t}\,v_{j}}{\sum_{j=1}^{t}\mathop{\mathrm{sim}}\left(q_{t},k_{j}\right)\,f_{j:t}},\qquad f_{j:t}=\prod_{u=j+1}^{t}f_{u}.
This product notation follows Dao and Gu (2024); the empty product gives . With a constant gate, depends only on the distance ; with varying gates, it depends on the intervening positions. The gates are data-dependent, computed from each token. With the exponential kernel, Equation 3 is Forgetting Attention (Lin et al., 2025); with the linear kernel, it is linear attention with a scalar data-dependent gate, as in Mamba-2. For linear attention, this decay preserves the recurrent form:
with .
2.2 Computing Causal Attention
The two kernels also differ in how they are computed. Let and denote the numbers of query and key positions. In standard self-attention , but we keep them separate because in Ark the exponential branch attends only to the retained keys, so can be much smaller than .
Softmax attention.
Computing the query–key scores and applying them to the values requires operations. This pairwise computation is highly parallelizable. A naive implementation additionally materializes an attention matrix; tiled implementations avoid this matrix and use storage for queries, keys, values, and outputs, up to hardware-dependent workspace (Dao et al., 2022). During autoregressive decoding, however, softmax attention keeps a KV cache of keys and values, requiring memory per KV group.
Linear attention.
Evaluated naively, the recurrence is sequential, which limits parallelism in training and prefill. Chunkwise algorithms (Yang et al., 2023; Dao and Gu, 2024) split the sequence into blocks of size , processing tokens within a block in parallel and passing the recurrent state between blocks. For , this costs operations, interpolating between the recurrent form () and the fully parallel form (). At inference, only the fixed-size recurrent states are kept, requiring memory.
Ark pays both costs, but on different sets: the chunkwise linear pass runs over all tokens, while exponential attention runs only over the retained keys (Section 4).
3 Attention Routing Kernels (Ark)
Softmax attention keeps every token in the KV cache; linear attention folds every token into a fixed-size recurrent state. In both cases the kernel dictates the memory (Section 2.1), and the choice is applied uniformly to every token. Yet retrieval in Transformers relies on a sparse, nonuniformly placed set of heads (Bick et al., 2025c; Bick et al., 2026), motivating KV-cache allocation that can vary across layers and KV groups.
Ark chooses the kernel separately for each entry, meaning one token within one KV group of one layer. An entry assigned to the exponential kernel stays in the KV cache; one assigned to the linear kernel is folded into the recurrent state. Both kernels share the temporal decay of Section 2.1. We describe the routed output (§3.1), how the router is trained (§3.2), and the full block (§3.3).
3.1 Token-Level Routing
For clarity, we fix a layer, a query head, and its associated KV group, and suppress these indices. The routing decision is shared by all query heads in the group. Let be the token representations. We formalize the kernel choice for each entry with a learned router : selects \mathop{\mathrm{sim}}_{\mathrm{exp}}\left(\cdot,\cdot\right), and selects \mathop{\mathrm{sim}}_{\mathrm{lin}}\left(\cdot,\cdot\right). Because depends only on , the decision is made when token is written, before any future query is seen. This keeps routing causal and lets decoding commit each entry to one memory immediately.
Define the retained set . Splitting the decayed attention of Equation 3 by routing decision gives the causal output at position :
o_{t}=\frac{\sum_{j=1}^{t}\mathop{\mathrm{sim}}\left(q_{t},k_{j}\right)\,f_{j:t}\,v_{j}}{\sum_{j=1}^{t}\mathop{\mathrm{sim}}\left(q_{t},k_{j}\right)\,f_{j:t}}=\frac{\sum_{j\in R(t)}\mathop{\mathrm{sim}}_{\mathrm{exp}}\left(q_{t},k_{j}\right)\,f_{j:t}\,v_{j}+\sum_{j\in[t]\setminus R(t)}\mathop{\mathrm{sim}}_{\mathrm{lin}}\left(q_{t},k_{j}\right)\,f_{j:t}\,v_{j}}{\sum_{j\in R(t)}\mathop{\mathrm{sim}}_{\mathrm{exp}}\left(q_{t},k_{j}\right)\,f_{j:t}+\sum_{j\in[t]\setminus R(t)}\mathop{\mathrm{sim}}_{\mathrm{lin}}\left(q_{t},k_{j}\right)\,f_{j:t}}.
Both branches share the decay , so an entry’s positional weighting is the same whichever memory stores it; routing changes how its content is compared. Substituting the two kernels from Section 2.1 (as in Figure 2) gives:
where the linear branch is represented by recurrent states as in Equation 2, now accumulating only the entries assigned to the linear kernel:
The output thus combines a cheap recurrent part with an expressive pairwise part over the retained set . The two parts share one denominator, which is why the linear branch keeps the normalizer of Equation 2. Each KV group keeps the recurrent states . For clarity, these equations use the same notation in both branches; the branch-specific projections are described in §3.3. Figure 2 illustrates the resulting readout. Routing partitions the columns of the score matrix: once an entry is assigned a kernel, every later query associated with that KV group reads it through that kernel.
3.2 Router Training Objective
Since the router must decide before future queries are seen, it needs a signal for which entries the linear kernel would represent poorly. We obtain one by treating the full decayed softmax distribution as a teacher: an entry should stay in the KV cache when scoring it with the linear kernel would make the routed distribution deviate noticeably from the teacher.
We parameterize the router separately for each layer and KV group as
where is the router score, indexes the KV groups, is learned, and is the routing threshold. Equality with selects the linear kernel, so the compression indicator is .
The router must balance two goals: match the softmax distribution where the linear kernel would not, and meet a per-sequence compression target. We encode these goals with
where is a fixed weight and is an adaptive penalty weight updated online by Equation 9.
\underbrace{\begin{pmatrix}{\color[rgb]{0.1797,0.4258,0.707}\exp\left(q_{1}^{\top}k_{1}\right)}&0&0&0&0\\ {\color[rgb]{0.1797,0.4258,0.707}\exp\left(q_{2}^{\top}k_{1}\right)}&{\color[rgb]{0.85,0.425,0}\phi\left(q_{2}\right)^{\top}\mkern-5.0mu\phi\left(k_{2}\right)}&0&0&0\\ {\color[rgb]{0.1797,0.4258,0.707}\exp\left(q_{3}^{\top}k_{1}\right)}&{\color[rgb]{0.85,0.425,0}\phi\left(q_{3}\right)^{\top}\mkern-5.0mu\phi\left(k_{2}\right)}&{\color[rgb]{0.1797,0.4258,0.707}\exp\left(q_{3}^{\top}k_{3}\right)}&0&0\\ {\color[rgb]{0.1797,0.4258,0.707}\exp\left(q_{4}^{\top}k_{1}\right)}&{\color[rgb]{0.85,0.425,0}\phi\left(q_{4}\right)^{\top}\mkern-5.0mu\phi\left(k_{2}\right)}&{\color[rgb]{0.1797,0.4258,0.707}\exp\left(q_{4}^{\top}k_{3}\right)}&{\color[rgb]{0.85,0.425,0}\phi\left(q_{4}\right)^{\top}\mkern-5.0mu\phi\left(k_{4}\right)}&0\\ {\color[rgb]{0.1797,0.4258,0.707}\exp\left(q_{5}^{\top}k_{1}\right)}&{\color[rgb]{0.85,0.425,0}\phi\left(q_{5}\right)^{\top}\mkern-5.0mu\phi\left(k_{2}\right)}&{\color[rgb]{0.1797,0.4258,0.707}\exp\left(q_{5}^{\top}k_{3}\right)}&{\color[rgb]{0.85,0.425,0}\phi\left(q_{5}\right)^{\top}\mkern-5.0mu\phi\left(k_{4}\right)}&{\color[rgb]{0.85,0.425,0}\phi\left(q_{5}\right)^{\top}\mkern-5.0mu\phi\left(k_{5}\right)}\end{pmatrix}\begin{pmatrix}v_{1}^{\top}\\ v_{2}^{\top}\\ v_{3}^{\top}\\ v_{4}^{\top}\\ v_{5}^{\top}\end{pmatrix}}_{\text{\large Full QKV}}\;=\;\underbrace{\begin{pmatrix}{\color[rgb]{0.1797,0.4258,0.707}\exp\left(q_{1}^{\top}k_{1}\right)}&0\\ {\color[rgb]{0.1797,0.4258,0.707}\exp\left(q_{2}^{\top}k_{1}\right)}&0\\ {\color[rgb]{0.1797,0.4258,0.707}\exp\left(q_{3}^{\top}k_{1}\right)}&{\color[rgb]{0.1797,0.4258,0.707}\exp\left(q_{3}^{\top}k_{3}\right)}\\ {\color[rgb]{0.1797,0.4258,0.707}\exp\left(q_{4}^{\top}k_{1}\right)}&{\color[rgb]{0.1797,0.4258,0.707}\exp\left(q_{4}^{\top}k_{3}\right)}\\ {\color[rgb]{0.1797,0.4258,0.707}\exp\left(q_{5}^{\top}k_{1}\right)}&{\color[rgb]{0.1797,0.4258,0.707}\exp\left(q_{5}^{\top}k_{3}\right)}\end{pmatrix}\begin{pmatrix}v_{1}^{\top}\\ v_{3}^{\top}\end{pmatrix}}_{\text{\large Packed QKV}}\;+\;\underbrace{\begin{pmatrix}0&0&0\\ {\color[rgb]{0.85,0.425,0}\phi\left(q_{2}\right)^{\top}\mkern-5.0mu\phi\left(k_{2}\right)}&0&0\\ {\color[rgb]{0.85,0.425,0}\phi\left(q_{3}\right)^{\top}\mkern-5.0mu\phi\left(k_{2}\right)}&0&0\\ {\color[rgb]{0.85,0.425,0}\phi\left(q_{4}\right)^{\top}\mkern-5.0mu\phi\left(k_{2}\right)}&{\color[rgb]{0.85,0.425,0}\phi\left(q_{4}\right)^{\top}\mkern-5.0mu\phi\left(k_{4}\right)}&0\\ {\color[rgb]{0.85,0.425,0}\phi\left(q_{5}\right)^{\top}\mkern-5.0mu\phi\left(k_{2}\right)}&{\color[rgb]{0.85,0.425,0}\phi\left(q_{5}\right)^{\top}\mkern-5.0mu\phi\left(k_{4}\right)}&{\color[rgb]{0.85,0.425,0}\phi\left(q_{5}\right)^{\top}\mkern-5.0mu\phi\left(k_{5}\right)}\end{pmatrix}\begin{pmatrix}v_{2}^{\top}\\ v_{4}^{\top}\\ v_{5}^{\top}\end{pmatrix}}_{\text{\large Recurrent QKV}}
Figure 2: Conceptual routed value readout. For one layer and KV group in a length- sequence with routing , the left side shows the routed score–value readout. The equality splits entries by column: blue entries are read from the KV cache through the exponential kernel, while orange entries are accumulated in the recurrent state and read through the linear kernel. Decay and the shared normalization are suppressed.
Approximation loss. The approximation loss teaches the router which entries the linear kernel approximates poorly. Since the hard decision in Equation 7 is not differentiable, we use the score (indices suppressed). We form a relaxed routed distribution by mixing the two branch-normalized distributions with weights and renormalizing:
P^{\mathrm{exp}}_{tj}=\frac{\mathop{\mathrm{sim}}_{\mathrm{exp}}\left(q_{t},k_{j}\right)f_{j:t}}{\sum_{u\leq t}\mathop{\mathrm{sim}}_{\mathrm{exp}}\left(q_{t},k_{u}\right)f_{u:t}},\qquad P^{\mathrm{lin}}_{tj}=\frac{\mathop{\mathrm{sim}}_{\mathrm{lin}}\left(q_{t},k_{j}\right)f_{j:t}}{\sum_{u\leq t}\mathop{\mathrm{sim}}_{\mathrm{lin}}\left(q_{t},k_{u}\right)f_{u:t}},We compare to the teacher , which uses the query scaling defined in Section 2.1. Averaging over all query positions would cost per query head, so we instead sample a multiset of query positions uniformly with replacement in each sequence and evaluate each sampled query against all its causal keys:
where the loss is averaged over batch elements, layers, and heads (omitted from notation). Because queries are sampled uniformly, : the sampled loss is an unbiased estimate of the full average over query positions. Sampling reduces the auxiliary pairwise work to per query head; we use , independent of sequence length, and Section 6 shows that larger samples bring only mild gains.
The auxiliary loss updates only the router: its token representations, branch scores, and decay factors are detached, so the backbone is trained solely by the language-modeling loss. Conversely, the router receives no gradient from the language-modeling loss: the forward pass uses hard routing decisions, so the router is trained only by the approximation and budget losses. Figure 4 illustrates this objective.
Figure 3: Router approximation loss. The softmax teacher (left) concentrates on a few keys. In the routed attention (right), retained keys (red outlines) are read through the exponential kernel and all other keys through the linear kernel. The router is trained to retain the keys the linear kernel cannot represent, by minimizing on sampled queries (dashed rows).
Figure 4: Ark mixer. Each kernel has its own normalized queries and keys ( exponential; linear, with LoRA dashed). Retained entries are appended to the KV cache (blue) and the rest update the recurrent state (orange). Both are read under a shared normalizer, then normalized, gated, and projected.
Budget loss. The relaxed approximation loss is minimized trivially by assigning every entry to the exponential kernel ( gives ). We therefore add a one-sided penalty that enforces a minimum compression rate. Let be the target fraction of entries kept in the KV cache, and the target fraction assigned to the linear kernel. For each sequence in a batch of size , we measure the realized linear fraction over all of its entries (layer , KV group , position ), pooled together, and penalize any shortfall. In words, the target is for each sequence to send at least a fraction of its entries to the recurrent state, counted over all layers and KV groups at once:
The forward pass uses the hard indicator; gradients flow through the smooth surrogate via a straight-through estimator (Bengio et al., 2013). Trained with this penalty alone, the router compresses nearly every entry (Section 6, ); the approximation loss is what keeps entries in the KV cache.
Two design choices shape this loss. First, pooling all of a sequence’s entries, rather than imposing a quota per layer or KV group, sets only how much the sequence compresses, not where: the router can keep many entries in some layers and KV groups and almost none in others. Second, the penalty is one-sided: beyond the floor, only the approximation loss keeps entries in the KV cache.
The penalty weight is not fixed: it grows while the batch compresses too little on average and shrinks once it compresses enough. Concretely, let be the batch’s average linear fraction; after each step we update
where the shortfall is smoothed by an exponential moving average (EMA). The budget is thus a soft training-time constraint: individual sequences may miss the target, without a hard cache cap at inference.
3.3 Block Design
Each layer pairs an Ark mixer (Figure 4) with a gated MLP (Shazeer, 2020). The mixer (1) projects the input into values , router scores , decay gates , and per-branch queries and keys; (2) routes each entry (Section 3.1); (3) reads out both memories under a shared normalizer; and (4) RMS-normalizes the output, applies a swish output gate (Yang et al., 2024a), and projects it back to the model dimension. Equation 5 used the same in both branches, but they differ in two ways.
Branch-specific query and key adapters.
The same queries and keys feed two substantially different operations: exact retrieval over a few retained entries, and compression of all others into a fixed-size state. One set of projections is therefore unlikely to serve both (Zhang et al., 2025). We add low-rank adapters (QK LoRA) (Hu et al., 2022) to the shared projections for the linear branch only, before normalization ( in Figure 4); the exponential branch uses the base projections.
Per-branch query–key normalization.
Each branch normalizes its own queries and keys with RMSNorm (QK-RMSNorm; Henry et al., 2020), keeping their scales comparable under the shared normalizer. Short convolutions reduce recall here, so the block omits them; §6 ablates all three choices.
4 Efficient Computation of Ark
This section presents the algorithms that compute Equation 5 efficiently and their costs; all are implemented as Triton kernels (Tillet et al., 2019) in our code. Once routing is fixed, the two branches can run independently: the exponential branch attends only over retained keys, and the linear branch runs a recurrence over the sequence with retained entries masked out. The branches interact only through the shared denominator of Equation 5, so each branch returns a partial result and a final step merges them.
Neither branch re-indexes time. The exponential branch stores each retained entry with its original position and computes from it, so the decay between a query and a retained key covers every token in between, including those sent to the recurrent state. The linear branch likewise applies the forget gate at every position, including retained ones (Sections C.1 and C.2). Splitting therefore introduces no approximation: together, the two branches compute Equation 4 exactly.
4.1 Exponential Branch: Packed Attention
The exponential branch gathers retained entries into a contiguous buffer, so its pairwise attention work scales with rather than . Packing uses one prefix scan over the routing mask per KV group and produces the packed keys and values together with four pieces of metadata: (i) the original position of each retained entry; (ii) for each query position, the number of retained keys at or before it, which gives its causal frontier; (iii) the number of retained keys in the group, used to mask padding; and (iv) the cumulative log-forget gate , where , at each retained position, used for decay.
The packed-attention Triton kernel then runs over the packed buffer. Following FoX (Lin et al., 2025), it adds decay as a logit offset using the stored , so gaps between retained keys cost nothing extra. Because packed keys are sorted by position, tiles entirely in the future are skipped, interior tiles are fully causal and need no per-pair comparison, and only boundary tiles need causal masking (Figure 5). Query heads in a KV group reuse the packed data and metadata, and online softmax (Milakov and Gimelshein, 2018; Dao et al., 2022) accumulates in FP32 (Algorithms 1 and 2).
| KV cache |
|---|
| recurrent |
| future |
Figure 5: Causal attention before and after KV packing. (Left) The router retains keys 0, 2, and 10 and folds the others into the recurrent state. (Right) Packing moves the retained keys into three KV slots while preserving their absolute positions . A packed key is causal when ; sorted position stamps let future-only tiles be skipped.
4.2 Linear Branch: Log-Space Chunkwise Recurrence
The linear branch takes a different approach. With the default target (§5), about 90% of entries are assigned to it, so packing would save little work while requiring the same metadata for nearly every entry. Instead, we run a chunked recurrence over the entire sequence with no metadata, masking retained entries (, with ) by suppressing their key contributions inside the Triton kernels while keeping their forget gates: . In log space, this mask is applied as
The masked log contributions therefore produce zero weights after exponentiation (). Queries and forget gates remain on the full timeline.
Separate recurrences for the numerator and denominator can be numerically unstable, so we store per feature the normalized value mean and log-mass , updating masses in log space. Prefill has three stages (Figure 6).
1. Local attention and chunk summaries.
Let denote the token positions in chunk . Each chunk independently computes causal log-scores
where equals for entries assigned to the linear kernel and zero otherwise, and includes forgetting at every intervening position.
The chunk also summarizes its keys and values at its final position: for each feature, max-shifted key weights give a weighted value mean and a log-mass .
2. State scan.
The scan first decays the incoming state by adding the chunk’s log-decay to its log-mass:
It then merges the decayed incoming state with the local summary:
State propagation therefore combines log-masses and normalized means rather than raw weighted sums. The scan is sequential across chunks and parallel across state entries.
3. Query readout.
Each query combines the preceding boundary state, decayed to its position, with causal keys in its own chunk. Query features weight the boundary state’s per-feature masses and means, yielding a boundary log-mass and normalized value . The boundary history then acts as one query-dependent weighted entry alongside the local keys:
o_{t}=\exp\left(\log Z_{t}^{\mathrm{prev}}-\log Z_{t}\right)\bar{V}_{t}^{\mathrm{prev}}+\sum_{\begin{subarray}{c}j\in\mathcal{C}_{c}\\ j\leq t\end{subarray}}\exp\left(A_{tj}-\log Z_{t}\right)v_{j}.
The Triton kernel evaluates these contributions under a common scale and normalizes once, in parallel across queries and chunks.
Appendix C provides the full summary and boundary readout equations and reset and empty-state handling.
Figure 6: Log-space chunkwise attention. Chunks compute local log-scores and KV contributions in parallel, applying causal and routing masks. Local KV contributions are . The scan applies decay and logaddexp to the masses and mixes means with normalized weights, producing . Readout jointly normalizes local and incoming-state contributions by logsumexp. Interaction map adapted from GLA (Yang et al., 2023).
4.3 Merging the Branches
Each branch returns, for query , a normalized output and its log-mass (the log of that branch’s denominator in Equation 5): and , where and . We keep this form rather than the raw numerator and denominator because exponential scores and decay accumulated over long contexts can overflow or underflow when summed directly. As in online softmax, each branch tracks its scale in log space. We weight each output by its branch’s share of the total mass:
This equals Equation 5, the sum of the two numerators divided by the combined denominator, computed without forming either raw sum. A branch with no keys has log-mass and receives zero weight.
4.4 Decoding
At decode time, the block applies the routing threshold from Equation 7 to each new token. For a fixed layer and KV group, write . An entry with updates the recurrent state; an entry with appends its key, value, original position, and cumulative log-forget value to the KV cache. Every query reads both the recurrent state and the KV cache. The packed-attention Triton kernel uses the stored positions for causality and the stored log-forget values for decay.
The unnormalized linear state follows Equation 6. When , the current key is inserted only into the KV cache, while the existing recurrent state still decays: and . For and a feature with positive mass, this common factor cancels in the stored mean:
Changing the log-mass alone therefore represents decay of both the numerator and denominator.
This cancellation makes retained steps cheap: when and , the decode kernel writes only the log-masses and skips the mean-matrix store. The state is updated once per KV group and shared across its query heads, and the two readouts are merged as in §4.3.
4.5 Cost and Memory
Training and prefill are typically compute-bound, whereas decoding is often limited by memory bandwidth. We therefore analyze arithmetic work for these, and persistent storage and memory accesses for decoding.
Prefill and training work.
Counting attention work only (no projections or router supervision; batch and heads suppressed), a length- sequence with chunk size costs
The terms are the linear path’s chunk summaries and boundary reads, its within-chunk contractions, and exponential attention over the retained keys; the cross-chunk scan adds only . The only quadratic term thus scales with rather than : at the default retention, exponential attention does about a tenth of the pairwise work of full attention. The backward pass has the same asymptotic order.
Decode memory accesses.
After decode step , Ark stores elements per request, layer, and KV group: a fixed-size recurrent state plus the retained entries, where is the prompt length. This excludes transient storage, such as prefill’s chunk summaries and boundary states, and training activations.
Each decode step reads the recurrent state, writes its mean matrix only when the new entry is assigned to the linear kernel, updates the log-masses, and reads every retained KV entry; full attention instead reads all entries. If each entry is retained with probability and tokens are generated, the expected logical scalar accesses per step, averaged over generation, are for Ark versus , with (Section C.7). This idealized count excludes reset writes, metadata, new KV writes, model weights, workspace traffic, and cache effects. For , Ark therefore uses fewer logical accesses than full attention once
about 136 tokens for (the 2B models of §5.2) and .
5 Empirical Validation
Ark stores a fraction of entries in the KV cache, so the central question is whether this saving costs quality, and whether it speeds up inference. We show that Ark is competitive with Transformers and hybrids on recall and language modeling and outperforms KV eviction at equal memory (§5.1), and that its smaller footprint makes it faster at long context (§5.2).
Setup.
All models are trained from scratch on SlimPajama (Soboleva et al., 2023): 400M and 800M models (24 layers) on 15B and 32B tokens, following the recipe of Yang et al. (2024b), and 2B models (28 layers) on 200B tokens (Appendix A). Hybrid baselines use 1:4 and 1:6 attention-to-recurrent ratios, within the range of the latest hybrids (Kimi Team et al., 2025; Yang et al., 2025), and we report each model’s memory rather than equalizing it. Unless noted, Ark uses the same grouped-query layout as the Transformer at each scale and targets 10% KV retention (). Ark also uses the simplest decay among the compared models: a single scalar data-dependent gate, whereas GLA uses a per-channel decay and GDN a delta-rule update. Since decay also encodes position (§2.1), Ark competes with less memory and a simpler decay.
Table conventions.
Scores are accuracy (%), with contains matching for extraction, QA, and retrieval; memory columns count millions of stored elements (recurrent state plus KV cache) at 8K context (Section A.4). Bold and underlining mark the best and second-best values per column.
5.1 Quality–Memory Trade-off
Recall across scales (Table 1).
Ark is competitive with the 1:6 hybrids on recall while storing 25–42% fewer elements. Its main gap is on the hardest needles at long context, where GDN 1:6 leads. We hypothesize that this gap stems from GDN’s richer decay rather than from Ark’s memory budget, and that pairing routing with richer decays would close it.
Type Model # Params State KV Cache Total Recall tasks NIAH-1 NIAH-2 NIAH-3 (M) numel (M) SWDE FDA SQuAD 2k 4k 8k 2k 4k 8k 2k 4k 8k 400M / 15B tokens Transformer w. RoPE 340 0 100.7 100.7 42.3 21.5 22.1 100 0.0 0.0 100 0.0 0.0 47.6 0.0 0.0 w. Gate (FoX) 376 0 103.8 103.8 52.5 64.3 30.1 100 32.2 8.0 100 100 24.0 85.6 64.2 11.6 MLA 375 0 113 113 57.2 21.6 17.7 100 0.0 0.0 100 0.0 0.0 93.4 0.0 0.0 Hybrid GLA 1:4 396 1.2 21.0 22.2 51.4 71.4 29.8 100 100 100 100 93.6 15.2 8.6 6.6 0.4 GDN 1:4 396 1.2 21.0 22.2 56.4 63.4 37.7 100 100 100 100 81.2 0.0 97.6 49.6 0.0 GLA 1:6 397 1.3 16.8 18.1 48.8 62.5 32.3 100 83.6 0.2 99.8 96.2 0.0 10.8 28.4 0.0 GDN 1:6 397 1.3 16.8 18.1 54.8 68.1 36.8 100 100 100 100 64.4 11.2 6.8 20.2 1.0 Ark 374 0.4 10.1 10.5 53.8 71.9 30.5 100 100 100 100 89.9 3.4 70.1 81.8 1.5 800M / 32B tokens Transformer w. RoPE 693 0 151 151 58.9 63.6 41.3 92.4 90.8 0.0 99.6 99.2 0.0 33.4 9.0 0.0 w. Gate (FoX) 694 0 155.7 155.7 64.9 80.0 41.5 100 100 99.0 100 100 67.4 83.2 63.8 0.2 MLA 745 0 151 151 67.5 72.6 23.0 100 100 0.0 100 100 0.0 98.0 82.8 0.0 Hybrid GLA 1:4 741 2.0 25.2 27.1 54.6 64.6 34.7 100 93.2 37.4 99.6 88.8 4.6 86.0 65.2 0.8 GDN 1:4 813 2.0 25.2 27.1 65.1 83.6 40.8 100 100 100 100 100 0.2 97.6 98.2 0.0 GLA 1:6 743 2.1 18.9 21 48.3 52.9 36.2 100 83.6 3.8 99.6 63.8 9.8 19.0 2.6 0.4 GDN 1:6 819 2.1 18.9 21 64.0 75.4 38.9 100 100 100 100 100 81.6 95.2 81.2 39.2 Ark 770 0.6 15.1 15.7 65.1 81.3 39.1 100 100 100 100 100 17.8 99.8 99.6 10.2 2B / 200B tokens Transformer w. RoPE 2091 0 234.9 234.9 77.2 73.0 51.5 96.4 93.6 91.2 100 100 90.8 99.2 98.4 73.0 w. NoPE 2091 0 234.9 234.9 76.3 77.0 27.3 100 100 100 100 100 99.8 99.8 98.6 93.8 w. Gate (FoX) 2092 0 239.5 239.5 80.5 75.3 52.2 100 100 100 100 100 97.4 99.2 93.2 73.0 Hybrid GLA 1:4 2344 3.8 41.9 45.7 72.3 78.3 44.9 100 100 98.8 100 100 88.2 99.4 89.0 76.6 GDN 1:4 2335 3.8 41.9 45.7 77.8 81.2 53.2 100 100 100 100 98.8 97.8 99.4 88.2 72.0 GLA 1:6 2344 3.9 33.6 37.5 75.1 76.3 44.2 100 99.8 94.0 100 100 92.6 96.2 94.0 70.8 GDN 1:6 2345 3.9 33.6 37.5 81.2 79.5 50.4 100 100 100 100 99.8 97.6 100 99.2 94.0 Ark 2275 1.8 23.5 25.3 78.0 79.5 51.9 100 100 99.0 100 100 99.4 92.2 88.4 71.4
Table 1: Retrieval accuracy and cache size across architectures. Baselines include MLA (DeepSeek-AI et al., 2024), FoX (Lin et al., 2025), and NoPE (Kazemnejad et al., 2023). Fully recurrent baselines appear in Table 18. Model configurations and memory accounting are in Section A.4, and task details are in Section A.2.
Synthetic long-context tasks (Tables 2 and 3).
The extended 2B suite, from RULER and BABILong, adds harder retrieval (multi-key, multi-value, and multi-query needles), multi-hop tracing, aggregation, and QA at 2K–8K context. With the smallest footprint of any model, Ark is the best model on several aggregation and QA tasks, but GDN 1:4 leads on several multi-item NIAH tasks.
Model # Params State KV Cache Total VT CWE FWE QA-Sq QA-Hp BABILong (M) numel (M) 2k 4k 8k 2k 4k 8k 2k 4k 8k 2k 4k 8k 2k 4k 8k 2k 4k 8k 2B / 200B tokens Transformer w. RoPE 2091 0 234.9 234.9 79.0 3.1 11.0 27.5 46.7 12.2 58.3 22.7 3.2 36.0 34.2 28.4 32.6 30.6 30.8 29.2 21.6 7.1 w. NoPE 2091 0 234.9 234.9 60.2 55.4 53.6 38.6 37.0 16.9 55.5 49.3 49.7 33.7 30.7 26.7 30.8 27.2 27.6 31.9 23.0 15.4 w. Gate (FoX) 2092 0 239.5 239.5 56.6 47.7 25.2 27.3 46.3 23.5 29.2 3.1 0.0 32.3 35.4 25.8 30.6 32.4 28.4 34.2 27.1 20.6 Hybrid GLA 1:4 2344 3.8 41.9 45.7 19.5 3.0 4.6 40.1 34.5 8.7 46.9 44.5 41.0 31.9 29.5 21.0 28.8 25.2 22.4 25.8 13.1 3.7 GDN 1:4 2335 3.8 41.9 45.7 47.3 36.2 17.1 30.2 53.9 28.6 32.1 20.5 19.3 38.0 36.6 29.1 33.0 31.6 28.2 34.8 28.0 19.1 GLA 1:6 2344 3.9 33.6 37.5 3.5 1.2 0.0 32.1 27.9 3.4 36.3 16.0 6.9 34.7 34.8 23.5 28.4 28.0 25.4 22.4 14.5 4.0 GDN 1:6 2345 3.9 33.6 37.5 18.6 22.9 24.8 38.9 60.0 35.9 51.3 41.3 44.7 30.8 31.9 26.6 28.6 27.8 31.6 34.4 25.7 18.0 Ark 2275 1.8 23.5 25.3 59.2 62.4 45.4 29.1 50.7 27.9 59.3 59.4 60.3 42.6 38.6 30.3 35.4 34.8 30.4 35.7 30.9 23.8
Table 2: RULER tracking, aggregation, and QA, and BABILong, for 2B models. VT: variable tracking; CWE/FWE: common/frequent-word extraction; QA-Sq/QA-Hp: SQuAD/HotpotQA-based QA. Task details are in Section A.2.
Model # Params State KV Cache Total NIAH-MK1 NIAH-MK2 NIAH-MK3 NIAH-MV NIAH-MQ (M) numel (M) 2k 4k 8k 2k 4k 8k 2k 4k 8k 2k 4k 8k 2k 4k 8k 2B / 200B tokens Transformer w. RoPE 2091 0 234.9 234.9 91.2 88.6 66.0 65.4 35.6 14.6 21.2 17.0 7.2 86.0 56.2 31.6 84.9 68.2 43.3 w. NoPE 2091 0 234.9 234.9 99.8 95.4 95.4 86.6 68.6 46.2 52.8 45.0 34.4 77.0 63.2 47.8 73.9 63.3 57.9 w. Gate (FoX) 2092 0 239.5 239.5 87.0 80.4 66.6 80.8 59.0 26.4 44.2 46.6 30.8 72.3 76.3 60.5 62.2 75.2 68.3 Hybrid GLA 1:4 2344 3.8 41.9 45.7 66.6 73.0 50.8 44.4 34.4 12.6 32.0 29.2 11.0 78.4 38.8 26.8 84.5 57.2 32.5 GDN 1:4 2335 3.8 41.9 45.7 93.0 92.8 81.0 97.8 93.8 84.4 49.2 50.4 36.6 96.0 86.4 75.8 96.4 92.0 83.9 GLA 1:6 2344 3.9 33.6 37.5 87.6 80.2 60.4 51.8 28.4 10.2 14.4 10.8 0.8 36.6 23.1 20.7 59.5 34.8 23.2 GDN 1:6 2345 3.9 33.6 37.5 95.6 92.4 74.0 72.0 48.2 22.8 57.4 55.4 33.8 91.4 85.0 54.8 89.2 80.7 56.7 Ark 2275 1.8 23.5 25.3 98.0 94.2 87.6 50.2 33.0 15.6 58.0 55.5 27.8 92.9 88.2 41.5 87.1 81.2 75.0
Table 3: RULER NIAH accuracy for 2B models. MK, MV, and MQ denote multi-key, multi-value, and multi-query needles. Ark uses the simplest decay among these models, a single scalar gate, whereas GLA uses a per-channel decay and GDN a delta-rule update. We hypothesize that GDN’s lead on the harder needles stems from this richer decay rather than from Ark’s memory budget. Task details are in Section A.2.
Document QA (Table 4).
We test QA over real documents: TriviaQA, DROP and Natural Questions truncated to 512–2048 tokens. The answer is in the provided document, so these tasks test reading comprehension rather than search through distractors. Ark averages within 1.4 points of the best model (39.5 vs. 40.9 for GDN 1:6) and ahead of both GLA hybrids and the NoPE and FoX Transformers, with the smallest footprint.
| Model | # Params | State | KV Cache | Total | Open-book QA | |||||
|---|---|---|---|---|---|---|---|---|---|---|
| (M) | numel (M) | TriviaQA | DROP | NQ@512 | NQ@1024 | NQ@2048 | Avg. | |||
| 2B / 200B tokens | ||||||||||
| Transformer | ||||||||||
| w. RoPE | 2091 | 0 | 234.9 | 234.9 | 64.5 | 25.3 | 33.2 | 31.9 | 29.5 | 40.4 |
| w. NoPE | 2091 | 0 | 234.9 | 234.9 | 59.2 | 21.5 | 29.1 | 27.3 | 27.9 | 36.3 |
| w. Gate (FoX) | 2092 | 0 | 239.5 | 239.5 | 63.8 | 20.9 | 31.7 | 32.3 | 31.7 | 38.9 |
| Hybrid | ||||||||||
| GLA 1:4 | 2344 | 3.8 | 41.9 | 45.7 | 60.1 | 21.1 | 28.8 | 28.2 | 25.8 | 36.3 |
| GDN 1:4 | 2335 | 3.8 | 41.9 | 45.7 | 64.9 | 25.4 | 32.0 | 31.2 | 31.6 | 40.6 |
| GLA 1:6 | 2344 | 3.9 | 33.6 | 37.5 | 60.8 | 22.9 | 29.6 | 28.0 | 25.4 | 37.1 |
| GDN 1:6 | 2345 | 3.9 | 33.6 | 37.5 | 63.4 | 24.8 | 35.6 | 33.5 | 34.1 | 40.9 |
| Ark | 2275 | 1.8 | 23.5 | 25.3 | 63.4 | 23.5 | 32.2 | 31.7 | 31.3 | 39.5 |
Table 4: Open-book QA accuracy for 2B models. NQ@ truncates the Natural Questions document to tokens. Avg. is the mean over TriviaQA, DROP, and NQ, with NQ first averaged over the three lengths. Task details are in Section A.2.
Language modeling (Table 5).
Ark preserves language-modeling quality with about a tenth of a Transformer’s KV cache: its zero-shot average is within one point of the best model at every scale (Table 17), and at 2B it exceeds the RoPE Transformer. Against hybrids at 2B, it outperforms both GLA hybrids and stays within one point of GDN 1:4 while storing 45% fewer elements. These commonsense tasks depend little on retrieval and can be solved by a small recurrent state (Bick et al., 2026), whose quality then depends mainly on its decay (Yang et al., 2024a). Consistent with this, forcing every entry into Ark’s recurrent state retains 94–101% of its accuracy on them (§7.1).
| Model | # Params | State | KV Cache | Total | LMB. | PIQA | Hella. | Wino. | ARC-e | ARC-c | Avg. | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| (M) | numel (M) | ppl | acc | acc | acc | acc | acc | acc | acc | |||
| 2B / 200B tokens | ||||||||||||
| Transformer | ||||||||||||
| w. RoPE | 2091 | 0 | 234.9 | 234.9 | 9.4 | 54.5 | 73.3 | 45.1 | 59.0 | 60.8 | 25.4 | 52.7 |
| w. NoPE | 2091 | 0 | 234.9 | 234.9 | 16.6 | 45.1 | 70.1 | 42.2 | 54.1 | 55.8 | 26.2 | 49.7 |
| w. Gate (FoX) | 2092 | 0 | 239.5 | 239.5 | 10.2 | 53.0 | 74.0 | 45.6 | 59.6 | 62.2 | 28.0 | 53.9 |
| Hybrid | ||||||||||||
| GLA 1:4 | 2344 | 3.8 | 41.9 | 45.7 | 13.0 | 48.0 | 72.5 | 43.4 | 56.3 | 59.8 | 25.6 | 51.5 |
| GDN 1:4 | 2335 | 3.8 | 41.9 | 45.7 | 9.4 | 53.7 | 74.0 | 46.2 | 60.8 | 63.0 | 28.2 | 54.4 |
| GLA 1:6 | 2344 | 3.9 | 33.6 | 37.5 | 11.6 | 49.2 | 73.1 | 43.1 | 57.0 | 60.1 | 27.0 | 52.1 |
| GDN 1:6 | 2345 | 3.9 | 33.6 | 37.5 | 9.7 | 52.6 | 72.9 | 46.0 | 61.1 | 61.4 | 27.0 | 53.7 |
| Ark | 2275 | 1.8 | 23.5 | 25.3 | 11.1 | 51.3 | 73.3 | 45.0 | 59.1 | 61.7 | 28.0 | 53.4 |
Table 5: Zero-shot language modeling at 2B after 200B training tokens. Avg. is the mean of the five commonsense tasks. Ark stays within one point of GDN 1:4 while storing 45% fewer elements. Table 17 covers 400M and 800M. Task details are in Section A.2.
Learned routing vs. inference-time eviction (Table 6).
Another way to shrink the cache is to train a full Transformer and evict entries at inference time. We test four training-free policies applied to full-cache Transformers: StreamingLLM (Xiao et al., 2023) keeps attention sinks plus a recent window, H2O (Zhang et al., 2023) keeps the tokens with the most accumulated attention, SnapKV (Li et al., 2024) scores tokens by the attention they receive from a recent observation window, and AdaKV (Feng et al., 2024) adapts the budget per head (Section A.5). At equal memory, Ark outperforms even the per-task best policy on nearly every task, often by a wide margin: at 800M, it nearly doubles FDA accuracy (81.3 vs. 41.9). Eviction discards entries chosen by a model trained with a full cache; Ark instead learns during training which entries to retain and compresses the rest into the recurrent state.
| Scale | Method | Memory (M elems.) | Contains | NIAH-1 | NIAH-2 | NIAH-3 | ||||
|---|---|---|---|---|---|---|---|---|---|---|
| SWDE | FDA | 2K | 4K | 2K | 4K | 2K | 4K | |||
| 400M | Best eviction | 10.5 | 50.4 | 31.6 | 97 | 23 | 90 | 24 | 46 | 8 |
| Ark | 10.5 | 53.8 | 71.9 | 100 | 100 | 100 | 89.9 | 70.1 | 81.8 | |
| 800M | Best eviction | 15.7 | 59.5 | 41.9 | 100 | 98 | 94 | 46 | 50 | 25 |
| Ark | 15.7 | 65.1 | 81.3 | 100 | 100 | 100 | 100 | 99.8 | 99.6 | |
| 2B | Best eviction | 25.3 | 78.8 | 71.1 | 100 | 100 | 100 | 96 | 100 | 37 |
| Ark | 25.3 | 78.0 | 79.5 | 100 | 100 | 100 | 100 | 92.2 | 88.4 |
Table 6: Learned routing vs. training-free KV eviction at equal memory. Best eviction reports the per-task best policy: the highest score per column among StreamingLLM, H2O, SnapKV, and AdaKV applied to RoPE, NoPE, and FoX Transformers, an upper bound no single policy attains. Baselines receive at least Ark’s memory. Per-policy results appear in Table 15.
5.2 Throughput Comparison
A smaller memory footprint matters only if it translates into speed. We therefore measure prefill and decode throughput of 2B models on one H100, comparing Ark with full attention using FlashAttention-4 (Zadouri et al., 2026) and the GLA 1:4 hybrid, the faster of our two hybrid families and thus the stronger speed baseline (Figure 7).
Decoding benefits from reducing memory traffic. Each decode step is bound by memory traffic, and Ark reads only its retained entries plus a fixed-size recurrent state (Section 4.5). As a result, it decodes faster than both baselines at every measured prompt length, reaching over full attention and over the GLA hybrid at 64K (batch size 8, 256 generated tokens, BF16; full protocol in Section A.7).
Prefill also benefits as prompts lengthen. On short prompts, attention is a small share of the cost, and full attention benefits from FlashAttention-4’s highly optimized kernels, so it is fastest, and the GLA hybrid also trails it. As prompts grow, the quadratic attention cost dominates and Ark’s reduced pairwise work takes over. In the batch-8 sweep, Ark first outpaces full attention at 8K and reaches its throughput at 64K. Ark also outpaces the GLA hybrid at every measured prompt length, reaching its throughput at 64K.
Figure 7: 2B decode and prefill throughput. Top: decode throughput as prompt length varies (left; batch 8, 256 generated tokens) and as generation length varies (right; batch 8, 4K prompt). Bottom: prefill throughput as batch size varies (left; 16K prompt) and as prompt length varies (right; batch 8). Rates are generated tokens/s above and prompt tokens/s below, measured over the whole batch. We compare Ark-2B at 10% target retention with full attention using FlashAttention-4 and Hybrid GLA 1:4 (width-4 short convolutions in its recurrent layers) on one H100. The two prefill panels use separate sweeps, both with FlashAttention-4 in the hybrid’s attention layers.
6 Design Ablations
We isolate the design choices behind Ark by varying one component at a time while keeping the rest of the model and training fixed. Unless noted, ablations use the 400M setting of §5 and report perplexity and SWDE, FDA, and SQuAD recall.
Linear feature map (Section 6).
The feature map determines what the recurrent state captures, and hence which entries the router must keep in the KV cache (§3.2). With the exponential kernel fixed, we compare three non-negative maps, , (Katharopoulos et al., 2020), and with a small , across query-group sizes (GQA, the number of query heads per KV group; smaller groups mean more KV groups, each with its own recurrent state and KV cache). exp is the weakest map: it gives the lowest FDA accuracy at every group size and is usually lowest on SWDE and SQuAD. 1+elu is the strongest map: it beats relu on SWDE at every group size and on FDA at three of four, so we use it by default.
Projections, normalization, and convolution (Section 6).
The two branches share base query and key projections but use different similarity functions. QK-RMSNorm improves all three recall scores (panel a), so we normalize each branch’s queries and keys separately. Linear-branch adapters before normalization give the best SWDE and FDA accuracy in panel b, at a small SQuAD cost; adapting both branches after normalization gives the best SQuAD accuracy. We use linear-only adapters before normalization for extraction (Section 3.3). Neither convolution placement improves recall over the convolution-free default (panel c), so we omit it.
| GQA | Feature map | Recall accuracy (%) | ||
|---|---|---|---|---|
| SWDE | FDA | SQuAD | ||
| 1 | 1+elu | 55.1 | 63.2 | 37.8 |
| 1 | relu | 52.8 | 65.2 | 34.9 |
| 1 | exp | 52.9 | 61.1 | 27.1 |
| 4 | 1+elu | 53.8 | 71.9 | 30.5 |
| 4 | relu | 52.4 | 62.3 | 36.1 |
| 4 | exp | 46.4 | 54.4 | 22.6 |
| 8 | 1+elu | 54.6 | 61.4 | 30.0 |
| 8 | relu | 53.2 | 54.4 | 29.0 |
| 8 | exp | 49.9 | 47.3 | 21.1 |
| 16 | 1+elu | 53.6 | 66.2 | 28.6 |
| 16 | relu | 53.3 | 54.6 | 29.9 |
| 16 | exp | 37.1 | 42.4 | 30.9 |
Table 7: GQA and feature-map ablations. GQA is the number of query heads per KV group; smaller values mean more KV groups.
| Variant | Placement | SWDE | FDA | SQuAD |
|---|---|---|---|---|
| (a) LoRA target projection | ||||
| (no Conv, Linear only LoRA Before norm) | ||||
| w/o QK-RMSNorm | 40.5 | 47.2 | 26.6 | |
| with QK-RMSNorm | 53.8 | 71.9 | 30.5 | |
| (b) LoRA placement & scope | ||||
| (no Conv, with QK-RMSNorm) | ||||
| Linear only | Before norm | 53.8 | 71.9 | 30.5 |
| Linear only | After norm | 38.4 | 61.0 | 31.2 |
| Both branches | Before norm | 50.0 | 52.5 | 31.6 |
| Both branches | After norm | 50.0 | 57.4 | 33.8 |
| None | — | 50.2 | 60.3 | 31.8 |
| (c) Convolution placement & scope | ||||
| (Linear only LoRA Before, with QK-RMSNorm) | ||||
| Linear branch only | After LoRA | 40.8 | 37.4 | 27.7 |
| Both branches | Before LoRA | 26.0 | 28.2 | 28.5 |
Table 8: Architecture ablation results. All variants use 1+elu and target KV retention. Bold marks the best results within the normalization and adapter panels. The default uses linear-branch adapters before QK-RMSNorm.
Positional information (Table 9).
Ark applies decay in every layer, so an entry’s position is weighted identically whichever memory holds it (§3.1); RoPE is not an option for the linear kernel (§2.1). This is a design choice, not a requirement of routing. Hybrids instead pair decayed recurrent layers with NoPE attention layers, which aids length generalization (Lieber et al., 2024). We test the same idea by disabling decay in both kernels in a subset of layers; models train at length 2048, so the 4K and 8K columns measure length generalization. Sparse NoPE trades gains for losses: NoPE in every sixth layer gives the best loss and FDA accuracy and improves 4K NIAH-1 and NIAH-3, but cuts 4K NIAH-2 from 78.4 to 33.0, and NoPE in half the layers degrades quality throughout. Since no configuration improves every task, we keep decay in every layer.
Generation NIAH-1 NIAH-2 NIAH-3 NoPE layers Loss SWDE FDA SQuAD 1k 2k 4k 8k 1k 2k 4k 8k 1k 2k 4k 8k None 2.525 53.8 71.9 30.5 100.0 100.0 100.0 100.0 100.0 100.0 89.9 3.4 75.2 70.1 81.8 1.5 12, 24 2.523 51.6 65.3 37.5 100.0 98.6 51.0 10.8 100.0 99.6 44.8 2.4 92.8 71.2 0.6 0.2 6, 12, 18, 24 2.518 47.9 69.5 36.1 100.0 97.0 63.2 17.4 100.0 100.0 33.0 0.6 99.4 97.6 39.0 0.2 4, 8, 12, 16, 20, 24 2.526 51.0 65.3 35.3 100.0 100.0 33.0 3.6 100.0 100.0 44.2 0.4 84.6 75.4 2.0 0.8 2, 4, 6, 8, …, 22, 24 2.597 49.0 49.0 23.6 99.0 99.8 56.8 2.0 100.0 100.0 7.2 0.0 77.4 64.8 0.0 0.0
Table 9: Ark positional-encoding sweep. The first column lists the layers (of 24) that use NoPE, meaning no decay in either branch; all other layers keep decay. Models train at length 2048, so the 4K and 8K columns test length generalization. Loss is averaged over the last steps of training.
Sampled-query supervision (Section 6).
Router supervision costs per head (§3.2), so we sweep from 0 to 200. With , the budget is the only training signal, and the router collapses to compressing nearly every entry, which hurts both perplexity and recall. A single sampled query per sequence prevents this collapse. Larger samples help only mildly, mainly on SQuAD (from 29.8 to 32–34), so we use , which keeps supervision cheap.
| | 0 | 1 | 5 | 10 | 20 | 60 | 200 | |---|---|---|---|---|---|---|---| | Realized comp. | 99.76 | 89.42 | 89.57 | 89.66 | 89.34 | 89.25 | 89.55 | | Val PPL | 13.86 | 12.64 | 12.63 | 12.65 | 12.65 | 12.63 | 12.65 | | SWDE | 11.2 | 51.6 | 50.9 | 53.8 | 49.0 | 53.9 | 50.9 | | FDA | 2.0 | 68.8 | 66.6 | 71.9 | 69.9 | 63.2 | 63.5 | | SQuAD | 19.3 | 29.8 | 32.1 | 30.5 | 33.6 | 34.0 | 31.9 |
Table 10: Router query sampling. : teacher queries per sequence ( = no approximation loss). Realized comp.: % of entries routed to the linear kernel. beats ; more adds only mild gains.
Learned vs. content-agnostic routing (Section 6).
Does the router’s choice of which entries to keep matter, or only the size of the KV cache? We compare the learned router with two allocations that ignore content: random, which retains each entry independently with the target probability, and periodic, which retains an evenly spaced fraction of entries. At a matched budget (top), the learned router improves extraction accuracy – and is the only policy that does well on the UUID needle (NIAH-3), reaching 70–75% where random and periodic placement stay below 7%. Larger budgets (bottom) narrow the gap but do not close it: even with as many KV entries, random routing recovers the easier needles but trails the learned router on the UUID needle and extraction. Which entries are kept matters more than how many.
| KV | Extraction | NIAH-1 | NIAH-2 | NIAH-3 | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Routing | budget | SWDE | FDA | SQuAD | 1K | 2K | 1K | 2K | 1K | 2K |
| Matched budget ( KV) | ||||||||||
| Learned (default) | 10.6% | 53.8 | 71.9 | 30.5 | 100 | 100 | 100 | 100 | 75.2 | 70.1 |
| Periodic | 9.8% | 20.2 | 15.4 | 17.4 | 67.2 | 22.8 | 85.0 | 57.8 | 6.6 | 1.8 |
| Random | 9.1% | 25.2 | 17.0 | 16.3 | 42.4 | 24.8 | 60.4 | 41.0 | 6.6 | 2.2 |
| Larger budgets | ||||||||||
| Periodic | 19.7% | 27.5 | 39.6 | 18.0 | 83.8 | 30.4 | 99.4 | 95.6 | 17.4 | 10.6 |
| Random | 48.5% | 39.3 | 49.6 | 22.9 | 94.8 | 89.4 | 97.2 | 96.6 | 49.0 | 31.0 |
Table 11: Learned vs. content-agnostic routing. All runs use M models trained for 15B tokens at length 2048 with identical architecture and training; only the allocation differs. Bold marks the best value among the matched-budget runs.
7 How Ark Uses Its Two Memories
Ark is trained to keep retrieval-intensive entries in the KV cache and compress the rest, but does the trained model actually rely on them? We test this with two interventions that override the routing decisions of a trained 400M model. First, we force every entry into a single memory, either all into the KV cache or all into the recurrent state, to see which memory retrieval relies on (§7.1). Second, we move only the answer tokens (every occurrence of the answer in the context) from the KV cache to the recurrent state while keeping all other decisions fixed, to test whether retrieval depends on those specific entries (§7.2).
7.1 Retrieval Needs the Exponential Kernel
We evaluate each trained Ark model under three routing policies without changing its weights: its learned router; all-recurrent ( everywhere), which compresses every entry into the recurrent state; and all-KV ( everywhere), which keeps every entry in the KV cache.
We use the default decay-based configuration, which retains about of entries under learned routing. Because each model was trained with mixed routing, these interventions test its dependence on both memories, rather than the performance of a model trained with either forced policy. Section 5.1 compares Ark with separately trained Transformers. Section 7.1 reports accuracy under the three policies and the fraction of learned-routing accuracy retained by each forced policy.
Retrieval needs the exponential kernel, but only for a few entries.
The few entries in the KV cache, about 10% under learned routing, carry nearly all of the model’s retrieval ability. All-recurrent routing leaves the model with fixed-size memory: it retains 94–101% of learned-routing accuracy on commonsense tasks, which therefore need no KV cache, but nearly eliminates retrieval and long-range prediction, down to 0% on FDA (Section 7.1). This matches Bick et al. (2025c), who find that retrieval runs through exact attention on only a few positions: exponential interactions are needed for retrieval, but not for every entry.
Ark relies on both memories.
The trained model depends on the KV cache for retained entries and on the recurrent state for the rest; the recurrent state is not merely a lossy fallback. Keeping every entry in the KV cache (all-KV routing) does not restore retrieval: it roughly halves FDA and SWDE accuracy.
| Accuracy (%) | Accuracy retained (%) | ||||
|---|---|---|---|---|---|
| Task | Learned | All-KV | All-recurrent | All-KV/Learned | All-rec./Learned |
| Retrieval and long-range prediction | |||||
| SWDE | 53.8 | 27.8 | 05.9 | 52% | 11% |
| FDA | 71.9 | 35.7 | 00.0 | 50% | 00% |
| SQuAD | 30.5 | 30.2 | 04.5 | 99% | 15% |
| LAMBADA | 31.5 | 26.6 | 00.6 | 84% | 02% |
| Commonsense tasks | |||||
| PIQA | 63.5 | 63.0 | 61.9 | 99% | 097% |
| WinoGrande | 52.5 | 51.0 | 53.0 | 97% | 101% |
| ARC-e | 44.1 | 41.9 | 41.5 | 95% | 094% |
Table 12: Forcing all entries into one memory. Learned uses the 400M model’s router; All-KV and All-recurrent force every entry into the KV cache () or the recurrent state (), respectively. All-KV/Learned and All-rec./Learned report accuracy relative to Learned.
| Accuracy (%) | |||
|---|---|---|---|
| Task | Learned | Answer linear | Drop |
| SWDE | 53.8 | 16.2 | 37.6 |
| FDA | 71.9 | 4.8 | 67.1 |
| SQuAD | 30.5 | 4.2 | 26.3 |
| Mean | 52.1 | 8.4 | 43.7 |
Table 13: Rerouting answer tokens to the recurrent state. Accuracy (%) of the 400M model before and after rerouting answer tokens in every layer and KV group; other routing is unchanged. Drop is in points.
7.2 Retrieval Needs the Answer Tokens in the KV Cache
Rerouting every entry to one memory shows that retrieval needs the exponential kernel, but does not identify which cached entries matter. We therefore reroute only the answer tokens. We locate every occurrence of the answer in the context by string matching (for SWDE and FDA, together with its field name; Section A.6). We generate twice: once with the learned router, and once with the answer tokens forced to the linear kernel in every layer and KV group. All other tokens keep the routing decisions from the normal run, so the answer tokens are the only entries whose memory changes. The recurrent update and decay rules, decoding, and task-level stopping rules are unchanged.
Section 7.1 shows that retrieval depends on the answer tokens being in the KV cache. Rerouting them to the recurrent state removes most of the model’s retrieval accuracy on all three tasks (on average across tasks, from 52.1% to 8.4%).
Together, these interventions show that the trained models rely on both memories and need the answer tokens in the KV cache for retrieval. This mirrors the training-time result of Section 6: allocations that ignore content perform worse at a similar KV budget.
8 Related Work
The Retrieval Problem of SSMs.
A growing body of work identifies in-context retrieval as the key capability separating Transformers from recurrent alternatives (Bick et al., 2025c; Jelassi et al., 2024; Arora et al., 2023a; Arora et al., 2024). SSMs struggle with tasks requiring precise copying or associative recall from context, and Bick et al. (2025c) localize this gap to a subset of attention heads that perform a “gather-and-aggregate” operation—collecting information from specific positions and combining it for the output. Within these heads, retrieval is concentrated on a small set of context positions. Raven (Afzal et al., 2026) shows that part of this gap is interference rather than capacity: writing each token to a few memory slots recovers recall that needs constant memory, but recall whose demand grows with context still exceeds any fixed-size state. Ark builds on these insights: it keeps exact entries in a KV cache and learns where to allocate this capacity across tokens and KV groups, so gather-and-aggregate behavior can develop where useful rather than in preassigned heads.
Approximating Attention.
A long line of work seeks to approximate softmax attention with sub-quadratic alternatives. Linear attention (Katharopoulos et al., 2020) replaces the exponential kernel with a linear kernel that factorizes, enabling recurrent computation. Random Fourier features (RFF) approximate shift-invariant kernels (Rahimi and Recht, 2007); Performer (Choromanski et al., 2021) uses positive random features to approximate the softmax attention kernel.
A complementary direction distills a pretrained softmax Transformer into a linear surrogate. Hedgehog (Zhang et al., 2024) trains a learnable feature map to match softmax attention weights, LoLCATs (Zhang et al., 2025) first trains linear attention to match softmax outputs (attention transfer) and then fine-tunes with LoRA, keeping sliding-window softmax for local context, MOHAWK (Bick et al., 2025b; Bick et al., 2025a) uses a multi-phase distillation pipeline that progressively replaces softmax layers with recurrent ones, Mamba-in-the-Llama (Wang et al., 2024) distills a hybrid Mamba model, and both have been applied to reasoning models (Paliotta et al., 2025). Retrieval-Aware Distillation (Bick et al., 2026) identifies the specific gather-and-aggregate heads that require softmax fidelity, distilling only those while converting the rest to linear. These methods linearize attention across layers or heads, sometimes keeping softmax in a fixed window or in selected heads. Ark makes the exact-or-compressed decision per key and KV group.
Sparse Attention.
Sparse attention restricts full attention to selected token pairs. Longformer (Beltagy et al., 2020) uses a fixed pattern of local windows and global tokens, whereas DeepSeek Sparse Attention (DSA) (DeepSeek-AI, 2025) learns an indexer that selects the top- past tokens for each query. NSA (Yuan et al., 2025) attends to compressed block summaries, uses their scores to select blocks for token-level attention, and attends to nearby tokens through a sliding window. MoBA (Lu et al., 2025) learns to select blocks of past keys for each query. In Ark, the cache decision is made when each key is processed, and excluded keys enter a recurrent state.
Another line of work (Raposo et al., 2024; Jiang et al., 2024; Sharma et al., 2025) uses learned routers to let some tokens skip full attention at a given layer; the skipped tokens contribute no keys or values to that layer’s attention. Keys excluded from exact attention in Ark enter a recurrent state that later queries can read.
Recurrent Memory Models.
Near the opposite extreme from full attention, a family of models compresses the entire history into a recurrent state instead of caching individual tokens. Linear recurrent models such as Mamba (Gu and Dao, 2024; Dao and Gu, 2024; Lahoti et al., 2026), GLA (Yang et al., 2023), and GDN (Yang et al., 2024a) carry a fixed-size state with content-dependent updates, compressing every token into the same bounded memory.
A recent line relaxes the fixed-size constraint and lets the recurrent memory grow: Guo et al. (2026) replace the hidden state of linear attention with a logarithmically growing set of states organized via Fenwick tree partitioning, achieving training complexity, while Behrouz et al. (2026) segment the sequence into fixed-size blocks, cache each block’s final recurrent state, and allow queries to attend to all cached memories, or to a top- subset, via gated aggregation. Their memory units follow predetermined partitions—logarithmic buckets or fixed-size segments—although queries can select among the resulting memories based on content. By comparison, Ark decides for each entry whether to store it explicitly or fold it into recurrent state.
Recurrent and KV Memory Hybrids.
Most layer-wise hybrids fix the attention-to-recurrence ratio: Jamba (Lieber et al., 2024), Zamba (Glorioso et al., 2024), Samba (Ren et al., 2024), and Nemotron-H (NVIDIA, 2025) interleave attention and recurrent layers. Our GLA hybrid baseline instantiates this pattern with GLA; Qwen3-Next combines attention and GDN (Qwen Team, 2025). Hymba (Dong et al., 2024) instead runs attention and SSM heads in parallel within each layer. Oryx (Li et al., 2026) shares projections between attention and a linear mixer, updates both memories with every token, and switches which mixer produces the output on a schedule fixed in training or chosen at inference. These designs fix the memory mechanisms used by a layer or head, or update both memories; Ark learns to assign each entry to exactly one memory, so only retained entries enter the KV cache.
HAM (Lufkin et al., 2026) is closest to Ark: a router caches selected tokens while a recurrent state absorbs every token. Ark differs in three ways: routing is per KV group rather than shared across heads; retained entries do not also update the recurrent state; and the router is supervised by sampled full-softmax attention, with both memories combined under one normalization and one shared decay.
KV-Cache Eviction.
KV-cache eviction reduces inference memory by removing past key–value entries; future queries attend only to the entries that remain. StreamingLLM uses recency and attention sinks (Xiao et al., 2023), H2O uses accumulated attention mass (Zhang et al., 2023), SnapKV uses observation-window scores (Li et al., 2024), and AdaKV adapts retention budgets across heads (Feng et al., 2024). Unlike Ark, these methods choose what to retain after training and discard evicted entries. Another line of work uses learned eviction policies. NAtS (Deng and Lindauer, 2025) learns how long to keep each token’s KV entry, while DuoAttention (Xiao et al., 2024) identifies which heads need every entry and which can keep only the first and most recent entries. Ark learns the allocation during training and compresses nonretained entries into a recurrent state that later queries can still read.
KV-Cache Reduction.
Finally, a body of work shrinks the KV cache along dimensions orthogonal to token selection. Multi-Query Attention (MQA; Shazeer, 2019) and Grouped-Query Attention (GQA; Ainslie et al., 2023) share key/value projections across heads, Multi-head Latent Attention (MLA; DeepSeek-AI et al., 2024) compresses keys and values into a low-rank latent space, and YOCO (Sun et al., 2024) reuses KV states across layers. These methods reduce or reuse the representation stored for many tokens. These reductions are complementary to Ark: they change the representation stored for each entry, while Ark decides which entries remain explicit.
9 Conclusion
Ark replaces the hand-designed split between attention and recurrent layers with a learned, per-entry choice of kernel. Every layer uses the same block; a router decides, for each token and KV group, whether the entry is kept in the KV cache or folded into a recurrent state. Across 400M–2B parameters, Ark remains competitive with strong hybrids while storing less. At 2B, it uses 45% fewer stored elements (recurrent state plus KV cache) than 1:4 hybrids at 8K context and stays within one point of the best hybrid on zero-shot accuracy. In the controlled 2B runtime benchmark at 10% retention and 64K context, it achieves the decoding throughput of FlashAttention-4 and that of the GLA hybrid. Memory can therefore be allocated at the level of individual entries, where the input needs it.
Limitations and future directions.
Ark’s limitations follow from three design choices, each of which suggests an extension. First, routing is decided once, at write time, before the queries that will need a token arrive; a token whose importance only becomes apparent later can no longer be recalled exactly. Routing that can revisit earlier decisions, for example by promoting entries back from the recurrent state, would remove this constraint. Second, the retention budget is a fixed target shared by all inputs, so the KV cache still grows linearly, at roughly a tenth of the full rate; letting the budget adapt to the input would spend memory only where retrieval demands it. Third, the linear branch uses a scalar decay, and GDN hybrids, whose delta rule gives a richer state transition, remain strongest on the harder multi-key tasks at 8K (Table 3); because routing is independent of the recurrence, the two can be combined.
References
- Afzal et al. [2026] Arshia Afzal, Aviv Bick, Eric P. Xing, Volkan Cevher, and Albert Gu. Raven: High-recall sequence modeling with sparse memory routing, 2026. URL https://arxiv.org/abs/2607.25357.
- Ainslie et al. [2023] Joshua Ainslie, James Lee-Thorp, Michiel de Jong, Yury Zemlyanskiy, Federico Lebrón, and Sumit Sanghai. Gqa: Training generalized multi-query transformer models from multi-head checkpoints, 2023. URL https://arxiv.org/abs/2305.13245.
- Arora et al. [2023a] Simran Arora, Sabri Eyuboglu, Aman Timalsina, Isys Johnson, Michael Poli, James Zou, Atri Rudra, and Christopher Ré. Zoology: Measuring and improving recall in efficient language models, 2023a. URL https://arxiv.org/abs/2312.04927.
- Arora et al. [2023b] Simran Arora, Brandon Yang, Sabri Eyuboglu, Avanika Narayan, Andrew Hojel, Immanuel Trummer, and Christopher Ré. Language models enable simple systems for generating structured views of heterogeneous data lakes. arXiv preprint arXiv:2304.09433, 2023b.
- Arora et al. [2024] Simran Arora, Sabri Eyuboglu, Michael Zhang, Aman Timalsina, Silas Alberti, Dylan Zinsley, James Zou, Atri Rudra, and Christopher Ré. Simple linear attention language models balance the recall-throughput tradeoff. arXiv preprint arXiv:2402.18668, 2024.
- Behrouz et al. [2026] Ali Behrouz, Zeman Li, Yuan Deng, Peilin Zhong, Meisam Razaviyayn, and Vahab Mirrokni. Memory caching: Rnns with growing memory, 2026. URL https://arxiv.org/abs/2602.24281.
- Beltagy et al. [2020] Iz Beltagy, Matthew E Peters, and Arman Cohan. Longformer: The long-document transformer. arXiv preprint arXiv:2004.05150, 2020.
- Bengio et al. [2013] Yoshua Bengio, Nicholas Léonard, and Aaron Courville. Estimating or propagating gradients through stochastic neurons for conditional computation, 2013.
- Bick et al. [2025a] Aviv Bick, Tobias Katsch, Nimit Sohoni, Arjun Desai, and Albert Gu. Llamba: Scaling distilled recurrent models for efficient language processing, 2025a. URL https://arxiv.org/abs/2502.14458.
- Bick et al. [2025b] Aviv Bick, Kevin Y. Li, Eric P. Xing, J. Zico Kolter, and Albert Gu. Transformers to ssms: Distilling quadratic knowledge to subquadratic models, 2025b. URL https://arxiv.org/abs/2408.10189.
- Bick et al. [2025c] Aviv Bick, Eric Xing, and Albert Gu. Understanding the skill gap in recurrent language models: The role of the gather-and-aggregate mechanism, 2025c. URL https://arxiv.org/abs/2504.18574.
- Bick et al. [2026] Aviv Bick, Eric P. Xing, and Albert Gu. Retrieval-aware distillation for transformer-ssm hybrids, 2026. URL https://arxiv.org/abs/2602.11374.
- Bisk et al. [2020] Yonatan Bisk, Rowan Zellers, Jianfeng Gao, Yejin Choi, et al. PIQA: Reasoning about physical commonsense in natural language. In Proceedings of the AAAI conference on Artificial Intelligence, volume 34, pages 7432–7439, 2020.
- Blakeman et al. [2025] Aaron Blakeman, Aaron Grattafiori, Aarti Basant, Abhibha Gupta, Abhinav Khattar, Adi Renduchintala, Aditya Vavre, Akanksha Shukla, Akhiad Bercovich, Aleksander Ficek, et al. Nvidia nemotron 3: Efficient and open intelligence. arXiv preprint arXiv:2512.20856, 2025.
- Choromanski et al. [2021] Krzysztof Marcin Choromanski, Valerii Likhosherstov, David Dohan, Xingyou Song, Andreea Gane, Tamas Sarlos, Peter Hawkins, Jared Quincy Davis, Afroz Mohiuddin, Lukasz Kaiser, David Benjamin Belanger, Lucy J Colwell, and Adrian Weller. Rethinking attention with performers. In International Conference on Learning Representations, 2021.
- Clark et al. [2018] Peter Clark, Isaac Cowhey, Oren Etzioni, Tushar Khot, Ashish Sabharwal, Carissa Schoenick, and Oyvind Tafjord. Think you have solved question answering? try ARC, the AI2 reasoning challenge. arXiv preprint arXiv:1803.05457, 2018.
- Dao and Gu [2024] Tri Dao and Albert Gu. Transformers are SSMs: Generalized models and efficient algorithms through structured state space duality. In International Conference on Machine Learning (ICML), 2024.
- Dao et al. [2022] Tri Dao, Daniel Y. Fu, Stefano Ermon, Atri Rudra, and Christopher Ré. Flashattention: Fast and memory-efficient exact attention with io-awareness, 2022.
- DeepSeek-AI [2025] DeepSeek-AI. Deepseek-v3.2: Pushing the frontier of open large language models, 2025. URL https://arxiv.org/abs/2512.02556.
- DeepSeek-AI et al. [2024] DeepSeek-AI, Aixin Liu, Bei Feng, Bin Wang, et al. Deepseek-v2: A strong, economical, and efficient mixture-of-experts language model, 2024. URL https://arxiv.org/abs/2405.04434.
- Deng and Lindauer [2025] Difan Deng and Marius Lindauer. Neural attention search, 2025. URL https://arxiv.org/abs/2502.13251.
- Dong et al. [2024] Xin Dong, Yonggan Fu, Shizhe Diao, Wonmin Byeon, Zijia Chen, Ameya Sunil Mahabaleshwarkar, Shih-Yang Liu, Matthijs Van Keirsbilck, Min-Hung Chen, Yoshi Suhara, Yingyan Lin, Jan Kautz, and Pavlo Molchanov. Hymba: A hybrid-head architecture for small language models, 2024. URL https://arxiv.org/abs/2411.13676.
- Dua et al. [2019] Dheeru Dua, Yizhong Wang, Pradeep Dasigi, Gabriel Stanovsky, Sameer Singh, and Matt Gardner. DROP: A reading comprehension benchmark requiring discrete reasoning over paragraphs. In Proceedings of NAACL-HLT, 2019.
- Dubey et al. [2024] Abhimanyu Dubey, Abhinav Jauhri, Abhinav Pandey, Abhishek Kadian, Ahmad Al-Dahle, Aiesha Letman, Akhil Mathur, Alan Schelten, Amy Yang, Angela Fan, et al. The llama 3 herd of models. arXiv preprint arXiv:2407.21783, 2024.
- Feng et al. [2024] Yuan Feng, Junlin Lv, Yukun Cao, Xike Xie, and S. Kevin Zhou. Ada-kv: Optimizing kv cache eviction by adaptive budget allocation for efficient llm inference, 2024. URL https://arxiv.org/abs/2407.11550.
- Gao et al. [2024] Leo Gao, Jonathan Tow, Baber Abbasi, Stella Biderman, Sid Black, Anthony DiPofi, Charles Foster, Laurence Golding, Jeffrey Hsu, Alain Le Noac’h, Haonan Li, Kyle McDonell, Niklas Muennighoff, Chris Ociepa, Jason Phang, Laria Reynolds, Hailey Schoelkopf, Aviya Skowron, Lintang Sutawika, Eric Tang, Anish Thite, Ben Wang, Kevin Wang, and Andy Zou. A framework for few-shot language model evaluation, 07 2024. URL https://zenodo.org/records/12608602.
- Glorioso et al. [2024] Paolo Glorioso, Quentin Anthony, Yury Tokpanov, James Whittington, Jonathan Pilault, Adam Ibrahim, and Beren Millidge. Zamba: A compact 7b ssm hybrid model, 2024. URL https://arxiv.org/abs/2405.16712.
- Gu and Dao [2024] Albert Gu and Tri Dao. Mamba: Linear-time sequence modeling with selective state spaces. In Conference on Learning and Modeling (COLM 2024), 2024.
- Guo et al. [2026] Han Guo, Songlin Yang, Tarushii Goel, Eric P. Xing, Tri Dao, and Yoon Kim. Log-linear attention, 2026. URL https://arxiv.org/abs/2506.04761.
- Henry et al. [2020] Alex Henry, Prudhvi Raj Dachapally, Shubham Pawar, and Yuxuan Chen. Query-key normalization for transformers. arXiv preprint arXiv:2010.04245, 2020.
- Hsieh et al. [2024] Cheng-Ping Hsieh, Simeng Sun, Samuel Kriman, Shantanu Acharya, Dima Rekesh, Fei Jia, Yang Zhang, and Boris Ginsburg. Ruler: What’s the real context size of your long-context language models?, 2024. URL https://arxiv.org/abs/2404.06654.
- Hu et al. [2022] Edward J. Hu, Yelong Shen, Phillip Wallis, Zeyuan Allen-Zhu, Yuanzhi Li, Shean Wang, Lu Wang, and Weizhu Chen. LoRA: Low-rank adaptation of large language models. In International Conference on Learning Representations, 2022.
- Jelassi et al. [2024] Samy Jelassi, David Brandfonbrener, Sham M. Kakade, and Eran Malach. Repeat after me: Transformers are better than state space models at copying, 2024. URL https://arxiv.org/abs/2402.01032.
- Jiang et al. [2024] Y. Jiang, H. Wang, L. Xie, H. Zhao, C. Zhang, H. Qian, and J. C. Lui. D-LLM: A token adaptive computing resource allocation strategy for large language models. In Advances in Neural Information Processing Systems, 2024.
- Joshi et al. [2017] Mandar Joshi, Eunsol Choi, Daniel S. Weld, and Luke Zettlemoyer. TriviaQA: A large scale distantly supervised challenge dataset for reading comprehension. In Proceedings of the 55th Annual Meeting of the Association for Computational Linguistics, 2017.
- Katharopoulos et al. [2020] Angelos Katharopoulos, Apoorv Vyas, Nikolaos Pappas, and François Fleuret. Transformers are rnns: Fast autoregressive transformers with linear attention. In International Conference on Machine Learning, pages 5156–5165. PMLR, 2020.
- Kazemnejad et al. [2023] Amirhossein Kazemnejad, Inkit Padhi, Karthikeyan Natesan Ramamurthy, Payel Das, and Siva Reddy. The impact of positional encoding on length generalization in transformers. Advances in Neural Information Processing Systems, 36:24892–24928, 2023.
- Kimi Team et al. [2025] Kimi Team, Yu Zhang, Zongyu Lin, Xingcheng Yao, Jiaxi Hu, Fanqing Meng, Chengyin Liu, Xin Men, Songlin Yang, Zhiyuan Li, et al. Kimi linear: An expressive, efficient attention architecture. arXiv preprint arXiv:2510.26692, 2025.
- Kingma and Ba [2015] Diederik P Kingma and Jimmy Ba. Adam: A method for stochastic optimization. In The International Conference on Learning Representations (ICLR), 2015.
- Kuratov et al. [2024] Yuri Kuratov, Aydar Bulatov, Petr Anokhin, Ivan Rodkin, Dmitry Sorokin, Artyom Sorokin, and Mikhail Burtsev. Babilong: Testing the limits of llms with long context reasoning-in-a-haystack. In Advances in Neural Information Processing Systems, volume 37, pages 106519–106554, 2024. URL https://arxiv.org/abs/2406.10149.
- Kwiatkowski et al. [2019] Tom Kwiatkowski, Jennimaria Palomaki, Olivia Redfield, Michael Collins, Ankur Parikh, Chris Alberti, Danielle Epstein, Illia Polosukhin, Jacob Devlin, Kenton Lee, et al. Natural questions: A benchmark for question answering research. Transactions of the Association for Computational Linguistics, 7:453–466, 2019.
- Lahoti et al. [2026] Aakash Sunil Lahoti, Kevin Li, Berlin Chen, Caitlin Wang, Aviv Bick, Zico Kolter, Tri Dao, and Albert Gu. Mamba-3: Improved sequence modeling using state space principles. In International Conference on Learning Representations (ICLR), 2026. URL https://arxiv.org/abs/2603.15569.
- Li et al. [2026] Kevin Y. Li, Asher Trockman, Ananda Theertha Suresh, and Ziteng Sun. Multi-mixer models: Flexible sequence modeling with shared representations, 2026. URL https://arxiv.org/abs/2605.28769.
- Li et al. [2024] Yuhong Li, Yingbing Huang, Bowen Yang, Bharat Venkitesh, Acyr Locatelli, Hanchen Ye, Tianle Cai, Patrick Lewis, and Deming Chen. Snapkv: Llm knows what you are looking for before generation, 2024. URL https://arxiv.org/abs/2404.14469.
- Lieber et al. [2024] Opher Lieber, Barak Lenz, Hofit Bata, Gal Cohen, Jhonathan Osin, Itay Dalmedigos, Erez Safahi, Shaked Meirom, Yonatan Belinkov, Shai Shalev-Shwartz, et al. Jamba: A hybrid transformer-mamba language model. arXiv preprint arXiv:2403.19887, 2024.
- Lin et al. [2025] Zhixuan Lin, Evgenii Nikishin, Xu Owen He, and Aaron Courville. Forgetting transformer: Softmax attention with a forget gate. arXiv preprint arXiv:2503.02130, 2025.
- Lu et al. [2025] Enzhe Lu, Zhejun Jiang, Jingyuan Liu, Yulun Du, et al. Moba: Mixture of block attention for long-context LLMs, 2025. URL https://arxiv.org/abs/2502.13189.
- Lufkin et al. [2026] Leon Lufkin, Tomás Figliolia, Beren Millidge, and Kamesh Krishnamurthy. Hybrid associative memories, 2026. URL https://arxiv.org/abs/2603.22325.
- Milakov and Gimelshein [2018] Maxim Milakov and Natalia Gimelshein. Online normalizer calculation for softmax, 2018.
- NVIDIA [2025] NVIDIA. Nemotron-h: A family of accurate and efficient hybrid mamba-transformer models, 2025. URL https://arxiv.org/abs/2504.03624.
- Paliotta et al. [2025] Daniele Paliotta, Junxiong Wang, Matteo Pagliardini, Kevin Y. Li, Aviv Bick, J. Zico Kolter, Albert Gu, François Fleuret, and Tri Dao. Thinking slow, fast: Scaling inference compute with distilled reasoners, 2025. URL https://arxiv.org/abs/2502.20339.
- Paperno et al. [2016] Denis Paperno, Germán Kruszewski, Angeliki Lazaridou, Ngoc-Quan Pham, Raffaella Bernardi, Sandro Pezzelle, Marco Baroni, Gemma Boleda, and Raquel Fernández. The LAMBADA dataset: Word prediction requiring a broad discourse context. In Proceedings of the 54th Annual Meeting of the Association for Computational Linguistics, pages 1525–1534, 2016.
- Qwen Team [2025] Qwen Team. Qwen3-next. https://qwen.ai/blog?id=qwen3-next, 2025. URL https://qwen.ai/blog?id=qwen3-next.
- Rahimi and Recht [2007] Ali Rahimi and Benjamin Recht. Random features for large-scale kernel machines. Advances in neural information processing systems, 20, 2007.
- Rajpurkar et al. [2018] Pranav Rajpurkar, Robin Jia, and Percy Liang. Know what you don’t know: Unanswerable questions for squad. arXiv preprint arXiv:1806.03822, 2018.
- Raposo et al. [2024] David Raposo, Samuel Ritter, Blake Richards, Timothy Lillicrap, Peter Conway Humphreys, and Adam Santoro. Mixture-of-depths: Dynamically allocating compute in transformer-based language models, 2024.
- Ren et al. [2024] Liliang Ren, Yang Liu, Yadong Lu, Yelong Shen, Chen Liang, and Weizhu Chen. Samba: Simple hybrid state space models for efficient unlimited context language modeling, 2024. URL https://arxiv.org/abs/2406.07522, 2406:07522, 2024.
- Sakaguchi et al. [2021] Keisuke Sakaguchi, Ronan Le Bras, Chandra Bhagavatula, and Yejin Choi. Winogrande: An adversarial Winograd schema challenge at scale. Communications of the ACM, 64(9):99–106, 2021.
- Sharma et al. [2025] Aman Sharma, Saeed Najafi, Parsa Farinneya, Benyamin Jamialahmadi, Marzieh S. Tahaei, Yuhe Fan, Mehdi Rezagholizadeh, Boxing Chen, and Aref Jafari. DTRNet: Dynamic token routing network to reduce quadratic costs in transformers, 2025.
- Shazeer [2019] Noam Shazeer. Fast transformer decoding: One write-head is all you need, 2019. URL https://arxiv.org/abs/1911.02150.
- Shazeer [2020] Noam Shazeer. Glu variants improve transformer. arXiv preprint arXiv:2002.05202, 2020.
- Soboleva et al. [2023] Daria Soboleva, Faisal Al-Khateeb, Robert Myers, Jacob R Steeves, Joel Hestness, and Nolan Dey. SlimPajama: A 627B token cleaned and deduplicated version of RedPajama, June 2023. URL https://huggingface.co/datasets/cerebras/SlimPajama-627B.
- Su et al. [2021] Jianlin Su, Yu Lu, Shengfeng Pan, Ahmed Murtadha, Bo Wen, and Yunfeng Liu. Roformer: Enhanced transformer with rotary position embedding. arXiv preprint arXiv:2104.09864, 2021.
- Sun et al. [2024] Yutao Sun, Li Dong, Yi Zhu, Shaohan Huang, Wenhui Wang, Shuming Ma, Quanlu Zhang, Jianyong Wang, and Furu Wei. You only cache once: Decoder-decoder architectures for language models, 2024. URL https://arxiv.org/abs/2405.05254.
- Tillet et al. [2019] Philippe Tillet, Hsiang-Tsung Kung, and David Cox. Triton: an intermediate language and compiler for tiled neural network computations. In Proceedings of the 3rd ACM SIGPLAN International Workshop on Machine Learning and Programming Languages, pages 10–19, 2019.
- Vaswani et al. [2023] Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Lukasz Kaiser, and Illia Polosukhin. Attention is all you need, 2023. URL https://arxiv.org/abs/1706.03762.
- Wang et al. [2024] Junxiong Wang, Daniele Paliotta, Avner May, Alexander M. Rush, and Tri Dao. The mamba in the llama: Distilling and accelerating hybrid models, 2024. URL https://arxiv.org/abs/2408.15237.
- Xiao et al. [2023] Guangxuan Xiao, Yuandong Tian, Beidi Chen, Song Han, and Mike Lewis. Efficient streaming language models with attention sinks, 2023.
- Xiao et al. [2024] Guangxuan Xiao, Jiaming Tang, Jingwei Zuo, Junxian Guo, Shang Yang, Haotian Tang, Yao Fu, and Song Han. Duoattention: Efficient long-context LLM inference with retrieval and streaming heads, 2024.
- Yang et al. [2025] An Yang, Anfeng Li, Baosong Yang, Beichen Zhang, Binyuan Hui, Bo Zheng, Bowen Yu, Chang Gao, Chengen Huang, Chenxu Lv, et al. Qwen3 technical report. arXiv preprint arXiv:2505.09388, 2025.
- Yang et al. [2023] Songlin Yang, Bailin Wang, Yikang Shen, Rameswar Panda, and Yoon Kim. Gated linear attention transformers with hardware-efficient training. arXiv preprint arXiv:2312.06635, 2023.
- Yang et al. [2024a] Songlin Yang, Jan Kautz, and Ali Hatamizadeh. Gated delta networks: Improving mamba2 with delta rule. arXiv preprint arXiv:2412.06464, 2024a.
- Yang et al. [2024b] Songlin Yang, Bailin Wang, Yu Zhang, Yikang Shen, and Yoon Kim. Parallelizing linear transformers with the delta rule over sequence length. arXiv preprint arXiv:2406.06484, 2024b.
- Yang et al. [2018] Zhilin Yang, Peng Qi, Saizheng Zhang, Yoshua Bengio, William W. Cohen, Ruslan Salakhutdinov, and Christopher D. Manning. HotpotQA: A dataset for diverse, explainable multi-hop question answering. In Proceedings of EMNLP, 2018.
- Yuan et al. [2025] Jing Yuan et al. Native sparse attention: Hardware-aligned and natively trainable sparse attention, 2025.
- Zadouri et al. [2026] Ted Zadouri, Markus Hoehnerbach, Jay Shah, Timmy Liu, Vijay Thakkar, and Tri Dao. FlashAttention-4: Algorithm and kernel pipelining co-design for asymmetric hardware scaling, 2026. URL https://arxiv.org/abs/2603.05451.
- Zellers et al. [2019] Rowan Zellers, Ari Holtzman, Yonatan Bisk, Ali Farhadi, and Yejin Choi. HellaSwag: Can a machine really finish your sentence? In Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics, 2019.
- Zhang et al. [2024] Michael Zhang, Kush Bhatia, Hermann Kumbong, and Christopher Ré. The hedgehog & the porcupine: Expressive linear attentions with softmax mimicry, 2024. URL https://arxiv.org/abs/2402.04347.
- Zhang et al. [2025] Michael Zhang, Simran Arora, Rahul Chalamala, Alan Wu, Benjamin Spector, Aaryan Singhal, Krithik Ramesh, and Christopher Ré. Lolcats: On low-rank linearizing of large language models, 2025. URL https://arxiv.org/abs/2410.10254.
- Zhang et al. [2023] Zhenyu Zhang, Ying Sheng, Tianyi Zhou, Tianlong Chen, Lianmin Zheng, Ruisi Cai, Zhao Song, Yuandong Tian, Christopher Ré, Clark Barrett, Zhangyang Wang, and Beidi Chen. H2o: Heavy-hitter oracle for efficient generative inference of large language models, 2023. URL https://arxiv.org/abs/2306.14048.
Appendix A Experimental Details
A.1 Training Recipe
Our controlled training and ablation runs follow the standard pipeline in the literature [Yang et al., 2023, Yang et al., 2024a, Dao and Gu, 2024], specifically that of Yang et al. [2024b], at 400M and 800M parameters. The main comparison tables additionally report 2B checkpoints trained on 200B tokens; unless stated otherwise, the recipe details below describe the 400M and 800M runs. All models are trained on SlimPajama-627B [Soboleva et al., 2023] with a global batch size of 256 sequences. We use the Adam optimizer [Kingma and Ba, 2015] with a learning rate of [Yang et al., 2024a]. The 400M models use a sequence length of 2048 and a training budget of 15B tokens; the 800M models use a sequence length of 4096 and a training budget of 32B tokens; and the 2B models use a sequence length of 8192 and a training budget of 200B tokens. The learning rate follows a cosine scheduler with 1,024 warmup steps ( 0.5B tokens for the 400M runs). We utilize the flash-linear-attention https://github.com/fla-org/flash-linear-attention repository for baselines as well as our codebase.
A.2 Evaluation Protocol
We evaluate with a v0.4.3-based lm-evaluation-harness fork [Gao et al., 2024], using its RULER port. Recall tasks use full validation splits of the Based suite [Arora et al., 2024] (SWDE and FDA [Arora et al., 2023b], SQuAD [Rajpurkar et al., 2018]); NIAH uses 1K/2K/4K/8K contexts, and other RULER tasks and BABILong [Kuratov et al., 2024] use 2K/4K/8K. Contexts use each checkpoint’s tokenizer and RULER seed 42. BABILong uses the 1k-sample release, two demonstrations, and mean accuracy over QA1–QA5. Generation is greedy with no chat template. We allow 48 tokens with a newline stop for SWDE/FDA; other tasks have no stop string, with limits of 32 for SQuAD-Completion and RULER QA, 128 for NIAH/MK/MV/MQ, 30/120/50 for VT/CWE/FWE, and 16 for BABILong. Based and BABILong use case-insensitive string matching; RULER scoring is defined below.
RULER variants.
We use the RULER implementations and prompts of Hsieh et al. [2024]. NIAH-1 inserts a word-to-number needle into a repeated-sentence haystack; NIAH-2 uses the same word-to-number needle in a Paul Graham essay haystack; and NIAH-3 replaces the number with a UUID.
In the extended RULER tables, MK1 places four word-to-number keys in an essay, MK2 retrieves a word-to-number record among distractor records, and MK3 retrieves a UUID value using a UUID key. MV asks for four values associated with one key, whereas MQ queries four keys. VT is variable tracking, CWE is common-word extraction, FWE is frequent-word extraction, QA-Sq uses answerable SQuAD-v2 questions, and QA-Hp uses HotpotQA [Yang et al., 2018]. Synthetic-task scores are the mean fraction of required answer strings found case-insensitively in the continuation; QA reports the fraction of accepted reference-answer strings found.
Language-modeling and open-book QA tasks.
Language-modeling tasks are LAMBADA [Paperno et al., 2016], PIQA [Bisk et al., 2020], HellaSwag [Zellers et al., 2019], WinoGrande [Sakaguchi et al., 2021], and ARC [Clark et al., 2018]; open-book QA tasks are TriviaQA [Joshi et al., 2017], DROP [Dua et al., 2019], and Natural Questions (NQ) [Kwiatkowski et al., 2019]. LAMBADA, PIQA, WinoGrande, and ARC-e report zero-shot acc; HellaSwag and ARC-c report acc_norm, following the GLA/GDN evaluation convention. NQ@ denotes Natural Questions with the document truncated to tokens and scored by case-insensitive substring match (contains), following the Based evaluation suite.
A.3 Model Configurations
Our baselines include the recurrent models GLA, Mamba-2, and GDN; GLA/GDN hybrids; and the attention variant MLA. We follow their original configurations at all three scales. Since single-state SSMs such as GLA and GDN employ only a single recurrence in their original configurations [Yang et al., 2024a], we expand their value dimension to make recurrent-state footprints comparable within each scale. Table 1 reports the resulting state, KV-cache, and total memory rather than assuming equal total memory across model classes.
All 400M and 800M models use 24 layers and all 2B models use 28 layers, except for Mamba-2, which uses 48 layers as it does not rely on a channel mixer. For GLA, we include the short-range convolution, as it has been shown to significantly improve performance [Yang et al., 2024b]; therefore, all our GLA baselines use short-range convolution. We also use the specialized Triton kernels provided by the flash-linear-attention repository for each model.
Transformer baselines use 16 query / 4 KV heads at 400M, 24 query / 6 KV heads at 800M, and 20 query / 4 KV heads at 2B, following the LLaMA architecture [Dubey et al., 2024]. We include three different positional encoding schemes, RoPE [Su et al., 2021], NoPE [Kazemnejad et al., 2023], and the Forgetting Transformer (FoX) [Lin et al., 2025], to ensure comprehensive evaluation.
A.4 Memory-Size Calculation Details
All memory columns report the number of stored scalars (numel) at context length . An attention layer with KV heads of dimension stores scalars (keys and values), and a linear-recurrent head stores a state. The 400M models use hidden size , heads, , , and 24 layers, so one attention layer stores scalars and one recurrent layer with 16 heads stores . The 800M models (24 layers, , ) and 2B models (28 layers, , ) store and KV scalars per token, versus at 400M. Table 14 applies these quantities to each model.
| Model | Recurrent state | KV cache | Total |
|---|---|---|---|
| Transformer | — | M | 100.7M |
| FoX | — | M | 103.8M |
| Hybrid 1:6 (4 attn. + 20 rec.) | M | M | 18.1M |
| Ark () | M | M | 10.5M |
| Ark, 2B | 1.8M | M | 25.3M |
Table 14: Carried memory at . Rows above the rule are 400M models. FoX additionally stores one decay term per head and token ( per layer). Ark keeps one recurrent state per KV group; its KV column uses the nominal target retention, while measured retention is slightly higher (e.g., in Section 6). For clarity, the hybrid’s recurrent state omits its short-convolution caches, which understates the hybrid’s memory.
Hybrid models.
The label names the nominal attention-to-recurrent ratio; the realized attention-layer counts are 4 of 24 at 400M (1:6), 3 of 24 at 800M (1:6), 5 of 28 at 2B (1:4), and 4 of 28 at 2B (1:6). Attention layers use the same KV heads as the Transformer at each scale. All hybrids use short convolutions in their recurrent layers.
Fully recurrent baselines.
We use the expanded configurations from Raven [Afzal et al., 2026], which match recurrent-memory budgets across model families by expanding the value dimensions of GLA and GDN; these differ from the smaller recurrent states in our hybrids. Following Raven’s Table 2, the State column counts both recurrent and convolution caches: 12.5M + 0.4M = 12.9M for GLA, GDN, and Mamba-2 at 400M; 16.5M + 0.4M = 16.9M for GLA and GDN at 800M; and 16.5M + 0.6M = 17.1M for Mamba-2 at 800M. At 400M this is about M recurrent elements per layer for GLA and GDN; Mamba-2 spreads the same total over 48 layers.
A.5 Training-Free KV Eviction Baselines
A simpler alternative to learning the routing is to keep the full Transformer and evict tokens from the KV cache at decode time. We evaluate four training-free policies—StreamingLLM (attention sinks recent window; Xiao et al., 2023), H2O (accumulated attention mass; Zhang et al., 2023), SnapKV (observation-window scoring; Li et al., 2024), and AdaKV (per-head adaptive budgets; Feng et al., 2024)—applied post-hoc to our Transformer (RoPE, NoPE) and Forgetting-Transformer baselines at 400M (16 query / 4 KV heads), 800M (24 query / 6 KV heads), and 2B (20 query / 4 KV heads). At each scale, we bound the baseline cache near Ark’s total carried-memory footprint (Section 5): a budget of retained tokens gives M elements with at 400M, M with at 800M, and M with at 2B. SWDE and FDA report contains accuracy, and NIAH reports the fraction of reference strings found, at 2K and 4K context (Section A.2).
Table 15 shows that training-free eviction is a poor substitute for learned allocation at matched memory. SnapKV most consistently recovers the word-to-number needles (NIAH-1/2), especially on FoX, but loses most UUID (NIAH-3) recall. NoPE is particularly brittle: at 800M, StreamingLLM falls to zero on every NIAH setting; at 2B, AdaKV’s 96–100% NIAH accuracy at 2K falls to 0% on NIAH-1 and 31% on NIAH-3 at 4K, while Ark retains 88.4–100% at 4K. Ark gives the best bounded-memory recall in every column at 400M and 800M; at 2B, NoPE with AdaKV is higher on SWDE ( vs. ) and on NIAH-3 at 2K ( vs. ).
| Model | Policy | Memory (M elems.) | Contains | NIAH-1 | NIAH-2 | NIAH-3 | ||||
|---|---|---|---|---|---|---|---|---|---|---|
| SWDE | FDA | 2K | 4K | 2K | 4K | 2K | 4K | |||
| 400M / 15B tokens (16 query / 4 KV heads) Baselines at 10.5M elements () | ||||||||||
| RoPE | StreamingLLM | 10.5 | 34.7 | 18.8 | 46 | 0 | 56 | 0 | 38 | 0 |
| H2O | 10.5 | 36.5 | 11.8 | 21 | 0 | 0 | 0 | 0 | 0 | |
| SnapKV | 10.5 | 38.6 | 15.8 | 97 | 0 | 29 | 0 | 3 | 0 | |
| AdaKV | 10.5 | 38.4 | 15.5 | 67 | 0 | 18 | 0 | 1 | 0 | |
| NoPE | StreamingLLM | 10.5 | 35.0 | 4.4 | 4 | 0 | 41 | 0 | 46 | 0 |
| H2O | 10.5 | 40.1 | 7.7 | 0 | 0 | 0 | 0 | 0 | 0 | |
| SnapKV | 10.5 | 46.0 | 9.3 | 62 | 0 | 13 | 0 | 1 | 0 | |
| AdaKV | 10.5 | 50.4 | 15.7 | 84 | 0 | 90 | 0 | 17 | 0 | |
| FoX | StreamingLLM | 10.5 | 36.6 | 22.2 | 46 | 23 | 56 | 24 | 45 | 8 |
| H2O | 10.5 | 38.0 | 27.7 | 0 | 0 | 0 | 0 | 0 | 0 | |
| SnapKV | 10.5 | 42.3 | 31.6 | 43 | 22 | 24 | 11 | 5 | 2 | |
| Ark | 10.5 | 53.8 | 71.9 | 100 | 100 | 100 | 89.9 | 70.1 | 81.8 | |
| 800M / 32B tokens (24 query / 6 KV heads) Baselines at 15.7M elements () | ||||||||||
| RoPE | StreamingLLM | 15.7 | 42.1 | 23.6 | 54 | 24 | 66 | 24 | 50 | 25 |
| H2O | 15.7 | 49.0 | 39.1 | 63 | 53 | 0 | 0 | 0 | 0 | |
| SnapKV | 15.7 | 53.0 | 31.0 | 95 | 93 | 94 | 34 | 2 | 1 | |
| AdaKV | 15.7 | 49.0 | 28.2 | 38 | 29 | 7 | 3 | 0 | 0 | |
| NoPE | StreamingLLM | 15.7 | 34.1 | 3.4 | 0 | 0 | 0 | 0 | 0 | 0 |
| H2O | 15.7 | 51.5 | 32.6 | 0 | 0 | 0 | 0 | 0 | 0 | |
| SnapKV | 15.7 | 38.6 | 10.2 | 35 | 0 | 11 | 13 | 2 | 0 | |
| AdaKV | 15.7 | 59.5 | 41.9 | 85 | 46 | 89 | 46 | 0 | 0 | |
| FoX | StreamingLLM | 15.7 | 46.0 | 23.5 | 55 | 24 | 66 | 24 | 38 | 3 |
| H2O | 15.7 | 47.9 | 34.3 | 0 | 0 | 0 | 0 | 0 | 0 | |
| SnapKV | 15.7 | 56.1 | 37.1 | 100 | 98 | 25 | 6 | 4 | 2 | |
| Ark | 15.7 | 65.1 | 81.3 | 100 | 100 | 100 | 100 | 99.8 | 99.6 | |
| 2B (20 query / 4 KV heads) Baselines at 25.3M elements () | ||||||||||
| RoPE | StreamingLLM | 25.3 | 62.6 | 30.9 | 67 | 26 | 88 | 28 | 89 | 37 |
| H2O | 25.3 | 69.6 | 58.0 | 5 | 0 | 31 | 0 | 0 | 0 | |
| SnapKV | 25.3 | 72.6 | 60.5 | 100 | 96 | 100 | 42 | 27 | 10 | |
| AdaKV | 25.3 | 71.5 | 48.8 | 99 | 67 | 92 | 31 | 7 | 3 | |
| NoPE | StreamingLLM | 25.3 | 50.7 | 8.2 | 0 | 0 | 0 | 0 | 0 | 0 |
| H2O | 25.3 | 70.8 | 54.4 | 32 | 18 | 18 | 0 | 0 | 0 | |
| SnapKV | 25.3 | 54.7 | 12.8 | 0 | 3 | 64 | 0 | 52 | 2 | |
| AdaKV | 25.3 | 78.8 | 71.1 | 96 | 0 | 100 | 96 | 100 | 31 | |
| FoX | StreamingLLM | 25.3 | 65.8 | 32.3 | 67 | 27 | 88 | 28 | 91 | 33 |
| H2O | 25.3 | 69.1 | 56.0 | 1 | 0 | 0 | 0 | 0 | 0 | |
| SnapKV | 25.3 | 77.9 | 64.6 | 100 | 100 | 100 | 52 | 38 | 11 | |
| Ark | 25.3 | 78.0 | 79.5 | 100 | 100 | 100 | 100 | 92.2 | 88.4 |
Table 15: Bounded-memory comparison with training-free KV eviction. Memory is millions of carried elements: KV-cache elements for the baselines, and recurrent state plus KV-cache elements for Ark. At each scale, bounded baselines receive at least Ark’s memory; is the retained-token budget. At 2B, all models are 200B-token checkpoints. FoX omits AdaKV because per-head retained sets are incompatible with its GPU decoding kernel.
A.6 Details for Answer-Token Rerouting
We evaluate the 400M model on SWDE, FDA, and SQuAD. We locate answer tokens by string matching: for SWDE and FDA, we match the requested field name followed by its value; for SQuAD, we match the answer span in the context; otherwise, we match the exact answer value. We override the router’s decision with for the answer tokens in every layer and KV group; all other tokens keep their normal routing. Generation, stopping, and scoring follow Section A.2.
A.7 Throughput Benchmark
We measure prefill and decode throughput of 2B models on one H100 (Table 16), comparing Ark at 10% target retention with full attention using FlashAttention-4 and the GLA 1:4 hybrid. The prefill panels in Figure 7 vary batch size at a 16K-token prompt and vary prompt length at batch size 8. Retention is the fraction of entries (one token in one KV group of one layer) stored in the KV cache; the remaining entries are folded into the recurrent state.
| Field | Setting |
|---|---|
| Models | 400M: 24 layers, width 1024, 16 query heads, 4 KV groups, head dim. 64. 2B: 28 layers, width 2560, 20 query heads, 4 KV groups, head dim. 128 |
| Parameter counts | 400M: Ark 374M, FA 340M, Hybrid GLA 396M. 2B: Ark 2275M, FA 2091M, Hybrid GLA 2344M |
| Baselines | FlashAttention-4 (full attention, NoPE); Hybrid GLA 1:4 (NoPE attention layers, GLA recurrent layers) |
| Ark target retention | 10% |
| Hardware | One NVIDIA H100 80GB HBM3 |
| Software | PyTorch 2.11 (CUDA 12.6), Triton 3.8, FlashAttention-4 (CuTeDSL), Python 3.13 |
| Precision | BF16 weights, activations, and KV cache; FP32 Ark recurrent state |
| CUDA graphs | Decode: enabled. Prefill: graph replay |
| Warm-up | One prefill and two decode steps, then graph capture; the prompt cache is restored afterwards |
| Timed region | Prefill: cache construction, forward pass, last-token selection. Decode: single-token forward passes with LM head and greedy sampling; prefill excluded |
| Timing statistic | Prefill: median of three fresh-cache runs. Decode: median of six full-generation timings over three input seeds |
Table 16: Systems benchmark configuration. Hybrid GLA places attention at layers 4, 9, 14, : 4 attention and 20 recurrent layers at 400M, and 5 attention and 23 recurrent layers at 2B.
Appendix B Additional Evaluation & Ablation Tables
B.1 Additional Evaluation Tables
Tables follow the conventions of §5. Table 17 reports zero-shot language-modeling results at every scale. Table 18 compares Ark with fully recurrent baselines on the recall tasks of Table 1.
| Model | # Params | State | KV Cache | Total | LMB. | PIQA | Hella. | Wino. | ARC-e | ARC-c | Avg. | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| (M) | numel (M) | ppl | acc | acc | acc | acc | acc | acc | acc | |||
| 400M / 15B tokens | ||||||||||||
| Transformer | ||||||||||||
| w. RoPE | 340 | 0 | 100.7 | 100.7 | 42.0 | 31.0 | 64.4 | 30.2 | 51.0 | 44.3 | 18.7 | 41.7 |
| w. Gate (FoX) | 376 | 0 | 103.8 | 103.8 | 48.1 | 30.6 | 64.9 | 30.7 | 51.1 | 44.7 | 18.9 | 42.1 |
| Hybrid | ||||||||||||
| GLA 1:6 | 397 | 1.3 | 16.8 | 18.1 | 35.2 | 32.4 | 59.7 | 30.4 | 50.8 | 40.5 | 22.0 | 40.7 |
| GDN 1:6 | 397 | 1.3 | 16.8 | 18.1 | 35.9 | 33.9 | 64.7 | 33.9 | 51.1 | 42.9 | 24.4 | 43.4 |
| Ark | 374 | 0.4 | 10.1 | 10.5 | 46.5 | 31.5 | 63.5 | 33.2 | 52.5 | 44.1 | 22.7 | 43.2 |
| SSM | ||||||||||||
| GLA | 475 | 12.9 | 0 | 12.9 | 42.1 | 30.7 | 64.4 | 30.1 | 52.7 | 43.8 | 19.6 | 42.1 |
| Mamba-2 | 382 | 12.9 | 0 | 12.9 | 43.0 | 29.9 | 65.0 | 31.5 | 51.2 | 47.5 | 20.5 | 43.1 |
| GDN | 475 | 12.9 | 0 | 12.9 | 40.1 | 31.6 | 65.6 | 31.4 | 50.2 | 45.7 | 19.3 | 42.4 |
| 800M / 32B tokens | ||||||||||||
| Transformer | ||||||||||||
| w. RoPE | 693 | 0 | 151.0 | 151.0 | 18.6 | 41.4 | 66.3 | 34.3 | 52.2 | 49.9 | 21.9 | 44.9 |
| w. Gate (FoX) | 694 | 0 | 155.7 | 155.7 | 25.3 | 42.1 | 68.4 | 35.6 | 53.1 | 51.2 | 22.6 | 46.2 |
| Hybrid | ||||||||||||
| GLA 1:6 | 743 | 2.1 | 18.9 | 21.0 | 22.4 | 38.6 | 66.1 | 33.8 | 51.9 | 48.2 | 21.1 | 44.2 |
| GDN 1:6 | 819 | 2.1 | 18.9 | 21.0 | 20.8 | 40.7 | 67.5 | 34.9 | 52.6 | 50.8 | 22.3 | 45.6 |
| Ark | 770 | 0.6 | 15.1 | 15.7 | 22.1 | 40.3 | 67.3 | 34.6 | 52.8 | 50.1 | 22.0 | 45.4 |
| SSM | ||||||||||||
| GLA | 892 | 16.9 | 0 | 16.9 | 23.6 | 38.3 | 67.0 | 33.4 | 52.4 | 48.5 | 21.3 | 44.5 |
| Mamba-2 | 711 | 17.1 | 0 | 17.1 | 24.6 | 36.0 | 68.1 | 35.4 | 52.6 | 52.3 | 22.3 | 46.1 |
| GDN | 892 | 16.9 | 0 | 16.9 | 21.3 | 39.4 | 68.1 | 35.2 | 53.0 | 52.5 | 22.1 | 46.2 |
| 2B / 200B tokens | ||||||||||||
| Transformer | ||||||||||||
| w. RoPE | 2091 | 0 | 234.9 | 234.9 | 9.4 | 54.5 | 73.3 | 45.1 | 59.0 | 60.8 | 25.4 | 52.7 |
| w. NoPE | 2091 | 0 | 234.9 | 234.9 | 16.6 | 45.1 | 70.1 | 42.2 | 54.1 | 55.8 | 26.2 | 49.7 |
| w. Gate (FoX) | 2092 | 0 | 239.5 | 239.5 | 10.2 | 53.0 | 74.0 | 45.6 | 59.6 | 62.2 | 28.0 | 53.9 |
| Hybrid | ||||||||||||
| GLA 1:4 | 2344 | 3.8 | 41.9 | 45.7 | 13.0 | 48.0 | 72.5 | 43.4 | 56.3 | 59.8 | 25.6 | 51.5 |
| GDN 1:4 | 2335 | 3.8 | 41.9 | 45.7 | 9.4 | 53.7 | 74.0 | 46.2 | 60.8 | 63.0 | 28.2 | 54.4 |
| GLA 1:6 | 2344 | 3.9 | 33.6 | 37.5 | 11.6 | 49.2 | 73.1 | 43.1 | 57.0 | 60.1 | 27.0 | 52.1 |
| GDN 1:6 | 2345 | 3.9 | 33.6 | 37.5 | 9.7 | 52.6 | 72.9 | 46.0 | 61.1 | 61.4 | 27.0 | 53.7 |
| Ark | 2275 | 1.8 | 23.5 | 25.3 | 11.1 | 51.3 | 73.3 | 45.0 | 59.1 | 61.7 | 28.0 | 53.4 |
Table 17: Zero-shot results for 400M (15B tokens), 800M (32B tokens), and 2B (200B tokens) models. Avg. is the mean over the five commonsense tasks. For fully recurrent baselines, State includes recurrent and convolution caches. Task details are in Section A.2.
Model # Params State KV Cache Total Recall tasks NIAH-1 NIAH-2 NIAH-3 (M) numel (M) SWDE FDA SQuAD 2k 4k 8k 2k 4k 8k 2k 4k 8k 400M / 15B tokens GLA 475 12.9 0 12.9 29.0 11.4 30.3 25.1 8.2 2.2 37.2 21.4 3.6 57.1 20.8 10.2 Mamba-2 382 12.9 0 12.9 25.7 14.9 31.9 95.6 52.2 12.8 98.0 68.2 15.4 53.6 17.4 1.8 GDN 475 12.9 0 12.9 29.5 8.3 31.3 100 99.8 92.0 92.0 43.6 17.8 80.6 37.8 5.2 Ark 374 0.4 10.1 10.5 53.8 71.9 30.5 100 100 100 100 89.9 3.4 70.1 81.8 1.5 800M / 32B tokens GLA 892 16.9 0 16.9 50.1 35.9 39.2 94.2 29.4 3.6 89.8 25.8 3.8 51.2 3.2 1.8 Mamba-2 711 17.1 0 17.1 42.7 21.3 34.6 63.4 13.6 1.8 49.2 24.2 6.6 17.4 14.6 1.4 GDN 892 16.9 0 16.9 46.0 31.9 35.9 100 100 100 95.4 35.2 14.2 65.4 10.6 6.4 Ark 770 0.6 15.1 15.7 65.1 81.3 39.1 100 100 100 100 100 17.8 99.8 99.6 10.2
Table 18: Retrieval accuracy of fully recurrent baselines. Same tasks and memory accounting as Table 1, whose Ark rows are repeated for reference. The GLA and GDN baselines use the expanded configurations of Raven (Appendix A); State includes their convolution caches.
B.2 Additional Ablation Details
Number of sampled query positions.
Section 6 varies , the number of query positions drawn with replacement per sequence for the approximation loss. For , realized compression (89.25–89.66%) and PPL (12.63–12.65) barely change, while recall varies without a monotone trend (e.g., FDA 63.2–71.9). With , the router compresses of entries and retrieval collapses. We therefore use , which keeps the approximation loss cheap.
Block architecture.
Section 6 compares which projections receive LoRA, where convolution is applied, and LoRA’s placement and branch scope, as discussed in Section 6.
Appendix C Extended Implementation Details
Once routing is fixed, Equation 5 separates into four terms: the numerator and denominator of the exponential branch, and the numerator and denominator of the linear branch. This section details how each branch computes its two terms (Sections C.1 and C.2), how the branches are merged (Section C.3), the full prefill and decode algorithms, and the decode memory-access model (Section C.7).
Throughout this section, denotes the query at position and the key and value at position , for positions . The forget gates are those of Equation 3; our parameterization gives , so all log-gates are finite. The linear-branch algorithms additionally handle defensively, which resets the history; the exponential branch assumes finite log-gates. For finite log-gates, the cumulative log-forget is with , always evaluated at original positions, so that
as in Equation 3.
C.1 Exponential Branch: Packed Causal Attention
We describe the computation of and , the numerator and denominator of the exponential branch in Equation 5.
The exponential branch stores only retained entries, packed in original-position order into one-based slots . Slot holds , where is the original position of the -th retained entry; slots beyond are padding. As in Section 3.1, denotes the retained set. Without routing (), and this reduces to contiguous forgetting attention [Lin et al., 2025].
Mathematical formulation.
The exponential branch’s normalized output is
Implementation.
The forward and backward passes follow Lin et al. [2025], which implements forgetting attention with the same logit offset and differentiates through the cumulative sum to obtain gradients for . Our Triton kernel differs in one respect: FoX assumes contiguous keys (slot holds position ), whereas here only retained entries are stored, so slot may hold any original position . Packing (Algorithm 1) uses one prefix scan over the routing mask per KV group and produces four pieces of metadata, as in Section 4.1:
- the original position of each slot;
- for each query position , the number of retained keys at or before it, , which gives its causal frontier: slot is causal for query if and only if ;
- the number of retained keys in the KV group, used to mask padding slots;
- the cumulative log-forget of each slot, stored at packing time and reused as the decay offset.
Query heads in a KV group share these metadata. In training, the forward Triton kernel reuses the same counts but gathers from the cumulative log-forget timeline rather than storing it at packing time; the backward one compares positions directly (). Because slots are sorted by position, key tiles entirely beyond a query tile’s causal frontier are skipped, interior tiles are fully causal and need no per-pair comparison, and only boundary tiles are masked (Figure 5).
Forgetting matrix.
For with routing (Figure 2), the exponential branch stores only the retained keys and (, ). Each decay term covers the full distance from the key’s original position to the query, including the forget gates of positions assigned to the linear kernel (Figure 8).
(a) Exponential branch
\begin{array}[]{@{}c@{\;}c@{\;}c@{}}\begin{array}[]{@{}r@{\;}c@{}}\begin{array}[]{@{}r@{}}\makebox[22.76219pt][r]{$q_{1}$}\\ \makebox[22.76219pt][r]{$q_{2}$}\\ \makebox[22.76219pt][r]{$q_{3}$}\\ \makebox[22.76219pt][r]{$q_{4}$}\\ \makebox[22.76219pt][r]{$q_{5}$}\end{array}&\begin{pmatrix}\makebox[54.06023pt][c]{${\color[rgb]{0.1797,0.4258,0.707}\exp\left(q_{1}^{\top}k_{1}\right)}$}&\makebox[54.06023pt][c]{$0$}\\ \makebox[54.06023pt][c]{${\color[rgb]{0.1797,0.4258,0.707}\exp\left(q_{2}^{\top}k_{1}\right)}$}&\makebox[54.06023pt][c]{$0$}\\ \makebox[54.06023pt][c]{${\color[rgb]{0.1797,0.4258,0.707}\exp\left(q_{3}^{\top}k_{1}\right)}$}&\makebox[54.06023pt][c]{${\color[rgb]{0.1797,0.4258,0.707}\exp\left(q_{3}^{\top}k_{3}\right)}$}\\ \makebox[54.06023pt][c]{${\color[rgb]{0.1797,0.4258,0.707}\exp\left(q_{4}^{\top}k_{1}\right)}$}&\makebox[54.06023pt][c]{${\color[rgb]{0.1797,0.4258,0.707}\exp\left(q_{4}^{\top}k_{3}\right)}$}\\ \makebox[54.06023pt][c]{${\color[rgb]{0.1797,0.4258,0.707}\exp\left(q_{5}^{\top}k_{1}\right)}$}&\makebox[54.06023pt][c]{${\color[rgb]{0.1797,0.4258,0.707}\exp\left(q_{5}^{\top}k_{3}\right)}$}\end{pmatrix}\\[10.0pt] &\begin{array}[]{@{}cc@{}}\makebox[54.06023pt][c]{\raisebox{-2.58334pt}{$k_{1}$}}&\makebox[54.06023pt][c]{\raisebox{-2.58334pt}{$k_{3}$}}\end{array}\end{array}&\odot&\begin{array}[]{@{}c@{}}\begin{pmatrix}\makebox[22.76219pt][c]{$1$}&\makebox[22.76219pt][c]{$0$}\\ \makebox[22.76219pt][c]{$f_{1:2}$}&\makebox[22.76219pt][c]{$0$}\\ \makebox[22.76219pt][c]{$f_{1:3}$}&\makebox[22.76219pt][c]{$1$}\\ \makebox[22.76219pt][c]{$f_{1:4}$}&\makebox[22.76219pt][c]{$f_{3:4}$}\\ \makebox[22.76219pt][c]{$f_{1:5}$}&\makebox[22.76219pt][c]{$f_{3:5}$}\end{pmatrix}\\[10.0pt] \begin{array}[]{@{}cc@{}}\makebox[22.76219pt][c]{\raisebox{-2.58334pt}{$k_{1}$}}&\makebox[22.76219pt][c]{\raisebox{-2.58334pt}{$k_{3}$}}\end{array}\end{array}\end{array}
(b) Linear branch
\begin{array}[]{@{}c@{\;}c@{\;}c@{}}\begin{array}[]{@{}r@{\;}c@{}}\begin{array}[]{@{}r@{}}\makebox[22.76219pt][r]{$q_{1}$}\\ \makebox[22.76219pt][r]{$q_{2}$}\\ \makebox[22.76219pt][r]{$q_{3}$}\\ \makebox[22.76219pt][r]{$q_{4}$}\\ \makebox[22.76219pt][r]{$q_{5}$}\end{array}&\begin{pmatrix}\makebox[54.06023pt][c]{$0$}&\makebox[54.06023pt][c]{$0$}&\makebox[54.06023pt][c]{$0$}\\ \makebox[54.06023pt][c]{${\color[rgb]{0.85,0.425,0}\phi\left(q_{2}\right)^{\top}\mkern-5.0mu\phi\left(k_{2}\right)}$}&\makebox[54.06023pt][c]{$0$}&\makebox[54.06023pt][c]{$0$}\\ \makebox[54.06023pt][c]{${\color[rgb]{0.85,0.425,0}\phi\left(q_{3}\right)^{\top}\mkern-5.0mu\phi\left(k_{2}\right)}$}&\makebox[54.06023pt][c]{$0$}&\makebox[54.06023pt][c]{$0$}\\ \makebox[54.06023pt][c]{${\color[rgb]{0.85,0.425,0}\phi\left(q_{4}\right)^{\top}\mkern-5.0mu\phi\left(k_{2}\right)}$}&\makebox[54.06023pt][c]{${\color[rgb]{0.85,0.425,0}\phi\left(q_{4}\right)^{\top}\mkern-5.0mu\phi\left(k_{4}\right)}$}&\makebox[54.06023pt][c]{$0$}\\ \makebox[54.06023pt][c]{${\color[rgb]{0.85,0.425,0}\phi\left(q_{5}\right)^{\top}\mkern-5.0mu\phi\left(k_{2}\right)}$}&\makebox[54.06023pt][c]{${\color[rgb]{0.85,0.425,0}\phi\left(q_{5}\right)^{\top}\mkern-5.0mu\phi\left(k_{4}\right)}$}&\makebox[54.06023pt][c]{${\color[rgb]{0.85,0.425,0}\phi\left(q_{5}\right)^{\top}\mkern-5.0mu\phi\left(k_{5}\right)}$}\end{pmatrix}\\[10.0pt] &\begin{array}[]{@{}ccc@{}}\makebox[54.06023pt][c]{\raisebox{-2.58334pt}{$k_{2}$}}&\makebox[54.06023pt][c]{\raisebox{-2.58334pt}{$k_{4}$}}&\makebox[54.06023pt][c]{\raisebox{-2.58334pt}{$k_{5}$}}\end{array}\end{array}&\odot&\begin{array}[]{@{}c@{}}\begin{pmatrix}\makebox[22.76219pt][c]{$0$}&\makebox[22.76219pt][c]{$0$}&\makebox[22.76219pt][c]{$0$}\\ \makebox[22.76219pt][c]{$1$}&\makebox[22.76219pt][c]{$0$}&\makebox[22.76219pt][c]{$0$}\\ \makebox[22.76219pt][c]{$f_{2:3}$}&\makebox[22.76219pt][c]{$0$}&\makebox[22.76219pt][c]{$0$}\\ \makebox[22.76219pt][c]{$f_{2:4}$}&\makebox[22.76219pt][c]{$1$}&\makebox[22.76219pt][c]{$0$}\\ \makebox[22.76219pt][c]{$f_{2:5}$}&\makebox[22.76219pt][c]{$f_{4:5}$}&\makebox[22.76219pt][c]{$1$}\end{pmatrix}\\[10.0pt] \begin{array}[]{@{}ccc@{}}\makebox[22.76219pt][c]{\raisebox{-2.58334pt}{$k_{2}$}}&\makebox[22.76219pt][c]{\raisebox{-2.58334pt}{$k_{4}$}}&\makebox[22.76219pt][c]{\raisebox{-2.58334pt}{$k_{5}$}}\end{array}\end{array}\end{array}
Figure 8: The two memory branches for and . (a) The exponential branch reads retained keys and . (b) The linear branch summarizes , , and . Both use decay products evaluated at the original positions. Here , as in Equation 3.
C.2 Linear Branch: Log-Space Chunkwise Recurrence
We describe the computation of and , the numerator and denominator of the linear branch in Equation 5. Let denote the entries up to assigned to the linear kernel.
Mathematical formulation.
The formulation mirrors Equation 10, with the exponential kernel replaced by the linear kernel (Item 2; default ):
As in Section 4, the recurrent state is stored per feature as the normalized value mean and the log-mass . For each query, the branch returns and its log-mass . The three prefill stages are shown in Figure 6 and given in full in Section C.5.
No metadata.
Unlike the exponential branch, the linear branch uses no packing metadata: its inputs are queries, keys, values, forget gates, and the routing mask. Retained entries are excluded by setting their key log-features to in the Triton kernels, so their weights vanish after exponentiation; values are unchanged.
Forgetting matrix.
For the same example (, ), the linear branch reads the keys , , and assigned to the linear kernel through the recurrent state. Each decay term runs from the key’s position to the query and includes the forget gates of retained positions (Figure 8).
Implementation.
The Triton kernels receive the routing mask separately and set the key log-features of retained entries to . This is equivalent to the masked key features of Section 4. Because the masked key factor is zero, the feature–value update also vanishes without modifying . The mask is shared by all query heads in a KV group. The forget gates remain on the full timeline, so a retained entry still contributes its gate to the decay between entries assigned to the linear kernel. Queries remain dense because every position reads the linear history. The linear branch is therefore a standard gated linear-attention recurrence over the contiguous sequence, with no gap-aware indexing.
C.3 Branch Combination
For query , each branch returns its normalized output and log-mass, and , where and are the two branch denominators in Equation 5. The branch-normalized outputs in Equation 10 and Equation 11 are therefore intermediate quantities. The final output is the merge of Section 4.3,
for . This equals the sum of the two numerators divided by the combined denominator. Subtracting keeps both exponents non-positive, and no denominator floor is added.
Empty branches are handled explicitly: a branch with no contributing keys has log-mass and receives zero weight, so when only one branch has positive mass, its normalized output is returned directly. Both branches can have zero mass only with feature maps that are not strictly positive, never with the default . In that case the output and its gradients through the merge are defined to be zero.
C.4 Packed Softmax Prefill Algorithms
Algorithms 1 and 2 give packing and tiled attention for the exponential branch during prefill. Batch indices are suppressed; indexes query heads and is the corresponding KV group. The router decision marks a retained entry, and denotes the cumulative log-forget; the algorithms suppress . The prefix differences below assume finite log-gates, which our gate parameterization guarantees (); the exponential branch therefore needs no reset handling. Positions and packed slots are one-based, and is the original position of the first query ( for full-sequence prefill). Query tiles contain up to consecutive query rows, and key tiles contain up to consecutive packed slots.
Packing preserves original-position order, so slot is causal for query position if and only if , the number of retained keys at or before . Query heads reuse the packing metadata of their KV group. The Triton kernel processes fully causal and boundary tiles in separate loops; the conditional in Algorithm 2 expresses this division compactly. Exponentials are written in natural-log form; the Triton kernel uses the equivalent base-two form.
Algorithm 1 Packed attention prefill: packing and metadata (per KV group)
1:
Keys k_{j}, values v_{j}, router decisions r_{j}, cumulative log-forget L(j), j=1,\ldots,T
2:
Packed K^{\mathrm{pack}},V^{\mathrm{pack}}; metadata p_{n}, c(t), N, L^{\mathrm{pack}}_{n}
3:
c(t)\leftarrow\sum_{j\leq t}r_{j} for t=1,\ldots,T; N\leftarrow c(T) \triangleright Prefix scan: causal frontiers and padding mask
4:
for all j with r_{j}=1 in parallel do
5:
n\leftarrow c(j); (K^{\mathrm{pack}}_{n},V^{\mathrm{pack}}_{n},p_{n},L^{\mathrm{pack}}_{n})\leftarrow(k_{j},v_{j},j,L(j)) \triangleright Original order is preserved
6:
end for
Algorithm 2 Packed attention prefill: tiled attention with forgetting
1:
Queries q_{i,h} at positions t_{i}=t_{0}+i-1 (1/\sqrt{d_{k}} absorbed) and their log-forget L(t_{i}); output of Algorithm 1 for the KV group of h
2:
Exponential-branch outputs o^{\mathrm{exp}}_{i,h} and log-masses \log Z^{\mathrm{exp}}_{i,h}
3:
for all query heads h and query tiles \mathcal{I} in parallel do
4:
n_{i}\leftarrow c(t_{i}) for i\in\mathcal{I} (0 for padded rows); m_{i}\leftarrow-\infty; Z_{i}\leftarrow 0; U_{i}\leftarrow 0
5:
for key tiles \mathcal{J}\subseteq\{1,\ldots,N\} with \min\mathcal{J}\leq\max_{i}n_{i}, in order do \triangleright Skip future tiles
6:
A_{in}\leftarrow q_{i,h}^{\top}K^{\mathrm{pack}}_{n}+L(t_{i})-L^{\mathrm{pack}}_{n} for i\in\mathcal{I}, n\in\mathcal{J}
7:
if \max\mathcal{J}>\min_{i}n_{i} then A_{in}\leftarrow-\infty where n>n_{i} \triangleright Mask boundary tiles only
8:
\tilde{m}_{i}\leftarrow\max_{n}A_{in}; p_{in}\leftarrow\exp(A_{in}-\tilde{m}_{i}) \triangleright Rows with \tilde{m}_{i}=-\infty are skipped
9:
m^{\prime}_{i}\leftarrow\max(m_{i},\tilde{m}_{i}); \alpha_{i}\leftarrow\exp(m_{i}-m^{\prime}_{i}); \beta_{i}\leftarrow\exp(\tilde{m}_{i}-m^{\prime}_{i})
10:
U_{i}\leftarrow\alpha_{i}U_{i}+\beta_{i}\sum_{n}p_{in}V^{\mathrm{pack}}_{n} \triangleright p cast to \mathrm{dtype}(V); FP32 accumulation
11:
Z_{i}\leftarrow\alpha_{i}Z_{i}+\beta_{i}\sum_{n}p_{in}; m_{i}\leftarrow m^{\prime}_{i}
12:
end for
13:
(o^{\mathrm{exp}}_{i,h},\log Z^{\mathrm{exp}}_{i,h})\leftarrow(U_{i}/Z_{i},\;m_{i}+\log Z_{i}), or (0,-\infty) if Z_{i}=0
14:
end for
C.5 Log-Space Linear Prefill Algorithms
Algorithms 4, 5 and 6 give the linear branch’s forward pass. Batch and head indices are suppressed: summaries and states are per KV group, and scores and outputs are per query head. The router decision marks a retained entry, whose key is masked out of the linear branch. Prefixes and reset counts are stored separately for each chunk, including its starting boundary. For positions in chunk (including that boundary), write for the reset-safe analogue of (Section 4). Reset handling is defensive: the gate parameterization always gives . Local scores are shown for clarity; the Triton kernels never materialize them. All three stages combine normalized values and log-masses with the stable merge of Algorithm 3, which also serves decode (Section C.6).
Algorithm 3 Stable merge of normalized values and log-masses
1:
function Merge(\{(x_{j},a_{j})\}_{j}) \triangleright Values x_{j} with log-masses a_{j}
2:
if a_{j}=-\infty for all j then return (0,-\infty) \triangleright Empty contribution
3:
m\leftarrow\max_{j}a_{j}; w_{j}\leftarrow\exp(a_{j}-m); Z\leftarrow\sum_{j}w_{j}
4:
return \bigl(\sum_{j}(w_{j}/Z)\,x_{j},\;m+\log Z\bigr) \triangleright Convex combination; never forms x_{i}-x_{j}
5:
end function
6:
\operatorname{LSE}_{j}a_{j} denotes the second output, m+\log Z (or -\infty).
Algorithm 4 Log-space linear prefill: local scores and chunk summaries
1:
Log-features \log\phi(q_{i}), \log\phi(k_{i}); values v_{i}; router decisions r_{i}; log-gates g_{i}; chunks \mathcal{C}_{c}=\{u+1,\ldots,v\}
2:
Local log-scores A_{tj}; decay \Delta^{(c)}; local states (\bar{V}_{c},\log z^{\mathrm{loc}}_{c})
3:
\log\tilde{\phi}(k_{i})\leftarrow\log\phi(k_{i}) if r_{i}=0, else -\infty \triangleright Mask keys, not gates
4:
for all chunks c in parallel do
5:
E_{c,i}\leftarrow\#\{j\in(u,i]:g_{j}=-\infty\}; \Lambda_{c,i}\leftarrow\sum_{j\in(u,i],\,g_{j}>-\infty}g_{j} \triangleright Compensated prefix sum
6:
\Delta^{(c)}_{s\to t}\leftarrow\Lambda_{c,t}-\Lambda_{c,s} if s\leq t and E_{c,s}=E_{c,t}, else -\infty
7:
A_{tj}\leftarrow\operatorname{LSE}_{d}\bigl(\log\phi(q_{t})_{d}+\log\tilde{\phi}(k_{j})_{d}\bigr)+\Delta^{(c)}_{j\to t} for t,j\in\mathcal{C}_{c}
8:
(\bar{V}_{c,d},\log z^{\mathrm{loc}}_{c,d})\leftarrow\textsc{Merge}(\{(v_{j},\;\log\tilde{\phi}(k_{j})_{d}+\Delta^{(c)}_{j\to v})\}_{j\in\mathcal{C}_{c}}) for each feature d
9:
end for
Algorithm 5 Log-space linear prefill: cross-chunk state scan
1:
Local states and \Delta^{(c)} from Algorithm 4; chunks \mathcal{C}_{c}=\{u+1,\ldots,v\}; initial state (\bar{V}^{\mathrm{acc}}_{0},\log z^{\mathrm{acc}}_{0}), or (0,-\infty) if empty
2:
Incoming boundary state of every chunk; final state (\bar{V}^{\mathrm{acc}}_{N},\log z^{\mathrm{acc}}_{N})
3:
for all features d in parallel do
4:
for c=1,\ldots,N do \triangleright Sequential across chunks
5:
Save (\bar{V}^{\mathrm{acc}}_{c-1,d},\log z^{\mathrm{acc}}_{c-1,d}) as the incoming state of chunk c
6:
(\bar{V}^{\mathrm{acc}}_{c,d},\log z^{\mathrm{acc}}_{c,d})\leftarrow\textsc{Merge}((\bar{V}^{\mathrm{acc}}_{c-1,d},\;\log z^{\mathrm{acc}}_{c-1,d}+\Delta^{(c)}_{u\to v}),\;(\bar{V}_{c,d},\;\log z^{\mathrm{loc}}_{c,d}))
7:
end for
8:
end for
Algorithm 6 Log-space linear prefill: fused query readout
1:
Local log-scores A_{tj} and \Delta^{(c)}; chunks \mathcal{C}_{c}=\{u+1,\ldots,v\}; incoming boundary states; query log-features; values v_{j}; s_{\mathrm{linear}}=1/\sqrt{d_{k}}
2:
Linear-branch outputs o^{\mathrm{lin}}_{t} and log-masses \log Z^{\mathrm{lin}}_{t}
3:
for all chunks c and queries t\in\mathcal{C}_{c} in parallel do
4:
\eta_{t,d}\leftarrow\log\phi(q_{t})_{d}+\log z^{\mathrm{acc}}_{c-1,d}+\Delta^{(c)}_{u\to t} for each feature d \triangleright Boundary state
5:
(o^{\mathrm{lin}}_{t},\log Z^{\mathrm{lin}}_{t})\leftarrow\textsc{Merge}(\{(\bar{V}^{\mathrm{acc}}_{c-1,d},\eta_{t,d})\}_{d}\cup\{(v_{j},A_{tj})\}_{j\in\mathcal{C}_{c}}) \triangleright One shared scale
6:
\log Z^{\mathrm{lin}}_{t}\leftarrow\log Z^{\mathrm{lin}}_{t}+\log s_{\mathrm{linear}}
7:
end for
C.6 Log-Space Decode Algorithms
These algorithms implement the decode step of Section 4.4: an entry with updates the recurrent state, an entry with is appended to the KV cache, and every query reads both memories. For the linear branch, decode replaces the local-summary and cross-chunk stages of Section C.5 with one state update per token, which every query head in the KV group reads immediately. Batch and KV-group indices are suppressed; indexes the query heads of the KV group. For each feature , the recurrent state stores a normalized value mean and a scalar log-mass . The stable merge of Algorithm 3 is used for the state update, the query readout in Algorithm 7, and the final merge of the two branches.
Algorithm 7 Log-space linear decode: fused state update and readout
1:
State (\bar{V}_{d},\log z_{d}), or (0,-\infty) if empty; \log\phi(q_{t,h}), \log\phi(k_{t}), v_{t}; r_{t}; g_{t}=\log f_{t}; s_{\mathrm{linear}}=1/\sqrt{d_{k}}
2:
Updated state; outputs o^{\mathrm{lin}}_{t,h} and log-masses \log Z^{\mathrm{lin}}_{t,h}
3:
for all features d in parallel do
4:
b_{d}\leftarrow\log\phi(k_{t})_{d} if r_{t}=0, else -\infty \triangleright Insert only entries routed to the linear kernel
5:
(\bar{V}_{d},\log z_{d})\leftarrow\textsc{Merge}((\bar{V}_{d},\;\log z_{d}+g_{t}),\;(v_{t},b_{d})) \triangleright In place; skip the store of \bar{V}_{d} if unchanged
6:
end for
7:
for all query heads h of the KV group in parallel do
8:
(o^{\mathrm{lin}}_{t,h},\log Z^{\mathrm{lin}}_{t,h})\leftarrow\textsc{Merge}(\{(\bar{V}_{d},\;\log\phi(q_{t,h})_{d}+\log z_{d})\}_{d})
9:
\log Z^{\mathrm{lin}}_{t,h}\leftarrow\log Z^{\mathrm{lin}}_{t,h}+\log s_{\mathrm{linear}}
10:
end for
KV-cache append and exponential-branch attention.
Algorithm 8 advances the decay metadata on every token, appends the current entry to the KV cache when , and scans the retained keys using online softmax. Appending before the scan gives the current entry zero log-decay. Each retained entry stores its key, value, original position , and cumulative log-forget . For an empty cache, initialize and . The cumulative log-forget advances by a plain FP32 sum; there are no reset epochs or compensated summation in the KV cache. Both branches use the same finite log-gate .
Algorithm 8 Decode: KV-cache append and exponential-branch attention
1:
Queries q_{t,h} (1/\sqrt{d_{k}} absorbed); k_{t}, v_{t}; r_{t}; g_{t}=\log f_{t}; KV cache \mathcal{R} of (k_{j},v_{j},p_{j},L(p_{j})); L=L(t-1)
2:
Updated \mathcal{R} and L=L(t); outputs o^{\mathrm{exp}}_{t,h} and log-masses \log Z^{\mathrm{exp}}_{t,h}
3:
L\leftarrow L+g_{t} \triangleright Every token, regardless of routing
4:
if r_{t}=1 then append (k_{t},v_{t},t,L) to \mathcal{R} \triangleright Once per KV group
5:
for all query heads h of the KV group in parallel do
6:
(o^{\mathrm{exp}}_{t,h},\log Z^{\mathrm{exp}}_{t,h})\leftarrow\textsc{Merge}(\{(v_{j},\;q_{t,h}^{\top}k_{j}+L-L(p_{j}))\}_{j\in\mathcal{R}}) \triangleright Online softmax over cache blocks
7:
end for
Merging the branches.
Algorithm 8 returns the exponential branch’s normalized output and log-mass , including the current entry when . The final output uses the same merge, which implements Equation 12:
1:
(o_{t,h},\,\cdot\,)\leftarrow\textsc{Merge}((o^{\mathrm{lin}}_{t,h},\log Z^{\mathrm{lin}}_{t,h}),(o^{\mathrm{exp}}_{t,h},\log Z^{\mathrm{exp}}_{t,h}))
An empty KV cache supplies .
The current entry contributes directly to exactly one branch, while both histories decay.
This is mathematical pseudocode: the Triton kernel tiles the feature–value contractions, merges scan partials in the same kernel, and does not write the linear-branch output to memory separately. A reset removes the old recurrent history; the current entry can still initialize a new state. Skipping the mean store when is valid when and the feature has positive mass (Section 4.4).
C.7 Decode Memory-Access Model
Consider one request, layer and KV group with key dimension and value dimension . We model the single recurrent state of this KV group, whose query heads share the reads counted below. Index the prompt tokens and generated tokens by , with as in Section 4.4. Assume no KV eviction and attention reads after the current token’s routing-dependent state update or KV append. At decode step , the retained KV count is , while full attention reads positions. In an idealized logical-access model, count one value-mean matrix read every step, a value-mean matrix write when , and one read of each retained key and value. We also count one read and one write of the recurrent state’s log-masses at every step, contributing accesses regardless of routing. These are persistent state entries; the exponential branch’s log-mass is computed during the scan and is not stored. The total scalar accesses are
For a simple closed form, assume every prompt and generated entry is retained in the KV cache with probability , so for all and . Independence between routing decisions is unnecessary. Taking the expectation of the total gives
The expectation is over the routing decisions , with and fixed. Dividing this expected total by gives the expected accesses per decode step:
For reference, full attention reads all key/value pairs at step , giving the deterministic generation-average access count
The assumption at every position matters because an entry retained early is read on more decode steps.
These equations count idealized logical scalar accesses, not bytes or measured GPU traffic: Triton kernels may reread elements, and cache hits can keep logical reads from reaching HBM. Estimating bytes moved requires weighting the counts by the element sizes of the recurrent state and the KV cache when their dtypes differ. As in Section 4.5, reset writes, metadata, new KV writes, model weights, and workspace traffic are omitted. Final-cache counts cannot replace generation-average KV reads without adjustment.