Introduction
Linear attention stores context in a fixed-size recurrent state, enabling linear-time sequence modeling and constant-memory decoding [30 , 50 , 54 ] . Its limited capacity makes retention important: as new associations are written, they can interfere with those already stored [2 , 31 ] . Recent gated recurrent models control retention using coefficients predicted from token representations [22 , 25 , 56 , 65 , 67 ] . These gates are data-dependent but state-independent: their coefficients do not directly read the recurrent memory of the same layer. State independence here refers to the gate predictor within a layer. Token representations may already contain context from earlier layers, but the predictor does not explicitly inspect the memory that its coefficients will modify.
This separation supports efficient chunkwise computation. A sequence is divided into chunks of consecutive tokens, with parallel matrix operations within each chunk and recurrent state propagation between chunks. The gate coefficients can be computed before the state updates, and their structure enables further reuse of computation. Gated DeltaNet (GDN) uses one decay coefficient per head, whereas Kimi Delta Attention (KDA) uses one per key channel. Both share decay coefficients across value channels, allowing their chunkwise algorithms to reuse transition factors [56 , 67 ] . A scalar gate cannot distinguish value rows or key channels, while a key-channel gate can distinguish columns but still treats all value rows alike.
The same design limits how gates use memory. For a fixed token representation, the gate is unchanged even if the layer stores different information. Although the delta update reads the state to correct stored associations, this read does not enter the gate predictor. Coefficient sharing also forces different state elements to use the same forgetting rate. Adding state-dependent, element-wise gates at every token, however, changes the structure used by existing chunkwise algorithms. Direct state feedback makes each gate depend on preceding state updates, while generic element-wise decay removes the transition sharing used by these kernels. The challenge is therefore to expose memory information to the retention mechanism at a point where it can be used without disrupting the base computation.
These constraints motivate our central question:
Question. How can we introduce state-dependent, element-wise forgetting while preserving parallel computation within each chunk?
We address this question with State-Dependent Gating (SDG), which applies the additional gate only at chunk boundaries (Figure 1 ). After the base layer processes a chunk, SDG subtracts the incoming state from the updated state and uses this difference to compute a separate retention coefficient for each state element. For these gated recurrences, the difference reflects how the chunk modifies the incoming memory through writing, erasing, and forgetting. The gate then scales the updated state before it enters the next chunk. Because the current chunk’s outputs have already been computed, its algorithm and parallel factorization remain unchanged. Both boundary states are available from the recurrence. The added computation evaluates and applies the boundary gate.
Figure 1. State-Dependent Gating (SDG). The base layer processes a chunk of C C C tokens, taking the incoming state S [ n ] + \mathbf{S}^{+}_{[n]} S [ n ] + to the updated state S [ n + 1 ] − \mathbf{S}^{-}_{[n+1]} S [ n + 1 ] − and producing outputs O [ n ] \mathbf{O}_{[n]} O [ n ] . SDG uses the difference between states to compute an element-wise gate and passes the new state S [ n + 1 ] + \mathbf{S}^{+}_{[n+1]} S [ n + 1 ] + to the next chunk.
The two levels of gating play different roles. Native token gates control the updates within each chunk, while the boundary gate controls the memory passed to subsequent chunks. This separation allows the added gate to use the completed chunk’s effect on memory. It also makes the feedback interval explicit: the gate observes a net state change once per chunk.
We support this design with theoretical analysis and empirical evaluation. Under a signal–noise model, our analysis compares fixed and shared gates with an ideal gate that can vary across boundary observations and state elements. This quantifies the potential reconstruction benefits of adaptive, element-wise decay. We assess the learned method across recurrent and hybrid architectures, including controls that replace state-change feedback with chunk information alone.
Our contributions are summarized as follows:
Boundary gating and fused implementation. We introduce element-wise decay from chunk-level state changes, applied at boundaries to preserve the base layer’s within-chunk algorithm. We develop fused kernels for GDN, KDA, Gated DeltaNet-2, and Mamba-3.
Theoretical characterization. Under a signal–noise model, we derive an exact decomposition of the excess reconstruction error of fixed and shared boundary gates. We also characterize boundary decay, with the realized gate held fixed, as an element-wise ridge proximal step.
Empirical evaluation. At the 1.3B scale with 100B training tokens, SDG improves WikiText perplexity and average real-world retrieval across four recurrent backbones. Retrieval gains extend to three sliding-window hybrids, while reasoning and broader long-context results are mixed. Ablations examine gate inputs, granularity, and projection, and runtime measurements quantify the cost of boundary gating.
Related Work
Recurrent models and forgetting. Linear attention [30 ] admits recurrent computation. Random-feature variants approximate softmax attention [13 , 43 ] . S4 [23 ] and Mamba [22 ] use structured and input-dependent state-space dynamics, respectively. Mamba-3 [33 ] adds exponential-trapezoidal discretization and complex-valued transitions. RetNet [54 ] , GLA [65 ] , and Mamba-2 [17 ] support efficient chunkwise computation.
Gated memory designs include outer-product updates in HGRN2 [45 ] , matrix memory in xLSTM’s mLSTM [7 ] , and slot-based reading in Gated Slot Attention [69 ] . DeltaNet [50 , 66 ] corrects stored associations using the current state. GDN [67 ] and KDA [56 ] add per-head scalar and per-key-channel decay, respectively. GDN-2 [25 ] decouples erase and write gates. Their gate predictors use token representations without directly reading the same layer’s recurrent memory. RWKV-7 [42 ] generalizes the delta rule with vector-valued gates and in-context learning rates. Forgetting Transformer [34 ] introduces data-dependent decay into softmax attention.
State feedback and transition expressivity. Comba [27 ] combines a closed-loop control interpretation, scalar-plus-low-rank transitions, state and output corrections, and efficient chunkwise computation. Its state correction reads memory, while its scalar forget gate is predicted from the token representation. DeltaProduct [52 ] composes multiple generalized Householder transformations per token to increase state-tracking expressivity. Complex KDA [53 ] extends the ranges of KDA’s channel-wise gate and delta coefficient to represent rotations while retaining diagonal-plus-rank-one transitions. SDG uses the change in the same layer’s memory across a chunk to predict element-wise boundary decay, retaining the supported backbones’ native token gates and within-chunk update rules. This separates the information used to choose the boundary gate from the structure of the token-level transition. State feedback enters after the chunk computation, so the native recurrence does not require a new gate at each token.
Memory capacity and retrieval. Empirical recall gaps [2 ] and finite-precision bounds for retrieval tasks [61 ] motivate better use of recurrent memory. Block-Recurrent Transformers [28 ] use attention and gated state updates across blocks, while Compressive Transformers [46 ] store older activations in a separate compressed memory. More recently, Sparse Delta Memory [12 ] expands GDN’s state through sparse addressing, and HOLA [16 ] augments a delta-rule state with a bounded exact key–value cache, using update residuals to select stored associations. These approaches increase or supplement memory capacity. SDG changes retention within the native state matrix, keeping its dimensions fixed and adding no retrieval cache. This distinction concerns the memory representation passed between chunks. Cached decoding still requires an additional source-state matrix to compute the boundary difference.
Online learning and memory optimization. Matrix associative memories store outer-product superpositions [31 ] . Fast-weight programmers learn context-dependent weight changes [51 ] , while decaying fast-weight memories retain recent activity [4 ] . Delta-rule models, test-time training, and Longhorn connect recurrent updates to online learning [35 , 50 , 55 ] . Test-time regression [60 ] unifies sequence models through regression weights, function classes, and optimization algorithms. Titans [9 ] combines gradient-based memory updates with momentum and forgetting. MesaNet [59 ] uses a chunkwise implementation and a conjugate-gradient solver for an in-context regression objective. Preconditioned DeltaNet [58 ] introduces diagonal curvature corrections to delta-rule models with efficient chunkwise algorithms. These methods refine memory learning, while SDG adds a learned retention step after the base chunk update. Its gate parameters are learned during training, and evaluating the gate at a chunk boundary does not require an iterative optimizer or an additional test-time regression solve.
Retention as regularization. MIRAS [8 ] separates associative-memory objectives, retention regularization, and online optimization, and derives alternative forgetting mechanisms. Consistent with this connection between forgetting and regularization, SDG boundary decay is an element-wise ridge proximal step when the realized gate is held fixed [19 , 20 , 41 ] . Its penalty coefficients depend on chunk-level state changes, and shrinkage is applied at chunk boundaries. Wiener shrinkage [63 ] informs our oracle reconstruction analysis of adaptive and shared boundary gates. The oracle comparison isolates the effects of gate adaptation and coefficient sharing under a fixed state distribution. It characterizes potential reconstruction gains, without assuming that the learned gate observes the useful memory and interference separately.
Preliminaries
Recurrent state and native gates
For one head, queries and keys q t , k t ∈ R d k q_t, k_t \in\mathbb{R}^{d_k} q t , k t ∈ R d k read and write a state S t ∈ R d v × d k S_t \in\mathbb{R}^{d_v \times d_k} S t ∈ R d v × d k , with value channels as rows and key channels as columns. Values and outputs satisfy v t , o t ∈ R d v v_t, o_t \in\mathbb{R}^{d_v} v t , o t ∈ R d v . The unnormalized additive recurrence is [30 , 50 ]
S t = S t − 1 + v t k t T , o t = S t q t . (1) S_t = S_{t-1} + v_t k_t^{\mathsf{T}}, \qquad o_t = S_t q_t. \tag*{(1)} S t = S t − 1 + v t k t T , o t = S t q t . (1)
The read includes the current write. Sequences start from S 0 = 0 S_0 = 0 S 0 = 0 . The state size is independent of sequence length.
In GDN, KDA, and GDN-2, native gates depend on token representations, whereas delta corrections read the recurrent state. GDN uses scalar decay, KDA uses key-channel decay, and GDN-2 separates erase and write gates. For fixed inputs, these layers share a key-space transition across value rows. Their token-dependent factors can therefore be prepared before the state scan. Appendix E.1 gives their token updates. Mamba-3 instead uses a d v × d s d_v \times d_s d v × d s state without delta correction (Appendix E.8).
Chunkwise computation
Training and prefill scan states across chunks with parallel computation within each chunk. Decoding uses the native token recurrence. For the formulas below, assume L = N C L = NC L = N C with N N N complete chunks of C C C tokens. The incoming state is S [ n ] = S ( n − 1 ) C S_{[n]} = S_{(n-1)C} S [ n ] = S ( n − 1 ) C . Additive and gated delta-rule chunks have a shared transition P [ n ] ∈ R d k × d k P_{[n]} \in\mathbb{R}^{d_k \times d_k} P [ n ] ∈ R d k × d k and a zero-memory response Ω [ n ] ∈ R d v × d k \Omega_{[n]} \in\mathbb{R}^{d_v \times d_k} Ω [ n ] ∈ R d v × d k :
S [ n + 1 ] = S [ n ] P [ n ] + Ω [ n ] , S [ n + 1 ] − S [ n ] = S [ n ] ( P [ n ] − I ) + Ω [ n ] . (2) \begin{aligned}
S_{[n+1]} &= S_{[n]}P_{[n]} + \Omega_{[n]},\\
S_{[n+1]} - S_{[n]} &= S_{[n]}(P_{[n]} - I) + \Omega_{[n]}. \tag*{(2)}
\end{aligned} S [ n + 1 ] S [ n + 1 ] − S [ n ] = S [ n ] P [ n ] + Ω [ n ] , = S [ n ] ( P [ n ] − I ) + Ω [ n ] . (2)
For fixed token inputs and native gates, both factors are independent of incoming memory. Thus gated state changes include the incoming-memory response; additive updates have P [ n ] = I P_{[n]} = I P [ n ] = I . Appendix E.1 expands the additive computation, and Appendix E.3 derives the gated forms.
State-Dependent Gating
Element-wise decay at chunk boundaries
SDG applies element-wise decay after the native chunk recurrence F \mathcal{F} F , retaining its token gates and within-chunk computation. Let S [ n ] + S^+_{[n]} S [ n ] + be the incoming state, S [ n + 1 ] − S^-_{[n+1]} S [ n + 1 ] − the updated state, S [ n + 1 ] + S^+_{[n+1]} S [ n + 1 ] + the gated state. X [ n ] \mathcal{X}_{[n]} X [ n ] contains projected token inputs and native gates, and ξ [ n ] \xi_{[n]} ξ [ n ] denotes auxiliary state. The computation returns the chunk outputs O [ n ] ∈ R C × d v O_{[n]} \in\mathbb{R}^{C \times d_v} O [ n ] ∈ R C × d v :
( O [ n ] , S [ n + 1 ] − , ξ [ n + 1 ] ) = F ( X [ n ] , S [ n ] + , ξ [ n ] ) , Λ [ n ] = G θ ( S [ n ] + , S [ n + 1 ] − ) , Λ [ n ] ∈ ( 0 , 1 ] d v × d k , S [ n + 1 ] + = Λ [ n ] ⊙ S [ n + 1 ] − . (3) \begin{aligned}
(O_{[n]}, S^-_{[n+1]}, \xi_{[n+1]}) &= \mathcal{F}(\mathcal{X}_{[n]}, S^+_{[n]}, \xi_{[n]}),\\
\Lambda_{[n]} &= \mathcal{G}_{\theta}(S^+_{[n]}, S^-_{[n+1]}), \qquad\Lambda_{[n]} \in(0,1]^{d_v \times d_k},\\
S^+_{[n+1]} &= \Lambda_{[n]} \odot S^-_{[n+1]}. \tag*{(3)}
\end{aligned} ( O [ n ] , S [ n + 1 ] − , ξ [ n + 1 ] ) Λ [ n ] S [ n + 1 ] + = F ( X [ n ] , S [ n ] + , ξ [ n ] ) , = G θ ( S [ n ] + , S [ n + 1 ] − ) , Λ [ n ] ∈ ( 0 , 1 ] d v × d k , = Λ [ n ] ⊙ S [ n + 1 ] − . (3)
Decay scales the entire updated state, including the current chunk’s writes. Outputs are formed first, so the gate affects only subsequent chunks. Native auxiliary states advance unchanged.
Token-level state feedback prevents gate precomputation from token representations alone, while general element-wise decay removes the shared value-row transitions of § 3 . Boundary placement preserves native within-chunk factorization and confines the additional dependency to the inter-chunk scan (Appendix § 14 ).
Gate parameterization
The gate uses the state change, which includes both the incoming-memory response and the chunk contribution: Δ S [ n ] = S [ n ] + ( P [ n ] − I ) + Ω [ n ] \Delta S_{[n]} = S^{+}_{[n]}(P_{[n]} - I) + \Omega_{[n]} Δ S [ n ] = S [ n ] + ( P [ n ] − I ) + Ω [ n ] by Eq. (2) . Each head learns an unconstrained projection W S ∈ R d k × d k W_S \in\mathbb{R}^{d_k \times d_k} W S ∈ R d k × d k across key channels within each value row and an unconstrained element-wise gain G ∈ R d v × d k G \in\mathbb{R}^{d_v \times d_k} G ∈ R d v × d k . These predict the gate without directly projecting the stored state:
Δ S [ n ] = S [ n + 1 ] − − S [ n ] + , X [ n ] = Δ S [ n ] W S T , Z [ n ] = G ⊙ X [ n ] , (4) \Delta S_{[n]} = S^{-}_{[n+1]} - S^{+}_{[n]}, \quad X_{[n]} = \Delta S_{[n]}W_S^{\mathsf{T}}, \quad Z_{[n]} = G \odot X_{[n]}, \tag*{(4)} Δ S [ n ] = S [ n + 1 ] − − S [ n ] + , X [ n ] = Δ S [ n ] W S T , Z [ n ] = G ⊙ X [ n ] , (4)
ρ [ n ] = Z [ n ] + Z [ n ] ⊙ Z [ n ] + ρ 0 2 1 , (5) \rho_{[n]} = Z_{[n]} + \sqrt{Z_{[n]} \odot Z_{[n]} + \rho_0^2 \mathbf{1}}, \tag*{(5)} ρ [ n ] = Z [ n ] + Z [ n ] ⊙ Z [ n ] + ρ 0 2 1 , (5)
Λ [ n ] = exp ( − ρ [ n ] ) , S [ n + 1 ] + = Λ [ n ] ⊙ S [ n + 1 ] − . (6) \Lambda_{[n]} = \exp(-\rho_{[n]}), \qquad S^{+}_{[n+1]} = \Lambda_{[n]} \odot S^{-}_{[n+1]}. \tag*{(6)} Λ [ n ] = exp ( − ρ [ n ] ) , S [ n + 1 ] + = Λ [ n ] ⊙ S [ n + 1 ] − . (6)
Equation (5) is twice Squareplus [6 ] , applied element-wise (definition and derivatives in Appendix § 15 ). Positive scores increase decay, while negative scores reduce it. For finite scores, 0 < Λ [ n ] < 1 0 < \Lambda_{[n]} < 1 0 < Λ [ n ] < 1 . We initialize G = 0 G = 0 G = 0 and fix ρ 0 = − log λ 0 \rho_0 = -\log\lambda_0 ρ 0 = − log λ 0 , λ 0 = 0.9999 \lambda_0 = 0.9999 λ 0 = 0.9999 , so all gates initially equal λ 0 1 \lambda_0 \mathbf{1} λ 0 1 . Appendix § 9 gives the remaining initialization details.
Algorithm 1 shows the computation order, with the added gate steps in bold. The native recurrence F \mathcal{F} F retains each backbone’s state and output computations. The algorithm assumes complete chunks, L = N C L = NC L = N C . For arbitrary lengths and cached continuations, Appendix § 12 .9 specifies the scan. Incomplete final chunks do not trigger boundary decay.
Algorithm 1 SDG: Boundary-Gated Chunk Scan
Require: Sequence length L = N C L = NC L = N C , and N = L / C N = L/C N = L / C complete chunks, native token quantities X \mathcal{X} X , initial state S [ 1 ] + S^{+}_{[1]} S [ 1 ] + and auxiliary state ξ [ 1 ] \xi_{[1]} ξ [ 1 ] , chunk size C C C , gate parameters W S W_S W S , G G G , and fixed base rate ρ 0 \rho_0 ρ 0 .
Partition X \mathcal{X} X into N N N complete chunks of C C C tokens, { X [ n ] } n = 1 N \{\mathcal{X}_{[n]}\}_{n=1}^{N} { X [ n ] } n = 1 N .
for n = 1 , … , N n = 1, \ldots, N n = 1 , … , N do
Retain the incoming state S s r c ← S [ n ] + \mathbf{S}^{\mathrm{src}} \leftarrow S^{+}_{[n]} S src ← S [ n ] + .
Compute ( O [ n ] , S [ n + 1 ] − , ξ [ n + 1 ] ) ← F ( X [ n ] , S [ n ] + , ξ [ n ] ) (O_{[n]}, S^{-}_{[n+1]}, \xi_{[n+1]}) \leftarrow\mathcal{F}(\mathcal{X}_{[n]}, S^{+}_{[n]}, \xi_{[n]}) ( O [ n ] , S [ n + 1 ] − , ξ [ n + 1 ] ) ← F ( X [ n ] , S [ n ] + , ξ [ n ] ) .
Compute Δ S [ n ] ← S [ n + 1 ] − − S s r c \Delta S_{[n]} \leftarrow S^{-}_{[n+1]} - \mathbf{S}^{\mathrm{src}} Δ S [ n ] ← S [ n + 1 ] − − S src .
Compute X [ n ] ← Δ S [ n ] W S T , Z [ n ] ← G ⊙ X [ n ] X_{[n]} \leftarrow\Delta S_{[n]}W_S^{\mathsf{T}}, Z_{[n]} \leftarrow G \odot X_{[n]} X [ n ] ← Δ S [ n ] W S T , Z [ n ] ← G ⊙ X [ n ] .
Compute ρ [ n ] ← 2 squareplus ( Z [ n ] ; ρ 0 ) , Λ [ n ] ← exp ( − ρ [ n ] ) \rho_{[n]} \leftarrow2\operatorname{squareplus}(Z_{[n]}; \rho_0), \Lambda_{[n]} \leftarrow\exp(-\rho_{[n]}) ρ [ n ] ← 2 squareplus ( Z [ n ] ; ρ 0 ) , Λ [ n ] ← exp ( − ρ [ n ] ) .
Set S [ n + 1 ] + ← Λ [ n ] ⊙ S [ n + 1 ] − S^{+}_{[n+1]} \leftarrow\Lambda_{[n]} \odot S^{-}_{[n+1]} S [ n + 1 ] + ← Λ [ n ] ⊙ S [ n + 1 ] − .
end for
return Concat ( O [ 1 ] , … , O [ N ] ) , S [ N + 1 ] + \operatorname{Concat}(O_{[1]}, \ldots, O_{[N]}), S^{+}_{[N+1]} Concat ( O [ 1 ] , … , O [ N ] ) , S [ N + 1 ] + , and ξ [ N + 1 ] \xi_{[N+1]} ξ [ N + 1 ] .
Fused kernel implementation
The boundary update is fused into the inter-chunk state scan using Triton [57 ] , while retaining native factor preparation and output kernels. Appendix § 15 gives forward and backward kernel details, with reference algorithms for additive linear attention in Algorithms 2 and 3, respectively. Each head adds O ( d v d k 2 ) O(d_v d_k^2) O ( d v d k 2 ) projection and O ( d v d k ) O(d_v d_k) O ( d v d k ) element-wise work per boundary, amortized over C C C tokens, plus backward computation (Appendix § 16 ). For Mamba-3, replace d k d_k d k by d s d_s d s . Cached decoding retains an additional source matrix and token counter. We use C = 64 C = 64 C = 64 to balance recurrent overhead and on-chip memory usage, matching the chunk size the adopted Flash Linear Attention kernels [64 ] . We apply the same boundary rules during training, prefill, and decoding.
Analysis
We characterize the realized boundary operation, then quantify potential gains from ideal reconstruction gates under a fixed upstream state distribution.
Boundary decay as an adaptive element-wise ridge
Holding the realized gate fixed, boundary decay is an element-wise ridge proximal step.
The rates set separate ridge weights, with κ = ρ [ n ] + O ( ρ [ n ] 2 ) \boldsymbol{\kappa} = \boldsymbol{\rho}_{[n]} + O(\boldsymbol{\rho}_{[n]}^{2}) κ = ρ [ n ] + O ( ρ [ n ] 2 ) at small rates. This identity applies to all four backbones and concerns only the boundary operation. Composing it with a chunk’s token updates is not generally one forward–backward step. Appendix F.1 gives the proof, converse, and backbone-specific token-update interpretations.
Optimal decay and the cost of sharing it
At one boundary, keep the upstream distribution fixed and model the state as useful memory plus residual interference [31 , 50 ] :
S − = S ⋆ + N , (8) \mathbf{S}^{-} = \mathbf{S}^{\star} + \mathbf{N}, \tag*{(8)} S − = S ⋆ + N , (8)
Here S ⋆ \mathbf{S}^{\star} S ⋆ is useful to future queries and N \mathbf{N} N is residual interference; neither is separately observed by the learned gate. For oracle information Φ \Phi Φ , a gate is admissible if it is Φ \Phi Φ -measurable with finite reconstruction risk R ( Λ ) = E ∥ Λ ⊙ S − − S ⋆ ∥ F 2 \mathcal{R}(\boldsymbol{\Lambda}) = \mathbb{E}\left\|\boldsymbol{\Lambda} \odot\mathbf{S}^{-} - \mathbf{S}^{\star}\right\|_{F}^{2} R ( Λ ) = E ∥ Λ ⊙ S − − S ⋆ ∥ F 2 . An independent isotropic query makes this risk proportional to readout error; other query models can change the optimum (Appendix F.3).
Lemma 1 (Conditional shrinkage and excess risk). Assume that S ⋆ \mathbf{S}^{\star} S ⋆ and N \mathbf{N} N have finite second moments and that m − = E [ S − ⊙ S − ∣ Φ ] > 0 \mathbf{m}_{-} = \mathbb{E}[\mathbf{S}^{-} \odot\mathbf{S}^{-} \mid\Phi] > 0 m − = E [ S − ⊙ S − ∣ Φ ] > 0 almost surely, and define
Λ ⋆ = E [ S ⋆ ⊙ S − ∣ Φ ] ⊘ m − . (9) \boldsymbol{\Lambda}^{\star} = \mathbb{E}[\mathbf{S}^{\star} \odot\mathbf{S}^{-} \mid\Phi] \oslash\mathbf{m}_{-}. \tag*{(9)} Λ ⋆ = E [ S ⋆ ⊙ S − ∣ Φ ] ⊘ m − . (9) Then every admissible gate satisfies
R ( Λ ) = R ( Λ ⋆ ) + E [ m − 1 / 2 ⊙ ( Λ − Λ ⋆ ) ] F 2 . (10) \mathcal{R}(\boldsymbol{\Lambda}) = \mathcal{R}(\boldsymbol{\Lambda}^{\star}) + \mathbb{E}\left[\mathbf{m}_{-}^{1/2} \odot(\boldsymbol{\Lambda} - \boldsymbol{\Lambda}^{\star})\right]_{F}^{2}. \tag*{(10)} R ( Λ ) = R ( Λ ⋆ ) + E [ m − 1/2 ⊙ ( Λ − Λ ⋆ ) ] F 2 . (10) If in addition E [ S ⋆ ⊙ N ∣ Φ ] = 0 \mathbb{E}[\mathbf{S}^{\star} \odot\mathbf{N} \mid\Phi] = 0 E [ S ⋆ ⊙ N ∣ Φ ] = 0 , then Λ ⋆ = m ⋆ ⊘ ( m ⋆ + m N ) ∈ [ 0 , 1 ] d v × d k \boldsymbol{\Lambda}^{\star} = \mathbf{m}_{\star} \oslash(\mathbf{m}_{\star} + \mathbf{m}_{N}) \in[0,1]^{d_v \times d_k} Λ ⋆ = m ⋆ ⊘ ( m ⋆ + m N ) ∈ [ 0 , 1 ] d v × d k , with m ⋆ = E [ S ⋆ ⊙ S ⋆ ∣ Φ ] \mathbf{m}_{\star} = \mathbb{E}[\mathbf{S}^{\star} \odot\mathbf{S}^{\star} \mid\Phi] m ⋆ = E [ S ⋆ ⊙ S ⋆ ∣ Φ ] , m N = E [ N ⊙ N ∣ Φ ] \mathbf{m}_{N} = \mathbb{E}[\mathbf{N} \odot\mathbf{N} \mid\Phi] m N = E [ N ⊙ N ∣ Φ ] and m − = m ⋆ + m N \mathbf{m}_{-} = \mathbf{m}_{\star} + \mathbf{m}_{N} m − = m ⋆ + m N . All operations are element-wise.
We compare fixed boundary coefficients with the adaptive oracle under the same state distribution. The fixed scalar and per-key families below describe coefficient sharing, not native GDN or KDA gates, which can vary with token inputs.
Corollary 1 (Cost of fixing and of sharing the gate). Let m ˉ = E [ m − ] \bar{\mathbf{m}} = \mathbb{E}[\mathbf{m}_{-}] m ˉ = E [ m − ] be finite and strictly positive. Consider
C s c a l a r = { λ 1 } ⊂ C k e y = { 1 d v λ T } ⊂ C e l e m = R d v × d k ⊂ C a d a p t = { admissible gates } , \mathcal{C}_{\mathrm{scalar}} = \{\lambda\mathbf{1}\} \subset\mathcal{C}_{\mathrm{key}} = \{\mathbf{1}_{d_v}\boldsymbol{\lambda}^{\mathsf{T}}\} \subset\mathcal{C}_{\mathrm{elem}} = \mathbb{R}^{d_v \times d_k} \subset\mathcal{C}_{\mathrm{adapt}} = \{\textit{admissible gates}\}, C scalar = { λ 1 } ⊂ C key = { 1 d v λ T } ⊂ C elem = R d v × d k ⊂ C adapt = { admissible gates } ,
where the first three contain only constants. Define the optimal constant element-wise gate and its weighted averages by
Λ ˉ = E [ S ⋆ ⊙ S − ] ⊘ m ˉ , m ˉ ⋅ b = ∑ a m ˉ a b , \bar{\Lambda} = \mathbb{E}[\mathbf{S}^{\star} \odot\mathbf{S}^{-}] \oslash\bar{\mathbf{m}}, \qquad\bar{m}_{\cdot b} = \sum_{a} \bar{m}_{ab}, Λ ˉ = E [ S ⋆ ⊙ S − ] ⊘ m ˉ , m ˉ ⋅ b = a ∑ m ˉ ab ,
μ b = ∑ a m ˉ a b Λ ˉ a b m ˉ ⋅ b , μ = ∑ b m ˉ ⋅ b μ b ∑ b m ˉ ⋅ b . \mu_b = \frac{\sum_a \bar{m}_{ab}\bar{\Lambda}_{ab}}{\bar{m}_{\cdot b}}, \qquad\mu= \frac{\sum_b \bar{m}_{\cdot b}\mu_b}{\sum_b \bar{m}_{\cdot b}}. μ b = m ˉ ⋅ b ∑ a m ˉ ab Λ ˉ ab , μ = ∑ b m ˉ ⋅ b ∑ b m ˉ ⋅ b μ b .
Then Λ ˉ \bar{\Lambda} Λ ˉ , 1 d v μ ⊤ \mathbf{1}_{d_v}\mu^{\top} 1 d v μ ⊤ , and μ 1 \mu\mathbf{1} μ 1 minimize R \mathcal{R} R over the constant element-wise, per-key, and scalar families, respectively, and
min C s c a l a r R − min C a d a p t R = E ∥ m ˉ − 1 / 2 ⊙ ( Λ ⋆ − Λ ˉ ) ∥ F 2 ⏟ E s t a t e + ∑ a , b m ˉ a b ( Λ ˉ a b − μ b ) 2 ⏟ E v a l u e + ∑ b m ˉ ⋅ b ( μ b − μ ) 2 ⏟ E k e y . (11) \min_{\mathcal{C}_{\mathrm{scalar}}} \mathcal{R} - \min_{\mathcal{C}_{\mathrm{adapt}}} \mathcal{R}
= \underbrace{\mathbb{E}\left\|\bar{\mathbf{m}}_{-}^{1/2}\odot(\Lambda^{\star}-\bar{\Lambda})\right\|_{\mathrm{F}}^{2}}_{\mathcal{E}_{\mathrm{state}}}
+ \underbrace{\sum_{a,b}\bar{m}_{ab}(\bar{\Lambda}_{ab}-\mu_b)^2}_{\mathcal{E}_{\mathrm{value}}}
+ \underbrace{\sum_b\bar{m}_{\cdot b}(\mu_b-\mu)^2}_{\mathcal{E}_{\mathrm{key}}}. \tag*{(11)} C scalar min R − C adapt min R = E state E m ˉ − 1/2 ⊙ ( Λ ⋆ − Λ ˉ ) F 2 + E value a , b ∑ m ˉ ab ( Λ ˉ ab − μ b ) 2 + E key b ∑ m ˉ ⋅ b ( μ b − μ ) 2 . (11)
Dropping E k e y \mathcal{E}_{\mathrm{key}} E key gives the per-key family’s excess risk; dropping the last two gives that of the constant element-wise family. If Λ ⋆ ∈ [ 0 , 1 ] d v × d k \Lambda^{\star} \in[0,1]^{d_v\times d_k} Λ ⋆ ∈ [ 0 , 1 ] d v × d k almost surely, all four minimizers lie in this box. Constraining the families to the box then leaves Eq. (11) unchanged.
The three nonnegative costs respectively arise from fixing coefficients across observations, sharing those fixed coefficients across value rows, and further sharing across key channels. Each vanishes when the corresponding optimal coefficients already satisfy the restriction. Appendix § 13 .§ 2 gives the conditional-shrinkage and projection proofs, oracle-rate endpoints, and adaptive-sharing counterpart. Appendix § 13 .§ 3 illustrates when costs are positive.
These are potential gains from adapting to Φ \Phi Φ . The first term alone does not measure information beyond token inputs. Constant scalar/per-key families are not native token-dependent GDN/KDA gates. The implemented gate uses only Δ S [ n ] \Delta S_{[n]} Δ S [ n ] through a restricted parameterization, which need not contain the full boundary-state pair’s information. The analysis neither identifies the gate found by training nor predicts trained-model ordering. Moreover, the risk in Eq. (11) is defined on unnormalized states. Because a non-uniform gate can also change a readout’s direction, the decomposition does not by itself characterize prediction error after RMS normalization. Table 4 evaluates the gate choices empirically; Appendix § 13 provides the complete proofs and additional results.
Table 4. Ablations of SDG on GDN. NIAH@4K averages S-NIAH-2, S-NIAH-3, and MK-NIAH-1 at 4K. Bold marks the highest score in each metric.
Experiments
We evaluate SDG’s effects on prediction quality, the contributions of its gate design, and its computational overhead. We also examine the local output changes caused by a single boundary update.
Experimental setup
We train paired GDN, KDA, Mamba-3 (SISO), and GDN-2 models on 100B FineWeb-Edu tokens [37 ] , using sequences of 4096 tokens and chunk size C = 64 C = 64 C = 64 . Each model has approximately 1.3B non-embedding parameters. Its +SDG counterpart adds a boundary gate to every recurrent layer. Table 6 gives parameter counts. Each pair shares the data order, optimizer settings, and initial values of shared parameters. Training details are in Appendix § 10 .
Table 6. Non-embedding parameter counts for recurrent models, excluding the input embedding and language-model head. SDG is added without reducing the width of the corresponding base model.
Evaluation covers language modeling, nine zero-shot accuracy tasks, four RULER needle-in-a-haystack tasks, six real-world retrieval tasks, and all 21 LongBench tasks. We also evaluate hybrid GDN, KDA, and GDN-2 models that alternate recurrent layers with 2K sliding-window attention.
Performance across backbones
Language modeling and zero-shot accuracy. SDG lowers WikiText perplexity by 0.10–0.58 across the four recurrent backbones (Table 1 ). LAMBADA perplexity improves for three models and rises slightly for KDA. Average zero-shot accuracy increases for GDN, Mamba-3, and GDN-2, while KDA is unchanged at the reported precision. Task-level effects remain mixed, including lower BoolQ accuracy in all four pairs.
Table 1. Language modeling and zero-shot accuracy. Avg. is the mean over the nine accuracy columns; a c c n acc_n a c c n denotes length-normalized accuracy. Bold marks the better result within each pair.
Ablations and boundary diagnostics
In-context retrieval on synthetic data. On the evaluated RULER [26 ] tasks, multi-key retrieval improves across all four backbones at 2K and 4K (Table 2 ). At 4K, MK-NIAH-1 gains are 0.2, 4.4, 13.6, and 9.8 percentage points for GDN, KDA, Mamba-3, and GDN-2, respectively. Single-needle results are less uniform: KDA falls from 36.4% to 24.2% on S-NIAH-3 at 4K. Thus, improvements vary even within the task length. The two tasks evaluated at 8K also give mixed results, so these gains do not establish better length extrapolation.
Table 2. RULER retrieval accuracy (%) for recurrent models trained at 4K. Columns give input lengths. Bold marks the better result within each baseline–SDG pair.
In-context retrieval on real-world tasks. Following Aurora et al. [3 ] , we evaluate six real-world retrieval tasks (Table 3 ). SDG raises reported mean accuracy by 0.39–0.83 percentage points across the four backbones.
Table 3. Real-world retrieval accuracy (%) for recurrent models. Avg. is the mean over the six tasks. SQD, TQA, and NQ denote SQuAD, TriviaQA, and Natural Questions. Best results within each model family are bold (ties included).
Long-context understanding. On LongBench [5 ] , SDG improves average performance for GDN, KDA, and Mamba-3. The Code category score increases across all four models. Appendix § 11 .§ 1 reports the full results and analysis.
Hybrid models. Figure 2 shows results for hybrid GDN, KDA, and GDN-2. SDG lowers LAMBADA perplexity and improves average real-world retrieval accuracy across all three models. S-NIAH-3 accuracy also improves at 4K. LongBench scores increase for KDA and GDN-2. These results suggest that SDG can complement hybrid architectures. Appendix § 11 .§ 2 reports the full results.
Figure 2. S-NIAH-3 accuracy, LAMBADA perplexity, mean six-task retrieval accuracy, and mean 21-task LongBench score on hybrid models. Open and filled marks denote baseline and +SDG.
Ablations and boundary diagnostics
Gate inputs. Table 4 compares gate inputs, coefficient sharing, and projection on GDN. Fixed boundary decay and a learned static gate score below SDG on all four metrics. To examine within-layer state feedback, the chunk-input control replaces Δ S [ n ] \Delta S_{[n]} Δ S [ n ] with Ω [ n ] \Omega_{[n]} Ω [ n ] , the native chunk contribution from a zero incoming state. For fixed chunk inputs, Ω [ n ] \Omega_{[n]} Ω [ n ] excludes the response of that layer’s incoming memory, while token representations can still carry context from earlier layers. The dynamic inputs use the same gate parameterization. Constructing Ω [ n ] \Omega_{[n]} Ω [ n ] requires an additional matrix product, whereas Δ S [ n ] \Delta S_{[n]} Δ S [ n ] uses a subtraction of two available states. Appendix § 11 .§ 3 compares their GDN operator latencies in forward and backward computation.
The Ω \Omega Ω control recovers most of SDG’s gains. Using Δ S [ n ] \Delta S_{[n]} Δ S [ n ] instead raises NIAH@4K by 0.67 points and real-world retrieval by 0.02 points, but lowers LongBench by 0.18 points. The difference between these two inputs is modest and task-dependent. Using the incoming state S [ n ] + S^{+}_{[n]} S [ n ] + gives lower scores than the state-change input on all four metrics. The reported scores are point estimates without uncertainty estimates; small gaps do not establish a statistically reliable advantage.
Sharing and projection. Element-wise gating scores above channel-wise gating on all four metrics, including a 1.47-point gain on NIAH@4K. The channel-wise variant shares one retention coefficient per key channel across all value rows and retains the same parameter count as element-wise gating. Learning W S W_{S} W S also improves all four scores relative to fixing W S = I W_{S} = I W S = I , with a 4.54-point gain on NIAH@4K. The static and identity-projection variants use fewer parameters. Appendix § 11 .§ 3 details these controls and costs.
Boundary output stability. We compare normal execution with skipping one boundary update across all recurrent layers of the same trained model. The two branches start from identical caches and consume the same subsequent ground-truth tokens. Over the first eight affected positions, top-1 predictions agree at 98.34–99.12%, and mean Kullback–Leibler (KL) divergence is below 6.5 × 10 − 4 6.5 \times10^{-4} 6.5 × 1 0 − 4 . The four-model-adjusted intervals for mean negative log-likelihood (NLL) change all contain zero, with upper bounds below 0.003 nat per token (Figure 3 ).
Figure 3. Effects of one SDG boundary update, with 128 observations per model. (a) The heatmap shows mean KL divergence from skip to normal at each of the first 32 affected positions. (b) Colored points show sequence means of Δ \Delta Δ NLL over positions 1–8, defined as normal minus skip. Black diamonds and bars show means and bootstrap intervals adjusted across four models for approximately 95% simultaneous coverage.
These small averages coexist with individual loss increases and decreases. They do not bound per-token changes or characterize free-running generation. Mamba-3 contributes summary statistics. Sample matching and intervention controls were checked for GDN, KDA, and GDN-2. We also use valid filler tokens to place answer generation before and after chunk boundaries across benchmarks, with absolute changes in accuracy of at most 0.5 percentage points on commonsense reasoning and 1 percentage point on retrieval. Appendix § 11 .§ 5 gives the protocol and results.
Efficiency
Training throughput. We measure end-to-end training throughput for recurrent-only models on a single NVIDIA H200, with 16,384 input tokens per optimizer step. Across the tested 2K–16K sequence lengths, SDG retains 85.0–89.4% of baseline throughput for GDN, KDA, and GDN-2, and 72.5–75.1% for Mamba-3. Preserving within-chunk computation therefore still incurs a measurable training cost. GDN and GDN-2 with SDG show a smaller throughput decline across the tested lengths than the full-attention reference (Figure 4 ). See Appendix § 10 .§ 4 for details.
Figure 4. End-to-end efficiency on a single NVIDIA H200. Left and middle: hybrid-model TTFT and TPOT at batch size one. Right: recurrent-only training throughput, with 16,384 input tokens per optimizer step. FlashAttention uses full attention in both comparisons.
Inference latency. Inference measurements use hybrids with alternating recurrent and 2K SWA layers, on a single NVIDIA H200 at batch size one. For GDN and GDN-2 with SDG, time to first token (TTFT) grows approximately linearly at long contexts. Time per output token (TPOT) stays nearly constant for prompts from 512 to 512K tokens (Figure 4 ). At 256K, SDG adds 0.23 and 0.25 seconds to their TTFT, yielding 1.75 and 1.91 seconds, compared with 18.34 seconds for the full-attention reference. KDA incurs prefill and decoding overhead, whereas Mamba-3 has higher TTFT but lower TPOT (Appendix § 10 .§ 5 ). The models retain favorable long-context scaling, with overhead depending on the backbone.
Conclusion and Limitation
We introduced State-Dependent Gating (SDG), which derives element-wise boundary decay from state changes while preserving native within-chunk computation. Fused implementations support the evaluated backbones. With the realized gate fixed, boundary decay is an element-wise ridge proximal step. Reconstruction analysis quantifies potential gains for ideal gate families under a signal–noise model. In 1.3B models trained on 100B tokens, SDG improves WikiText perplexity and average real-world retrieval across four recurrent backbones. Average retrieval gains extend to three sliding-window hybrids, while zero-shot accuracy and broader long-context results remain mixed.
The gate uses only the net state change and cannot distinguish write–erase histories with the same resulting difference. We evaluate only on a 64-token boundary interval, so the effect of other intervals on memory control and parallel efficiency remains untested. Runtime overhead varies across backbones, and cached decoding requires an additional source-state matrix.
Notation
Table 5. Symbols used throughout the paper. Shapes are per head unless stated otherwise.
Gate parameters and initialization
The gate function in § 4.2 learns a projection W S \mathbf{W}_{S} W S and an element-wise gain G \mathbf{G} G for each head. This adds
H ( d k 2 + d v d k ) (12) H(d_k^2+d_vd_k) \tag*{(12)} H ( d k 2 + d v d k ) (12)
parameters to each SDG-enabled linear attention layer. We initialize
G = 0 , ρ 0 = − log λ 0 , λ 0 = 0.9999. (13) \mathbf{G}=\mathbf{0},\qquad\rho_0=-\log\lambda_0,\qquad\lambda_0=0.9999. \tag*{(13)} G = 0 , ρ 0 = − log λ 0 , λ 0 = 0.9999. (13)
This gives Λ [ n ] = λ 0 1 \boldsymbol{\Lambda}_{[n]}=\lambda_0\mathbf{1} Λ [ n ] = λ 0 1 at every boundary before training, independently of the state and projection. Each head’s W S \mathbf{W}_{S} W S uses Xavier uniform initialization with bounds ± 3 / d k \pm\sqrt{3/d_k} ± 3/ d k . Both W S \mathbf{W}_{S} W S and G \mathbf{G} G are stored in FP32. They are trainable, while ρ 0 \rho_0 ρ 0 is fixed throughout training. At initialization, the zero gain makes the gradient of W S \mathbf{W}_{S} W S zero. The projection begins to learn after G \mathbf{G} G changes.
Experimental settings
Models
Table 6 reports parameter counts. The counts include normalization parameters and all additional SDG parameters. The models have 18 layers and hidden width 2304. GDN, GDN-2, and KDA use head dimension 128. The Mamba-3 experiments use the SISO variant. Hybrid models replace every other recurrent layer with sliding-window attention and use a window of 2048 tokens.
Training
The models are trained for 100B tokens using sequences of 4096 tokens and a global batch of 512 sequences. We train with AdamW, β 1 = 0.9 \beta_{1} = 0.9 β 1 = 0.9 , β 2 = 0.95 \beta_{2} = 0.95 β 2 = 0.95 , weight decay 0.1, and gradient clipping at 1.0. The peak learning rate is 4 × 10 − 4 4 \times10^{-4} 4 × 1 0 − 4 . The learning rate follows a linear warm-up and cosine decay, with a warm-up over 1B tokens and a final rate of one tenth of the peak rate. Training uses bfloat16.
Each baseline and its +SDG counterpart use the same data order and optimizer settings. The initial boundary decay factor is λ 0 = 0.9999 \lambda_{0} = 0.9999 λ 0 = 0.9999 , corresponding to the base rate ρ 0 = − log λ 0 \rho_{0} = -\log\lambda_{0} ρ 0 = − log λ 0 in Eq. (13) .
Evaluation
We evaluate language modeling and zero-shot reasoning using the Language Model Evaluation Harness [21 ] . Language modeling performance is measured by perplexity on WikiText [38 ] and LAMBADA [40 ] . The zero-shot suite comprises LAMBADA, PIQA [11 ] , HellaSwag [68 ] , WinoGrande [48 ] , ARC-Easy, ARC-Challenge [15 ] , OpenBookQA [39 ] , SocialIQA [49 ] , and BoolQ [14 ] . We report accuracy on these tasks, with length normalization for HellaSwag and ARC-Challenge.
For synthetic retrieval, we evaluate S-NIAH-1 and S-NIAH-2 at 1K, 2K, 4K, and 8K tokens, and S-NIAH-3 and MK-NIAH-1 at 1K, 2K, and 4K tokens. Real-world retrieval is evaluated on SWDE [24 , 36 ] , FDA [1 ] , SQuAD [47 ] , DROP [18 ] , Natural Questions [32 ] , and TriviaQA [29 ] . We assess long-context understanding on all 21 LongBench [5 ] tasks, reporting category means and the unweighted average over tasks in Table 10 .
Table 10. LongBench scores. Columns give category means. Avg. is the unweighted mean over all 21 tasks.
Efficiency protocol
Training throughput. We measure end-to-end training throughput for the recurrent-only models on a single NVIDIA H200. Each step processes 16,384 input tokens, using sequence-length × batch-size configurations of 2K×8, 4K×4, 8K×2, and 16K×1. We report median throughput after warm-up in thousands of input tokens per second (K tokens/s). Each timed step includes gradient reset, the forward pass and loss computation, backpropagation, gradient clipping, and the AdamW update. The optimizer updates FP32 master parameters and copies the updated weights to the model. Models receive identical inputs. We use neither distributed training nor gradient accumulation.
Inference latency. We measure end-to-end inference latency on a single NVIDIA H200 with batch size one. After warm-up, we run five TTFT trials and three TPOT trials. TTFT is the synchronized elapsed time for prompt processing and first-token prediction. TPOT is the average time per token over 256 subsequent cached greedy decoding steps. We report the median across trials for each metric.
Detailed efficiency results
Tables 7 and 8 give the complete median inference latencies for the four backbones and the FlashAttention reference, including the GDN and GDN-2 curves in Figure 4 . These inference runs use hybrid models with alternating recurrent and sliding-window attention layers (window size 2048), whereas the training runs in Table 9 use recurrent-only models. FlashAttention uses full attention in both comparisons. All runs use a single NVIDIA H200. Sequence-length labels use 1K = 1024 tokens.
Table 9. End-to-end training throughput in thousands of input tokens/s (higher is better). Each column specifies sequence length × microbatch size and processes 16,384 input tokens per optimizer step. Parentheses give +SDG throughput as a percentage of its corresponding base model. These are the values used for the training curves in Figure 4 , with KDA and Mamba-3 included for completeness.
Table 8. Time per output token (TPOT, ms/token). Each trial averages 256 cached decoding steps. Entries are medians over three trials at batch size one. Model configurations follow Table 7 .
Table 7. Time to first token (TTFT, ms). Values are medians over five trials at batch size one. Base and +SDG denote the original and gated hybrid models, respectively. FlashAttn. is the full-attention reference. The - indicates OOM.
Additional experimental results
LongBench results for recurrent models
On LongBench [5 ] , SDG raises the Code category score by 1.81–2.62 points across all four backbones (Table 10 ). Average scores improve for GDN, KDA, and Mamba-3, but fall from 11.65 to 11.15 for GDN-2. Its few-shot score falls from 26.94 to 20.85, outweighing gains in code and question answering. Retrieval improvements thus do not translate uniformly to broader long-context performance.
Hybrid models
Tables 11–14 report results for hybrid models that alternate recurrent layers with sliding-window attention. The evaluation follows the recurrent-model comparisons in § 6 . Bold marks the better result within each baseline–SDG pair, including ties.
Language modeling and reasoning. Table 11 shows that SDG improves LAMBADA perplexity across all three hybrid models. GDN also improves on WikiText and average commonsense reasoning accuracy, while KDA and GDN-2 show small declines on these measures. The language modeling and reasoning benefits are thus less consistent than in the recurrent-only models.
Table 11. Language modeling and zero-shot reasoning for hybrid models. Metrics follow Table 1 . Avg. is the mean over the nine accuracy columns.
Synthetic retrieval. Table 12 shows that the effect of SDG varies across tasks and input lengths. GDN-2 benefits most broadly, improving multi-key retrieval across all evaluated lengths and single-needle retrieval in several longer-context settings. GDN shows clear gains on S-NIAH-3, while KDA has a more mixed response. As in the recurrent-only models, improvements on synthetic retrieval do not imply uniformly better length extrapolation.
Table 12. RULER retrieval accuracy (%) for hybrid models.
Real-world retrieval. Table 13 shows higher average retrieval accuracy for all three hybrid models, extending the trend observed in the recurrent-only setting. GDN and KDA show clearer average gains, while GDN-2 changes little overall because improvements and declines across tasks largely offset one another. These results suggest that SDG can complement sliding-window attention in hybrid models.
Table 13. Real-world retrieval accuracy (%) for hybrid models. Avg. is the mean over the six tasks.
Long-context understanding. Table 14 shows consistent gains in code and few-shot learning across all three hybrid models. Average performance improves for KDA and GDN-2 but declines for GDN, whose gains are outweighed by weaker question answering and summarization. As in the recurrent-only setting, retrieval improvements do not translate uniformly to broader long-context understanding.
Table 14. Table 14 LongBench scores (%) for hybrid models. Columns give category means. Avg. is the unweighted mean over all 21 tasks. Higher is better.
Ablation settings
Gate inputs. The fixed boundary control uses Λ [ n ] = 0.99991 \Lambda_{[n]} = 0.99991 Λ [ n ] = 0.99991 . The learned static control sets Z [ n ] = G Z_{[n]} = \mathbf{G} Z [ n ] = G in Eq. (5) , with zero-initialized trainable G \mathbf{G} G . These controls examine whether the boundary gate benefits from adapting to its input. The chunk-input control further tests whether directly using the layer’s state changes provides additional value. It uses Ω [ n ] \Omega_{[n]} Ω [ n ] from the affine chunk transition in Eq. (79) of Appendix § 14 . For fixed chunk token representations and native data-dependent gates, this is the state produced by the native chunk update from a zero incoming state. In GDN, it is obtained by setting S [ n ] + = 0 \mathbf{S}^{+}_{[n]} = 0 S [ n ] + = 0 in Eq. (37) . It retains the chunk’s writes and their subsequent within-chunk updates, while excluding the response of the incoming memory.
The control replaces Δ S [ n ] \Delta\mathbf{S}_{[n]} Δ S [ n ] with Ω [ n ] \Omega_{[n]} Ω [ n ] in Eq. (4) and retains the rate and boundary update in Eqs. (5) –(6) . The main recurrence still starts from the actual S [ n ] + \mathbf{S}^{+}_{[n]} S [ n ] + , and the gate scales the entire updated state S [ n + 1 ] − \mathbf{S}^{-}_{[n+1]} S [ n + 1 ] − . Only the gate input changes. The independence of Ω [ n ] \Omega_{[n]} Ω [ n ] from the incoming state is within the current layer, since its token representations can contain context from earlier layers.
The state-input control replaces Δ S [ n ] \Delta\mathbf{S}_{[n]} Δ S [ n ] with S [ n ] + \mathbf{S}^{+}_{[n]} S [ n ] + in Eq. (4) . It reads the memory entering the chunk and retains the same gate parameterization and boundary update, allowing a comparison between the incoming state and its change across the chunk.
Channel-wise parameterization. The channel-wise variant retains the per-head projection W S ∈ R d k × d k \mathbf{W}_{S} \in\mathbb{R}^{d_k \times d_k} W S ∈ R d k × d k and gain G ∈ R d v × d k \mathbf{G} \in\mathbb{R}^{d_v \times d_k} G ∈ R d v × d k of element-wise SDG. It computes Z [ n ] = G ⊙ ( Δ S [ n ] W S T ) Z_{[n]} = \mathbf{G} \odot(\Delta\mathbf{S}_{[n]}\mathbf{W}_{S}^{\mathsf{T}}) Z [ n ] = G ⊙ ( Δ S [ n ] W S T ) as in Eq. (4) and averages these scores over value rows before applying the nonlinear rate map:
z ˉ [ n ] , b = 1 d v ∑ a = 1 d v Z [ n ] , a b , (14) \bar{z}_{[n],b} = \frac{1}{d_v}\sum_{a=1}^{d_v} Z_{[n],ab}, \tag*{(14)} z ˉ [ n ] , b = d v 1 a = 1 ∑ d v Z [ n ] , ab , (14)
λ [ n ] , b = exp ( − z ˉ [ n ] , b − z ˉ [ n ] , b 2 + ρ 0 2 ) . (15) \lambda_{[n],b} = \exp\left(-\bar{z}_{[n],b} - \sqrt{\bar{z}_{[n],b}^{2} + \rho_{0}^{2}}\right). \tag*{(15)} λ [ n ] , b = exp ( − z ˉ [ n ] , b − z ˉ [ n ] , b 2 + ρ 0 2 ) . (15)
The resulting coefficient for each key channel is broadcast across all value rows, giving Λ [ n ] , a b = λ [ n ] , b \Lambda_{[n],ab} = \lambda_{[n],b} Λ [ n ] , ab = λ [ n ] , b and Λ [ n ] = 1 d v λ [ n ] T \Lambda_{[n]} = \mathbf{1}_{d_v}\lambda_{[n]}^{\mathsf{T}} Λ [ n ] = 1 d v λ [ n ] T . This gate scales the entire updated state through Eq. (6) . The variant uses the same zero initialization for G \mathbf{G} G and the same fixed ρ 0 = − log λ 0 \rho_{0} = -\log\lambda_{0} ρ 0 = − log λ 0 , so all retention coefficients initially equal λ 0 = 0.9999 \lambda_{0} = 0.9999 λ 0 = 0.9999 . It adds H ( d k 2 + d v d k ) H(d_k^2 + d_vd_k) H ( d k 2 + d v d k ) parameters per layer, matching element-wise SDG.
Paired training. Both gate-input controls and SDG use identical initial values for the backbone and W S \mathbf{W}_{S} W S , with G = 0 \mathbf{G} = 0 G = 0 and λ 0 = 0.9999 \lambda_{0} = 0.9999 λ 0 = 0.9999 . They therefore start from the same model function. The comparison holds the data order, training token budget, optimizer, learning-rate schedule, chunk size, gated layers, and evaluation settings fixed. Each variant uses its own gate input throughout training and evaluation. A comparison at a reduced training budget requires training all compared variants at that budget.
Parameter and computation costs. All three dynamic inputs use H ( d k 2 + d v d k ) H(d_k^2+d_vd_k) H ( d k 2 + d v d k ) additional parameters per layer and the same gate projection. Constructing Ω [ n ] \Omega_{[n]} Ω [ n ] explicitly requires a matrix multiplication costing approximately 2 C d v d k 2Cd_vd_k 2 C d v d k forward FLOPs per head and boundary, whereas constructing Δ S [ n ] \Delta S_{[n]} Δ S [ n ] requires a state subtraction. The state-input control uses the already available S [ n ] + \mathbf{S}^{+}_{[n]} S [ n ] + . Thus, matching the parameter count and gate function does not imply equal total computation. The identity-projection control retains the state-difference input and element-wise gain while removing the learned projection and its matrix multiplication. The gate-input comparison therefore matches parameter count while allowing different input-construction costs.
Scope of the comparisons. The Ω \Omega Ω -input and incoming-state controls test the input choice with the gate parameterization fixed. The granularity comparison changes coefficient sharing while retaining the same parameter count. The identity-projection control reduces the parameter count by removing W S \mathbf{W}_{S} W S . The reported scores are point estimates without uncertainty estimates, so small differences between variants do not establish a statistically reliable advantage.
Gate-input runtime. Table 15 compares the complete GDN operator with Δ S \Delta S Δ S - and Ω \Omega Ω -input SDG. Timing includes query/key normalization, WY preparation, the fused state scan, and output kernels. Backward includes boundary recomputation and gradients for all inputs and gate parameters. The timings are measured independently, with backward-only runs reusing a fixed forward graph, so their medians need not be additive. At 16,384 tokens per batch, Ω \Omega Ω increases forward latency by 1.30–6.07%, backward latency by 46.17–49.29%, and combined latency by 35.89–39.17%. At batch size one, the differences are more shape-dependent, with a small forward decrease at 512 tokens. These measurements favor Δ S \Delta S Δ S for training-time operator efficiency but do not measure full-model runtime.
Table 15. Median GDN operator latency (ms) on an RTX 5090. Δ t \Delta t Δ t is the percentage change for Ω \Omega Ω relative to Δ S \Delta S Δ S . The upper block fixes L B = 16 , 384 LB = 16,384 L B = 16 , 384 tokens per batch, and the lower block uses B = 1 B = 1 B = 1 .
Boundary gate distributions
We examine the distribution of the element-wise retention coefficient Λ \Lambda Λ at observed chunk boundaries. We report the fractional reduction d = 1 − Λ d = 1-\Lambda d = 1 − Λ , so larger values indicate stronger decay. Figure 5 shows the mean reduction across layers and heads. Table 16 reports statistics from the original model archives.
Figure 5. Mean fractional reduction 1 − Λ 1-\Lambda 1 − Λ across layers and heads on a shared logarithmic color scale. Mamba-3 statistics use the first 16 heads.
Table 16. Measured gate statistics pooled across layers with equal weight per observed cell. All entries are percentages; threshold fractions use the archived FP32 comparisons.
Observations and aggregation. Each model archive contains 18 layers, 32 sample IDs, and eight boundary positions per sample: 64, 640, 1216, 1792, 2368, 2944, 3520, and 4096 tokens consumed. This gives 256 boundary observations per layer. GDN, KDA, and GDN-2 each contribute 67,108,864 gate-cell observations per layer, across 16 heads. For Mamba-3, gate statistics are computed from the first 16 heads. Each measured heatmap cell averages the reduction over all observed samples, boundaries, and state elements for one layer and head. Means and threshold fractions use all observed cells; the reported medians use a uniform reservoir of 65,536 cells per layer. Repeated observations are not treated as independent experimental replicates. The reduction is computed stably as − expm1 ( − ρ ) -\operatorname{expm1}(-\rho) − expm1 ( − ρ ) , retaining small values even when FP32 retention rounds to one.
Distributions in the delta-rule models. For GDN, KDA, and GDN-2, every layer’s sampled median reduction is approximately 10 − 4 10^{-4} 1 0 − 4 , corresponding to retention near the initialization value 0.9999. The means are higher and vary across layers. Averaged over all observed cells, the reduction is 0.3104%, 0.0538%, and 0.1496%, respectively (Table 16 ). GDN and GDN-2 reach their largest layer means at layer 14 (1.0982% and 0.4693%); KDA peaks at layer 8 (0.1161%). Only 0.69%, 0.06%, and 0.25% of cells, respectively, have retention below 0.9. Thus, large reductions are concentrated in a small fraction of observations even though the median remains close to its initial value.
Boundary output stability
Paired boundary intervention. We compare normal execution with skipping one SDG update in the same trained model. At the selected boundary, we clone the complete cache before applying the gate. The normal branch applies SDG in all recurrent layers, while the skip branch passes the unmodified pre-gate states to the next chunk. All other operations are unchanged. Both branches then consume the same subsequent ground-truth tokens through cached decoding. This comparison isolates the effect of the selected update without changing the input or comparing separately trained models.
Prediction positions and metrics. Let b b b be the input position after which the selected boundary update occurs, and let r r r count subsequent input positions. The logits at position b + r b+r b + r predict the ground-truth token y b + r + 1 y_{b+r+1} y b + r + 1 . The output at r = 0 r=0 r = 0 is computed before the boundary update and is therefore unaffected. We exclude this position from all window averages. Top-1 agreement is the fraction of affected positions at which both branches assign the highest probability to the same token. We report this fraction over r = 1 , … , 8 r=1,\ldots,8 r = 1 , … , 8 and r = 1 , … , 32 r=1,\ldots,32 r = 1 , … , 32 , with equal weight for every sequence and position. At each position, we also measure KL divergence from the skip distribution to the normal distribution. This measures a change in the full output distribution rather than only its most probable token. All 32 positions precede the next boundary update.
Prediction loss. Agreement alone does not measure prediction quality, since both branches can predict the same incorrect token. We therefore also measure the negative log-likelihood (NLL) of the ground-truth next token. Given the common token prefix y ≤ b + r y_{\le b+r} y ≤ b + r , it is
NLL ( r ) = − log p ( y b + r + 1 ∣ y ≤ b + r ) , \operatorname{NLL}(r)=-\log p(y_{b+r+1}\mid y_{\le b+r}), NLL ( r ) = − log p ( y b + r + 1 ∣ y ≤ b + r ) ,
where p p p is the predictive distribution of the branch under consideration. We use the natural logarithm, so losses are measured in nats. Lower NLL means that the model assigns greater probability to the ground-truth token. We define the loss change as
Δ NLL ( r ) = NLL n o r m a l ( r ) − NLL s k i p ( r ) . (16) \Delta\operatorname{NLL}(r)=\operatorname{NLL}_{\mathrm{normal}}(r)-\operatorname{NLL}_{\mathrm{skip}}(r). \tag*{(16)} Δ NLL ( r ) = NLL normal ( r ) − NLL skip ( r ) . (16)
Positive values indicate that applying the update increases the target loss, while negative values indicate a decrease. We average r = 1 , … , 8 r=1,\ldots,8 r = 1 , … , 8 within each sequence before averaging across sequences, and inspect the loss changes at all 32 affected positions.
Samples and controls. The diagnostic includes 128 observations per model. GDN, KDA, and GDN-2 use the same 128 evaluation sequences at training step 47,683, with one selected boundary per sequence. Boundaries at input positions 1024, 2048, and 3072 account for 43, 43, and 42 sequences, respectively. Each intervention covers all 18 recurrent layers, with 16 heads per layer. For these three models, two unmodified executions produce identical logits, and the logit difference at r = 0 r=0 r = 0 is zero. Each layer receives exactly one boundary intervention. Mamba-3 contributes position-wise and sequence-level summaries; cross-model sample matching and intervention controls are assessed for GDN, KDA, and GDN-2.
Prediction agreement. Figure 6 shows that the two branches predict the same token at 98.34–99.12% of the first eight affected positions. Over 32 positions, agreement is 98.90%, 99.07%, 98.95%, and 99.17% for GDN, KDA, Mamba-3, and GDN-2, respectively. These are position-level rates, not the fraction of entire sequences with identical predictions. For GDN, KDA, and GDN-2, all 32 top-1 predictions agree in 70.31%, 71.88%, and 75.00% of the evaluation sequences, respectively. The remaining sequences contain at least one changed prediction. The small KL values complement the agreement rates by showing that the average change in the full distribution is also small.
Figure 6. Effects of one SDG boundary update under identical inputs. (a) Median relative state change. (b) KL divergence from skip to normal. (c) Top-1 agreement. (d) Sequence-level mean Δ \Delta Δ NLL over positions 1–8. Black diamonds and bars denote means and four-model-adjusted bootstrap intervals.
Uncertainty estimates. We resample whole sequences 5,000 times. Percentile-bootstrap intervals for mean loss changes use Bonferroni correction across four models, with quantiles 0.00625 and 0.99375, targeting approximately 95% simultaneous coverage. The ϵ = 0.01 \epsilon=0.01 ϵ = 0.01 line in Figure 7 is a descriptive reference for the population mean loss increase, not a per-sequence or per-token bound; our conclusions use the measured confidence bounds. Figure 8 shows pointwise 95% intervals, while the KL heatmap in Figure 3 shows the corresponding means. Window-level agreement percentages are descriptive averages without confidence intervals.
Figure 7. Prediction loss after a single SDG boundary update relative to skipping that update. The left panel reports mean Δ \Delta Δ NLL over the first eight affected positions with bootstrap intervals over sequences adjusted across four models for approximately 95% simultaneous coverage. The dotted line marks the reference tolerance ϵ = 0.01 \epsilon= 0.01 ϵ = 0.01 nat per token. The right panel shows the empirical distribution of sequence-level mean changes. Positive values indicate increased loss.
Figure 8. Prediction changes following a single SDG boundary update relative to skipping it. The panels show mean Δ \Delta Δ NLL, KL divergence from the skip distribution to the normal distribution, and the fraction of changed top-1 predictions. Shaded regions are pointwise 95% bootstrap intervals over sequences. Position zero is unaffected because its output precedes the update.
Average loss changes. Table 17 summarizes loss and output changes over the first eight affected positions. All four corrected intervals contain zero, and their upper bounds are below 0.003 nat per token. The small upper bounds constrain the average loss increase under the sampling protocol. The average KL divergence is below 0.00065 nat, while top-1 predictions differ at 0.88–1.66% of the first eight affected positions. Figure 8 retains the full position-wise variation rather than smoothing the curves.
Table 17. Prediction changes over the first eight affected positions. Loss and KL values are in nats. Confidence intervals are adjusted across four models.
Changes to the state. For each head, we measure the relative change caused by the boundary gate as
∥ S [ n + 1 ] + − S [ n + 1 ] − ∥ F ∥ S [ n + 1 ] − ∥ F . (17) \frac{\left\lVert\mathbf{S}^{+}_{[n+1]}-\mathbf{S}^{-}_{[n+1]}\right\rVert_F}{\left\lVert\mathbf{S}^{-}_{[n+1]}\right\rVert_F}. \tag*{(17)} S [ n + 1 ] − F S [ n + 1 ] + − S [ n + 1 ] − F . (17)
This measures the gate’s effect on the state, not the change Δ S [ n ] \Delta\mathbf{S}_{[n]} Δ S [ n ] across the chunk used to compute the gate. Figure 9 averages Eq. (17) over heads and sequences for each layer. Its scatter plot relates each sequence’s mean change across layers and heads to its mean loss change over the first eight affected positions. The median state changes across sequences, shown in Figure 6 , are approximately 1.85%, 1.10%, 2.57%, and 1.91% for GDN, KDA, Mamba-3, and GDN-2, respectively.
Figure 9. State changes at chunk boundaries. Left: relative Frobenius change per layer, averaged over heads and sequences, on a common scale. Right: sequence-level mean state change versus mean Δ \Delta Δ NLL over the first eight affected positions.
Individual loss increases. The 95th percentiles of sequence-level mean loss changes range from 0.0147 to 0.0161 nat across the four models. Individual-token analysis covers GDN, KDA, and GDN-2. Among GDN’s 4,096 affected positions, one has a loss increase of 0.656645 nat, occurring 16 positions after the boundary at input position 3072. The normal and skip losses are 1.864409 and 1.207765, respectively, so the normal branch assigns the target about 51.9% of the probability assigned by the skip branch. Both top-1 predictions are the same and incorrect. This event contributes to the response at position 16 in Figure 8 , outside the primary eight-position window. Its sequence-level mean state change is about 1.97%, so an unusually large average state change does not identify it. KDA and GDN-2 have no positions with a loss increase above 0.5 nat in this sample.
Boundary-offset diagnostic. We insert valid filler tokens into benchmark inputs to place the start of answer generation before and after chunk boundaries. As specified in Appendix § 12 .9, these tokens enter the native recurrence and advance the within-chunk token counter. They therefore shift answer generation relative to the C C C -token boundary schedule. Across the tested benchmarks, absolute changes in accuracy are at most 0.5 percentage points on commonsense reasoning and 1 percentage point on retrieval. These are observed changes in benchmark accuracy, measured in percentage points rather than relative percentages. Because the filler tokens also change the input sequence, this diagnostic measures sensitivity to the combined change in input and boundary alignment. It complements the paired boundary intervention above, which holds the token sequence fixed and skips one boundary update.
State updates and implementation
Extended preliminaries
State convention. (1) uses value channels as state rows and key channels as columns. The output reads the state after the current write, so it includes the current token. At a fresh sequence start, S 0 = 0 \mathbf{S}_0 = 0 S 0 = 0 . The state size is independent of sequence length L L L .
Native token updates. DeltaNet [50 , 66 ] corrects the value stored at the current key using a gradient step [62 ] on the local regression loss
ℓ t ( S ) = 1 2 ∥ S k t − v t ∥ 2 2 . (18) \ell_t(\mathbf{S}) = \frac{1}{2}\lVert\mathbf{S}\mathbf{k}_t-\mathbf{v}_t\rVert_2^2. \tag*{(18)} ℓ t ( S ) = 2 1 ∥ S k t − v t ∥ 2 2 . (18)
Starting from S t − 1 \mathbf{S}_{t-1} S t − 1 , a gradient step with data-dependent step size β t ∈ [ 0 , 1 ] \beta_t \in[0,1] β t ∈ [ 0 , 1 ] gives
S t = S t − 1 + β t ( v t − S t − 1 k t ) k t T = S t − 1 ( I − β t k t k t T ) + β t v t k t T . (19) \mathbf{S}_t = \mathbf{S}_{t-1} + \beta_t(\mathbf{v}_t-\mathbf{S}_{t-1}\mathbf{k}_t)\mathbf{k}_t^{\mathsf{T}} = \mathbf{S}_{t-1}(\mathbf{I}-\beta_t\mathbf{k}_t\mathbf{k}_t^{\mathsf{T}}) + \beta_t\mathbf{v}_t\mathbf{k}_t^{\mathsf{T}}. \tag*{(19)} S t = S t − 1 + β t ( v t − S t − 1 k t ) k t T = S t − 1 ( I − β t k t k t T ) + β t v t k t T . (19)
For unit-norm keys, β t \beta_t β t controls how much of the stored value is replaced by v t \mathbf{v}_t v t .
Gated DeltaNet (GDN) [67 ] applies a data-dependent decay gate α t ∈ ( 0 , 1 ] \alpha_t \in(0,1] α t ∈ ( 0 , 1 ] before the delta update:
S t = α t S t − 1 ( I − β t k t k t T ) + β t v t k t T . (20) \mathbf{S}_t = \alpha_t\mathbf{S}_{t-1}(\mathbf{I}-\beta_t\mathbf{k}_t\mathbf{k}_t^{\mathsf{T}}) + \beta_t\mathbf{v}_t\mathbf{k}_t^{\mathsf{T}}. \tag*{(20)} S t = α t S t − 1 ( I − β t k t k t T ) + β t v t k t T . (20)
The scalar α t \alpha_t α t sets one retention rate for all state elements within a head.
Kimi Delta Attention (KDA) [56 ] assigns a decay coefficient to each key channel. Let D t = Diag ( α t ) \mathbf{D}_t = \operatorname{Diag}(\boldsymbol{\alpha}_t) D t = Diag ( α t ) with α t ∈ ( 0 , 1 ] d k \boldsymbol{\alpha}_t \in(0,1]^{d_k} α t ∈ ( 0 , 1 ] d k . The state update becomes
S t = S t − 1 D t ( I − β t k t k t T ) + β t v t k t T . (21) \mathbf{S}_t = \mathbf{S}_{t-1}\mathbf{D}_t(\mathbf{I}-\beta_t\mathbf{k}_t\mathbf{k}_t^{\mathsf{T}}) + \beta_t\mathbf{v}_t\mathbf{k}_t^{\mathsf{T}}. \tag*{(21)} S t = S t − 1 D t ( I − β t k t k t T ) + β t v t k t T . (21)
Each decay coefficient is shared across value channels, while β t \beta_t β t controls both erasing and writing.
Gated DeltaNet-2 (GDN-2) [25 ] replaces the shared delta step size β t \beta_t β t with separate erase and write gates, retaining the decay matrix D t \mathbf{D}_t D t . Let e t = b t ⊙ k t \mathbf{e}_t = \mathbf{b}_t \odot\mathbf{k}_t e t = b t ⊙ k t and z t = w t ⊙ v t \mathbf{z}_t = \mathbf{w}_t \odot\mathbf{v}_t z t = w t ⊙ v t , where b t ∈ [ 0 , 1 ] d k \mathbf{b}_t \in[0,1]^{d_k} b t ∈ [ 0 , 1 ] d k and w t ∈ [ 0 , 1 ] d v \mathbf{w}_t \in[0,1]^{d_v} w t ∈ [ 0 , 1 ] d v are the erase and write gates. Its update is
S t = S t − 1 D t ( I − e t k t T ) + z t k t T . (22) \mathbf{S}_t = \mathbf{S}_{t-1}\mathbf{D}_t(\mathbf{I}-\mathbf{e}_t\mathbf{k}_t^{\mathsf{T}}) + \mathbf{z}_t\mathbf{k}_t^{\mathsf{T}}. \tag*{(22)} S t = S t − 1 D t ( I − e t k t T ) + z t k t T . (22)
The erase gate weights the key channels used to read stored content, and the write gate scales the incoming value channels. Setting b t = β t 1 d k \mathbf{b}_t = \beta_t\mathbf{1}_{d_k} b t = β t 1 d k and w t = β t 1 d v \mathbf{w}_t = \beta_t\mathbf{1}_{d_v} w t = β t 1 d v recovers KDA. Further setting D t = α t I \mathbf{D}_t = \alpha_t\mathbf{I} D t = α t I recovers GDN.
In these layers, the gate coefficients are predicted from token representations without directly reading the recurrent state; the delta correction itself reads that state. For fixed token inputs, every value row is propagated through the same transition in key space. This shared structure supports the chunkwise computation in § 3.2 .
The Mamba-3 SISO backbone [33 ] has a matrix state and no delta read-and-correct term. Its state-space recurrence and our boundary gating are detailed in Appendix § 12 .8.
Additive chunk computation. We use the complete-chunk convention stated in § 3.2 . The chunkwise kernels considered here combine a recurrent state scan across chunks with parallel matrix operations within each chunk [25 , 44 , 56 , 65 , 66 , 67 ] . Chunk n ∈ { 1 , … , N } n \in\{1,\ldots,N\} n ∈ { 1 , … , N } contains tokens ( n − 1 ) C + 1 , … , n C (n-1)C+1,\ldots,nC ( n − 1 ) C + 1 , … , n C , with incoming state S [ n ] = S ( n − 1 ) C \mathbf{S}_{[n]} = \mathbf{S}_{(n-1)C} S [ n ] = S ( n − 1 ) C . Let Q [ n ] , K [ n ] ∈ R C × d k \mathbf{Q}_{[n]}, \mathbf{K}_{[n]} \in\mathbb{R}^{C \times d_k} Q [ n ] , K [ n ] ∈ R C × d k and V [ n ] , O [ n ] ∈ R C × d v \mathbf{V}_{[n]}, \mathbf{O}_{[n]} \in\mathbb{R}^{C \times d_v} V [ n ] , O [ n ] ∈ R C × d v stack the corresponding token vectors as rows. In the additive case of Eq. (1) ,
S [ n + 1 ] = S [ n ] + V [ n ] T K [ n ] , (23) \mathbf{S}_{[n+1]} = \mathbf{S}_{[n]} + \mathbf{V}_{[n]}^{\mathsf{T}}\mathbf{K}_{[n]}, \tag*{(23)} S [ n + 1 ] = S [ n ] + V [ n ] T K [ n ] , (23)
O [ n ] = Q [ n ] S [ n ] T + ( Q [ n ] K [ n ] T ⊙ M C ) V [ n ] , (24) \mathbf{O}_{[n]} = \mathbf{Q}_{[n]}\mathbf{S}_{[n]}^{\mathsf{T}} + \left(\mathbf{Q}_{[n]}\mathbf{K}_{[n]}^{\mathsf{T}} \odot\mathbf{M}_{C}\right)\mathbf{V}_{[n]}, \tag*{(24)} O [ n ] = Q [ n ] S [ n ] T + ( Q [ n ] K [ n ] T ⊙ M C ) V [ n ] , (24)
where M C \mathbf{M}_{C} M C is a binary lower-triangular mask including the diagonal. The two output terms read the incoming memory and combine causal interactions within the chunk. For fixed chunk size and head dimensions, the arithmetic work scales linearly with sequence length.
Shared factors and the incoming-memory response. Gated delta-rule layers combine cumulative decay with compact WY representations of the accumulated rank-one updates [10 , 25 , 56 , 66 , 67 ] . Their factors are shared across value rows and can be computed from token representations before the state scan. Let P [ n ] ∈ R d k × d k \mathbf{P}_{[n]} \in\mathbb{R}^{d_k \times d_k} P [ n ] ∈ R d k × d k denote the shared chunk transition and Ω [ n ] ∈ R d v × d k \mathbf{\Omega}_{[n]} \in\mathbb{R}^{d_v \times d_k} Ω [ n ] ∈ R d v × d k the state produced from zero incoming memory. The resulting affine update and state difference are given in Eq. (2) . For fixed token representations and native gates, P [ n ] \mathbf{P}_{[n]} P [ n ] and Ω [ n ] \mathbf{\Omega}_{[n]} Ω [ n ] do not depend on this layer’s incoming state. The additive case has P [ n ] = I \mathbf{P}_{[n]} = \mathbf{I} P [ n ] = I , so its state change contains only new writes. In the gated layers, the change also reflects how the chunk transforms the existing memory. Appendix § 12 .§ 3 gives the exact chunk formulas.
Training and prefill use chunkwise computation; decoding applies the native recurrence one token at a time. § 4 uses the incoming and updated chunk states to compute an additional boundary gate.
Chunkwise notation and boundary gating
We present each backbone in the WY/UT matrix form used by GDN [67 ] , KDA [56 ] , and GDN-2 [25 ] . We retain the state orientation of this paper, S ∈ R d v × d k \mathbf{S} \in\mathbb{R}^{d_v \times d_k} S ∈ R d v × d k , so the KDA and GDN-2 state equations are transposed relative to their original presentations. For one head and complete chunk n n n , Q , K ∈ R C × d k \mathbf{Q}, \mathbf{K} \in\mathbb{R}^{C \times d_k} Q , K ∈ R C × d k and V ∈ R C × d v \mathbf{V} \in\mathbb{R}^{C \times d_v} V ∈ R C × d v stack the native token vectors. We suppress [ n ] [n] [ n ] on these chunk-local quantities and their WY factors, but retain it on the input state, output block, and state passed to the next chunk. Let tril ( ⋅ ) \operatorname{tril}(\cdot) tril ( ⋅ ) include the diagonal and tril ( ⋅ , − 1 ) \operatorname{tril}(\cdot,-1) tril ( ⋅ , − 1 ) exclude it; ⊘ \oslash ⊘ denotes element-wise division.
In every model, S [ n ] − \mathbf{S}^{-}_{[n]} S [ n ] − enters the original chunk computation, which produces O [ n ] \mathbf{O}_{[n]} O [ n ] and the raw state S [ n + 1 ] − \mathbf{S}^{-}_{[n+1]} S [ n + 1 ] − . SDG then computes
Δ S [ n ] = S [ n + 1 ] − − S [ n ] + , \Delta\mathbf{S}_{[n]} = \mathbf{S}^{-}_{[n+1]} - \mathbf{S}^{+}_{[n]}, Δ S [ n ] = S [ n + 1 ] − − S [ n ] + ,
Z [ n ] = G ⊙ ( Δ S [ n ] W S T ) , \mathbf{Z}_{[n]} = \mathbf{G} \odot\left(\Delta\mathbf{S}_{[n]}\mathbf{W}_{S}^{\mathsf{T}}\right), Z [ n ] = G ⊙ ( Δ S [ n ] W S T ) ,
Λ [ n ] = exp [ − Z [ n ] − Z [ n ] ⊙ Z [ n ] + ρ 0 2 1 ] . (25) \mathbf{\Lambda}_{[n]} = \exp\left[-\mathbf{Z}_{[n]} - \sqrt{\mathbf{Z}_{[n]} \odot\mathbf{Z}_{[n]} + \rho_{0}^{2}\mathbf{1}}\right]. \tag*{(25)} Λ [ n ] = exp [ − Z [ n ] − Z [ n ] ⊙ Z [ n ] + ρ 0 2 1 ] . (25)
We display the final update S [ n + 1 ] + = Λ [ n ] ⊙ S [ n + 1 ] − \mathbf{S}^{+}_{[n+1]} = \mathbf{\Lambda}_{[n]} \odot\mathbf{S}^{-}_{[n+1]} S [ n + 1 ] + = Λ [ n ] ⊙ S [ n + 1 ] − alongside each backbone’s chunk equations below. In all four cases SDG changes only the matrix carried to the next chunk: the gate acts on the entire raw state including the chunk’s writes, whereas the WY factors, the pseudo-value term, the intra-chunk product, the output block, and the native query scaling, normalization, output gates, and output projections are untouched. The WY factors are computed from token-local inputs, while Λ [ n ] \mathbf{\Lambda}_{[n]} Λ [ n ] is evaluated inside the state scan. We do not repeat this per backbone below.
The closed forms in Appendices § 12 .§ 5 –§ 12 .§ 7 are three specializations of one lemma. Within a complete chunk, stack e i T \mathbf{e}_i^{\mathsf{T}} e i T into E ∈ R C × d k \mathbf{E} \in\mathbb{R}^{C \times d_k} E ∈ R C × d k and z i T \mathbf{z}_i^{\mathsf{T}} z i T into Z ∈ R C × d v \mathbf{Z} \in\mathbb{R}^{C \times d_v} Z ∈ R C × d v (chunk-local matrices; this Z \mathbf{Z} Z is not the SDG score Z [ n ] \mathbf{Z}_{[n]} Z [ n ] ), and let γ i = ⨀ j ≤ i α j \gamma_i = \bigodot_{j \leq i}\alpha_j γ i = ⨀ j ≤ i α j with the convention γ 0 = 1 \gamma_0 = 1 γ 0 = 1 . Define the cumulative and remaining decay matrices Γ p r e , Γ t a i l ∈ R C × d k \mathbf{\Gamma}^{\mathrm{pre}}, \mathbf{\Gamma}^{\mathrm{tail}} \in\mathbb{R}^{C \times d_k} Γ pre , Γ tail ∈ R C × d k row-wise by
Γ i , : p r e = γ i T , Γ i , : t a i l = ( γ C ⊘ γ i ) T , (26) \mathbf{\Gamma}^{\mathrm{pre}}_{i,:} = \gamma_i^{\mathsf{T}}, \qquad\mathbf{\Gamma}^{\mathrm{tail}}_{i,:} = \left(\gamma_C \oslash\gamma_i\right)^{\mathsf{T}}, \tag*{(26)} Γ i , : pre = γ i T , Γ i , : tail = ( γ C ⊘ γ i ) T , (26)
together with
K ˉ = K ⊘ Γ p r e , E ˉ = Γ p r e ⊙ E , A = [ I C + tril ( E ˉ K ˉ T , − 1 ) ] − 1 , Y = A E ˉ , U = A Z . (27) \bar{\mathbf{K}} = \mathbf{K} \oslash\Gamma^{\mathrm{pre}}, \qquad\bar{\mathbf{E}} = \Gamma^{\mathrm{pre}} \odot\mathbf{E}, \qquad\mathbf{A} = \left[\mathbf{I}_{C} + \operatorname{tril}(\bar{\mathbf{E}}\bar{\mathbf{K}}^{\mathsf{T}},-1)\right]^{-1}, \qquad\mathbf{Y} = \mathbf{A}\bar{\mathbf{E}}, \qquad\mathbf{U} = \mathbf{A}\mathbf{Z}. \tag*{(27)} K ˉ = K ⊘ Γ pre , E ˉ = Γ pre ⊙ E , A = [ I C + tril ( E ˉ K ˉ T , − 1 ) ] − 1 , Y = A E ˉ , U = AZ . (27)
Lemma 2 (Unified chunk closed form). Let S i = S i − 1 D i ( I − e i k i T ) + z i k i T \mathbf{S}_{i} = \mathbf{S}_{i-1}\mathbf{D}_{i}(\mathbf{I}-e_{i}k_{i}^{\mathsf{T}})+z_{i}k_{i}^{\mathsf{T}} S i = S i − 1 D i ( I − e i k i T ) + z i k i T with D i = Diag ( α i ) \mathbf{D}_{i} = \operatorname{Diag}(\alpha_{i}) D i = Diag ( α i ) and S 0 = S [ n ] + \mathbf{S}_{0} = \mathbf{S}_{[n]}^{+} S 0 = S [ n ] + . Then
S i = S 0 Diag ( γ i ) + ∑ j ≤ i δ j ( k j ⊙ γ i ⊘ γ j ) T , Δ = U − Y S 0 T , (28) \mathbf{S}_{i} = \mathbf{S}_{0}\operatorname{Diag}(\gamma_{i}) + \sum_{j \leq i}\delta_{j}(k_{j}\odot\gamma_{i}\oslash\gamma_{j})^{\mathsf{T}}, \qquad\Delta= \mathbf{U}-\mathbf{Y}\mathbf{S}_{0}^{\mathsf{T}}, \tag*{(28)} S i = S 0 Diag ( γ i ) + j ≤ i ∑ δ j ( k j ⊙ γ i ⊘ γ j ) T , Δ = U − Y S 0 T , (28) where Δ ∈ R C × d v \Delta\in\mathbb{R}^{C\times d_{v}} Δ ∈ R C × d v stacks the rows δ j T \delta_{j}^{\mathsf{T}} δ j T . Consequently
S [ n + 1 ] − = S 0 Diag ( γ C ) + Δ T ( Γ t a i l ⊙ K ) , O [ n ] = Q γ S 0 T + tril ( Q γ K ˉ T ) Δ , (29) \mathbf{S}_{[n+1]}^{-} = \mathbf{S}_{0}\operatorname{Diag}(\gamma_{C})+\Delta^{\mathsf{T}}(\Gamma^{\mathrm{tail}}\odot\mathbf{K}), \qquad\mathbf{O}_{[n]} = \mathbf{Q}_{\gamma}\mathbf{S}_{0}^{\mathsf{T}}+\operatorname{tril}(\mathbf{Q}_{\gamma}\bar{\mathbf{K}}^{\mathsf{T}})\Delta, \tag*{(29)} S [ n + 1 ] − = S 0 Diag ( γ C ) + Δ T ( Γ tail ⊙ K ) , O [ n ] = Q γ S 0 T + tril ( Q γ K ˉ T ) Δ , (29) with Q γ = Γ p r e ⊙ Q \mathbf{Q}_{\gamma}=\Gamma^{\mathrm{pre}}\odot\mathbf{Q} Q γ = Γ pre ⊙ Q .
Proof. Induct on i i i . The claim holds at i = 0 i=0 i = 0 . Assume it at i − 1 i-1 i − 1 . Since Diag ( γ i − 1 ) D i = Diag ( γ i ) \operatorname{Diag}(\gamma_{i-1})\mathbf{D}_{i}=\operatorname{Diag}(\gamma_{i}) Diag ( γ i − 1 ) D i = Diag ( γ i ) and
( k j ⊙ γ i − 1 ⊘ γ j ) T D i = ( k j ⊙ γ i ⊘ γ j ) T , (k_{j}\odot\gamma_{i-1}\oslash\gamma_{j})^{\mathsf{T}}\mathbf{D}_{i}=(k_{j}\odot\gamma_{i}\oslash\gamma_{j})^{\mathsf{T}}, ( k j ⊙ γ i − 1 ⊘ γ j ) T D i = ( k j ⊙ γ i ⊘ γ j ) T ,
S i − 1 D i = S 0 Diag ( γ i ) + ∑ j < i δ j ( k j ⊙ γ i ⊘ γ j ) T . \mathbf{S}_{i-1}\mathbf{D}_{i}=\mathbf{S}_{0}\operatorname{Diag}(\gamma_{i})+\sum_{j<i}\delta_{j}(k_{j}\odot\gamma_{i}\oslash\gamma_{j})^{\mathsf{T}}. S i − 1 D i = S 0 Diag ( γ i ) + j < i ∑ δ j ( k j ⊙ γ i ⊘ γ j ) T .
Writing δ i = z i − S i − 1 D i e i \delta_{i}=z_{i}-\mathbf{S}_{i-1}\mathbf{D}_{i}e_{i} δ i = z i − S i − 1 D i e i gives S i = S i − 1 D i + δ i k i T \mathbf{S}_{i}=\mathbf{S}_{i-1}\mathbf{D}_{i}+\delta_{i}k_{i}^{\mathsf{T}} S i = S i − 1 D i + δ i k i T , which is Eq. (28) at i i i because γ i ⊘ γ i = 1 \gamma_{i}\oslash\gamma_{i}=1 γ i ⊘ γ i = 1 . Using Diag ( γ i ) e i = E ˉ : , i T \operatorname{Diag}(\gamma_{i})e_{i}=\bar{\mathbf{E}}_{:,i}^{\mathsf{T}} Diag ( γ i ) e i = E ˉ : , i T and ( k j ⊙ γ i ⊘ γ j ) T e i = K ˉ j , : E ˉ : , i T (k_{j}\odot\gamma_{i}\oslash\gamma_{j})^{\mathsf{T}}e_{i}=\bar{\mathbf{K}}_{j,:}\bar{\mathbf{E}}_{:,i}^{\mathsf{T}} ( k j ⊙ γ i ⊘ γ j ) T e i = K ˉ j , : E ˉ : , i T ,
δ i + ∑ j < i ( E ˉ K ˉ T ) i j δ j = z i − S 0 E ˉ : , i T , \delta_{i}+\sum_{j<i}(\bar{\mathbf{E}}\bar{\mathbf{K}}^{\mathsf{T}})_{ij}\delta_{j}=z_{i}-\mathbf{S}_{0}\bar{\mathbf{E}}_{:,i}^{\mathsf{T}}, δ i + j < i ∑ ( E ˉ K ˉ T ) ij δ j = z i − S 0 E ˉ : , i T ,
that is [ I C + tril ( E ˉ K ˉ T , − 1 ) ] Δ = Z − E ˉ S 0 T [\mathbf{I}_{C}+\operatorname{tril}(\bar{\mathbf{E}}\bar{\mathbf{K}}^{\mathsf{T}},-1)]\Delta=\mathbf{Z}-\bar{\mathbf{E}}\mathbf{S}_{0}^{\mathsf{T}} [ I C + tril ( E ˉ K ˉ T , − 1 )] Δ = Z − E ˉ S 0 T , which is the stated Δ \Delta Δ . Evaluating Eq. (28) at i = C i=C i = C gives the state in Eq. (29) , and contracting row i i i with q i q_{i} q i gives the output; the mask includes the diagonal because j ≤ i j\leq i j ≤ i .
Specializations. GDN-2 takes E = B ⊙ K \mathbf{E}=\mathbf{B}\odot\mathbf{K} E = B ⊙ K and Z = Z w r i t e \mathbf{Z}=\mathbf{Z}^{\mathrm{write}} Z = Z write , so Eq. (27) coincides with Eq. (47) and Eq. (29) reproduces Eqs. (49) –(50) . KDA takes e i = β i k i e_{i}=\beta_{i}k_{i} e i = β i k i and z i = β i v i z_{i}=\beta_{i}v_{i} z i = β i v i , so E ˉ = B β ( Γ p r e ⊙ K ) \bar{\mathbf{E}}=\mathbf{B}_{\beta}(\Gamma^{\mathrm{pre}}\odot\mathbf{K}) E ˉ = B β ( Γ pre ⊙ K ) and Z = B β V \mathbf{Z}=\mathbf{B}_{\beta}\mathbf{V} Z = B β V . Its transform in Eq. (41) equals A B β \mathbf{A}\mathbf{B}_{\beta} A B β for the A \mathbf{A} A of Eq. (27) , so the lemma’s factors coincide with Eq. (42) : Y = A B β ( Γ p r e ⊙ K ) = W \mathbf{Y}=\mathbf{A}\mathbf{B}_{\beta}(\Gamma^{\mathrm{pre}}\odot\mathbf{K})=\mathbf{W} Y = A B β ( Γ pre ⊙ K ) = W and U = A B β V \mathbf{U}=\mathbf{A}\mathbf{B}_{\beta}\mathbf{V} U = A B β V . GDN further sets α i = α i 1 d k \alpha_{i}=\alpha_{i1_{d_{k}}} α i = α i 1 d k with a scalar α i \alpha_{i} α i , so
E ˉ K ˉ T = Diag ( γ ) B β K K T Diag ( γ ) − 1 . \bar{\mathbf{E}}\bar{\mathbf{K}}^{\mathsf{T}}=\operatorname{Diag}(\gamma)\mathbf{B}_{\beta}\mathbf{K}\mathbf{K}^{\mathsf{T}}\operatorname{Diag}(\gamma)^{-1}. E ˉ K ˉ T = Diag ( γ ) B β K K T Diag ( γ ) − 1 .
Diagonal similarity preserves strict lower-triangular structure entrywise, so
A = Diag ( γ ) [ I C + tril ( B β K K T , − 1 ) ] − 1 Diag ( γ ) − 1 = [ I C + tril ( B β ( K K T ⊙ Γ ) , − 1 ) ] − 1 , (30) \mathbf{A}=\operatorname{Diag}(\gamma)\left[\mathbf{I}_{C}+\operatorname{tril}(\mathbf{B}_{\beta}\mathbf{K}\mathbf{K}^{\mathsf{T}},-1)\right]^{-1}\operatorname{Diag}(\gamma)^{-1}=\left[\mathbf{I}_{C}+\operatorname{tril}(\mathbf{B}_{\beta}(\mathbf{K}\mathbf{K}^{\mathsf{T}}\odot\Gamma),-1)\right]^{-1}, \tag*{(30)} A = Diag ( γ ) [ I C + tril ( B β K K T , − 1 ) ] − 1 Diag ( γ ) − 1 = [ I C + tril ( B β ( K K T ⊙ Γ ) , − 1 ) ] − 1 , (30)
whence Y = Diag ( γ ) W \mathbf{Y}=\operatorname{Diag}(\gamma)\mathbf{W} Y = Diag ( γ ) W with W \mathbf{W} W from Eq. (35) , and U = A B β V \mathbf{U}=\mathbf{A}\mathbf{B}_{\beta}\mathbf{V} U = A B β V coincides with Eq. (36) . Equations (37) –(38) then follow from Eq. (29) . Numerically, K ˉ = K ⊘ Γ p r e \bar{\mathbf{K}}=\mathbf{K}\oslash\Gamma^{\mathrm{pre}} K ˉ = K ⊘ Γ pre is never formed explicitly; the kernels evaluate the required ratios through differences of cumulative log-decays, as noted at the end of Appendix E.7.
For Eq. (53) , we claim
S i = γ i H [ n ] + ∑ j ≤ i w j ( i ) J j , w j ( i ) = { ( γ i / γ j ) η j , j < i , c i , j = i , (31) \mathbf{S}_{i}=\gamma_{i}\mathbf{H}_{[n]}+\sum_{j\leq i}w_{j}^{(i)}\mathbf{J}_{j}, \qquad w_{j}^{(i)}=\begin{cases}(\gamma_{i}/\gamma_{j})\eta_{j}, & j<i,\\ c_{i}, & j=i,\end{cases} \tag*{(31)} S i = γ i H [ n ] + j ≤ i ∑ w j ( i ) J j , w j ( i ) = { ( γ i / γ j ) η j , c i , j < i , j = i , (31)
with H [ n ] \mathbf{H}_{[n]} H [ n ] and η j \eta_{j} η j from Eq. (54) . At i = 1 i=1 i = 1 , S 1 = α 1 ( S 0 + p 1 J 0 ) + c 1 J 1 = γ 1 H [ n ] + c 1 J 1 \mathbf{S}_{1}=\alpha_{1}(\mathbf{S}_{0}+p_{1}\mathbf{J}_{0})+c_{1}\mathbf{J}_{1}=\gamma_{1}\mathbf{H}_{[n]}+c_{1}\mathbf{J}_{1} S 1 = α 1 ( S 0 + p 1 J 0 ) + c 1 J 1 = γ 1 H [ n ] + c 1 J 1 . Assume Eq. (31) at i − 1 i-1 i − 1 . Then α i γ i − 1 = γ i \alpha_{i}\gamma_{i-1}=\gamma_{i} α i γ i − 1 = γ i ; for j < i − 1 j<i-1 j < i − 1 , α i w j ( i − 1 ) = ( γ i / γ j ) η j \alpha_{i}w_{j}^{(i-1)}=(\gamma_{i}/\gamma_{j})\eta_{j} α i w j ( i − 1 ) = ( γ i / γ j ) η j ; for j = i − 1 j=i-1 j = i − 1 the decayed diagonal term α i c i − 1 \alpha_i c_{i-1} α i c i − 1 combines with the explicit α i p i J i − 1 \alpha_i p_i \mathbf{J}_{i-1} α i p i J i − 1 to give α i ( c i − 1 + p i ) = ( γ i / γ i − 1 ) η i − 1 \alpha_i(c_{i-1}+p_i)=(\gamma_i/\gamma_{i-1})\eta_{i-1} α i ( c i − 1 + p i ) = ( γ i / γ i − 1 ) η i − 1 ; and c i J i c_i\mathbf{J}_i c i J i supplies the new diagonal term. This is Eq. (31) at i i i and matches Γ t r a p \mathbf{\Gamma}^{\mathrm{trap}} Γ trap in Eq. (55) . Setting i = C i=C i = C gives w j ( C ) = ω j w_j^{(C)}=\omega_j w j ( C ) = ω j and ∑ j ω j ′ v j k j T = V T Diag ( ω ) K \sum_j\omega_j'v_jk_j^{\mathsf T}=\mathbf{V}^{\mathsf T}\operatorname{Diag}(\omega)\mathbf{K} ∑ j ω j ′ v j k j T = V T Diag ( ω ) K , which is Eq. (56) ; contracting Eq. (31) with q i q_i q i gives Eq. (57) . The weight η C = c C \eta_C=c_C η C = c C excludes the next token’s trapezoidal term, which is why that term is added only after the boundary gate, as in Eq. (59) .
Gated DeltaNet
Cumulative decay and WY factors. For GDN [67 ] , define γ i = ∏ j = 1 i α j \gamma_i=\prod_{j=1}^{i}\alpha_j γ i = ∏ j = 1 i α j , γ = ( γ 1 , … , γ C ) T \gamma=(\gamma_1,\ldots,\gamma_C)^{\mathsf T} γ = ( γ 1 , … , γ C ) T , and B β = Diag ( β 1 , … , β C ) \mathbf{B}_{\beta}=\operatorname{Diag}(\beta_1,\ldots,\beta_C) B β = Diag ( β 1 , … , β C ) . Its causal decay mask is
Γ i j = { γ i / γ j , i ≥ j , 0 , i < j . (32) \Gamma_{ij}=
\begin{cases}
\gamma_i/\gamma_j, & i\ge j,\\
0, & i<j.
\end{cases} \tag*{(32)} Γ ij = { γ i / γ j , 0 , i ≥ j , i < j . (32)
Using the original GDN convention, the rows w i T , u i T \mathbf{w}_i^{\mathsf T},\mathbf{u}_i^{\mathsf T} w i T , u i T of the WY factors satisfy
w i = β i ( k i − ∑ j < i ( k j T k i ) w j ) . (33) \mathbf{w}_i=\beta_i\left(\mathbf{k}_i-\sum_{j<i}(\mathbf{k}_j^{\mathsf T}\mathbf{k}_i)\mathbf{w}_j\right). \tag*{(33)} w i = β i ( k i − j < i ∑ ( k j T k i ) w j ) . (33)
u i = β i ( v i − ∑ j < i γ i γ j ( k j T k i ) u j ) . (34) \mathbf{u}_i=\beta_i\left(\mathbf{v}_i-\sum_{j<i}\frac{\gamma_i}{\gamma_j}(\mathbf{k}_j^{\mathsf T}\mathbf{k}_i)\mathbf{u}_j\right). \tag*{(34)} u i = β i ( v i − j < i ∑ γ j γ i ( k j T k i ) u j ) . (34)
The UT form writes these factors as matrix products with unit lower-triangular inverses:
W = [ I C + tril ( B β K K T , − 1 ) ] − 1 B β K , (35) \mathbf{W}=\left[\mathbf{I}_C+\operatorname{tril}(\mathbf{B}_{\beta}\mathbf{K}\mathbf{K}^{\mathsf T},-1)\right]^{-1}\mathbf{B}_{\beta}\mathbf{K}, \tag*{(35)} W = [ I C + tril ( B β K K T , − 1 ) ] − 1 B β K , (35)
U = [ I C + tril ( B β ( K K T ⊙ Γ ) , − 1 ) ] − 1 B β V . (36) \mathbf{U}=\left[\mathbf{I}_C+\operatorname{tril}\left(\mathbf{B}_{\beta}(\mathbf{K}\mathbf{K}^{\mathsf T}\odot\mathbf{\Gamma}),-1\right)\right]^{-1}\mathbf{B}_{\beta}\mathbf{V}. \tag*{(36)} U = [ I C + tril ( B β ( K K T ⊙ Γ ) , − 1 ) ] − 1 B β V . (36)
Here W ∈ R C × d k \mathbf{W}\in\mathbb{R}^{C\times d_k} W ∈ R C × d k is a WY factor, distinct from the learned W S \mathbf{W}_S W S . Scalar cumulative decay remains outside W \mathbf{W} W in the following equations.
Chunkwise computation with SDG. The state and output have the GDN chunkwise form, followed by our boundary update:
S [ n + 1 ] − = γ C S [ n ] + + ( U − Diag ( γ ) W ( S [ n ] + ) T ) T Diag ( γ C / γ ) K , (37) \mathbf{S}^{-}_{[n+1]}=\gamma_C\mathbf{S}^{+}_{[n]}+\left(\mathbf{U}-\operatorname{Diag}(\gamma)\mathbf{W}(\mathbf{S}^{+}_{[n]})^{\mathsf T}\right)^{\mathsf T}\operatorname{Diag}(\gamma_C/\gamma)\mathbf{K}, \tag*{(37)} S [ n + 1 ] − = γ C S [ n ] + + ( U − Diag ( γ ) W ( S [ n ] + ) T ) T Diag ( γ C / γ ) K , (37)
O [ n ] = Diag ( γ ) Q ( S [ n ] + ) T + ( Q K T ⊙ Γ ) ( U − Diag ( γ ) W ( S [ n ] + ) T ) , (38) \mathbf{O}_{[n]}=\operatorname{Diag}(\gamma)\mathbf{Q}(\mathbf{S}^{+}_{[n]})^{\mathsf T}+(\mathbf{Q}\mathbf{K}^{\mathsf T}\odot\mathbf{\Gamma})\left(\mathbf{U}-\operatorname{Diag}(\gamma)\mathbf{W}(\mathbf{S}^{+}_{[n]})^{\mathsf T}\right), \tag*{(38)} O [ n ] = Diag ( γ ) Q ( S [ n ] + ) T + ( Q K T ⊙ Γ ) ( U − Diag ( γ ) W ( S [ n ] + ) T ) , (38)
S [ n + 1 ] + = Λ [ n ] ⊙ S [ n + 1 ] − . (39) \mathbf{S}^{+}_{[n+1]}=\mathbf{\Lambda}_{[n]}\odot\mathbf{S}^{-}_{[n+1]}. \tag*{(39)} S [ n + 1 ] + = Λ [ n ] ⊙ S [ n + 1 ] − . (39)
The pseudo-value term U − Diag ( γ ) W ( S [ n ] + ) T \mathbf{U}-\operatorname{Diag}(\gamma)\mathbf{W}(\mathbf{S}^{+}_{[n]})^{\mathsf T} U − Diag ( γ ) W ( S [ n ] + ) T is shared by the state and output computations. SDG leaves this term and the WY preparation unchanged, and replaces the raw state carried to the next chunk with the final line above.
Kimi Delta Attention
Channel-wise decay and the UT transform. For KDA [56 ] , let γ i = ⨀ j = 1 i α j \gamma_i=\bigodot_{j=1}^{i}\alpha_j γ i = ⨀ j = 1 i α j and recall Eq. (26) ,
Γ i , : p r e = γ i T , Γ i , : t a i l = ( γ C ⊘ γ i ) T . (40) \mathbf{\Gamma}^{\mathrm{pre}}_{i,:}=\gamma_i^{\mathsf T},\qquad\mathbf{\Gamma}^{\mathrm{tail}}_{i,:}=(\gamma_C\oslash\gamma_i)^{\mathsf T}. \tag*{(40)} Γ i , : pre = γ i T , Γ i , : tail = ( γ C ⊘ γ i ) T . (40)
These are the cumulative decay from the chunk start and the remaining decay to its end, respectively. With B β = Diag ( β 1 , … , β C ) B_{\beta} = \operatorname{Diag}(\beta_1,\ldots,\beta_C) B β = Diag ( β 1 , … , β C ) , KDA’s UT transform and WY factors are
A = [ I C + tril ( B β ( Γ p r e ⊙ K ) ( K ⊘ Γ p r e ) T , − 1 ) ] − 1 B β , (41) A = \left[I_C + \operatorname{tril}\left(B_{\beta}(\Gamma^{\mathrm{pre}} \mathbin{\odot} K)(K \mathbin{\oslash} \Gamma^{\mathrm{pre}})^{\mathsf{T}},-1\right)\right]^{-1}B_{\beta}, \tag*{(41)} A = [ I C + tril ( B β ( Γ pre ⊙ K ) ( K ⊘ Γ pre ) T , − 1 ) ] − 1 B β , (41)
W = A ( Γ p r e ⊙ K ) , U = A V . (42) W = A(\Gamma^{\mathrm{pre}} \mathbin{\odot} K), \qquad U = AV. \tag*{(42)} W = A ( Γ pre ⊙ K ) , U = A V . (42)
Here A A A denotes the UT transform, reserving M C M_C M C for the causal mask. In this convention, cumulative channel-wise decay is already included in W W W .
Chunkwise computation with SDG. The resulting state, output, and boundary update are
S [ n + 1 ] − = S [ n ] + Diag ( γ C ) + ( U − W ( S [ n ] + ) T ) T ( Γ t a i l ⊙ K ) , (43) S^{-}_{[n+1]} = S^{+}_{[n]}\operatorname{Diag}(\gamma_C) + \left(U - W(S^{+}_{[n]})^{\mathsf{T}}\right)^{\mathsf{T}}(\Gamma^{\mathrm{tail}} \mathbin{\odot} K), \tag*{(43)} S [ n + 1 ] − = S [ n ] + Diag ( γ C ) + ( U − W ( S [ n ] + ) T ) T ( Γ tail ⊙ K ) , (43)
O [ n ] = ( Γ p r e ⊙ Q ) ( S [ n ] + ) T + tril ( ( Γ p r e ⊙ Q ) ( K ⊘ Γ p r e ) T ) ( U − W ( S [ n ] + ) T ) , (44) \begin{aligned}
O_{[n]} &= (\Gamma^{\mathrm{pre}} \mathbin{\odot} Q)(S^{+}_{[n]})^{\mathsf{T}} \\
&\quad+ \operatorname{tril}\left((\Gamma^{\mathrm{pre}} \mathbin{\odot} Q)(K \mathbin{\oslash} \Gamma^{\mathrm{pre}})^{\mathsf{T}}\right)\left(U-W(S^{+}_{[n]})^{\mathsf{T}}\right), \tag*{(44)}
\end{aligned} O [ n ] = ( Γ pre ⊙ Q ) ( S [ n ] + ) T + tril ( ( Γ pre ⊙ Q ) ( K ⊘ Γ pre ) T ) ( U − W ( S [ n ] + ) T ) , (44)
S [ n + 1 ] + = Λ [ n ] ⊙ S [ n + 1 ] − ⏟ SDG boundary update . (45) S^{+}_{[n+1]} = \underbrace{\Lambda_{[n]} \mathbin{\odot} S^{-}_{[n+1]}}_{\text{SDG boundary update}}. \tag*{(45)} S [ n + 1 ] + = SDG boundary update Λ [ n ] ⊙ S [ n + 1 ] − . (45)
The two output terms are the inter-chunk read and intra-chunk masked matrix product. The shared pseudo-values remain U − W ( S [ n ] + ) T U-W(S^{+}_{[n]})^{\mathsf{T}} U − W ( S [ n ] + ) T . KDA’s diagonal token decay is retained; SDG adds element-wise decay only after the raw chunk state has been formed.
Gated DeltaNet-2
Asymmetric erase and write factors. GDN-2 [25 ] uses the same Γ p r e \Gamma^{\mathrm{pre}} Γ pre and Γ t a i l \Gamma^{\mathrm{tail}} Γ tail as KDA. Let B ∈ R C × d k B \in\mathbb{R}^{C \times d_k} B ∈ R C × d k and W w r i t e ∈ R C × d v W^{\mathrm{write}} \in\mathbb{R}^{C \times d_v} W write ∈ R C × d v stack its erase gates b i b_i b i and write gates w i w_i w i . Following its asymmetric WY form, define
K ‾ = K ⊘ Γ p r e , E ‾ = Γ p r e ⊙ ( B ⊙ K ) , Z w r i t e = W w r i t e ⊙ V . (46) \overline{K} = K \mathbin{\oslash} \Gamma^{\mathrm{pre}}, \qquad\overline{E} = \Gamma^{\mathrm{pre}} \mathbin{\odot} (B \mathbin{\odot} K), \qquad Z^{\mathrm{write}} = W^{\mathrm{write}} \mathbin{\odot} V. \tag*{(46)} K = K ⊘ Γ pre , E = Γ pre ⊙ ( B ⊙ K ) , Z write = W write ⊙ V . (46)
The superscript write distinguishes these token-write quantities from the SDG score and WY factors. GDN-2’s triangular inverse and erase/write auxiliaries are
T = tril ( E ‾ K ‾ T , − 1 ) , A = ( I C + T ) − 1 , Y = A E ‾ , U = A Z w r i t e . (47) T = \operatorname{tril}(\overline{E}\overline{K}^{\mathsf{T}},-1), \qquad A = (I_C + T)^{-1}, \qquad Y = A\overline{E}, \qquad U = AZ^{\mathrm{write}}. \tag*{(47)} T = tril ( E K T , − 1 ) , A = ( I C + T ) − 1 , Y = A E , U = A Z write . (47)
The notation Y Y Y follows the erase-side auxiliary in GDN-2. Define its output and tail factors as
Q γ = Γ p r e ⊙ Q , K t a i l = Γ t a i l ⊙ K , A q k = tril ( Q γ K ‾ T ) . (48) Q_{\gamma} = \Gamma^{\mathrm{pre}} \mathbin{\odot} Q, \qquad K_{\mathrm{tail}} = \Gamma^{\mathrm{tail}} \mathbin{\odot} K, \qquad A_{qk} = \operatorname{tril}(Q_{\gamma}\overline{K}^{\mathsf{T}}). \tag*{(48)} Q γ = Γ pre ⊙ Q , K tail = Γ tail ⊙ K , A q k = tril ( Q γ K T ) . (48)
Chunkwise computation with SDG. In the state orientation used here, the GDN-2 equations and our insertion are
S [ n + 1 ] − = S [ n ] + Diag ( γ C ) + ( U − Y ( S [ n ] + ) T ) T K t a i l , (49) S^{-}_{[n+1]} = S^{+}_{[n]}\operatorname{Diag}(\gamma_C) + \left(U-Y(S^{+}_{[n]})^{\mathsf{T}}\right)^{\mathsf{T}}K_{\mathrm{tail}}, \tag*{(49)} S [ n + 1 ] − = S [ n ] + Diag ( γ C ) + ( U − Y ( S [ n ] + ) T ) T K tail , (49)
O [ n ] = Q γ ( S [ n ] + ) T + A q k ( U − Y ( S [ n ] + ) T ) , (50) O_{[n]} = Q_{\gamma}(S^{+}_{[n]})^{\mathsf{T}} + A_{qk}\left(U-Y(S^{+}_{[n]})^{\mathsf{T}}\right), \tag*{(50)} O [ n ] = Q γ ( S [ n ] + ) T + A q k ( U − Y ( S [ n ] + ) T ) , (50)
S [ n + 1 ] + = Λ [ n ] ⊙ S [ n + 1 ] − ⏟ SDG boundary update . (51) S^{+}_{[n+1]} = \underbrace{\Lambda_{[n]} \mathbin{\odot} S^{-}_{[n+1]}}_{\text{SDG boundary update}}. \tag*{(51)} S [ n + 1 ] + = SDG boundary update Λ [ n ] ⊙ S [ n + 1 ] − . (51)
The erase and write gates enter through E ‾ \overline{E} E and Z w r i t e Z^{\mathrm{write}} Z write , respectively. SDG changes only the matrix carried between chunks; A q k A_{qk} A q k , K t a i l K_{\mathrm{tail}} K tail , and the native WY preparation are retained. Tying b i b_i b i and w i w_i w i to β i \beta_i β i recovers KDA, with Y = W Y=W Y = W . Under scalar decay, this equals Diag ( γ ) W \operatorname{Diag}(\gamma)W Diag ( γ ) W in the GDN convention above.
All triangular inverses above denote solves with unit lower-triangular matrices. Decay ratios are evaluated through cumulative log-decays and their differences in the kernels. The mathematical notation does not require explicitly storing inverse cumulative decays.
Mamba-3 SISO
Trapezoidal write factors. For Mamba-3 [33 ] , Q , K ∈ R C × d s \mathbf{Q},\mathbf{K} \in\mathbb{R}^{C \times d_s} Q , K ∈ R C × d s contain the native normalized, biased, and rotated queries and keys. Let δ i > 0 \delta_i > 0 δ i > 0 be the step size, τ i ∈ [ 0 , 1 ] \tau_i \in[0,1] τ i ∈ [ 0 , 1 ] the trapezoidal mixing coefficient, and α i \alpha_i α i the scalar decay. Define
p i = ( 1 − τ i ) δ i , c i = τ i δ i , J i = v i k i T . (52) p_i = (1-\tau_i)\delta_i,\qquad c_i = \tau_i\delta_i,\qquad\mathbf{J}_i = \mathbf{v}_i\mathbf{k}_i^{\mathsf{T}}. \tag*{(52)} p i = ( 1 − τ i ) δ i , c i = τ i δ i , J i = v i k i T . (52)
Its native physical-state recurrence, with S 0 = S [ n ] + \mathbf{S}_0 = \mathbf{S}^{+}_{[n]} S 0 = S [ n ] + , is
S i = α i S i − 1 + α i p i J i − 1 + c i J i , o i = S i q i . (53) \mathbf{S}_i = \alpha_i\mathbf{S}_{i-1} + \alpha_i p_i\mathbf{J}_{i-1} + c_i\mathbf{J}_i,\qquad\mathbf{o}_i = \mathbf{S}_i\mathbf{q}_i. \tag*{(53)} S i = α i S i − 1 + α i p i J i − 1 + c i J i , o i = S i q i . (53)
To give the same inter-chunk plus intra-chunk matrix presentation, set γ i = ∏ j = 1 i α j \gamma_i = \prod_{j=1}^{i}\alpha_j γ i = ∏ j = 1 i α j , γ = ( γ 1 , … , γ C ) T \boldsymbol{\gamma} = (\gamma_1,\ldots,\gamma_C)^{\mathsf{T}} γ = ( γ 1 , … , γ C ) T , and
H [ n ] = S [ n ] + + p 1 J 0 , η j = { c j + p j + 1 , j < C , c C , j = C . (54) \mathbf{H}_{[n]} = \mathbf{S}^{+}_{[n]} + p_1\mathbf{J}_0,\qquad
\eta_j =
\begin{cases}
c_j+p_{j+1}, & j<C,\\
c_C, & j=C.
\end{cases} \tag*{(54)} H [ n ] = S [ n ] + + p 1 J 0 , η j = { c j + p j + 1 , c C , j < C , j = C . (54)
Here J 0 \mathbf{J}_0 J 0 uses the preceding token’s cached key and value, or is zero at a fresh sequence start; the carry H [ n ] \mathbf{H}_{[n]} H [ n ] is unrelated to the head count H H H . The trapezoidal mask and tail weights are
Γ i j t r a p = { ( γ i / γ j ) η j , i > j , c i , i = j , 0 , i < j , ω j = ( γ C / γ j ) η j . (55) \Gamma^{\mathrm{trap}}_{ij} =
\begin{cases}
(\gamma_i/\gamma_j)\eta_j, & i>j,\\
c_i, & i=j,\\
0, & i<j,
\end{cases}
\qquad
\omega_j = (\gamma_C/\gamma_j)\eta_j. \tag*{(55)} Γ ij trap = ⎩ ⎨ ⎧ ( γ i / γ j ) η j , c i , 0 , i > j , i = j , i < j , ω j = ( γ C / γ j ) η j . (55)
Chunkwise computation with SDG. The SISO chunk computation can then be written as
S [ n + 1 ] − = γ C H [ n ] + V T Diag ( ω ) K , (56) \mathbf{S}^{-}_{[n+1]} = \gamma_C\mathbf{H}_{[n]} + \mathbf{V}^{\mathsf{T}}\operatorname{Diag}(\boldsymbol{\omega})\mathbf{K}, \tag*{(56)} S [ n + 1 ] − = γ C H [ n ] + V T Diag ( ω ) K , (56)
O [ n ] = Diag ( γ ) Q H [ n ] T + ( Q K T ⊙ Γ t r a p ) V , (57) \mathbf{O}_{[n]} = \operatorname{Diag}(\boldsymbol{\gamma})\mathbf{Q}\mathbf{H}_{[n]}^{\mathsf{T}} + (\mathbf{Q}\mathbf{K}^{\mathsf{T}} \mathbin{\odot} \boldsymbol{\Gamma}^{\mathrm{trap}})\mathbf{V}, \tag*{(57)} O [ n ] = Diag ( γ ) Q H [ n ] T + ( Q K T ⊙ Γ trap ) V , (57)
S [ n + 1 ] + = Λ [ n ] ⊙ S [ n + 1 ] − ⏟ SDG boundary update . (58) \mathbf{S}^{+}_{[n+1]} = \boldsymbol{\Lambda}_{[n]} \mathbin{\odot} \underbrace{\mathbf{S}^{-}_{[n+1]}}_{\text{SDG boundary update}}. \tag*{(58)} S [ n + 1 ] + = Λ [ n ] ⊙ SDG boundary update S [ n + 1 ] − . (58)
This has the same separation into an incoming-state read and a causal within-chunk matrix product. Mamba-3 has no delta-rule erase term, so its value factor is V \mathbf{V} V rather than a WY pseudo-value. Its native skip connection and output gate are applied without modification.
Boundary placement and the next chunk. Equation (25) uses the physical states S [ n ] + \mathbf{S}^{+}_{[n]} S [ n ] + and S [ n + 1 ] − \mathbf{S}^{-}_{[n+1]} S [ n + 1 ] − , not the corrected carry H [ n ] \mathbf{H}_{[n]} H [ n ] . The last write weight η C = c C \eta_C = c_C η C = c C excludes the next token’s trapezoidal contribution. Only after SDG has updated the physical state is that contribution added to the next carry:
H [ n + 1 ] = S [ n + 1 ] + + p [ n + 1 ] , 1 J [ n ] , C . (59) \mathbf{H}_{[n+1]} = \mathbf{S}^{+}_{[n+1]} + p_{[n+1],1}\mathbf{J}_{[n],C}. \tag*{(59)} H [ n + 1 ] = S [ n + 1 ] + + p [ n + 1 ] , 1 J [ n ] , C . (59)
The saved SDG source is S [ n + 1 ] + \mathbf{S}^{+}_{[n+1]} S [ n + 1 ] + , before this correction. Thus the gate does not scale the next token’s previous-key/value contribution. The rotary phase and previous-key/value caches continue with their native updates.
Reference boundary scan
The following procedure describes how the state is updated during training, prefill, and decoding. Its cache contains the current state S \mathbf{S} S , the state S s r c \mathbf{S}^{\mathrm{src}} S src at the preceding completed boundary, native auxiliary state ξ \boldsymbol{\xi} ξ , and a valid-token counter r ∈ { 0 , … , C − 1 } r \in\{0,\ldots,C-1\} r ∈ { 0 , … , C − 1 } . The procedure below makes the order of reads, writes, and
Model implementations
boundary decay explicit. Let X \mathcal{X} X denote the projected token inputs and native token gates. For a segment of the sequence, the input and output states satisfy
( O s e g , S o u t , ξ ′ ) = F ( X s e g , S i n , ξ ) . (\mathbf{O}^{\mathrm{seg}}, \mathbf{S}^{\mathrm{out}}, \boldsymbol{\xi}') = \mathcal{F}(\mathcal{X}^{\mathrm{seg}}, \mathbf{S}^{\mathrm{in}}, \boldsymbol{\xi}). ( O seg , S out , ξ ′ ) = F ( X seg , S in , ξ ) .
At an aligned chunk start, S i n = S s r c = S [ n ] + \mathbf{S}^{\mathrm{in}} = \mathbf{S}^{\mathrm{src}} = \mathbf{S}_{[n]}^{+} S in = S src = S [ n ] + . During continuation of an incomplete chunk, S i n \mathbf{S}^{\mathrm{in}} S in is instead the current cached state and generally differs from the retained S s r c \mathbf{S}^{\mathrm{src}} S src used by the eventual gate function.
Input. Native token-local quantities X \mathcal{X} X for L L L valid tokens, chunk size C C C , and cache ( S , S s r c , ξ , r ) (\mathbf{S}, \mathbf{S}^{\mathrm{src}}, \boldsymbol{\xi}, r) ( S , S src , ξ , r ) . Set p ← 1 p \leftarrow1 p ← 1 and O ← [ ] \mathbf{O} \leftarrow[\ ] O ← [ ] .
While p ≤ L p \le L p ≤ L , set m ← min { C − r , L − p + 1 } m \leftarrow\min\{C-r, L-p+1\} m ← min { C − r , L − p + 1 } and run the original recurrence on the next contiguous segment.
( O s e g , S o u t , ξ ′ ) ← F ( X p : p + m − 1 , S , ξ ) . (\mathbf{O}^{\mathrm{seg}}, \mathbf{S}^{\mathrm{out}}, \boldsymbol{\xi}') \leftarrow\mathcal{F}(\mathcal{X}_{p:p+m-1}, \mathbf{S}, \boldsymbol{\xi}). ( O seg , S out , ξ ′ ) ← F ( X p : p + m − 1 , S , ξ ) .
Append O s e g \mathbf{O}^{\mathrm{seg}} O seg to O \mathbf{O} O and set S ← S o u t \mathbf{S} \leftarrow\mathbf{S}^{\mathrm{out}} S ← S out , ξ ← ξ ′ \boldsymbol{\xi} \leftarrow\boldsymbol{\xi}' ξ ← ξ ′ , r ← r + m r \leftarrow r+m r ← r + m , and p ← p + m p \leftarrow p+m p ← p + m .
If r = C r=C r = C , compute Λ ← G θ ( S s r c , S o u t ) \boldsymbol{\Lambda} \leftarrow\mathcal{G}_{\theta}(\mathbf{S}^{\mathrm{src}}, \mathbf{S}^{\mathrm{out}}) Λ ← G θ ( S src , S out ) and then set S ← Λ ⊙ S o u t \mathbf{S} \leftarrow\boldsymbol{\Lambda} \odot\mathbf{S}^{\mathrm{out}} S ← Λ ⊙ S out , S s r c ← S \mathbf{S}^{\mathrm{src}} \leftarrow\mathbf{S} S src ← S , and r ← 0 r \leftarrow0 r ← 0 . The segment outputs and native auxiliary update have already been formed. The boundary changes neither.
Repeat Steps 2–4 and return O , ( S , S s r c , ξ , r ) \mathbf{O},(\mathbf{S}, \mathbf{S}^{\mathrm{src}}, \boldsymbol{\xi}, r) O , ( S , S src , ξ , r ) .
Proposition 1 (Segmentation invariance). Assume the base recurrence is segmentation consistent, that is, for every split of a token stream, F \mathcal{F} F applied to the concatenation equals the sequential composition of F \mathcal{F} F on the two parts with the intermediate state and auxiliary state passed through. Then for any partition of a stream into consecutive calls, the procedure above returns the same outputs and the same final cache as a single call on the whole stream, and both agree with the chunkwise definition of Eq. (3) with boundaries at absolute positions that are multiples of C C C .
Proof. Induct on the number of calls, starting from r = 0 r=0 r = 0 at a fresh sequence. Step 2 chooses m = min { C − r , L − p + 1 } m=\min\{C-r,L-p+1\} m = min { C − r , L − p + 1 } , so no segment crosses a boundary and the hypothesis applies to each segment. The counter r r r therefore records the absolute position modulo C C C , and the set of positions at which Step 4 fires is determined by absolute positions alone, independently of the partition. Between two consecutive firings, S \mathbf{S} S and ξ \boldsymbol{\xi} ξ evolve only through F \mathcal{F} F , whose composition is split invariant by assumption, and S s r c \mathbf{S}^{\mathrm{src}} S src is written only in Step 4. Hence at the boundary after chunk n n n the two arguments of G θ \mathcal{G}_{\theta} G θ are exactly S [ n ] + \mathbf{S}_{[n]}^{+} S [ n ] + and S [ n + 1 ] − \mathbf{S}_{[n+1]}^{-} S [ n + 1 ] − , as in Eq. (3) , and the outputs of each segment are formed before the gate is applied. For Mamba-3 the auxiliary state carries the previous key and value, and the gate acts on the physical state, so Eq. (59) composes in the same way. □ \square □
The identity holds in exact arithmetic; in finite precision the two execution paths group the same products differently, so our correctness tests compare them with a tolerance rather than bitwise. Consequently training with the chunkwise form, prefill in one call, and decoding one token per call define the same function of the token stream.
The remaining conventions are implementation choices. For a fresh sequence S = S s r c \mathbf{S}=\mathbf{S}^{\mathrm{src}} S = S src is the supplied initial state or zero and ξ \boldsymbol{\xi} ξ uses the base model’s initialization; each nonempty packed example owns an independent cache tuple, and empty packed examples are rejected. Masked padding neither invokes the recurrence nor advances r r r in fresh, prefill, and packed execution, whereas the GDN-2, KDA, and Mamba-3 cached one-token paths assume that every cache row supplies one valid token. In the boundary-offset diagnostic, the inserted filler tokens are valid inputs that enter the recurrence and advance r r r , thereby shifting answer generation relative to chunk boundaries. A cache is retained only while continuing the same sequence and is reset when it ends. Step 4 also shows why S s r c \mathbf{S}^{\mathrm{src}} S src must not be overwritten while an incomplete tail accumulates.
Model implementations
GDN, GDN-2, and KDA. All three adapters return current-chunk outputs before applying SDG. Their native token gates, delta residuals, WY constructions, and output gates remain unchanged. The optimized implementations replace or extend only the persistent inter-chunk state scan and its vector–Jacobian product.
Mamba-3. For the bundled SISO recurrence, the native recurrent tuple is
( s a n g l e , S s s m , k p r e v , v p r e v ) . (60) \left(s^{\mathrm{angle}}, S^{\mathrm{ssm}}, k^{\mathrm{prev}}, v^{\mathrm{prev}}\right). \tag*{(60)} ( s angle , S ssm , k prev , v prev ) . (60)
SDG additionally stores the state S s r c , s s m S^{\mathrm{src,ssm}} S src , ssm and tail counter r r r . Only S s s m S^{\mathrm{ssm}} S ssm is passed to G θ G_\theta G θ and multiplied by its decay gate. All other tuple components come directly from the native transition.
Supported configurations. The GDN adapter supports key and value head dimensions up to 128. The GDN-2 and KDA adapters currently require equal numbers of value and query/key heads. Their fused paths support d k , d v ≤ 128 d_k,d_v \le128 d k , d v ≤ 128 , with wider states using a fallback path. The current projected state-change configurations use boundary recomputation. The Mamba-3 adapter targets the bundled SISO implementation and exposes only successive one-token cached decoding calls. These are implementation limits, not requirements of the method.
Complete proofs
Adaptive element-wise ridge
Remark 1 is stated in § 5.1 . The following argument establishes the identity and its converse, followed by the backbone-specific token-update interpretations [19 , 20 , 41 ] .
Proof of Remark 1. Write S = S [ n + 1 ] \mathbf{S}=\mathbf{S}_{[n+1]} S = S [ n + 1 ] , ρ = ρ [ n ] \rho=\rho_{[n]} ρ = ρ [ n ] , and κ = e ρ − 1 \kappa=e^\rho-1 κ = e ρ − 1 . The objective
J ( M ) = 1 2 ∥ M − S ∥ F 2 + 1 2 ∑ a , b κ a b M a b 2 J(\mathbf{M})=\frac{1}{2}\|\mathbf{M}-\mathbf{S}\|_{F}^{2}+\frac{1}{2}\sum_{a,b}\kappa_{ab}M_{ab}^{2} J ( M ) = 2 1 ∥ M − S ∥ F 2 + 2 1 a , b ∑ κ ab M ab 2
is separable across entries and strictly convex because 1 + κ a b = e ρ a b > 0 1+\kappa_{ab}=e^{\rho_{ab}}>0 1 + κ ab = e ρ ab > 0 . From ∂ J / ∂ M a b = e ρ a b M a b − S a b \partial J/\partial M_{ab}=e^{\rho_{ab}}M_{ab}-S_{ab} ∂ J / ∂ M ab = e ρ ab M ab − S ab , the unique minimizer is M a b = e − ρ a b S a b = Λ a b S a b M_{ab}=e^{-\rho_{ab}}S_{ab}=\Lambda_{ab}S_{ab} M ab = e − ρ ab S ab = Λ ab S ab , which is Eq. (7) . For the converse, we show that the quadratic is the only separable differentiable penalty with this proximal operator, up to an additive constant. Let g ( M ) = ∑ a , b g a b ( M a b ) g(\mathbf{M})=\sum_{a,b}g_{ab}(M_{ab}) g ( M ) = ∑ a , b g ab ( M ab ) be separable and differentiable with prox g ( S ) = Λ ⊙ S \operatorname{prox}_{g}(\mathbf{S})=\Lambda\odot\mathbf{S} prox g ( S ) = Λ ⊙ S for every S \mathbf{S} S . Stationarity at M a b = Λ a b S a b M_{ab}=\Lambda_{ab}S_{ab} M ab = Λ ab S ab reads Λ a b S a b − S a b + g a b ′ ( Λ a b S a b ) = 0 \Lambda_{ab}S_{ab}-S_{ab}+g'_{ab}(\Lambda_{ab}S_{ab})=0 Λ ab S ab − S ab + g ab ′ ( Λ ab S ab ) = 0 for all S a b S_{ab} S ab , hence g a b ′ ( u ) = ( Λ a b − 1 − 1 ) u g'_{ab}(u)=(\Lambda_{ab}^{-1}-1)u g ab ′ ( u ) = ( Λ ab − 1 − 1 ) u and g a b ( u ) = 1 2 κ a b u 2 + c o n s t g_{ab}(u)=\frac{1}{2}\kappa_{ab}u^{2}+\mathrm{const} g ab ( u ) = 2 1 κ ab u 2 + const with κ a b = Λ a b − 1 − 1 = e ρ a b − 1 \kappa_{ab}=\Lambda_{ab}^{-1}-1=e^{\rho_{ab}}-1 κ ab = Λ ab − 1 − 1 = e ρ ab − 1 . Boundary decay is thus the prox of a uniquely determined ridge penalty, and κ = ρ + O ( ρ 2 ) \kappa=\rho+O(\rho^{2}) κ = ρ + O ( ρ 2 ) as ρ → 0 \rho\to0 ρ → 0 . □
When the token update is a gradient step. Let S ~ = S t − 1 D t \widetilde{\mathbf{S}}=\mathbf{S}_{t-1}\mathbf{D}_{t} S = S t − 1 D t be the state after token decay, so that Eqs. (19) –(22) all take the form
S t = S ~ − ( S ~ e t − z t ) k t T . (61) \mathbf{S}_{t}=\widetilde{\mathbf{S}}-\left(\widetilde{\mathbf{S}}\mathbf{e}_{t}-\mathbf{z}_{t}\right)\mathbf{k}_{t}^{\mathsf{T}}. \tag*{(61)} S t = S − ( S e t − z t ) k t T . (61)
Lemma 3. Fix k t ≠ 0 \mathbf{k}_{t}\ne0 k t = 0 , e t \mathbf{e}_{t} e t , and z t \mathbf{z}_{t} z t . The field F ( S ~ ) = ( S ~ e t − z t ) k t T \mathbf{F}(\widetilde{\mathbf{S}})=\left(\widetilde{\mathbf{S}}\mathbf{e}_{t}-\mathbf{z}_{t}\right)\mathbf{k}_{t}^{\mathsf{T}} F ( S ) = ( S e t − z t ) k t T is the gradient of a scalar function of S ~ \widetilde{\mathbf{S}} S with respect to the Frobenius inner product if and only if e t = c k t \mathbf{e}_{t}=c\mathbf{k}_{t} e t = c k t for some c ∈ R c\in\mathbb{R} c ∈ R .
Proof. F \mathbf{F} F is affine with constant Jacobian A ( H ) = ( H e t ) k t T \mathcal{A}(\mathbf{H})=(\mathbf{H}\mathbf{e}_{t})\mathbf{k}_{t}^{\mathsf{T}} A ( H ) = ( H e t ) k t T , and
⟨ A ( H ) , G ⟩ F = e t T H T G k t = ⟨ H , ( G k t ) e t T ⟩ F , \langle\mathcal{A}(\mathbf{H}),\mathbf{G}\rangle_{F}=\mathbf{e}_{t}^{\mathsf{T}}\mathbf{H}^{\mathsf{T}}\mathbf{G}\mathbf{k}_{t}=\langle\mathbf{H},(\mathbf{G}\mathbf{k}_{t})\mathbf{e}_{t}^{\mathsf{T}}\rangle_{F}, ⟨ A ( H ) , G ⟩ F = e t T H T G k t = ⟨ H , ( G k t ) e t T ⟩ F ,
so A ∗ ( G ) = ( G k t ) e t T \mathcal{A}^{*}(\mathbf{G})=(\mathbf{G}\mathbf{k}_{t})\mathbf{e}_{t}^{\mathsf{T}} A ∗ ( G ) = ( G k t ) e t T . On a convex domain a C 1 C^{1} C 1 field is a gradient field if and only if its Jacobian is self-adjoint, here if and only if H ( e t k t T − k t e t T ) = 0 \mathbf{H}(\mathbf{e}_{t}\mathbf{k}_{t}^{\mathsf{T}}-\mathbf{k}_{t}\mathbf{e}_{t}^{\mathsf{T}})=0 H ( e t k t T − k t e t T ) = 0 for all H \mathbf{H} H , that is e t k t T = k t e t T \mathbf{e}_{t}\mathbf{k}_{t}^{\mathsf{T}}=\mathbf{k}_{t}\mathbf{e}_{t}^{\mathsf{T}} e t k t T = k t e t T . Right-multiplying by k t \mathbf{k}_{t} k t gives e t = k t ( e t T k t ) / ∥ k t ∥ 2 2 \mathbf{e}_{t}=\mathbf{k}_{t}(\mathbf{e}_{t}^{\mathsf{T}}\mathbf{k}_{t})/\|\mathbf{k}_{t}\|_{2}^{2} e t = k t ( e t T k t ) /∥ k t ∥ 2 2 . Conversely e t = c k t \mathbf{e}_{t}=c\mathbf{k}_{t} e t = c k t with c ≠ 0 c\ne0 c = 0 gives F = ∇ S ~ [ 1 2 ∥ S k t − z t / c ∥ 2 2 ] \mathbf{F}=\nabla_{\widetilde{\mathbf{S}}}\left[\frac{1}{2}\|\mathbf{S}\mathbf{k}_{t}-\mathbf{z}_{t}/c\|_{2}^{2}\right] F = ∇ S [ 2 1 ∥ S k t − z t / c ∥ 2 2 ] , and c = 0 c=0 c = 0 gives a constant field. □
Remark 2 (GDN-2 as a preconditioned gradient step). Let b t > 0 b_t > 0 b t > 0 , k ~ t = b t ⊙ k t \tilde{k}_t = b_t \odot k_t k ~ t = b t ⊙ k t , and ℓ t ( S ) = 1 2 ∥ S k ~ t − z t ∥ 2 2 \ell_t(S) = \frac{1}{2}\lVert S\tilde{k}_t-z_t\rVert_2^2 ℓ t ( S ) = 2 1 ∥ S k ~ t − z t ∥ 2 2 , so ∇ ℓ t ( S ~ ) = ( S ~ k ~ t − z t ) k ~ t ⊤ \nabla\ell_t(\tilde{S}) = (\tilde{S}\tilde{k}_t-z_t)\tilde{k}_t^{\top} ∇ ℓ t ( S ~ ) = ( S ~ k ~ t − z t ) k ~ t ⊤ . Since k ~ t ⊤ Diag ( b t ) − 1 = k t ⊤ \tilde{k}_t^{\top}\operatorname{Diag}(b_t)^{-1}=k_t^{\top} k ~ t ⊤ Diag ( b t ) − 1 = k t ⊤ ,
∇ ℓ t ( S ~ ) Diag ( b t ) − 1 = ( S ~ k ~ t − z t ) k t ⊤ = F ( S ~ ) , (62) \nabla\ell_t(\tilde{S})\operatorname{Diag}(b_t)^{-1}=(\tilde{S}\tilde{k}_t-z_t)k_t^{\top}=F(\tilde{S}), \tag*{(62)} ∇ ℓ t ( S ~ ) Diag ( b t ) − 1 = ( S ~ k ~ t − z t ) k t ⊤ = F ( S ~ ) , (62)
so F F F is the gradient of ℓ t \ell_t ℓ t in the key-weighted inner product ⟨ A , B ⟩ = tr ( A Diag ( b t ) B ⊤ ) \langle A,B\rangle=\operatorname{tr}(A\operatorname{Diag}(b_t)B^{\top}) ⟨ A , B ⟩ = tr ( A Diag ( b t ) B ⊤ ) : GDN-2’s token update is a right-preconditioned gradient step. After the chunk’s token updates, the boundary decay is the separate proximal step characterized by Remark 1.
DeltaNet, GDN, and KDA have e t = β t k t e_t=\beta_t k_t e t = β t k t and z t = β t v t z_t=\beta_t v_t z t = β t v t , so Eq. (61) is S ~ − β t ∇ ℓ t ( S ~ ) \tilde{S}-\beta_t\nabla\ell_t(\tilde{S}) S ~ − β t ∇ ℓ t ( S ~ ) with ℓ t \ell_t ℓ t from Eq. (18) : an exact gradient step at each token. A chunk applies these local updates sequentially before the boundary proximal step; their composition is not generally one gradient step on a single loss. GDN-2 has e t = b t ⊙ k t e_t=b_t\odot k_t e t = b t ⊙ k t and meets the condition of Lemma 3 only when b t , j b_{t,j} b t , j is constant on { j : k t , j ≠ 0 } \{j:k_{t,j}\ne0\} { j : k t , j = 0 } . When b t > 0 b_t>0 b t > 0 , Remark 2 instead gives a preconditioned-gradient interpretation. If an erase-gate entry is zero, Diag ( b t ) \operatorname{Diag}(b_t) Diag ( b t ) is singular and this positive-definite metric interpretation does not apply. Mamba-3’s recurrence contains no read-and-correct term.
Conditional shrinkage and excess risk
§ 5.2 states Lemma 1 and Corollary 1. This appendix gives their proofs, the readout connection, oracle-rate interpretation, and detailed conditional and projection calculations.
Isotropic readout risk. For the reconstruction risk defined in § 5.2 , let S ^ = Λ ⊙ S − \widehat{S}=\Lambda\odot S^{-} S = Λ ⊙ S − and take q q q independent of the reconstruction error, with E [ q q ⊤ ] = d k − 1 I \mathbb{E}[qq^{\top}]=d_k^{-1}I E [ q q ⊤ ] = d k − 1 I . Then
E [ ∥ ( S ^ − S ⋆ ) q ∥ 2 2 ] = 1 d k E [ ∥ S ^ − S ⋆ ∥ F 2 ] . (63) \mathbb{E}\left[\lVert(\widehat{S}-S^\star)q\rVert_2^2\right]=\frac{1}{d_k}\mathbb{E}\left[\lVert\widehat{S}-S^\star\rVert_F^2\right]. \tag*{(63)} E [ ∥( S − S ⋆ ) q ∥ 2 2 ] = d k 1 E [ ∥ S − S ⋆ ∥ F 2 ] . (63)
Other query models can favor different shrinkage; Appendix § 13 .§ 3 compares this criterion with querying a stored key.
Let Φ \Phi Φ denote the information available to an oracle gate, and call a gate admissible if it is a function of Φ \Phi Φ with finite risk. The full boundary-state pair Φ = ( S [ n ] + , S [ n + 1 ] − ) \Phi=(S_{[n]}^+,S_{[n+1]}^-) Φ = ( S [ n ] + , S [ n + 1 ] − ) provides one oracle reference. The implemented gate uses only Δ S [ n ] \Delta S_{[n]} Δ S [ n ] through § 4.2 ’s parameterization, so it belongs to a restricted subclass. The difference need not contain all the information in the pair.
Oracle rate under conditional uncorrelatedness. Under the additional condition E [ S ⋆ ⊙ N ∣ Φ ] = 0 \mathbb{E}[S^\star\odot N\mid\Phi]=0 E [ S ⋆ ⊙ N ∣ Φ ] = 0 in Lemma 1, the oracle retention on entries with m ⋆ , a b > 0 m_{\star,ab}>0 m ⋆ , ab > 0 and m N , a b > 0 m_{N,ab}>0 m N , ab > 0 satisfies
κ ⋆ = m N ⊘ m ⋆ , ρ ⋆ = log ( 1 + m N ⊘ m ⋆ ) . (64) \kappa^\star=m_N\oslash m_\star,\qquad\rho^\star=\log(1+m_N\oslash m_\star). \tag*{(64)} κ ⋆ = m N ⊘ m ⋆ , ρ ⋆ = log ( 1 + m N ⊘ m ⋆ ) . (64)
Thus both the optimal ridge weight and decay rate are finite and strictly positive on these entries. If m N , a b = 0 m_{N,ab}=0 m N , ab = 0 , the oracle is the identity gate with ρ a b ⋆ = κ a b ⋆ = 0 \rho^\star_{ab}=\kappa^\star_{ab}=0 ρ ab ⋆ = κ ab ⋆ = 0 ; if m ⋆ , a b = 0 m_{\star,ab}=0 m ⋆ , ab = 0 , it is the zero gate, obtained only as ρ a b , κ a b → ∞ \rho_{ab},\kappa_{ab}\to\infty ρ ab , κ ab → ∞ . Because finite scores yield retention strictly between zero and one, these endpoint gates occur only as limits. This is an oracle identity for moments conditioned on Φ \Phi Φ , not a claim that the learned gate explicitly estimates those moments.
Proof of Lemma 1. Fix an entry ( a , b ) (a,b) ( a , b ) and abbreviate x = S a b ⋆ x=S^\star_{ab} x = S ab ⋆ , y = S a b − y=S^-_{ab} y = S ab − , λ = Λ a b \lambda=\Lambda_{ab} λ = Λ ab , m = E [ y 2 ∣ Φ ] > 0 m=\mathbb{E}[y^2\mid\Phi]>0 m = E [ y 2 ∣ Φ ] > 0 , and c = E [ x y ∣ Φ ] c=\mathbb{E}[xy\mid\Phi] c = E [ x y ∣ Φ ] . Because λ \lambda λ is Φ \Phi Φ -measurable it factors out of the conditional expectation, so
E [ ( λ y − x ) 2 ∣ Φ ] = λ 2 m − 2 λ c + E [ x 2 ∣ Φ ] = m ( λ − c m ) 2 + E [ x 2 ∣ Φ ] − c 2 m . (65) \mathbb{E}\left[(\lambda y-x)^2\mid\Phi\right]=\lambda^2m-2\lambda c+\mathbb{E}[x^2\mid\Phi]=m\left(\lambda-\frac{c}{m}\right)^2+\mathbb{E}[x^2\mid\Phi]-\frac{c^2}{m}. \tag*{(65)} E [ ( λ y − x ) 2 ∣ Φ ] = λ 2 m − 2 λ c + E [ x 2 ∣ Φ ] = m ( λ − m c ) 2 + E [ x 2 ∣ Φ ] − m c 2 . (65)
The conditional minimizer is λ ⋆ = c / m \lambda^\star=c/m λ ⋆ = c / m , which is Eq. (9) element-wise; summing over entries and taking expectations gives Eq. (10) with R ( Λ ⋆ ) = E ∑ a , b ( E [ x 2 ∣ Φ ] − c 2 / m ) \mathcal{R}(\Lambda^\star)=\mathbb{E}\sum_{a,b}(\mathbb{E}[x^2\mid\Phi]-c^2/m) R ( Λ ⋆ ) = E ∑ a , b ( E [ x 2 ∣ Φ ] − c 2 / m ) . Under E [ S ⋆ ⊙ N ∣ Φ ] = 0 \mathbb{E}[S^\star\odot N\mid\Phi]=0 E [ S ⋆ ⊙ N ∣ Φ ] = 0 we get $c=m_\star and m = m ⋆ + m N m = m_{\star} + m_{\mathrm{N}} m = m ⋆ + m N , both non-negative with m > 0 m > 0 m > 0 , so the ratio lies in [ 0 , 1 ] [0,1] [ 0 , 1 ] . Conditional Cauchy–Schwarz gives E [ m ( λ ⋆ ) 2 ] = E [ c 2 / m ] ≤ E [ x 2 ] < ∞ \mathbb{E}[m(\lambda^{\star})^{2}] = \mathbb{E}[c^{2}/m] \le\mathbb{E}[x^{2}] < \infty E [ m ( λ ⋆ ) 2 ] = E [ c 2 / m ] ≤ E [ x 2 ] < ∞ , so Λ ⋆ \Lambda^{\star} Λ ⋆ has finite weighted norm. □
The noise-to-signal interpretation in Eq. (64) requires conditional uncorrelatedness for the specified Φ \Phi Φ ; unconditional orthogonality alone does not imply this condition.
Proof of Corollary 1. Let H \mathcal{H} H be the space of Φ \Phi Φ -measurable d v × d k d_{v} \times d_{k} d v × d k random matrices with E ∥ m − ⊙ Λ ∥ F 1 / 2 < ∞ \mathbb{E}\lVert\mathbf{m}_{-} \odot\Lambda\rVert_{F}^{1/2} < \infty E ∥ m − ⊙ Λ ∥ F 1/2 < ∞ , with inner product ⟨ A , B ⟩ m = E ∑ a , b m − , a b A a b B a b \langle A, B\rangle_{m} = \mathbb{E}\sum_{a,b}m_{-,ab}A_{ab}B_{ab} ⟨ A , B ⟩ m = E ∑ a , b m − , ab A ab B ab and induced norm ∥ ⋅ ∥ m \lVert\cdot\rVert_{m} ∥ ⋅ ∥ m . By Lemma 1, R ( Λ ) = R ( Λ ⋆ ) + ∥ Λ − Λ ⋆ ∥ m 2 \mathcal{R}(\Lambda) = \mathcal{R}(\Lambda^{\star}) + \lVert\Lambda- \Lambda^{\star}\rVert_{m}^{2} R ( Λ ) = R ( Λ ⋆ ) + ∥ Λ − Λ ⋆ ∥ m 2 , so minimizing R \mathcal{R} R over a closed linear subspace is orthogonal projection of Λ ⋆ \Lambda^{\star} Λ ⋆ onto it. The constant families form nested finite-dimensional subspaces C s c a l a r ⊂ C k e y ⊂ C e l e m ⊂ H \mathcal{C}_{\mathrm{scalar}} \subset\mathcal{C}_{\mathrm{key}} \subset\mathcal{C}_{\mathrm{elem}} \subset\mathcal{H} C scalar ⊂ C key ⊂ C elem ⊂ H , so their projections compose and
∥ Λ ⋆ − Π s c a l a r Λ ⋆ ∥ m 2 = ∥ Λ ⋆ − Π e l e m Λ ⋆ ∥ m 2 + ∥ Π e l e m Λ ⋆ − Π k e y Λ ⋆ ∥ m 2 + ∥ Π k e y Λ ⋆ − Π s c a l a r Λ ⋆ ∥ m 2 , (66) \lVert\Lambda^{\star} - \Pi_{\mathrm{scalar}}\Lambda^{\star}\rVert_{m}^{2}
=
\lVert\Lambda^{\star} - \Pi_{\mathrm{elem}}\Lambda^{\star}\rVert_{m}^{2}
+
\lVert\Pi_{\mathrm{elem}}\Lambda^{\star} - \Pi_{\mathrm{key}}\Lambda^{\star}\rVert_{m}^{2}
+
\lVert\Pi_{\mathrm{key}}\Lambda^{\star} - \Pi_{\mathrm{scalar}}\Lambda^{\star}\rVert_{m}^{2}, \tag*{(66)} ∥ Λ ⋆ − Π scalar Λ ⋆ ∥ m 2 = ∥ Λ ⋆ − Π elem Λ ⋆ ∥ m 2 + ∥ Π elem Λ ⋆ − Π key Λ ⋆ ∥ m 2 + ∥ Π key Λ ⋆ − Π scalar Λ ⋆ ∥ m 2 , (66)
because the first difference is orthogonal to C e l e m \mathcal{C}_{\mathrm{elem}} C elem , which contains the other two, and the second is orthogonal to C k e y \mathcal{C}_{\mathrm{key}} C key , which contains the third. For a constant c c c , ∥ Λ ⋆ − c 1 ∥ m 2 = ∑ a , b E [ m − , a b ( Λ a b ⋆ − c a b ) 2 ] \lVert\Lambda^{\star} - c\mathbf{1}\rVert_{m}^{2} = \sum_{a,b}\mathbb{E}[m_{-,ab}(\Lambda^{\star}_{ab} - c_{ab})^{2}] ∥ Λ ⋆ − c 1 ∥ m 2 = ∑ a , b E [ m − , ab ( Λ ab ⋆ − c ab ) 2 ] is minimized at
c a b = E [ m − , a b Λ a b ⋆ ] m ‾ a b = E [ E [ S a ⋆ S a b − ∣ Φ ] ] m ‾ a b = Λ ‾ a b , c_{ab} = \frac{\mathbb{E}[m_{-,ab}\Lambda^{\star}_{ab}]}{\overline{m}_{ab}} = \frac{\mathbb{E}[\mathbb{E}[S^{\star}_{a}S^{-}_{ab}\mid\Phi]]}{\overline{m}_{ab}} = \overline{\Lambda}_{ab}, c ab = m ab E [ m − , ab Λ ab ⋆ ] = m ab E [ E [ S a ⋆ S ab − ∣ Φ ]] = Λ ab ,
using m − ⊙ Λ ⋆ = E [ S ⋆ ⊙ S − ∣ Φ ] \mathbf{m}_{-} \odot\Lambda^{\star} = \mathbb{E}[S^{\star} \odot S^{-}\mid\Phi] m − ⊙ Λ ⋆ = E [ S ⋆ ⊙ S − ∣ Φ ] and the tower property. Restricted to constants the inner product is ∑ a , b m ‾ a b A a b B a b \sum_{a,b}\overline{m}_{ab}A_{ab}B_{ab} ∑ a , b m ab A ab B ab , so projecting Λ ‾ \overline{\Lambda} Λ onto row-constant matrices gives μ b \mu_{b} μ b and onto multiples of 1 \mathbf{1} 1 gives μ \mu μ ; the two expressions for μ \mu μ agree because ∑ b m ‾ ⋅ b μ b = ∑ a , b m ‾ a b Λ ‾ a b \sum_{b}\overline{m}_{\cdot b}\mu_{b} = \sum_{a,b}\overline{m}_{ab}\overline{\Lambda}_{ab} ∑ b m ⋅ b μ b = ∑ a , b m ab Λ ab . Substituting into Eq. (66) gives Eq. (11) . Each projection is an m ‾ \overline{m} m -weighted average of values of Λ ⋆ \Lambda^{\star} Λ ⋆ , so the box constraint is inactive whenever Λ ⋆ ∈ [ 0 , 1 ] \Lambda^{\star} \in[0,1] Λ ⋆ ∈ [ 0 , 1 ] almost surely. □
Corollary 2 (A second chain: the cost of adaptive sharing). Let C k e y a d a p t = { 1 d v λ ( Φ ) ⊤ : λ Φ -measurable } ∩ H \mathcal{C}^{\mathrm{adapt}}_{\mathrm{key}} = \{\mathbf{1}_{d_{v}}\lambda(\Phi)^{\top} : \lambda\ \Phi\text{-measurable}\} \cap\mathcal{H} C key adapt = { 1 d v λ ( Φ ) ⊤ : λ Φ -measurable } ∩ H . Then C s c a l a r ⊂ C k e y ⊂ C k e y a d a p t ⊂ C a d a p t \mathcal{C}_{\mathrm{scalar}} \subset\mathcal{C}_{\mathrm{key}} \subset\mathcal{C}^{\mathrm{adapt}}_{\mathrm{key}} \subset\mathcal{C}_{\mathrm{adapt}} C scalar ⊂ C key ⊂ C key adapt ⊂ C adapt is a second chain whose middle projection is
λ b ( Φ ) = ∑ a m − , a b Λ a b ⋆ ∑ a m − , a b = ∑ a E [ S a ⋆ S a b − ∣ Φ ] ∑ a E [ ( S a b − ) 2 ∣ Φ ] , \lambda_{b}(\Phi) = \frac{\sum_{a}m_{-,ab}\Lambda^{\star}_{ab}}{\sum_{a}m_{-,ab}} = \frac{\sum_{a}\mathbb{E}[S^{\star}_{a}S^{-}_{ab}\mid\Phi]}{\sum_{a}\mathbb{E}[(S^{-}_{ab})^{2}\mid\Phi]}, λ b ( Φ ) = ∑ a m − , ab ∑ a m − , ab Λ ab ⋆ = ∑ a E [( S ab − ) 2 ∣ Φ ] ∑ a E [ S a ⋆ S ab − ∣ Φ ] ,
and
min C s c a l a r R − min C a d a p t R = E ∑ a , b m − , a b ( Λ a b ⋆ − λ b ( Φ ) ) 2 ⏟ E c o n d v a l u e + E ∑ a , b m − , a b ( λ b ( Φ ) − μ b ) 2 ⏟ E k e y s t a t e + E k e y . (67) \min_{\mathcal{C}_{\mathrm{scalar}}}\mathcal{R} - \min_{\mathcal{C}_{\mathrm{adapt}}}\mathcal{R}
=
\underbrace{\mathbb{E}\sum_{a,b}m_{-,ab}(\Lambda^{\star}_{ab}-\lambda_{b}(\Phi))^{2}}_{\mathcal{E}_{\mathrm{cond}}^{\mathrm{value}}}
+
\underbrace{\mathbb{E}\sum_{a,b}m_{-,ab}(\lambda_{b}(\Phi)-\mu_{b})^{2}}_{\mathcal{E}_{\mathrm{key}}^{\mathrm{state}}}
+\mathcal{E}_{\mathrm{key}}. \tag*{(67)} C scalar min R − C adapt min R = E cond value E a , b ∑ m − , ab ( Λ ab ⋆ − λ b ( Φ ) ) 2 + E key state E a , b ∑ m − , ab ( λ b ( Φ ) − μ b ) 2 + E key . (67)
Proof. C k e y a d a p t \mathcal{C}^{\mathrm{adapt}}_{\mathrm{key}} C key adapt is a closed linear subspace of H \mathcal{H} H containing C k e y \mathcal{C}_{\mathrm{key}} C key , so the proof of Corollary 1 applies with C e l e m \mathcal{C}_{\mathrm{elem}} C elem replaced by C k e y a d a p t \mathcal{C}^{\mathrm{adapt}}_{\mathrm{key}} C key adapt . Minimizing E ∑ a , b m − , a b ( Λ a b ⋆ − λ b ) 2 \mathbb{E}\sum_{a,b}m_{-,ab}(\Lambda^{\star}_{ab}-\lambda_{b})^{2} E ∑ a , b m − , ab ( Λ ab ⋆ − λ b ) 2 pointwise in Φ \Phi Φ and b b b gives the stated λ b ( Φ ) \lambda_{b}(\Phi) λ b ( Φ ) , and the second form follows from m − ⊙ Λ ⋆ = E [ S ⋆ ⊙ S − ∣ Φ ] \mathbf{m}_{-} \odot\Lambda^{\star} = \mathbb{E}[S^{\star} \odot S^{-}\mid\Phi] m − ⊙ Λ ⋆ = E [ S ⋆ ⊙ S − ∣ Φ ] . The last term is the same E k e y \mathcal{E}_{\mathrm{key}} E key because both chains project onto C k e y \mathcal{C}_{\mathrm{key}} C key and then onto C s c a l a r \mathcal{C}_{\mathrm{scalar}} C scalar . □
The two chains share E k e y \mathcal{E}_{\mathrm{key}} E key but are not comparable term by term, since C e l e m \mathcal{C}_{\mathrm{elem}} C elem and C k e y a d a p t \mathcal{C}^{\mathrm{adapt}}_{\mathrm{key}} C key adapt are not nested: one fixes the gate while keeping element-wise freedom, the other allows adaptation to Φ \Phi Φ while sharing across value rows. These families provide idealized counterparts to the variants in Table 4 : element-wise SDG belongs to a restricted subclass of C a d a p t \mathcal{C}_{\mathrm{adapt}} C adapt , channel-wise SDG to a restricted subclass of C k e y a d a p t \mathcal{C}^{\mathrm{adapt}}_{\mathrm{key}} C key adapt , the learned static gate to C e l e m \mathcal{C}_{\mathrm{elem}} C elem , and fixed boundary decay to C s c a l a r \mathcal{C}_{\mathrm{scalar}} C scalar . The excess-risk formulas compare the optima of these families under one fixed state distribution, not the trained variants themselves.
Remark 3 (Bayes optimality under state dependence). Suppose S − S^{-} S − is Φ \Phi Φ -measurable, as for the full boundary-state oracle. Then m − = S − ⊙ S − \mathbf{m}_{-} = S^{-} \odot S^{-} m − = S − ⊙ S − and Λ ⋆ = E [ S ⋆ ∣ Φ ] ⊘ S − \Lambda^{\star} = \mathbb{E}[S^{\star}\mid\Phi] \oslash S^{-} Λ ⋆ = E [ S ⋆ ∣ Φ ] ⊘ S − , so
Λ ⋆ ⊙ S − = E [ S ⋆ ∣ Φ ] , (68) \Lambda^{\star} \odot S^{-} = \mathbb{E}[S^{\star}\mid\Phi], \tag*{(68)} Λ ⋆ ⊙ S − = E [ S ⋆ ∣ Φ ] , (68)
the minimum mean-squared-error estimator of S ⋆ S^\star S ⋆ among all Φ \Phi Φ -measurable estimators, not only multiplicative ones; R ( Λ ⋆ ) R(\Lambda^\star) R ( Λ ⋆ ) is thus the Bayes risk. Restricting the gate to ( 0 , 1 ] (0,1] ( 0 , 1 ] attains Eq. (68) only where 0 < E [ S a b ⋆ ∣ Φ ] / S a b − ≤ 1 0 < \mathbb{E}[S^\star_{ab} \mid\Phi]/S^-_{ab} \le1 0 < E [ S ab ⋆ ∣ Φ ] / S ab − ≤ 1 , that is, where the posterior mean shrinks the observed entry without changing sign, whereas a constant gate is confined to linear shrinkage however informative Φ \Phi Φ is. These are conditions for the oracle family. The implemented SDG gate uses only Δ S [ n ] \Delta S_{[n]} Δ S [ n ] , which need not determine S − S^- S − , and its finite-score parameterization yields gates strictly between zero and one.
Superposition memory and two shrinkage criteria
Example: superposition memory. Let S ⋆ = ∑ i ∈ F v i k i T S^\star= \sum_{i\in\mathcal{F}} v_i k_i^{\mathsf{T}} S ⋆ = ∑ i ∈ F v i k i T and N = ∑ j ∈ O u j g j T N = \sum_{j\in\mathcal{O}} u_j g_j^{\mathsf{T}} N = ∑ j ∈ O u j g j T collect useful and interfering associations. Take independent keys uniform on the unit sphere. Values are zero-mean, independent across associations and of the keys, with E [ v i , a 2 ] = σ a 2 \mathbb{E}[v_{i,a}^2] = \sigma_a^2 E [ v i , a 2 ] = σ a 2 and E [ u j , a 2 ] = τ a 2 \mathbb{E}[u_{j,a}^2] = \tau_a^2 E [ u j , a 2 ] = τ a 2 . The index sets are independent of both keys and values. For this example, let the oracle observe only the counts, Φ c n t = ( ∣ F ∣ , ∣ O ∣ ) \Phi_{\mathrm{cnt}} = (|\mathcal{F}|,|\mathcal{O}|) Φ cnt = ( ∣ F ∣ , ∣ O ∣ ) . Assume ∣ F ∣ > 0 |\mathcal{F}| > 0 ∣ F ∣ > 0 almost surely, E ∣ F ∣ < ∞ \mathbb{E}|\mathcal{F}| < \infty E ∣ F ∣ < ∞ , 0 < E ∣ O ∣ < ∞ 0 < \mathbb{E}|\mathcal{O}| < \infty 0 < E ∣ O ∣ < ∞ , and 0 < σ a 2 , τ a 2 < ∞ 0 < \sigma_a^2,\tau_a^2 < \infty 0 < σ a 2 , τ a 2 < ∞ for every value channel. These conditions make the following conditional moments and ratios well-defined. The optimal counts-only gate is
Λ a b ⋆ , c n t = ∣ F ∣ σ a 2 ∣ F ∣ σ a 2 + ∣ O ∣ τ a 2 = ( 1 + ∣ O ∣ ∣ F ∣ ⋅ τ a 2 σ a 2 ) − 1 . (69) \Lambda^{\star,\mathrm{cnt}}_{ab} = \frac{|\mathcal{F}|\sigma_a^2}{|\mathcal{F}|\sigma_a^2 + |\mathcal{O}|\tau_a^2}
= \left(1+\frac{|\mathcal{O}|}{|\mathcal{F}|}\cdot\frac{\tau_a^2}{\sigma_a^2}\right)^{-1}. \tag*{(69)} Λ ab ⋆ , cnt = ∣ F ∣ σ a 2 + ∣ O ∣ τ a 2 ∣ F ∣ σ a 2 = ( 1 + ∣ F ∣ ∣ O ∣ ⋅ σ a 2 τ a 2 ) − 1 . (69)
The following calculation derives this gate and the associated risk terms.
Element-wise moments. With S ⋆ = ∑ i ∈ F v i k i T S^\star= \sum_{i\in\mathcal{F}} v_i k_i^{\mathsf{T}} S ⋆ = ∑ i ∈ F v i k i T and N = ∑ j ∈ O u j g j T N = \sum_{j\in\mathcal{O}} u_j g_j^{\mathsf{T}} N = ∑ j ∈ O u j g j T as defined above, entry ( a , b ) (a,b) ( a , b ) satisfies S a b ⋆ = ∑ i ∈ F v i , a k i , b S^\star_{ab} = \sum_{i\in\mathcal{F}} v_{i,a}k_{i,b} S ab ⋆ = ∑ i ∈ F v i , a k i , b . The values are independent across associations, zero-mean, and independent of the keys, so all cross terms vanish and
E [ ( S a b ⋆ ) 2 ∣ F , O ] = ∑ i ∈ F E [ v i , a 2 ] E [ k i , b 2 ] = ∣ F ∣ σ a 2 d k , E [ N a b 2 ∣ F , O ] = ∣ O ∣ τ a 2 d k , (70) \mathbb{E}[(S^\star_{ab})^2 \mid\mathcal{F},\mathcal{O}] = \sum_{i\in\mathcal{F}}\mathbb{E}[v_{i,a}^2]\mathbb{E}[k_{i,b}^2] = \frac{|\mathcal{F}|\sigma_a^2}{d_k},
\qquad
\mathbb{E}[N_{ab}^2 \mid\mathcal{F},\mathcal{O}] = \frac{|\mathcal{O}|\tau_a^2}{d_k}, \tag*{(70)} E [( S ab ⋆ ) 2 ∣ F , O ] = i ∈ F ∑ E [ v i , a 2 ] E [ k i , b 2 ] = d k ∣ F ∣ σ a 2 , E [ N ab 2 ∣ F , O ] = d k ∣ O ∣ τ a 2 , (70)
using E [ k k T ] = d k − 1 I \mathbb{E}[kk^{\mathsf{T}}] = d_k^{-1}I E [ k k T ] = d k − 1 I for keys uniform on the unit sphere. The same independence gives E [ S a b ⋆ N a b ∣ F , O ] = 0 \mathbb{E}[S^\star_{ab}N_{ab}\mid\mathcal{F},\mathcal{O}] = 0 E [ S ab ⋆ N ab ∣ F , O ] = 0 . Because the index sets are independent of the keys and values, conditioning only on their cardinalities preserves these moments and the zero cross moment. Lemma 1 therefore yields Eq. (69) . Both Λ a b ⋆ , c n t \Lambda^{\star,\mathrm{cnt}}_{ab} Λ ab ⋆ , cnt and m ˉ a b \bar{m}_{ab} m ˉ ab are independent of b b b , so Corollary 1 gives E k e y = 0 \mathcal{E}_{\mathrm{key}} = 0 E key = 0 and
E v a l u e = d k ∑ a m ˉ a ( Λ ˉ a − μ ) 2 , m ˉ a = E ∣ F ∣ σ a 2 + E ∣ O ∣ τ a 2 d k , Λ ˉ a = ( 1 + E ∣ O ∣ E ∣ F ∣ ⋅ τ a 2 σ a 2 ) − 1 , (71) \mathcal{E}_{\mathrm{value}} = d_k\sum_a \bar{m}_a(\bar{\Lambda}_a-\mu)^2,
\qquad
\bar{m}_a = \frac{\mathbb{E}|\mathcal{F}|\sigma_a^2+\mathbb{E}|\mathcal{O}|\tau_a^2}{d_k},
\qquad
\bar{\Lambda}_a = \left(1+\frac{\mathbb{E}|\mathcal{O}|}{\mathbb{E}|\mathcal{F}|}\cdot\frac{\tau_a^2}{\sigma_a^2}\right)^{-1}, \tag*{(71)} E value = d k a ∑ m ˉ a ( Λ ˉ a − μ ) 2 , m ˉ a = d k E ∣ F ∣ σ a 2 + E ∣ O ∣ τ a 2 , Λ ˉ a = ( 1 + E ∣ F ∣ E ∣ O ∣ ⋅ σ a 2 τ a 2 ) − 1 , (71)
Under the stated positivity assumptions, Eq. (71) is strictly positive exactly when τ a 2 / σ a 2 \tau_a^2/\sigma_a^2 τ a 2 / σ a 2 is not constant across value channels. Moreover, for every channel ( 1 + r τ a 2 / σ a 2 ) − 1 (1+r\tau_a^2/\sigma_a^2)^{-1} ( 1 + r τ a 2 / σ a 2 ) − 1 is strictly decreasing in r = ∣ O ∣ / ∣ F ∣ r=|\mathcal{O}|/|\mathcal{F}| r = ∣ O ∣/∣ F ∣ . Since the conditional weights are positive, E s t a t e ( Φ c n t ) > 0 \mathcal{E}_{\mathrm{state}}(\Phi_{\mathrm{cnt}})>0 E state ( Φ cnt ) > 0 exactly when this count ratio is not almost surely constant.
These conclusions apply to the counts-only oracle. Conditioning on the realized state may change both the optimal gate and the conditional signal–noise cross moment, and we assume no information inclusion between Φ c n t \Phi_{\mathrm{cnt}} Φ cnt and either the boundary-state pair or Δ S [ n ] \Delta S_{[n]} Δ S [ n ] . More generally, if σ ( Φ 1 ) ⊆ σ ( Φ 2 ) \sigma(\Phi_1)\subseteq\sigma(\Phi_2) σ ( Φ 1 ) ⊆ σ ( Φ 2 ) under the same state distribution, then
E s t a t e ( Φ 1 ) ≤ E s t a t e ( Φ 2 ) , \mathcal{E}_{\mathrm{state}}(\Phi_1)\leq\mathcal{E}_{\mathrm{state}}(\Phi_2), E state ( Φ 1 ) ≤ E state ( Φ 2 ) ,
because the larger admissible family cannot have greater minimum risk, whereas the best constant element-wise risk is unchanged. No such ordering follows without nested information.
Readout-level shrinkage and why the two criteria differ. A complementary calculation places the criterion at the readout rather than the state. Take m > 1 m>1 m > 1 independent keys uniform on the unit sphere, values independent, zero-mean, and independent of the keys with E [ v j v j T ] = σ v 2 I \mathbb{E}[v_jv_j^{\mathsf{T}}]=\sigma_v^2 I E [ v j v j T ] = σ v 2 I , and query with a stored key q = k i q=k_i q = k i :
y = S k i = x + ϵ , x = v i , ϵ = ∑ j ≠ i v j ( k j T k i ) . (72) y = Sk_i = x+\epsilon,\qquad x=v_i,\qquad\epsilon=\sum_{j\ne i}v_j(k_j^{\mathsf{T}}k_i). \tag*{(72)} y = S k i = x + ϵ , x = v i , ϵ = j = i ∑ v j ( k j T k i ) . (72)
Conditionally on k i k_i k i , each z j = k j ⊤ k i z_j = k_j^\top k_i z j = k j ⊤ k i has mean zero and second moment 1 / d k 1/d_k 1/ d k , so
E ∥ x ∥ 2 = d v σ v 2 , E ∥ ϵ ∥ 2 = m − 1 d k d v σ v 2 , E [ x ⊤ ϵ ] = 0 , (73) \mathbb{E}\lVert x\rVert^2 = d_v\sigma_v^2,\qquad\mathbb{E}\lVert\epsilon\rVert^2 = \frac{m-1}{d_k}d_v\sigma_v^2,\qquad\mathbb{E}[x^\top\epsilon] = 0, \tag*{(73)} E ∥ x ∥ 2 = d v σ v 2 , E ∥ ϵ ∥ 2 = d k m − 1 d v σ v 2 , E [ x ⊤ ϵ ] = 0 , (73)
giving S N R r e a d o u t = d k / ( m − 1 ) \mathrm{SNR}_{\mathrm{readout}} = d_k/(m-1) SNR readout = d k / ( m − 1 ) and, by the same completion of the square, the scalar minimizer
λ r e a d o u t ⋆ = d k d k + m − 1 = S N R r e a d o u t 1 + S N R r e a d o u t . (74) \lambda^\star_{\mathrm{readout}} = \frac{d_k}{d_k+m-1} = \frac{\mathrm{SNR}_{\mathrm{readout}}}{1+\mathrm{SNR}_{\mathrm{readout}}}. \tag*{(74)} λ readout ⋆ = d k + m − 1 d k = 1 + SNR readout SNR readout . (74)
The corresponding state-level quantity for the same memory is different. With one target and m − 1 m-1 m − 1 interfering associations and σ a = τ a = σ v \sigma_a=\tau_a=\sigma_v σ a = τ a = σ v , Eq. (70) gives Λ a b ∗ = 1 / m \Lambda^\ast_{ab}=1/m Λ ab ∗ = 1/ m uniformly, whereas Eq. (74) is close to one for m ≪ d k m\ll d_k m ≪ d k . The discrepancy is entirely a difference of query model, not an inconsistency: Eq. (63) weights all d k d_k d k directions equally, while Eq. (72) uses a query aligned with the target’s key and therefore amplifies the target by a factor d k d_k d k relative to the isotropic average. We report the state-level criterion in the main text because it is separable across entries, which is what makes element-wise gate families directly comparable; a general query covariance couples entries and destroys this separability. Neither calculation characterizes the capacity of learned linear attention.
Isotropic future queries. For Eq. (63) , condition on A = S ^ − S ∗ A=\widehat{S}-S^\ast A = S − S ∗ . Independence and isotropy of q q q give
E q ∥ A q ∥ 2 = tr ( A ⊤ A E [ q q ⊤ ] ) = 1 d k ∥ A ∥ F 2 . (75) \mathbb{E}_q\lVert Aq\rVert^2=\operatorname{tr}\left(A^\top A\mathbb{E}[qq^\top]\right)=\frac{1}{d_k}\lVert A\rVert_F^2. \tag*{(75)} E q ∥ A q ∥ 2 = tr ( A ⊤ A E [ q q ⊤ ] ) = d k 1 ∥ A ∥ F 2 . (75)
Taking the remaining expectation proves the identity.
State propagation and value-row structure
Token-wise gates and shared transitions. A direct extension of GDN or KDA replaces the token-wise scalar or diagonal decay with a full matrix gate:
S t = ( Λ t ⊙ S t − 1 ) ( I − β t k t k t ⊤ ) + β t v t k t ⊤ , Λ t ∈ ( 0 , 1 ] d v × d k . (76) S_t=(\Lambda_t\odot S_{t-1})(I-\beta_t k_t k_t^\top)+\beta_t v_t k_t^\top,\qquad\Lambda_t\in(0,1]^{d_v\times d_k}. \tag*{(76)} S t = ( Λ t ⊙ S t − 1 ) ( I − β t k t k t ⊤ ) + β t v t k t ⊤ , Λ t ∈ ( 0 , 1 ] d v × d k . (76)
This recurrence is well-defined, but its chunkwise computation differs from that of the base layer. In KDA, every value row shares the same key-space transition. At position r r r within a chunk, its homogeneous transition is
P r = ∏ i = 1 r D i ( I − β i k i k i ⊤ ) , (77) P_r=\prod_{i=1}^{r}D_i(I-\beta_i k_i k_i^\top), \tag*{(77)} P r = i = 1 ∏ r D i ( I − β i k i k i ⊤ ) , (77)
with earlier factors on the left. The chunk index is suppressed; P C P_C P C is P [ n ] P_{[n]} P [ n ] in Eq. (2) . One set of WY factors therefore serves all value channels [56 , 67 ] .
For a general element-wise gate, let λ i ( a ) \lambda_i^{(a)} λ i ( a ) denote row a a a of Λ i \Lambda_i Λ i . Given the realized token gates, row a a a has homogeneous transition
P r ( a ) = ∏ i = 1 r Diag ( λ i ( a ) ) ( I − β i k i k i ⊤ ) . (78) P_r^{(a)}=\prod_{i=1}^{r}\operatorname{Diag}(\lambda_i^{(a)})(I-\beta_i k_i k_i^\top). \tag*{(78)} P r ( a ) = i = 1 ∏ r Diag ( λ i ( a ) ) ( I − β i k i k i ⊤ ) . (78)
These transitions generally differ across value rows, requiring up to d v d_v d v sets of factors instead of the shared set used by existing kernels. If the gates also read the running state, the factors cannot be prepared from token inputs alone. Equation (78) describes propagation along the realized gate path, not the Jacobian of the full state-dependent recurrence. Boundary placement retains the native shared transitions within each chunk.
Boundary-gated state propagation. This section unrolls the boundary-gated recurrence into a temporal kernel over past writes and shows that this kernel is diagonal: it scales each value coordinate separately rather than mixing them.
S [ n + 1 ] + = S [ n ] + P [ n ] + Ω [ n ] , (79) \mathbf{S}_{[n+1]}^{+}=\mathbf{S}_{[n]}^{+}\mathbf{P}_{[n]}+\mathbf{\Omega}_{[n]}, \tag*{(79)} S [ n + 1 ] + = S [ n ] + P [ n ] + Ω [ n ] , (79)
where P [ n ] ∈ R d k × d k \mathbf{P}_{[n]} \in\mathbb{R}^{d_k \times d_k} P [ n ] ∈ R d k × d k summarizes the within-chunk transition and Ω [ n ] \mathbf{\Omega}_{[n]} Ω [ n ] collects writes. Vectorize the state column-wise and let
D [ n ] = Diag ( vec Λ [ n ] ) , T [ n ] = D [ n ] ( P [ n ] T ⊗ I d v ) . (80) \mathbf{D}_{[n]}=\operatorname{Diag}(\operatorname{vec}\boldsymbol{\Lambda}_{[n]}),\qquad\mathbf{T}_{[n]}=\mathbf{D}_{[n]}(\mathbf{P}_{[n]}^{\mathsf{T}}\otimes\mathbf{I}_{d_v}). \tag*{(80)} D [ n ] = Diag ( vec Λ [ n ] ) , T [ n ] = D [ n ] ( P [ n ] T ⊗ I d v ) . (80)
Conditional on the realized gate trajectory,
vec ( S [ n + 1 ] + ) = T [ n ] vec ( S [ n ] + ) + D [ n ] vec ( Ω [ n ] ) , (81) \operatorname{vec}(\mathbf{S}_{[n+1]}^{+})=\mathbf{T}_{[n]}\operatorname{vec}(\mathbf{S}_{[n]}^{+})+\mathbf{D}_{[n]}\operatorname{vec}(\mathbf{\Omega}_{[n]}), \tag*{(81)} vec ( S [ n + 1 ] + ) = T [ n ] vec ( S [ n ] + ) + D [ n ] vec ( Ω [ n ] ) , (81)
and unrolling gives
vec ( S [ n + 1 ] + ) = ( ∏ ℓ = 1 n T [ ℓ ] ) vec ( S [ 1 ] + ) + ∑ r = 1 n ( ∏ ℓ = r + 1 n T [ ℓ ] ) D [ r ] vec ( Ω [ r ] ) , (82) \operatorname{vec}(\mathbf{S}_{[n+1]}^{+})=
\left(\prod_{\ell=1}^{n}\mathbf{T}_{[\ell]}\right)\operatorname{vec}(\mathbf{S}_{[1]}^{+})
+\sum_{r=1}^{n}\left(\prod_{\ell=r+1}^{n}\mathbf{T}_{[\ell]}\right)\mathbf{D}_{[r]}\operatorname{vec}(\mathbf{\Omega}_{[r]}), \tag*{(82)} vec ( S [ n + 1 ] + ) = ( ℓ = 1 ∏ n T [ ℓ ] ) vec ( S [ 1 ] + ) + r = 1 ∑ n ( ℓ = r + 1 ∏ n T [ ℓ ] ) D [ r ] vec ( Ω [ r ] ) , (82)
with later transitions ordered on the left. With the readout o t = ( q t T ⊗ I d v ) vec ( S t ) \mathbf{o}_t=(\mathbf{q}_t^{\mathsf{T}}\otimes\mathbf{I}_{d_v})\operatorname{vec}(\mathbf{S}_t) o t = ( q t T ⊗ I d v ) vec ( S t ) , a zero initial state, and the realized transition and gate factors held fixed, Eq. (82) expresses the output as a temporal kernel applied to past writes,
o t = ∑ j ≤ t K t , j z j , K t , j ∈ R d v × d v , (83) \mathbf{o}_t=\sum_{j\leq t}\mathbf{K}_{t,j}\mathbf{z}_j,\qquad\mathbf{K}_{t,j}\in\mathbb{R}^{d_v\times d_v}, \tag*{(83)} o t = j ≤ t ∑ K t , j z j , K t , j ∈ R d v × d v , (83)
where z j \mathbf{z}_j z j is the write vector of token j j j : w j ⊙ v j \mathbf{w}_j\odot\mathbf{v}_j w j ⊙ v j for GDN-2, β j v j \beta_j\mathbf{v}_j β j v j for GDN and KDA, and a trapezoidal combination of v j − 1 \mathbf{v}_{j-1} v j − 1 and v j \mathbf{v}_j v j for Mamba-3. This kernel is not an arbitrary operator.
Lemma 4 (Value-row decoupling). Suppose the base recurrence has the form
S t = S t − 1 A t + ∑ ℓ = 1 L z t ( ℓ ) ( k t ( ℓ ) ) T , \mathbf{S}_t=\mathbf{S}_{t-1}\mathbf{A}_t+\sum_{\ell=1}^{L}z_t^{(\ell)}\left(\mathbf{k}_t^{(\ell)}\right)^{\mathsf{T}}, S t = S t − 1 A t + ℓ = 1 ∑ L z t ( ℓ ) ( k t ( ℓ ) ) T , with A t ∈ R d k × d k \mathbf{A}_t\in\mathbb{R}^{d_k\times d_k} A t ∈ R d k × d k and all k t ( ℓ ) \mathbf{k}_t^{(\ell)} k t ( ℓ ) determined by token-local quantities. This covers Eqs. (19) –(22) with L = 1 L=1 L = 1 and A t = D t ( I − e t k t T ) \mathbf{A}_t=\mathbf{D}_t(\mathbf{I}-\mathbf{e}_t\mathbf{k}_t^{\mathsf{T}}) A t = D t ( I − e t k t T ) , and Eq. (53) with L = 2 L=2 L = 2 and A t = α t I \mathbf{A}_t=\alpha_t\mathbf{I} A t = α t I . Add the boundary update of Eq. (25) . Then for every a a a , row a a a of the state follows a recurrence involving only row a a a of the initial state, the shared key-side factors { A t , k t ( ℓ ) } \{\mathbf{A}_t,\mathbf{k}_t^{(\ell)}\} { A t , k t ( ℓ ) } , the scalar sources { z t , a ( ℓ ) } \{z_{t,a}^{(\ell)}\} { z t , a ( ℓ ) } , and row a a a of G \mathbf{G} G . Consequently the kernel of Eq. (83) is diagonal,
K t , j = Diag ( c t , j ( 1 ) , … , c t , j ( d v ) ) . (84) \mathbf{K}_{t,j}=\operatorname{Diag}(c_{t,j}^{(1)},\ldots,c_{t,j}^{(d_v)}). \tag*{(84)} K t , j = Diag ( c t , j ( 1 ) , … , c t , j ( d v ) ) . (84) Proof. Row a a a of the update is s t − 1 , a A t + ∑ ℓ z t , a ( ℓ ) ( k t ( ℓ ) ) T \mathbf{s}_{t-1,a}\mathbf{A}_t+\sum_{\ell}z_{t,a}^{(\ell)}(\mathbf{k}_t^{(\ell)})^{\mathsf{T}} s t − 1 , a A t + ∑ ℓ z t , a ( ℓ ) ( k t ( ℓ ) ) T , because right multiplication acts on the key index only and each outer product contributes to row a a a alone. At a boundary, row a a a is multiplied element-wise by row a a a of Λ [ n ] \boldsymbol{\Lambda}_{[n]} Λ [ n ] , and row a a a of Z [ n ] = G ⊙ ( Δ S [ n ] W T ) \mathbf{Z}_{[n]}=\mathbf{G}\odot(\Delta\mathbf{S}_{[n]}\mathbf{W}^{\mathsf{T}}) Z [ n ] = G ⊙ ( Δ S [ n ] W T ) equals g a ⊙ ( W S Δ s a ) \mathbf{g}_a\odot(\mathbf{W}\mathbf{S}\Delta\mathbf{s}_a) g a ⊙ ( WS Δ s a ) , which depends only on row a a a of Δ S [ n ] \Delta\mathbf{S}_{[n]} Δ S [ n ] . Both steps preserve the property, so by induction over tokens and boundaries row a a a never depends on row a ′ ≠ a a'\ne a a ′ = a . Since o t = S t q t \mathbf{o}_t=\mathbf{S}_t\mathbf{q}_t o t = S t q t , coordinate a a a of o t \mathbf{o}_t o t is a linear functional of row a a a alone, which is Eq. (84) . □
In the base models c t , j ( a ) c_{t,j}^{(a)} c t , j ( a ) does not depend on a a a , so the kernel is c t , j I d v c_{t,j}\mathbf{I}_{d_v} c t , j I d v : one weight shared by all value coordinates. An element-wise boundary gate makes it a diagonal operator with value-channel-specific entries. Two scopes differ here. Diagonality is structural and holds for every realization, because row a a a of the gate reads only row a a a of the state change. The linear representation in Eq. (83) is conditional on the realized gate path: D [ n ] \mathbf{D}_{[n]} D [ n ] depends on the evolving state, so the coefficients are themselves functions of past values and cannot be precomputed from positions or reduced to one input-independent attention matrix.
Lemma 4 also justifies two implementation choices. Within a chunk A t A_t A t is shared across value rows, since SDG acts only at boundaries, so one set of WY factors still serves all value channels—the requirement identified in Eqs. (77) –(78) . Across value rows the augmented recurrence is embarrassingly parallel, so the state scan may be tiled along d v d_v d v with no cross-tile communication, while each tile holds full rows along d k d_k d k because W S W_S W S mixes key channels.
Kernel and backward details
Boundary gate and implementation. For a fixed base rate ρ 0 > 0 \rho_0 > 0 ρ 0 > 0 , define
squareplus ( z ; ρ 0 2 ) = 1 2 ( z + z 2 + ρ 0 2 ) , ρ ( z ) = 2 squareplus ( z ; ρ 0 2 ) . \operatorname{squareplus}(z;\rho_0^2) = \frac{1}{2}\left(z+\sqrt{z^2+\rho_0^2}\right), \qquad\rho(z) = 2\operatorname{squareplus}(z;\rho_0^2). squareplus ( z ; ρ 0 2 ) = 2 1 ( z + z 2 + ρ 0 2 ) , ρ ( z ) = 2 squareplus ( z ; ρ 0 2 ) .
This is the Squareplus parameterization [6 ] in Eq. (5) . The rate is smooth and increasing, with value ρ 0 \rho_0 ρ 0 and derivative one at zero. If the state is unchanged, then Δ S [ n ] = 0 \Delta S_{[n]} = 0 Δ S [ n ] = 0 and the gate is e − ρ 0 1 e^{-\rho_0}\mathbf{1} e − ρ 0 1 .
Forward pass. We implement SDG in Triton [57 ] , building on Flash Linear Attention [64 ] . The boundary update is fused into the inter-chunk state scan; native factor preparation and output kernels are retained. On supported fused paths, each program holds a state tile in SRAM or registers, forms the difference in FP32, and projects it using Tensor Cores. The projected difference, score, rate, and gate remain on chip, avoiding HBM writes for these forward intermediates. Appendix E gives backbone-specific details and supported configurations.
Backward pass. The backward pass traverses the state scan in reverse order [25 ] . Differentiating the gate produces gradients for both the raw state and the incoming state. The former enters the native chunk backward computation; the latter is added directly to its incoming-state gradient. We save or recompute boundary states, recompute gate intermediates on chip, and accumulate the gain gradient during the scan. A separate reduction computes the projection gradient from saved gradients of X [ n ] X_{[n]} X [ n ] . The following subsections give the gate VJP and additive reference forward and backward algorithms.
Gate-function derivatives
For one boundary, write S s r c S^{\mathrm{src}} S src for the state at the preceding boundary and S o u t S^{\mathrm{out}} S out for the gated result, and define
Δ S = S − − S s r c , X = Δ S W S T , Z = G ⊙ X , ρ = Z + Z ⊙ Z + ρ 0 2 1 , Λ = exp ( − ρ ) , S o u t = Λ ⊙ S − . (85) \begin{aligned}
\Delta S &= S^{-} - S^{\mathrm{src}}, \qquad X = \Delta S W_S^{\mathsf{T}},\\
Z &= G \odot X, \qquad\rho= Z + \sqrt{Z \odot Z + \rho_0^2\mathbf{1}},\\
\Lambda&= \exp(-\rho), \qquad S^{\mathrm{out}} = \Lambda\odot S^{-}. \tag*{(85)}
\end{aligned} Δ S Z Λ = S − − S src , X = Δ S W S T , = G ⊙ X , ρ = Z + Z ⊙ Z + ρ 0 2 1 , = exp ( − ρ ) , S out = Λ ⊙ S − . (85)
For a tensor T \mathbf{T} T , write d T = ∂ L / ∂ T \mathrm{d}\mathbf{T} = \partial\mathcal{L}/\partial\mathbf{T} d T = ∂ L / ∂ T . Given d S o u t \mathrm{d}S^{\mathrm{out}} d S out , the gate vector–Jacobian product computes
d ρ = − d S o u t ⊙ S o u t , d Z = d ρ ⊙ ρ Z ⊙ Z + ρ 0 2 1 , d X = d Z ⊙ G , (86) \mathrm{d}\rho= -\mathrm{d}S^{\mathrm{out}} \odot S^{\mathrm{out}}, \qquad\mathrm{d}Z = \mathrm{d}\rho\odot\frac{\rho}{\sqrt{Z \odot Z + \rho_0^2\mathbf{1}}}, \qquad\mathrm{d}X = \mathrm{d}Z \odot G, \tag*{(86)} d ρ = − d S out ⊙ S out , d Z = d ρ ⊙ Z ⊙ Z + ρ 0 2 1 ρ , d X = d Z ⊙ G , (86)
with element-wise division, and then
d G = d Z ⊙ X , d W S = d X T Δ S , (87) \mathrm{d}G = \mathrm{d}Z \odot X, \qquad\mathrm{d}W_S = \mathrm{d}X^{\mathsf{T}}\Delta S, \tag*{(87)} d G = d Z ⊙ X , d W S = d X T Δ S , (87)
summed over chunks and batch examples. The state gradients are
d S − = d S o u t ⊙ Λ + d X W S , (88) \mathrm{d}S^{-} = \mathrm{d}S^{\mathrm{out}} \odot\Lambda+ \mathrm{d}XW_S, \tag*{(88)} d S − = d S out ⊙ Λ + d X W S , (88)
d S s r c = − d X W S , (89) \mathrm{d}S^{\mathrm{src}} = -\mathrm{d}XW_S, \tag*{(89)} d S src = − d X W S , (89)
the two gate-path terms having opposite signs because of the subtraction in Δ S \Delta S Δ S , and d S s r c \mathrm{d}S^{\mathrm{src}} d S src is added to the gradient returned by the base chunk recurrence. This gives a consistency check used in our tests: for standard linear attention Δ S [ n ] = V [ n ] ⊤ K [ n ] \Delta S_{[n]} = V_{[n]}^{\top}K_{[n]} Δ S [ n ] = V [ n ] ⊤ K [ n ] is independent of the incoming state, so the two terms must cancel exactly once accumulated into d S [ n ] \mathrm{d}S_{[n]} d S [ n ] .
For stable evaluation, the kernel computes z 2 + ρ 0 2 \sqrt{z^2+\rho_0^2} z 2 + ρ 0 2 with a scaled norm. When z < 0 z<0 z < 0 , it evaluates the equivalent expression ρ 0 2 / ( z 2 + ρ 0 2 − z ) \rho_0^2/(\sqrt{z^2+\rho_0^2}-z) ρ 0 2 / ( z 2 + ρ 0 2 − z ) to avoid cancellation. The derivative is ρ ( z ) / z 2 + ρ 0 2 \rho(z)/\sqrt{z^2+\rho_0^2} ρ ( z ) / z 2 + ρ 0 2 , where ρ ( z ) = z + z 2 + ρ 0 2 \rho(z)=z+\sqrt{z^2+\rho_0^2} ρ ( z ) = z + z 2 + ρ 0 2 . This expression is positive on both sides of zero and equals one at zero.
Additive reference forward pass
Algorithm 2 expands Algorithm 1 for unnormalized additive linear attention. Its on-chip steps illustrate the arithmetic rather than a common kernel launch schedule for all backbones. In this special case, Δ S [ n ] = V [ n ] ⊤ K [ n ] \Delta S_{[n]}=V_{[n]}^{\top}K_{[n]} Δ S [ n ] = V [ n ] ⊤ K [ n ] is independent of the incoming state for fixed chunk inputs. The gated recurrent layers evaluated here retain their native state transitions, so their state differences also depend on the incoming memory. This example assumes complete chunks, L = N C L=NC L = N C ; arbitrary lengths and cached continuations follow Appendix § 12 .9, where incomplete final chunks do not trigger boundary decay.
Algorithm 2 SDG: Illustrative Forward Pass for Additive Linear Attention
Require: L = N C L=NC L = N C and N = L / C N=L/C N = L / C complete chunks; Q , K ∈ R L × d k \mathbf{Q},\mathbf{K}\in\mathbb{R}^{L\times d_k} Q , K ∈ R L × d k , V ∈ R L × d v \mathbf{V}\in\mathbb{R}^{L\times d_v} V ∈ R L × d v , initial state S [ 1 ] + ∈ R d v × d k \mathbf{S}_{[1]}^{+}\in\mathbb{R}^{d_v\times d_k} S [ 1 ] + ∈ R d v × d k , chunk size C C C , and gate parameters W S , G \mathbf{W}_{S},\mathbf{G} W S , G with fixed base rate ρ 0 \rho_0 ρ 0 .
Partition Q , K , V \mathbf{Q},\mathbf{K},\mathbf{V} Q , K , V into N N N complete chunks of C C C tokens, { Q [ n ] , K [ n ] , V [ n ] } n = 1 N \{\mathbf{Q}_{[n]},\mathbf{K}_{[n]},\mathbf{V}_{[n]}\}_{n=1}^{N} { Q [ n ] , K [ n ] , V [ n ] } n = 1 N .
Load S [ 1 ] + \mathbf{S}_{[1]}^{+} S [ 1 ] + from HBM to SRAM and construct the causal mask M C M_C M C on chip.
Load W S , G \mathbf{W}_{S},\mathbf{G} W S , G from HBM to SRAM.
for n = 1 , … , N n=1,\ldots,N n = 1 , … , N do
Load Q [ n ] , K [ n ] , V [ n ] \mathbf{Q}_{[n]},\mathbf{K}_{[n]},\mathbf{V}_{[n]} Q [ n ] , K [ n ] , V [ n ] from HBM to SRAM.
On chip, compute O [ n ] = Q [ n ] ( S [ n ] + ⊤ + ( Q [ n ] K [ n ] ⊤ ⊙ M C ) V [ n ] \mathbf{O}_{[n]}=\mathbf{Q}_{[n]}(\mathbf{S}_{[n]}^{+\top}+(\mathbf{Q}_{[n]}\mathbf{K}_{[n]}^{\top}\odot M_C)\mathbf{V}_{[n]} O [ n ] = Q [ n ] ( S [ n ] + ⊤ + ( Q [ n ] K [ n ] ⊤ ⊙ M C ) V [ n ] .
On chip, compute S [ n + 1 ] − = S [ n ] + + V [ n ] ⊤ K [ n ] \mathbf{S}_{[n+1]}^{-}=\mathbf{S}_{[n]}^{+}+\mathbf{V}_{[n]}^{\top}\mathbf{K}_{[n]} S [ n + 1 ] − = S [ n ] + + V [ n ] ⊤ K [ n ] .
On chip, compute Δ S [ n ] = S [ n + 1 ] − − S [ n ] + \Delta\mathbf{S}_{[n]}=\mathbf{S}_{[n+1]}^{-}-\mathbf{S}_{[n]}^{+} Δ S [ n ] = S [ n + 1 ] − − S [ n ] + .
On chip, compute X [ n ] = Δ S [ n ] W S ⊤ \mathbf{X}_{[n]}=\Delta\mathbf{S}_{[n]}\mathbf{W}_{S}^{\top} X [ n ] = Δ S [ n ] W S ⊤ , Z [ n ] = G ⊙ X [ n ] \mathbf{Z}_{[n]}=\mathbf{G}\odot\mathbf{X}_{[n]} Z [ n ] = G ⊙ X [ n ] .
On chip, compute Λ [ n ] = exp [ − 2 squareplus ( Z [ n ] ; ρ 0 ) ] \mathbf{\Lambda}_{[n]}=\exp[-2\operatorname{squareplus}(\mathbf{Z}_{[n]};\rho_0)] Λ [ n ] = exp [ − 2 squareplus ( Z [ n ] ; ρ 0 )] .
On chip, compute S [ n + 1 ] + = Λ [ n ] ⊙ S [ n + 1 ] − \mathbf{S}_{[n+1]}^{+}=\mathbf{\Lambda}_{[n]}\odot\mathbf{S}_{[n+1]}^{-} S [ n + 1 ] + = Λ [ n ] ⊙ S [ n + 1 ] − .
Store O [ n ] \mathbf{O}_{[n]} O [ n ] from SRAM to HBM.
end for
Store S [ N + 1 ] + \mathbf{S}_{[N+1]}^{+} S [ N + 1 ] + from SRAM to HBM.
return O = Concat ( O [ 1 ] , … , O [ N ] ) \mathbf{O}=\operatorname{Concat}(\mathbf{O}_{[1]},\ldots,\mathbf{O}_{[N]}) O = Concat ( O [ 1 ] , … , O [ N ] ) and S [ N + 1 ] + \mathbf{S}_{[N+1]}^{+} S [ N + 1 ] + .
Additive reference backward pass
Algorithm 3 gives the reverse chunk scan for the additive example in Algorithm 2. The prefix d denotes the gradient of the loss with respect to a tensor. The quantities d S [ n + 1 ] \mathrm{d}\mathbf{S}_{[n+1]} d S [ n + 1 ] and d S [ n ] r e c \mathrm{d}\mathbf{S}_{[n]}^{\mathrm{rec}} d S [ n ] rec are the gradients returned by the boundary update with respect to S [ n + 1 ] − \mathbf{S}_{[n+1]}^{-} S [ n + 1 ] − and S [ n ] + \mathbf{S}_{[n]}^{+} S [ n ] + . They follow Eqs. (86) –(89) . The scan saves d X [ n ] \mathrm{d}\mathbf{X}_{[n]} d X [ n ] for a separate tiled reduction of the projection gradient.
Algorithm 3 SDG: Fused Backward Pass for Standard Linear Attention
Require: Q , K , V \mathbf{Q}, \mathbf{K}, \mathbf{V} Q , K , V , output gradients d O \mathrm{d}\mathbf{O} d O , saved or recomputed boundary states, and d S [ N + 1 ] s r c \mathrm{d}\mathbf{S}^{\mathrm{src}}_{[N+1]} d S [ N + 1 ] src , with W S , G , ρ 0 \mathbf{W}_{S}, \mathbf{G}, \rho_{0} W S , G , ρ 0 .
Initialize parameter gradients to zero and construct M C \mathbf{M}_{C} M C on chip.
Load W S , G \mathbf{W}_{S}, \mathbf{G} W S , G from HBM to SRAM.
for n = N , … , 1 n=N,\ldots,1 n = N , … , 1 do
Load Q [ n ] , K [ n ] , V [ n ] , d O [ n ] , S [ n ] + \mathbf{Q}_{[n]}, \mathbf{K}_{[n]}, \mathbf{V}_{[n]}, \mathrm{d}\mathbf{O}_{[n]}, \mathbf{S}^{+}_{[n]} Q [ n ] , K [ n ] , V [ n ] , d O [ n ] , S [ n ] + , and S [ n + 1 ] − \mathbf{S}^{-}_{[n+1]} S [ n + 1 ] − from HBM to SRAM.
On chip, compute ( d S [ n + 1 ] , d S [ n ] s r c ) = V J P E q s . ( 4 ) – ( 6 ) ( d S [ n + 1 ] − ) (\mathrm{d}\mathbf{S}_{[n+1]},\mathrm{d}\mathbf{S}^{\mathrm{src}}_{[n]})=\mathrm{VJP}_{\mathrm{Eqs.}\ (4)\text{--}(6)}(\mathrm{d}\mathbf{S}^{-}_{[n+1]}) ( d S [ n + 1 ] , d S [ n ] src ) = VJP Eqs. ( 4 ) – ( 6 ) ( d S [ n + 1 ] − ) .
On chip, accumulate d G + = d Z [ n ] ⊙ X [ n ] \mathrm{d}\mathbf{G} += \mathrm{d}\mathbf{Z}_{[n]} \odot\mathbf{X}_{[n]} d G + = d Z [ n ] ⊙ X [ n ] .
Store d X [ n ] \mathrm{d}\mathbf{X}_{[n]} d X [ n ] from SRAM to HBM.
On chip, compute A q k , [ n ] = Q [ n ] K [ n ] T ⊙ M C \mathbf{A}_{qk,[n]}=\mathbf{Q}_{[n]}\mathbf{K}_{[n]}^{\mathsf{T}}\odot\mathbf{M}_{C} A q k , [ n ] = Q [ n ] K [ n ] T ⊙ M C and d A q k , [ n ] = d O [ n ] V [ n ] T \mathrm{d}\mathbf{A}_{qk,[n]}=\mathrm{d}\mathbf{O}_{[n]}\mathbf{V}_{[n]}^{\mathsf{T}} d A q k , [ n ] = d O [ n ] V [ n ] T .
On chip, compute d Q [ n ] = d O [ n ] S [ n ] + + ( d A q k , [ n ] ⊙ M C ) K [ n ] \mathrm{d}\mathbf{Q}_{[n]}=\mathrm{d}\mathbf{O}_{[n]}\mathbf{S}^{+}_{[n]}+(\mathrm{d}\mathbf{A}_{qk,[n]}\odot\mathbf{M}_{C})\mathbf{K}_{[n]} d Q [ n ] = d O [ n ] S [ n ] + + ( d A q k , [ n ] ⊙ M C ) K [ n ] .
On chip, compute d K [ n ] = ( d A q k , [ n ] ⊙ M C ) T Q [ n ] + V [ n ] d S [ n + 1 ] \mathrm{d}\mathbf{K}_{[n]}=(\mathrm{d}\mathbf{A}_{qk,[n]}\odot\mathbf{M}_{C})^{\mathsf{T}}\mathbf{Q}_{[n]}+\mathbf{V}_{[n]}\mathrm{d}\mathbf{S}_{[n+1]} d K [ n ] = ( d A q k , [ n ] ⊙ M C ) T Q [ n ] + V [ n ] d S [ n + 1 ] .
On chip, compute d V [ n ] = A q k , [ n ] T d O [ n ] + K [ n ] ( d S [ n + 1 ] ) T \mathrm{d}\mathbf{V}_{[n]}=\mathbf{A}_{qk,[n]}^{\mathsf{T}}\mathrm{d}\mathbf{O}_{[n]}+\mathbf{K}_{[n]}(\mathrm{d}\mathbf{S}_{[n+1]})^{\mathsf{T}} d V [ n ] = A q k , [ n ] T d O [ n ] + K [ n ] ( d S [ n + 1 ] ) T .
On chip, accumulate d S [ n ] = d S [ n + 1 ] + d O [ n ] T Q [ n ] + d S [ n ] s r c \mathrm{d}\mathbf{S}_{[n]}=\mathrm{d}\mathbf{S}_{[n+1]}+\mathrm{d}\mathbf{O}_{[n]}^{\mathsf{T}}\mathbf{Q}_{[n]}+\mathrm{d}\mathbf{S}^{\mathrm{src}}_{[n]} d S [ n ] = d S [ n + 1 ] + d O [ n ] T Q [ n ] + d S [ n ] src .
Store d Q [ n ] , d K [ n ] \mathrm{d}\mathbf{Q}_{[n]},\mathrm{d}\mathbf{K}_{[n]} d Q [ n ] , d K [ n ] , and d V [ n ] \mathrm{d}\mathbf{V}_{[n]} d V [ n ] to HBM.
end for
Load tiles of d X [ n ] , S [ n ] + \mathrm{d}\mathbf{X}_{[n]},\mathbf{S}^{+}_{[n]} d X [ n ] , S [ n ] + , and S [ n + 1 ] − \mathbf{S}^{-}_{[n+1]} S [ n + 1 ] − from HBM to SRAM.
On chip, compute d W S = ∑ n = 1 N d X [ n ] T ( S [ n + 1 ] − S [ n ] + ) \mathrm{d}\mathbf{W}_{S}=\sum_{n=1}^{N}\mathrm{d}\mathbf{X}_{[n]}^{\mathsf{T}}(\mathbf{S}_{[n+1]}-\mathbf{S}^{+}_{[n]}) d W S = ∑ n = 1 N d X [ n ] T ( S [ n + 1 ] − S [ n ] + ) by tiled reduction.
return input, initial-state, and gate-parameter gradients.
Fused kernel implementation
GDN. The adapter retains GDN’s native projections, token gates, WY preparation, intra-chunk interaction, and output path. The fused state scan applies the boundary gate after the raw state of a complete chunk has been formed. Its backward pass either reads saved boundary states or recomputes them according to the configured path.
GDN-2. The native channel-wise WY preparation, intra-chunk interaction, and output kernel are retained. A persistent state program consumes the native transition factors, holds one key/value state tile, computes the boundary branch after a complete chunk, and writes the gated state. Its custom backward mirrors the state scan and can use saved boundary states or recomputation according to the configured path.
KDA. The adapter retains KDA’s gate, intra-chunk, output, and local backward kernels. It reuses the boundary state scan where the WY state interface matches GDN-2, while preserving the KDA-specific token transition.
Mamba-3. The boundary branch is integrated into the native SSM matrix-state scan and corresponding backward pass. Rotary phase, trapezoidal quantities, output gates, and auxiliary state recurrences remain unchanged. The one-token decode path advances a device-resident counter. Inactive rows perform no matrix-sized boundary work, while rows completing a C C C -token interval update the matrix and source cache.
Complexity and saved state
For sequence lengths L n L_n L n , the exact number of newly completed boundaries depends on incoming tail counters r n r_n r n and is
N b n d = ∑ n ⌊ r n + L n C ⌋ . (90) N_{\mathrm{bnd}}=\sum_n\left\lfloor\frac{r_n+L_n}{C}\right\rfloor. \tag*{(90)} N bnd = n ∑ ⌊ C r n + L n ⌋ . (90)
For linear attention layers, forward gate-function work is Θ ( N b n d H d v d k ) \Theta(N_{\mathrm{bnd}}H d_v d_k) Θ ( N bnd H d v d k ) for the projection and Θ ( N b n d H d v d k ) \Theta(N_{\mathrm{bnd}}H d_v d_k) Θ ( N bnd H d v d k ) for the element-wise operations. For Mamba-3, replace d k d_k d k by d s d_s d s . A decode cache adds one source matrix and one integer counter per enabled layer and sequence. Training stores or recomputes boundary states. backward scan also writes d X [ n ] \mathrm{d}\mathbf{X}_{[n]} d X [ n ] to HBM for the projection-gradient reduction. This reduction has the same asymptotic arithmetic cost as the forward projection.
FLOPs analysis
Counting convention. We count a multiply–add as two floating-point operations (FLOPs), so a dense ( m × k ) ( k × n ) (m \times k)(k \times n) ( m × k ) ( k × n ) product costs 2 m k n 2mkn 2 mk n FLOPs. Consider a sequence of length L L L , H H H recurrent heads, state dimensions d v × d k d_v \times d_k d v × d k , and chunk size C C C . The counts below describe the additional gate computation in one SDG-enabled layer; they exclude the unchanged base recurrence, input/output projections, and feed-forward network. We report the leading matrix-multiplication cost explicitly and group element-wise arithmetic into lower-order terms. Square roots and exponentials are evaluated once per state element in the forward gate; their hardware-dependent costs are not equated to those of an addition or multiplication.
Forward computation. At each completed boundary, the product Δ S W S T \Delta\mathbf{S}\mathbf{W}_{S}^{\mathsf{T}} Δ S W S T costs 2 H d v d k 2 2Hd_vd_k^2 2 H d v d k 2 FLOPs. Forming the state difference, applying the gain, evaluating the rate and gate, and scaling the state require O ( H d v d k ) O(Hd_vd_k) O ( H d v d k ) additional element-wise work. For an aligned sequence with C ∣ L C \mid L C ∣ L , there are L / C L/C L / C boundaries, giving
F S D G , f w d = 2 L H d v d k 2 C + O ( L H d v d k C ) , F S D G , f w d L = 2 H d v d k 2 C + O ( H d v d k C ) . (91) F_{\mathrm{SDG},\mathrm{fwd}} = \frac{2LHd_vd_k^2}{C} + O\left(\frac{LHd_vd_k}{C}\right), \qquad\frac{F_{\mathrm{SDG},\mathrm{fwd}}}{L} = \frac{2Hd_vd_k^2}{C} + O\left(\frac{Hd_vd_k}{C}\right). \tag*{(91)} F SDG , fwd = C 2 L H d v d k 2 + O ( C L H d v d k ) , L F SDG , fwd = C 2 H d v d k 2 + O ( C H d v d k ) . (91)
For arbitrary lengths or cached continuations, replace L / C L/C L / C by the number of completed boundaries: ⌊ L / C ⌋ \lfloor L/C \rfloor ⌊ L / C ⌋ for a fresh sequence, or N b n d N_{\mathrm{bnd}} N bnd from Eq. (90) for a batch with incoming tail counters. A partial final chunk does not trigger a boundary gate. Ordinary decoding steps perform no gate matrix multiplication; a step completing a boundary pays the full 2 H d v d k 2 2Hd_vd_k^2 2 H d v d k 2 projection cost. Thus, amortized cost and individual boundary-step cost differ by a factor of C C C for complete intervals. For the Mamba-3 matrix state, replace d k d_k d k by d s d_s d s .
Backward computation and recomputation. The gate derivatives require two matrix products: d X W S \mathrm{d}\mathbf{X}\mathbf{W}_{S} d X W S for the state gradients and d X T Δ S \mathrm{d}\mathbf{X}^{\mathsf{T}}\Delta\mathbf{S} d X T Δ S for the projection gradient. Each costs 2 H d v d k 2 2Hd_vd_k^2 2 H d v d k 2 FLOPs per boundary. The first product is shared by both state-gradient paths in Eqs. (88) and (89) ; it need not be evaluated twice. With saved gate intermediates, a forward and backward evaluation therefore costs 6 H d v d k 2 6Hd_vd_k^2 6 H d v d k 2 projection FLOPs per boundary. Recomputing X \mathbf{X} X once during backward, as in the fused gate path, adds another 2 H d v d k 2 2Hd_vd_k^2 2 H d v d k 2 . Element-wise derivatives and gain-gradient accumulation add lower-order work. Replaying the base recurrence to recover boundary states, further activation checkpointing, and the optimizer update are separate costs and are excluded from these projection counts.
Batch and model scaling. For a batch of B B B sequences of length L L L and M M M SDG-enabled layers with the same dimensions and chunk size, the leading added forward cost is 2 B M L H d v d k 2 / C 2BMLHd_vd_k^2/C 2 B M L H d v d k 2 / C . The corresponding forward-plus-backward projection cost is 6 B M L H d v d k 2 / C 6BMLHd_vd_k^2/C 6 B M L H d v d k 2 / C with saved intermediates, or 8 B M L H d v d k 2 / C 8BMLHd_vd_k^2/C 8 B M L H d v d k 2 / C with one gate recomputation. For heterogeneous layers, sum each layer’s count instead of multiplying by M M M . If d k = d v = d d_k=d_v=d d k = d v = d , the forward cost simplifies to
F S D G , f w d m o d e l = 2 B M L H d 3 C + O ( B M L H d 2 C ) . (92) F_{\mathrm{SDG},\mathrm{fwd}}^{\mathrm{model}} = \frac{2BMLHd^3}{C} + O\left(\frac{BMLHd^2}{C}\right). \tag*{(92)} F SDG , fwd model = C 2 B M L H d 3 + O ( C B M L H d 2 ) . (92)
Only layers using SDG contribute to this additional cost, including in hybrid models.
Scaling and measured efficiency. For fixed head dimensions and C C C , the additional FLOPs grow linearly with the number of tokens, and their amortized value decreases as 1 / C 1/C 1/ C . This does not make C C C a cost-only tuning parameter: changing it also changes when the model applies decay. The relative arithmetic overhead is F S D G / F b a s e F_{\mathrm{SDG}}/F_{\mathrm{base}} F SDG / F base under the same counting scope, and cannot be inferred from the added parameter count alone because gate parameters are used once per boundary. Nor does a FLOP ratio predict a latency ratio. The gate runs in the sequential state scan; matrix size, Tensor Core utilization, register pressure, and memory traffic affect its runtime. Fusion avoids materializing forward gate intermediates in HBM, whereas backward recomputation and the projection-gradient reduction introduce additional work and traffic. The end-to-end throughput and latency measurements in § 6 complement these arithmetic counts.