Summary
The second architecture lecture, covering two advanced departures from the vanilla transformer: linear-time alternatives to attention, and mixture of experts. The first half modifies the attention block to escape quadratic dependence on sequence length; the second half modifies the MLP block to add parameters without adding FLOPs. Both are framed as responses to the same pressure — context windows and model sizes are growing faster than compute budgets. The lecture closes by walking through the DeepSeek v1/v2/v3 MoE lineage as a worked example of how these ideas compose in a real model.
Key Takeaways
- Feed-forward cost grows linearly with sequence length while attention grows quadratically, so attention overtakes the MLP as the dominant cost at long context; FlashAttention is a constant-factor systems fix (roughly 2x, and it avoids materializing the attention matrix) but does not change the asymptotics.
- Linear attention drops the softmax so that matrix multiplication can be reassociated from (QK^T)V to Q(K^TV), changing the cost from n²·d_k to n·d_k·d_v; the reassociated form is algebraically an RNN with a fixed-size state, giving a parallel form for training and a recurrent form for cheap inference. Dropping the softmax is the lossy step; the linear-to-recurrent equivalence after that is exact.
- Mamba-2 adds an input-dependent gate that modulates how much state carries forward. Gated DeltaNet adds a second gate controlling whether current information is written at all, plus a delta-rule projector (I − β_t k_t k_t^T) that erases the current key direction before writing — the same update that appears independently in fast-weight programming and test-time training.
- The rule of thumb for these recurrences: as long as the gates depend only on the current input and not on the state, the parallel/serial duality survives, which is what makes them trainable at scale.
- Every deployed design is a hybrid, not pure linear attention — MiniMax M1 uses 7:1 linear-to-softmax layers, Qwen Next / Qwen 3.5 use 3:1 gated DeltaNet-to-attention. Ablations show little loss at low hybrid ratios and clear degradation on long-context retrieval and QA as the ratio approaches pure RNN.
- DeepSeek Sparse Attention (v3.2) takes an orthogonal route: a lightweight indexer scores tokens via ReLU’d qk inner products, top-k selects a small subset, and full attention runs only on that subset. It is still quadratic in the indexer, but the indexer can run in low precision and low dimension, and it is bolted on during long-context extension rather than trained from scratch. GLM adopted the same approach.
- MoE replaces one MLP with many, routing each token to top-k experts, so parameters scale while per-token FLOPs stay fixed. Token-choice top-k routing with a simple learned inner-product router is the consensus design; expert choice, hashing, RL/bandit routing, and optimal linear assignment all exist but lost out.
- The DeepSeekMoE design — many fine-grained experts plus always-on shared experts that bypass the router — became the standard others copied. OLMoE’s controlled ablations agree that fine-grained experts help but disagree on the value of shared experts.
- Training is the hard part: top-k routing is non-differentiable and unchosen experts give no signal, so a rich-get-richer dynamic collapses routing onto a few experts. The fix in practice is not RL or stochastic exploration but an auxiliary load-balancing loss whose gradient pushes down probability mass on popular experts proportional to their token share; removing it sends nearly all tokens to two experts. DeepSeek adds device-level balancing for utilization, and a router z-loss or FP32 router for softmax stability.
Extracted Notes
- None yet.