Sam Babichenko

Reading notes / Deep Learning Alchemy

Signal propagation in time

From Lecture 8 of Stanford CS 312 Deep Learning Alchemy (Fall 2026), taught by Tatsunori Hashimoto and Suhas Kotha

slides quiz answers assignment code

Sequence layer
xsx_sinput of a sequence layer at position ss
yty_toutput of a sequence layer at position tt
JtsJ_{ts}Jacobian Jts=∂yt/∂xsJ_{ts}=\partial y_t/\partial x_s of the output at position tt with respect to the input at position s≤ts\le t (the lecture writes MtsM_{ts})
TTsequence length
ddmodel width, the size of each position's vector (512 in the course's models)
Recurrent cells
hth_thidden state of a recurrent layer after reading position tt; ht=tanh⁡(at)h_t=\tanh(a_t) in the tanh RNN
ata_tpreactivation of the tanh RNN, at=Wxxt+Whht−1+ba_t=W_xx_t+W_hh_{t-1}+b
WxW_xinput weights of the RNN, applied to the input xtx_t in at=Wxxt+Whht−1+ba_t=W_xx_t+W_hh_{t-1}+b
WhW_hrecurrent weights of the RNN, applied to the previous state ht−1h_{t-1} at every step
bbbias of the RNN preactivation at=Wxxt+Whht−1+ba_t=W_xx_t+W_hh_{t-1}+b
γ\gammabound on the absolute value of the activation's derivative (1 for tanh, 1/4 for the sigmoid)
σmax⁡\sigma_{\max}largest singular value of a matrix, its operator norm
ctc_tLSTM memory cell, ct=ft⊙ct−1+it⊙gtc_t=f_t\odot c_{t-1}+i_t\odot g_t; in the residual-in-time RNN, the tanh candidate in ht=ht−1+cth_t=h_{t-1}+c_t
gtg_tLSTM candidate write, scaled by the input gate iti_t before it is added to the cell ctc_t
iti_tLSTM input gate in (0,1)d(0,1)^d, which scales the candidate write gtg_t
ftf_tLSTM forget gate, which scales the old cell in ct=ft⊙ct−1+it⊙gtc_t=f_t\odot c_{t-1}+i_t\odot g_t
oto_tLSTM output gate, in ht=ot⊙tanh⁡(ct)h_t=o_t\odot\tanh(c_t)
ztz_tGRU write gate in (0,1)d(0,1)^d, in ht=(1−zt)⊙ht−1+zt⊙h~th_t=(1-z_t)\odot h_{t-1}+z_t\odot\tilde h_t
h~t\tilde h_tGRU tanh candidate state, mixed into hth_t with weight ztz_t
⊙\odotelementwise product
LTL_Tnext-token loss at the last position TT only
Lˉ\bar Lmean next-token loss over all positions, Lˉ=T−1∑s=1TLs\bar L=T^{-1}\sum_{s=1}^TL_s
Attention
qtq_tquery vector at position tt, of dimension dkd_k
ksk_skey vector at position ss, of dimension dkd_k
vsv_svalue vector at position ss, of dimension dvd_v
dkd_kdimension of keys and queries (64 in the capacity example)
dvd_vdimension of values
AtsA_{ts}attention weight of output position tt on position ss, Ats=eqt⊤ks/dk/∑r≤teqt⊤kr/dkA_{ts}=e^{q_t^\top k_s/\sqrt{d_k}}/\sum_{r\le t}e^{q_t^\top k_r/\sqrt{d_k}} for softmax attention
stss_{ts}raw attention score of position tt on position ss, before a softmax or sigmoid turns it into a weight
ε\varepsilonsink threshold (0.3, Gu et al.); a head counts as a sink when its average attention to the first token exceeds it
Matrix-state layers
StS_tdv×dkd_v\times d_k matrix state of a linear-attention-style layer after position tt, read as yt=Stqty_t=S_tq_t
αt\alpha_tdecay in (0,1)(0,1) computed from the input, which multiplies the old state, as in Mamba-2's St=αtSt−1+vtkt⊤S_t=\alpha_tS_{t-1}+v_tk_t^\top
βt\beta_twrite strength in (0,1)(0,1), the delta rule's step size in St=St−1−βt(St−1kt−vt)kt⊤S_t=S_{t-1}-\beta_t(S_{t-1}k_t-v_t)k_t^\top
PPnumber of key-value pairs stored in a linear memory S=∑iviki⊤S=\sum_iv_ik_i^\top
KKmatrix whose columns are the stored keys kik_i
VVmatrix whose columns are the stored values viv_i
K+K^+pseudo-inverse of the key matrix KK; the least-squares memory is S=VK+S=VK^+

Context. A recurrent network applies the same weights at every step to a fresh input, so unrolled across a sequence it is a deep network with tied weights. It therefore inherits the vanishing and exploding gradients of depth. As Lecture 8 of Stanford's CS 312, Deep Learning Alchemy (Hashimoto and Kotha, Fall 2026), recounts, RNNs and LSTMs were for years as hard to train well as deep plain networks. The lecture asks what carries over from signal propagation in depth to propagation in time. Its unifying object is the sequence layer's generalized Jacobian, whose blocks the Jacobian ∂yt/∂xs\partial y_t/\partial x_s of the output at position tt with respect to the input at position s≤ts\le t, a d×dd\times d matrix for layer width dd; the lecture writes MtsM_{ts} for inputs xsx_s and outputs yty_t form a block lower-triangular matrix. Three properties of this matrix organize sequence architectures: how well a signal travels from the input at one position ss to the output at a later position tt, that is, whether the Jacobian block JtsJ_{ts} stays large; a recurrence loses it through long products of per-step Jacobians, while attention keeps a direct path, how one output yty_t combines information from many earlier inputs xsx_s, for example through attention weights AtsA_{ts}, which must sum to one, and how many earlier inputs a layer can still recover at a given position; a fixed-size state caps it, at about dkd_k key-value pairs for a linear memory read with its keys. Retention measures how well a signal travels from one past position to a later one, while mixing describes how one output combines many inputs. Capacity counts how many past inputs remain recoverable at time tt.

Each architecture family runs into a different one of these three limits. Recurrences fix retention the same way deep networks do, through an additive path in the state; the LSTM memory cell is a residual connection in time. One difference remains: the layer must decide token by token what to keep and what to erase, so input-dependent gates work where depth-style initialization tricks do not. Attention removes the retention bottleneck by linking every output directly to every input, shifting the pressure to mixing. Because softmax weights must sum to one, an idle head dumps its weight onto a sink token unless given an explicit no-op. Matrix-state recurrences (linear attention, Mamba-2, DeltaNet, and Gated DeltaNet) keep constant cost per token, so capacity becomes the binding constraint. A fixed state stores only so many key-value pairs, and the update rule (decay, selective overwrite, or both) decides which pairs survive. Modern hybrids such as Qwen3-Next pair three gated matrix-state layers with one attention layer.

Setting. Assignment 4 compares three architectures trained with one recipe: model width d=512d=512, vocabulary 4,096, context length 1,024 tokens, 614.4M training tokens, and Adam with decoupled weight decay; each coordinate moves by the learning rate times a running average of its gradient (the momentum), divided by the square root of a running average of its squared gradient, so every coordinate takes a step of similar size; weight decay then shrinks every weight by a small fixed fraction per step, applied to the weights directly instead of through that division (Loshchilov and Hutter, 2019). The transformer uses 8 blocks with normalizing each sublayer's input and adding the sublayer's output to a stream that is itself never normalized. Reading note: Signal propagation in depth, rotary position embedding: queries and keys are rotated by angles proportional to their positions, so attention scores depend on relative position, and gated MLPs. The modern tanh RNN uses 4 blocks, each pairing a tanh recurrence and an MLP with depth residuals and pre-norm layer normalization: subtract a vector's mean across its coordinates, divide by their standard deviation, then apply a learned gain and bias. The gated recurrent unit: a recurrent cell whose state is a gated average of its previous value and a tanh candidate, ht=(1−zt)⊙ht−1+zt⊙h~th_t=(1-z_t)\odot h_{t-1}+z_t\odot\tilde h_t (Cho et al., 2014; Chung et al., 2014) shares that same 4-block depth stack.

Vanishing and exploding gradients in RNNs. Because a recurrent layer multiplies by the same weight matrix at every step, long-range sensitivities vanish or explode exponentially with sequence length. Write the hidden state of a recurrent layer after reading position tt, carried to the next position for the hidden state of a tanh RNN, ht=tanh⁡(at)h_t=\tanh(a_t), with preactivation at=Wxxt+Whht−1+ba_t=W_xx_t+W_hh_{t-1}+b from input weights WxW_x, recurrent weights WhW_h, and bias bb. By the chain rule across t−st-s steps,∂ht∂hs=∏r=s+1tdiag(tanh⁡′(ar)) Wh.\frac{\partial h_t}{\partial h_s}=\prod_{r=s+1}^{t}\mathrm{diag}\big(\tanh'(a_r)\big)\,W_h.Pascanu et al. (2013) bound this product when the activation's derivative has magnitude at most γ\gamma (γ=1\gamma=1 for tanh, 1/41/4 for the sigmoid). With the largest singular value of a matrix, its operator norm the largest singular value, ∥∂ht/∂hs∥≤(γ σmax⁡(Wh))t−s\|\partial h_t/\partial h_s\|\le(\gamma\,\sigma_{\max}(W_h))^{t-s}. So σmax⁡(Wh)<1/γ\sigma_{\max}(W_h)\lt 1/\gamma guarantees exponential vanishing, and σmax⁡(Wh)>1/γ\sigma_{\max}(W_h)>1/\gamma is necessary for explosion. Because the same WhW_h repeats in every factor, the stable window is razor thin. Exploding gradients appear as steep walls in the loss surface where one update throws the weights far away. Pascanu et al. contain them with replacing the gradient gg by τg/∥g∥\tau g/\|g\| whenever ∥g∥>τ\|g\|>\tau, for a threshold τ\tau, which caps the step at a wall, though clipping cannot rescue vanishing gradients. In the 4-block tanh RNN, this decay shows directly in gradients with respect to the first layer's hidden states h1,th_{1,t}. The gradient of the last-token loss the next-token loss at the last position TT of the sequence only passes back through T−tT-t Jacobians and decays exponentially toward the start of the sequence. The mean loss the mean next-token loss over all positions, Lˉ=T−1∑s=1TLs\bar L=T^{-1}\sum_{s=1}^TL_s, with LsL_s the loss at position ss supervises every position directly and leaves a roughly flat gradient profile.

The LSTM cell and input-dependent gates. The LSTM's cell is a residual connection in time, and input-dependent gates make it usable over long sequences. Hochreiter and Schmidhuber (1997) replaced repeated multiplication with an additive memory cell ct=ct−1+it⊙gtc_t=c_{t-1}+i_t\odot g_t, where ⊙\odot is the elementwise product. An input gate it∈(0,1)di_t\in(0,1)^d scales a candidate write gtg_t, and an output gate oto_t reads ht=ot⊙tanh⁡(ct)h_t=o_t\odot\tanh(c_t). Apart from the gates' own dependence on the past, ∂ct/∂ct−1=I\partial c_t/\partial c_{t-1}=I, so gradients carry back over 1,000 steps and more. Without a way to clear old writes, though, the cell grows unchecked over long sequences, much like an unnormalized residual stream in depth. Gers et al. (2000) added a forget gate ft∈(0,1)df_t\in(0,1)^d, giving ct=ft⊙ct−1+it⊙gtc_t=f_t\odot c_{t-1}+i_t\odot g_t and letting the model shrink its state token by token instead of normalizing it. The GRU merges both gates into one write gate zt∈(0,1)dz_t\in(0,1)^d that blends the old state with a tanh candidate h~t\tilde h_t, giving ht=(1−zt)⊙ht−1+zt⊙h~th_t=(1-z_t)\odot h_{t-1}+z_t\odot\tilde h_t. Large architecture sweeps show little else is essential. Greff et al. (2017) found only the forget gate and output tanh indispensable. Searching about 10,000 variants, Jozefowicz et al. (2015) found that initializing the forget-gate bias to 1 lets the LSTM match the GRU, with nothing clearly better. Applying depth tricks to time confirms that initialization alone falls short. Orthogonal or unitary WhW_h, critical initialization, and fixed diagonal linear recurrences such as structured state space sequence model: a linear recurrence ht=Aht−1+Bxth_t=Ah_{t-1}+Bx_t with a fixed, specially structured AA and linear recurrent unit: the linear recurrence ht=Aht−1+Bxth_t=Ah_{t-1}+Bx_t of S4, with a fixed complex diagonal AA all solve long toy tasks of 784 to over 1,000 steps. None improved language models until a recurrent state-space layer, a linear recurrence like S4's whose decay and write strength are computed from the current input, so the layer can choose per token what to keep; it was the first such recurrence to improve language models (Gu and Dao, 2023) (Gu and Dao, 2023) made the decay depend on the input.

Controlled tests on the 4-block RNN. Changing only the time update in the 4-block RNN, while holding depth residuals, LayerNorm, and MLPs fixed, isolates what each mechanism buys. A plain residual in time, ht=ht−1+cth_t=h_{t-1}+c_t with ctc_t the tanh candidate, adds a write at every step with no way to erase one, so the state norm grows across the sequence. The course's answer slides note that this unscaled path also turns vanishing early-step gradients into exploding ones. Dividing hth_t by its RMS after each step restores stability, yet still trails the plain tanh baseline. The course reads that gap as the cost of stripping away input-dependent control over the state's norm. Replacing the GRU's learned write gate with one tuned constant zz also hurts substantially. In the trained GRU runs, learned write gates vary across layers and inputs and often sit near 0 or 1, with about 40% of them outside [0.1,0.9][0.1,0.9]. Switching writes on and off per token matters beyond the average gate value.

Context use and positional structure. Recurrent language models use a short window of context, while attention uses all of it. Khandelwal et al. (2018) found that LSTM language models effectively use about 200 tokens of context and rely on word order only within roughly the last 50. Attention links every pair of positions in one hop instead of t−st-s recurrent steps. Kaplan et al. (2020) found that transformers keep lowering per-token loss across the whole context window, whereas LSTMs plateau after fewer than 100 tokens, and the gap widens with scale. Assignment 4 tests context use directly on the final target, comparing the full 1,023-input loss against keeping only the most recent KK inputs plus the first token. Recurrent states restart while transformer positions stay intact. Truncating hurts the transformer most, the tanh RNN least, and the GRU in between. The two families also get order from different sources. A recurrence encodes position through its step-by-step update, while a transformer sees order only through its causal mask and positional encoding. Adding RoPE therefore helps the transformer far more than its analogue helps the RNN.

Attention reads directly, and idle heads park weight on a sink. In a causal attention head, position tt forms a query qt∈Rdkq_t\in\mathbb R^{d_k}, scores past keys ks∈Rdkk_s\in\mathbb R^{d_k}, and returns a weighted sum of values vs∈Rdvv_s\in\mathbb R^{d_v}:yt=∑s≤tAtsvs,Ats=eqt⊤ks/dk∑r≤teqt⊤kr/dk.\begin{aligned}y_t&=\sum_{s\le t}A_{ts}v_s,\\A_{ts}&=\frac{e^{q_t^\top k_s/\sqrt{d_k}}}{\sum_{r\le t}e^{q_t^\top k_r/\sqrt{d_k}}}.\end{aligned}A head needs three read behaviors: sharp lookup of one token, broad averaging across many tokens, and a no-op when it has nothing useful to read, which is common in upper layers. Nonnegative weights summing to one handle the first two naturally, yet force an idle head to park its mass somewhere harmless. Trained models routinely carry idle heads and build such a dumping ground. In BERT, over half of middle-layer attention lands on [SEP] (Clark et al., 2019), and in a translation transformer, pruning 38 of 48 heads costs only 0.15 BLEU (Voita et al., 2019). In autoregressive language models past the first two layers, most heads attend heavily to the first token (Xiao et al., 2023). That token's value vector is near zero, so attending to it contributes almost nothing (Gu et al., 2025), making it an a token, usually the first, that receives a large share of attention while contributing almost nothing to the output. Sinks matter immediately at serving time. In Xiao et al.'s sliding-window cache test, evicting the first token spikes perplexity to 5,158. Keeping four initial tokens alongside the window holds perplexity at 5.40, matching the 5.43 of recomputing the window from scratch. Sun et al. (2024) link sinks to a few hidden-state coordinates, usually on the first token, that are orders of magnitude larger than the rest, which vanish once heads receive an explicit key and value bias.

The sum-to-one constraint causes the sink. To test whether softmax normalization itself drives sinks, Gu et al. (2025) pre-train Llama-style models of about 60M non-embedding parameters on 5B tokens of the a large open English text dataset assembled from 22 sources, alongside 1B-parameter runs. They count a head as a sink when its mean attention to the first token exceeds the threshold on a head's average attention to the first token above which Gu et al. count the head as a sink, and report the fraction of such heads as the sink measure. Sinks emerge only after sufficient optimization on enough data. The first token acts as an implicit key bias: its key has small norm yet aligns with queries, while its value stays small. Adding a learned key bias to every head absorbs the sink, whereas a value bias alone does not. Changing only how raw scores stss_{ts} map to weights settles the mechanism:
Sink measure and validation loss (Gu et al., 2025)
WeightsSinkLoss
Softmax18.2%3.73
Sigmoid, divided by the row sum30.2%3.74
Sigmoid σ(sts)\sigma(s_{ts}), no normalization0.4%3.70
1B parameters
Softmax45.1%3.07
Sigmoid, no normalization2.5%3.10
Dividing sigmoid weights by their sum brings the sink back; dropping normalization nearly eliminates it at comparable loss.

Practical fixes give a head an explicit no-op. Every modern fix relaxes the forced sum-to-one write onto real tokens. One option adds a learned sink logit to the softmax denominator so weights over real tokens can sum to less than one, as in a family of open-weight language models released in 2025, whose attention adds an extra learned logit to the softmax denominator so that a head's weights can sum to less than one. Other fixes add a learnable zero-value sink token or use unnormalized sigmoid attention. Another puts a sigmoid gate on each head's output (Qiu et al., 2025; used in Qwen3-Next), which lowered the average attention on the first token from 46.7% to 4.8%.

Matrix-state recurrences: linear attention and Mamba-2. Full attention's KV cache grows linearly with sequence length, so constant-cost alternatives compress past tokens into a fixed matrix state. Removing the softmax yields attention with the softmax removed (up to a feature map and normalizer), so that it is the recurrence St=St−1+vtkt⊤S_t=S_{t-1}+v_tk_t^\top, yt=Stqty_t=S_tq_t on a fixed-size matrix state (Katharopoulos et al., 2020). Reading note: Softmax attention as a sum of RNNs. Reassociating the product as (QK⊤)V=Q(K⊤V)(QK^\top)V=Q(K^\top V) turns it into a recurrence over a dv×dkd_v\times d_k matrix state the state of a linear-attention-style layer after position tt: a dv×dkd_v\times d_k matrix that stores value-key associations (a separate note treats softmax attention as a sum of RNNs):St=St−1+vtkt⊤,yt=Stqt.\begin{aligned}S_t&=S_{t-1}+v_tk_t^\top,\\y_t&=S_tq_t.\end{aligned}Training runs the parallel matrix product, while inference steps the recurrence at constant cost per token. Plain linear attention only adds outer products and never forgets. a recurrent layer with a matrix state like linear attention's, St=αtSt−1+vtkt⊤S_t=\alpha_tS_{t-1}+v_tk_t^\top, whose scalar decay αt∈(0,1)\alpha_t\in(0,1) is computed from the input and forgets every stored pair at the same rate (Dao and Gu, 2024). Reading note: Softmax attention as a sum of RNNs therefore multiplies the old state by an input-dependent scalar decay αt∈(0,1)\alpha_t\in(0,1), giving St=αtSt−1+vtkt⊤S_t=\alpha_tS_{t-1}+v_tk_t^\top plus a skip term. That decay clears room by shrinking every stored pair at the same rate.

Selective overwrite: DeltaNet and Gated DeltaNet. Uniform decay shrinks useful memories alongside stale ones. a recurrent layer with a matrix state like linear attention's, updated by the delta rule, St=St−1+βt(vt−St−1kt)kt⊤S_t=S_{t-1}+\beta_t(v_t-S_{t-1}k_t)k_t^\top; it overwrites the value stored under key ktk_t instead of adding to it, with write strength βt∈(0,1)\beta_t\in(0,1) (Schlag et al., 2021) (Schlag et al., 2021; Yang et al., 2024, explained in Yang's blog post) instead updates StS_t with one gradient step of size βt∈(0,1)\beta_t\in(0,1) on the current pair's squared retrieval error 12∥Skt−vt∥2\tfrac12\|Sk_t-v_t\|^2:St=St−1−βt(St−1kt−vt)kt⊤=St−1(I−βtktkt⊤)+βtvtkt⊤.\begin{aligned}S_t&=S_{t-1}-\beta_t(S_{t-1}k_t-v_t)k_t^\top\\&=S_{t-1}(I-\beta_tk_tk_t^\top)+\beta_tv_tk_t^\top.\end{aligned}Here St−1ktS_{t-1}k_t is the value currently stored under ktk_t, so the update erases it along ktk_t and writes vtv_t. For a unit-norm key with βt=1\beta_t=1, reading back at ktk_t returns vtv_t exactly. Plain linear attention takes the same gradient step on the linear loss −⟨Skt,vt⟩-\langle Sk_t,v_t\rangle, which can only add. Gated DeltaNet combines both updates, St=αtSt−1(I−βtktkt⊤)+βtvtkt⊤S_t=\alpha_tS_{t-1}(I-\beta_tk_tk_t^\top)+\beta_tv_tk_t^\top, and gives a clean no-op at αt=1\alpha_t=1, βt=0\beta_t=0. One step for a single head in PyTorch:
# S: (d_v, d_k) state; k: (d_k,) unit-norm key; v: (d_v,); q: (d_k,)
# alpha, beta: scalars in (0, 1) computed from the current token
old = S @ k                                    # value stored under k
S = alpha * (S - beta * torch.outer(old, k))   # decay, erase along k
S = S + beta * torch.outer(v, k)               # write the new value
y = S @ q                                      # read with the query

Long-context retrieval trades decay against overwrite. Lecture 8's table of 1.3B models shows why neither forgetting rule suffices alone. On a passkey hidden in synthetic filler at 8K tokens, decay alone (Mamba-2) succeeds 30.4% of the time, the delta rule alone (DeltaNet) reaches 98.8%, and Gated DeltaNet reaches 91.8%. On a number hidden in essays at 4K tokens, the first two swap places: Mamba-2 reaches 56.2%, DeltaNet drops to 18.6%, and Gated DeltaNet reaches 92.2%. Uniform decay discards long-lived memories inside filler, while the delta rule alone writes a trace on every varied token of real text and clogs the state. Adding the decay gate lets Gated DeltaNet clear stale noise while keeping selective overwrite.

State capacity and nonlinear readouts. State geometry sets a hard ceiling on how many past items survive. An RNN or LSTM carries a vector of dd numbers, where growing dd costs quadratic compute. Matrix-state layers carry a dv×dkd_v\times d_k matrix decoupled from model width, while attention's KV cache stores 2d2d numbers per past token and grows linearly with tt. For a linear memory S=∑i=1Pviki⊤S=\sum_{i=1}^Pv_ik_i^\top holding the number of key-value pairs stored in a memory pairs, reading with key kjk_j splits into signal and cross-talk:Skj=vj (kj⊤kj)⏟signal+∑i≠jvi (ki⊤kj)⏟interference.\begin{aligned}Sk_j&=\underbrace{v_j\,(k_j^\top k_j)}_{\text{signal}}\\&\quad+\underbrace{\textstyle\sum_{i\ne j}v_i\,(k_i^\top k_j)}_{\text{interference}}.\end{aligned}With random unit keys and values in dkd_k dimensions, each cross term ki⊤kjk_i^\top k_j has size about 1/dk1/\sqrt{d_k}. Summing P−1P-1 random terms gives interference of norm about P/dk\sqrt{P/d_k}, which matches the signal near P=dkP=d_k (64 pairs at dk=64d_k=64; a simulation here agrees). Stack the viv_i and kik_i as columns of VV and KK with pseudo-inverse K+K^+; the least-squares memory S=VK+S=VK^+ is the optimal linear memory and recovers any dkd_k linearly independent keys exactly. The delta rule takes an online gradient step toward VK+VK^+, though one pass falls short. In a check here with βt=1\beta_t=1 and 16 random unit keys in 64 dimensions, mean read-back error is about 0.33 times the stored value's norm. Nonlinear readouts hold far more. In the lecture's calculation (after Wang, 2026), a squared-ReLU MLP stores about 2dk2/3≈2,7002d_k^2/3\approx2{,}700 pairs, and softmax over a cache at inverse temperature dk\sqrt{d_k} separates about e14≈1.2e^{14}\approx1.2 million.

Copying, recall probes, and hybrid architectures. Empirical recall tests line up with these capacity gaps. Jelassi et al. (2024) found that transformers learn string copying from far fewer examples than state-space models, generalize better to longer strings, and copy better than perplexity-matched pretrained Mamba models. Synthetic probes such as multi-query associative recall: a context of key-value pairs followed by queries for several of the keys, scored on recalling their values map accuracy against state size, though optimization quirks can distort them. Okpekpe and Orvieto (2025) found that attention solves MQAR across almost any learning rate, while Mamba and a sequence layer built from long convolutions whose filters are generated by a small network, interleaved with elementwise gates (Poli et al., 2023) learn it only inside a narrow learning-rate window that standard sweeps can miss. In their runs, recurrent layers also gained most from width, while attention gained most from depth. In practice, models mix both families: Qwen3-Next places three Gated DeltaNet layers per attention layer for fast inference, though controlled ablations of the mixing ratio remain scarce.

Limits. Most numbers above come from individual papers with distinct setups. The head-pruning, sink, and retrieval comparisons each draw on a single table, and the 4-block RNN measurements are single runs. The sink measure depends on its threshold ε\varepsilon, and for unnormalized sigmoid attention Gu et al. compute it from scores normalized after the fact. The capacity estimates assume random keys and one read per key.

Terms

generalized Jacobian
Jts=∂yt/∂xsJ_{ts}=\partial y_t/\partial x_s, s≤ts\le t: retention (one pair), mixing (one row), capacity (how many inputs survive)
RNN gradient
∏rdiag(tanh⁡′(ar))Wh\prod_r\mathrm{diag}(\tanh'(a_r))W_h; norm at most (γ σmax⁡(Wh))t−s(\gamma\,\sigma_{\max}(W_h))^{t-s}
gradient clipping
rescale the gradient to a threshold norm when it exceeds it; fixes exploding, not vanishing
LSTM cell
ct=ft⊙ct−1+it⊙gtc_t=f_t\odot c_{t-1}+i_t\odot g_t: a residual in time with a learned forget gate
GRU
ht=(1−zt)⊙ht−1+zt⊙h~th_t=(1-z_t)\odot h_{t-1}+z_t\odot\tilde h_t; learned gates near 0 or 1 matter
attention sink
first token that takes much of a head's attention with a near-zero value: a no-op under sum-to-one weights
sink fixes
sink logit, learned sink token, unnormalized sigmoid attention, per-head output gate
linear attention
St=St−1+vtkt⊤S_t=S_{t-1}+v_tk_t^\top, yt=Stqty_t=S_tq_t
Mamba-2
St=αtSt−1+vtkt⊤S_t=\alpha_tS_{t-1}+v_tk_t^\top: input-dependent decay
delta rule
St=St−1−βt(St−1kt−vt)kt⊤S_t=S_{t-1}-\beta_t(S_{t-1}k_t-v_t)k_t^\top: erase the old value along ktk_t, write the new
Gated DeltaNet
St=αtSt−1(I−βtktkt⊤)+βtvtkt⊤S_t=\alpha_tS_{t-1}(I-\beta_tk_tk_t^\top)+\beta_tv_tk_t^\top
linear-memory capacity
interference about P/dk\sqrt{P/d_k} for random unit keys: about dkd_k pairs; nonlinear readouts hold far more

Sources

Lecture 8, “Architecture 1: Signal propagation in time” (Oct 27, 2026), of Stanford CS 312 Deep Learning Alchemy, Fall 2026. Taught by Tatsunori Hashimoto and Suhas Kotha; course staff Kaiyue Wen and Tristan Thrush (CAs).

Course site Lecture slides Online quiz Quiz answers Assignment Assignment code

The lessons, experiments, figures and quiz problems in this note are the course's, shown here with the instructors' permission.

Connected notes

  • Linear attention's state is a running sum of key-value products that never forgets. Of Mamba-2's components added one at a time to a 300M model, a data-dependent decay of that sum and a short convolution carry nearly all the gain. Test loss goes from 3.13 to 2.88 with the decay alone, 2.93 with the convolution alone and 2.77 with both, while the other components move it by 0.07 or less.

  • PreNorm's unweighted running sum grows with depth and dilutes every earlier output, so Attention Residuals replace it with softmax-weighted averages over earlier block sums, bounding the mixed input by max⁡jRMS(vj)\max_j\mathrm{RMS}(v_j) while keeping direct shortcuts across depth without the matrix-product instability of multi-stream mixing.

  • Because every layer reads the residual stream linearly and adds its output back, an attention-only transformer expands directly into a sum of independent paths, linking any earlier write matrix WO1W_O^1 directly to any later read matrix WI2W_I^2 through virtual weights WI2WO1W_I^2W_O^1 across intervening layers.

  • The ordinary residual stream already carries early layers forward. In an 8-layer model a value shortcut from layer 2 or later adds little, because H1H_1 is reachable through the stream, and it helps once the residual chain is started at H2H_2. Deep layers want the first-layer shortcut most, so a direct path helps where the single running sum no longer carries that information cleanly.

Threads