Stanford CS336: Language Modeling from Scratch Lecture 4 — Attention Alternatives & Mixtures of Experts

Breaking Quadratic Sequence Cost and Dense FFN Compute
Late 2026 Edition

Two Scaling Bottlenecks in Dense Transformers

Part 1: Attention Alternatives
Context lengths reached 1M tokens, where $O(n^2)$ attention and KV cache dominate.
  • Linear attention & recurrent duality
  • Mamba-2 gating & Gated DeltaNet
  • Hybrids, MLA & sparse attention (DSA, QSA, MSA, CSA2)
Part 2: Mixtures of Experts (MoE)
Dense FFNs tie total parameter count directly to per-token FLOPs.
  • Sparse routing, granularity & shared experts
  • Load balancing, FP32 routers & z-loss
  • Expert parallelism, grouped GEMMs, LatentMoE & online replication

Part 3 synthesizes both with late-2026 frontier models (DeepSeek-V4.1-Flash, Kimi K3, Qwen3.8-Flash-Next, GLM-5.3) plus mHC and MTP.

Why Attention Alternatives?

Sequence length n Step latency Attention: O(n²d) FFN: O(nd²) 16K → 1M
  • Context windows grew by three orders of magnitude
    • Historical baselines: a few thousand tokens (GPT-3, 2020)
    • 2026 frontier: 1M context is standard (DeepSeek-V4.1-Flash, Kimi K3, MiniMax-M3)
  • Standard softmax attention scales as $O(n^2 d)$ in prefill FLOPs
  • During decode, the KV cache grows linearly with $n$ and turns generation memory-bandwidth-bound

Goal: keep long-range recall while bringing both prefill FLOPs and decode KV footprint under control.

The Basic Toolkit — and Its Ceiling

Sliding Window band width w ≪ n Local + Global Stack Global Attention Local Attention Local Attention Local Attention Global Attention Systems engineering (FlashAttention) Avoids HBM n × n matrix & OOM, still O(n²) FLOPs
  • Local + global interleaving: most layers attend only inside a sliding window; periodic layers attend globally
  • IO-aware kernels (FlashAttention): tile $Q, K, V$ in SRAM so naive PyTorch OOMs vanish and hardware utilization rises sharply
  • Why it is not enough: global layers still cost $O(n^2)$ FLOPs and cache $O(n)$ KV pairs

To achieve asymptotic savings at 1M context, we change the sequence mixer itself: linear/recurrent layers or dynamic sparse attention.

Linear Attention: The Associativity Trick

Standard attention for $Q, K \in \mathbb{R}^{n \times d_k}$ and $V \in \mathbb{R}^{n \times d_v}$ computes $\mathrm{Attn}(Q, K, V) = \rho(QK^\top) V$, costing $n^2 d_k + n^2 d_v$.

When $\rho$ is the identity (or a kernel map): $\quad (QK^\top)V = Q(K^\top V)$
Q n × dk × Kᵀ dk × n → QKᵀ n × n bottleneck! × V Cost: n²dk + n²dv (quadratic in n) Q × Kᵀ × V → KᵀV dk × dv Cost: 2ndkdv (linear in n)

Shen et al. (2018); Katharopoulos et al. (2020) for kernel feature maps $\phi(Q)\phi(K)^\top$; closely linked to fast weight programmers.

Recurrent Form and Parallel–Serial Duality

$$S_t = S_{t-1} + k_t v_t^\top \qquad\text{and}\qquad y_t = q_t^\top S_t$$

St-1 + St kt vtᵀ yt = qtᵀSt to t+1 Fixed state size dk × dv regardless of context length t
  • Causal linear attention is a matrix-valued RNN whose hidden state $S_t$ sums outer products $k_i v_i^\top$
  • Duality gives the best of both worlds:
    • Training: parallel matrix form saturates GPU Tensor Cores
    • Decode: serial recurrence costs $O(1)$ memory and compute per step
  • Weighting $S_{t-1}$ by a fixed scalar decay $\gamma$ yields RetNet: $S_t = \gamma S_{t-1} + k_t v_t^\top$

Next: fixed decay forgets indiscriminately — how do we make the recurrence input-dependent?

From Linear Attention to Mamba-2

Generalize linear attention by adding a data-dependent decay gate $\gamma_t = f(x_t)$ and skip projection $D$:

Linear attention: $\quad S_t = S_{t-1} + k_t v_t^\top, \quad y_t = q_t^\top S_t$

Mamba-2: $\quad S_t = \color{#c00000}{\gamma_t} S_{t-1} + k_t v_t^\top, \quad y_t = q_t^\top S_t + \color{#c00000}{v_t^\top D} \quad \text{with } \color{#c00000}{\gamma_t = f(x_t)}$

Mamba-2 scales the entire state $S_{t-1}$ by one scalar $\gamma_t$ — can we erase selectively by key?

Gated DeltaNet: Selective State Erasure

$$S_t = \gamma_t\big(I - \color{#1438c8}{\beta_t k_t k_t^\top}\big) S_{t-1} + \color{#1438c8}{\beta_t} k_t v_t^\top, \qquad y_t = q_t^\top S_t$$ with data-dependent decay $\gamma_t = f(x_t)$ and write gate $\beta_t = f(x_t)$
FamilyState Update Rule ($S_t$)What It Controls
RetNet / Lightning$S_t = \gamma S_{t-1} + k_t v_t^\top$Static exponential decay
Mamba-2$S_t = \gamma_t S_{t-1} + k_t v_t^\top$Input-dependent global decay
DeltaNet$S_t = S_{t-1}(I - \beta_t k_t k_t^\top) + \beta_t k_t v_t^\top$Targeted key overwrite
Gated DeltaNet$S_t = \gamma_t (I - \beta_t k_t k_t^\top) S_{t-1} + \beta_t k_t v_t^\top$Both global decay and targeted erasure

Hybrid Architectures and Gated Attention

Repeated 3:1 Hybrid Block 1× Global Attention (Gated) + MoE FFN Linear / GDN Layer 3 + MoE Linear / GDN Layer 2 + MoE Linear / GDN Layer 1 + MoE 3 cheap recurrent layers per 1 global layer
  • Why hybrids beat pure linear: fixed-size states lose exact multi-key recall; controlled ablations (ByteDance Seed / UCSC) show 3:1 hybrids match Transformer recall while pure linear drops sharply
  • Historical 2025 design: MiniMax M1 used a 7:1 lightning-linear to full-attention hybrid for linear scaling in context length
  • Gated Attention (Qwen, 2025): a sigmoid gate applied after attention improves training stability and allows larger learning rates
    • Used in full-attention layers of Qwen3-Next / Qwen3.5 and in Kimi K3's gated MLA

Next: how do we compress the global attention layers themselves?

Multi-Head Latent Attention (MLA)

Input hidden ht Latent ctKV cached at inference ktR RoPE Latent ctQ [qtC; qtR] ktC vtC Multi-Head Attention → ut
  • Core idea (DeepSeek V2/V3 → GLM-5.3, Kimi K3): project $\mathbf{h}_t$ to a compact latent $\mathbf{c}_t^{KV} = W^{DKV}\mathbf{h}_t$, with $\mathbf{k}_t^C = W^{UK}\mathbf{c}_t^{KV}$ and $\mathbf{v}_t^C = W^{UV}\mathbf{c}_t^{KV}$
    • Inference caches only $\mathbf{c}_t^{KV}$ (and queries use $\mathbf{c}_t^Q$ to save training activations)
  • RoPE conflict:
    • Without RoPE: $\langle \mathbf{h}W^Q,\, W^{UK}\mathbf{c}_t^{KV}\rangle = \langle \mathbf{h}(W^Q W^{UK}),\, \mathbf{c}_t^{KV}\rangle$ ($W^{UK}$ absorbs into $W^Q$)
    • With RoPE: $R_q R_k$ sits between $W^Q$ and $W^{UK}$, blocking absorption
  • Fix: decoupled RoPE on a small extra slice $\mathbf{k}_t^R$ (e.g., GLM-5.3: kv_lora_rank 512 + RoPE dim 64)

MLA shrinks the KV cache per token, yet still attends densely over all $n$ positions unless paired with sparsity.

Alternative to Hybrids: Dynamic Sparse Attention (DSA)

Instead of compressing history into a recurrent state, score all past tokens cheaply and attend only to the top-$k$.

1. Lightning indexer (few heads $H^I$, ReLU, runs in FP8): $$I_{t,s} = \sum_{j=1}^{H^I} w_{t,j}^I \cdot \mathrm{ReLU}\!\left(\mathbf{q}_{t,j}^I \cdot \mathbf{k}_s^I\right)$$ 2. Fine-grained token selection: $$\mathbf{u}_t = \mathrm{Attn}\!\left(\mathbf{h}_t,\; \big\{\mathbf{c}_s \;\big|\; I_{t,s} \in \mathrm{Top}\text{-}k(I_{t,:})\big\}\right)$$

Next: how late-2026 labs push sparse exact attention and cross-layer compression even further.

2026 Sparse Exact Attention: MiniMax MSA & Qwen QSA

MiniMax Sparse Attention (MSA)
MiniMax-M3, June 2026
  • Replaces MiniMax M1's 2025 7:1 linear hybrid with blockwise sparse attention on GQA
  • Lightweight index branch selects top-$k$ KV blocks independently per GQA group; main branch runs exact block-sparse attention
  • MiniMax report: matches GQA quality on a 109B model while cutting per-token attention compute by 28.4× at 1M context
Qwen Sparse Attention (QSA)
Qwen3.8-Flash-Next, Aug 2026
  • 125B total / 6B active; retains the 3:1 Gated DeltaNet to global-attention backbone
  • During continued pretraining, replaces full-attention layers with QSA
  • Scores micro-blocks using a compressed lightweight indexer (indexer budget 2048 in config)

Trend: the field is moving from linear-plus-dense hybrids toward sparse exact attention inside global layers.

DeepSeek-V4 (2026): CSA + HCA Hybrid

Full Token Sequence (n up to 1M) Local Window window = 128 CSA Compress seq KV → top-k sparse HCA Heavy compress → dense attn Local + Sparse Global + Summary
  • Local backbone: sliding-window attention handles fine-grained local context cheaply (window 128 in DeepSeek-V4.1-Flash)
  • CSA (Compressed Sparse Attention): compresses KV along the sequence dimension, then runs DSA-style top-$k$ sparse selection
  • HCA (Heavily Compressed Attention): compresses the sequence KV even more aggressively, then runs dense attention over the compact summary

Pairing sparse selective retrieval (CSA) with a cheap global summary (HCA) covers both needle lookup and broad context.

DeepSeek-V4.1-Flash (Sept 2026): CSA2 & KV Reuse

1. Full Layer Compute global KV + run indexer top-k 2. Reindex Layer Reuse earlier KV & KI select fresh top-k indices 3. Reuse Layer Reuse earlier KV AND reuse top-k indices share KV KV + idx Static cross-layer sharing pushes DSA + compression to the limit

The 2026 Attention Landscape: Three-Axis Design Space

Model (Release)Local / Cheap MixerGlobal Layer RatioGlobal Selection / Compression
DeepSeek-V4.1-Flash (Sept 2026)Sliding window (128)Cross-layer Full/Reindex/ReuseCSA2 + FP4 KV (890 B/tok)
Kimi K3 / K3.1 (July 2026)Kimi Delta Attn (GDN family)3:1 (3 KDA + 1 global)Gated MLA
Qwen3.8-Flash-Next (Aug 2026)Gated DeltaNet3:1 (3 GDN + 1 global)QSA micro-block sparse (budget 2048)
GLM-5.3 (2026)— (all global MLA)All 78 layersMLA + DSA top-$k$ (2048)
MiniMax-M3 (June 2026)— (block-sparse GQA)All global (sparse)MSA per-GQA-group top-$k$ blocks
Nemotron 3.5 (Oct 2026)Mamba-2Hybrid Mamba-TransformerSelf-attention layers
Takeaway — three axes of late-2026 attention: (1) cheap local/recurrent mixing, (2) a minority of global layers, and (3) sparse or compressed selection inside those global layers.

Next: Part 2 — tackling the other half of the Transformer block, the dense FFN, with Mixtures of Experts.

Part 2: What Is a Mixture of Experts (MoE)?

Dense Transformer Block Self-Attention + Residual One Large Dense FFN Add & Norm → Output token "The" token "Dog" Sparse MoE Block Self-Attention + Residual Router (Top-K) FFN 1 FFN 2 FFN 3 FFN 4 Weighted Sum + Residual → Output "The" → FFN 2 "Dog" → FFN 1

Adapted from Fedus et al. (2022).

Why MoEs Dominate Frontier LLMs

2026 Frontier ModelTotal / Backbone ParamsActive Params / TokenTotal : Active
DeepSeek-V4.1-Flash (Sept 2026)552B backbone16B decode (8B prefill)~34× (decode)
Kimi K3 / K3.1 (July 2026)2.8T104B2.8T : 104B
Qwen3.8-Flash-Next (Aug 2026)125B6B125B : 6B

Sparse models give frontier knowledge capacity at a fraction of dense training and inference FLOPs.

Historical Hurdles — and the MoE Design Space

Why MoEs were once hard to adopt
  • Multi-node systems complexity: hosting all experts requires many GPUs plus high-throughput all-to-all dispatch (Fedus et al. 2022)
  • Training instability: heuristic objectives and sensitive routers caused loss spikes worse than dense Transformers (Zoph et al. 2022)
What varies across MoE designs?
  1. Routing function: token choice vs. expert choice, softmax vs. sigmoid
  2. Expert sizes & structure: fine-grained segmentation, shared experts, LatentMoE
  3. Training & systems: load balancing, router precision, grouped GEMMs, online replication

By 2026, each hurdle has a clean engineering solution — we examine all three axes next.

Routing Paradigms: Who Chooses Whom?

Token Chooses Expert (TC) Tokens (columns) → Top-K Top-K Top-K Standard in LLMs Expert Chooses Token (EC) Experts (rows) → Top-C tokens Top-C tokens Top-C tokens Perfect balance, awkward at decode Global Optimization Full matrix matching Linear Assignment (e.g., BASE Layers) Needs batch-wide solve

Top-$K$ Routing: From Softmax to Renormalized Sigmoid

$$\mathbf{h}_t^l = \mathbf{u}_t^l + \sum_{i=1}^{N} g_{i,t}\,\mathrm{FFN}_i(\mathbf{u}_t^l), \qquad g'_{i,t} = \begin{cases} s_{i,t} & s_{i,t} \in \mathrm{Top}K(\{s_{j,t}\}_{j=1}^N,\, K) \\ 0 & \text{otherwise} \end{cases}$$

Historical Softmax Routers
  • Softmax before Top-$K$: $s_{i,t} = \mathrm{Softmax}_i(\mathbf{u}_t^{l\top}\mathbf{e}_i^l)$ (DeepSeek V1–V2, Grok, early Qwen)
  • Softmax after Top-$K$: apply softmax only over the winning $K$ logits (Mixtral, DBRX)
2026 Frontier Default: Sigmoid + Renorm
  • Compute independent affinities $s_{i,t} = \sigma(\mathbf{u}_t^{l\top}\mathbf{e}_i^l)$
  • Select Top-$K$ (with bias term), then renormalize: $g_{i,t} = g'_{i,t} \big/ \sum_{j=1}^N g'_{j,t}$
  • Standard in DeepSeek V3 → V4, Kimi K3, and GLM-5.3

Sigmoid avoids zero-sum logit competition across hundreds of experts while renormalization preserves activation scale.

Fine-Grained Experts and Shared Expert Isolation

(a) Conventional Top-2 1 2 N Router (K=2) Coarse FFNs (b) Fine-Grained (2N, K=4) 1 2 3 4 … 2N Router (K=4) Same FLOPs, more combinations (c) + Shared Expert Isolation S1 1 2 3 2N-1 Router (K=3) Always-on shared + routed

Empirical Ablations: Fine-Grained vs. Shared Experts

DeepSeekMoE Ablations (Fixed Params & FLOPs)
  • Baseline: 0 shared + top-2 of 16 routed (GShard style)
  • Adding 1 shared expert (1 + top-1 of 15) improves knowledge benchmarks (TriviaQA, NaturalQuestions)
  • Increasing granularity (1 + top-3 of 31 → 1 + top-7 of 63) delivers the strongest overall gains across HellaSwag, ARC, TriviaQA, and NaturalQuestions
OLMoE Ablations (Controlled)
  • Fine-grained experts clearly win: 64 experts > 32 experts > 8 experts on C4 validation loss, HellaSwag, and MMLU
  • Shared expert showed no gain: 32 routed matched 31 routed + 1 shared across loss and downstream curves
  • 2026 practice: despite OLMoE's null result, 1–2 shared experts are standard across DeepSeek, Kimi, GLM, and Qwen3.8

Shared experts also provide a convenient dense path that overlaps naturally with all-to-all communication.

MoE Routing Setups: Historical to Late 2026

ModelEraRouted ExpertsActive ($K$)SharedFine-Grained Ratio
GShard / Switch Transformer2021–222048 / 642 / 101
Mixtral / DBRX / Grok2023–248 / 16 / 82 / 4 / 201
DeepSeek V1 / OLMoE202464 / 646 / 82 / 01/4  /  1/8
Llama 4 (Maverick)Apr 2025128111/2
DeepSeek-V3Dec 2024256811/14
GLM-5.3202625681—
DeepSeek-V4.1-FlashSept 202638461—
Qwen3.8-Flash-NextAug 2026512101—
Kimi K3.1 ProJuly 2026896162—

Two clear trajectories: routed expert counts climbed from 64 (DeepSeek V1) to 896 (Kimi K3.1 Pro), and 1–2 shared experts became universal.

Training MoEs: Non-Differentiable Discrete Routing

Sparse selection gives training-time FLOP savings, but discrete top-$K$ decisions are non-differentiable and prone to collapse.

  1. Reinforcement learning (REINFORCE) (Clark et al. 2020)
    • Principled gradient estimator, scales similarly to S-BASE and Hash routing, but high gradient variance and complexity limit adoption
  2. Stochastic perturbations
    • Shazeer et al. (2017): Gaussian noise before Top-$K$: $H(x)_i = (x W_g)_i + \mathcal{N}(0,1)\cdot\mathrm{Softplus}((x W_{\text{noise}})_i)$
    • Fedus et al. (2022): uniform multiplicative jitter $\mathcal{U}(1-\varepsilon, 1+\varepsilon)$ on router logits
    • Zoph et al. (2022) removed jitter: stability rose (4/6 → 3/3) but quality dipped slightly ($-1.755 \to -1.777$)
  3. Heuristic load-balancing objectives & online biases — what works in practice

Heuristic Load-Balancing Losses

Systems efficiency requires even token distribution across experts — Switch Transformer (Fedus et al. 2022) adds:

$$\mathcal{L}_{\text{aux}} = \alpha \cdot N \sum_{i=1}^{N} f_i \cdot P_i, \qquad f_i = \frac{1}{T}\sum_{x\in\mathcal{B}} \mathbb{1}\{\arg\max p(x) = i\}, \qquad P_i = \frac{1}{T}\sum_{x\in\mathcal{B}} p_i(x)$$

Aux-Loss-Free Balancing via Per-Expert Biases

Auxiliary losses trade off load balance against language-modeling gradients. DeepSeek-V3 (Dec 2024) decouples them:

$$g'_{i,t} = \begin{cases} s_{i,t} & s_{i,t} + \color{#1438c8}{b_i} \in \mathrm{Top}K\big(\{s_{j,t} + \color{#1438c8}{b_j}\}_{j=1}^{N_r},\, K_r\big) \\ 0 & \text{otherwise} \end{cases}$$

MoE Training Stability: FP32 Routers and Z-Loss

router_logits = (x @ W_gate).to(torch.float32)
router_scores = torch.sigmoid(router_logits)  # or softmax in FP32

MoE Systems (1): Expert Parallelism & All-to-All

Rank 1 (e.g., B200) Attn (data shard 1) Router Local Experts 1…k Next Layer (shard 1) Rank E (e.g., B200) Attn (data shard E) Router Local Experts …N Next Layer (shard E) All-to-All Dispatch All-to-All Combine
  • Expert Parallelism (EP) places disjoint subsets of experts across GPUs (e.g., NVLink-connected NVIDIA Blackwell B200/B300 nodes)
  • Composes orthogonally with Data Parallelism (DP) and Tensor/Model Parallelism (TP)
  • Two collective barriers per layer:
    • All-to-All Dispatch sends routed token activations to destination expert ranks
    • All-to-All Combine returns expert outputs to each token's home rank
  • High interconnect bandwidth and overlap with shared-expert / attention compute are critical

MoE Systems (2): Grouped GEMMs & Block-Sparse Kernels

(A) Batched GEMM X0 × E0 = X1 × E1 = X2 × E2 = Fixed capacity → pad or drop (B) Block-Diagonal Equal-size blocks on diagonal (C) Block-Sparse / Grouped GEMM E0 (busy) E1 E2 Variable token counts, zero drops!

MoE Systems (3): LatentMoE Cuts All-to-All Traffic

Standard MoE Hidden dmodel All-to-All (dmodel) Routed Experts All-to-All (dmodel) Output + SE LatentMoE Hidden dmodel Latent down-proj Dispatch (dlat) Latent Experts Combine (dlat) Latent up-proj Output + Shared Expert Shared Expert
  • Bottleneck: All-to-All communication volume scales as $K \times d_{\text{model}}$ bytes per token
  • LatentMoE: down-project activations to $d_{\text{lat}} < d_{\text{model}}$ before dispatch, run routed experts in the latent space, and up-project after combine
  • From one lab to frontier practice:
    • Introduced in Nemotron 3 (early-2026) for hardware-aware accuracy per byte
    • Adopted at 2.8T scale as Stable LatentMoE in Kimi K3 (July 2026)

Fixed Capacity, Token Dropping & Batch Stochasticity

(1) Routing "the" → E1 "quick" → E0 "brown" → E2 "fox" → E0 "over" → E0 (2) Permute (cap = 2) E2: ["brown", pad] E1: ["the", "jumped"] E0: ["quick", "fox"] ✕ "over" DROPPED! (3) Expert Compute Expert 2 Expert 1 Expert 0 (4) Un-Permute & Scale E1("the") · p1 E0("quick") · p2 … "over" → 0 (residual only) Capacity is enforced across the entire serving batch

Static-Shape MoE via Online Expert Replication

Skewed Static Placement (Straggler) E1 (Hot)2× load E2 E3 Rank 0Rank 1Rank 2 Replicate hot expert Online Replication (Static Shapes) E1 (half) E2 E1 copy+ E3 Rank 0Rank 1Rank 2 Identical token count per rank — no drops, no padding

MoE Fine-Tuning & Sparse Upcycling

Sparse Upcycling (Dense → MoE) Dense Block Attn + Norm Dense MLP copy Replicate E× copies Upcycled MoE Block Attn + Norm New Router MLP copy 1 MLP copy 2 ⋮ MLP copy E
  • Fine-tuning overfitting: high parameter count causes sparse models to overfit small SFT sets (SuperGLUE CB gap, Zoph et al. 2022)
    • Fix A (small data): fine-tune only non-MoE weights
    • Fix B (scale data): e.g., DeepSeek's 1.4M curated SFT examples
  • Sparse Upcycling: reuse a pretrained dense model to initialize an MoE (copy Attention/Norms, replicate MLP $E\times$, fresh router)
    • MiniCPM-MoE (13.6B / ~4B active, top-2 of 8, ~520B tokens): beats dense MiniCPM-2.4B
    • Qwen1.5-MoE-A2.7B (14.3B / 2.7B active, from Qwen 1.8B, 60+4 experts, top-4): matches 7B dense models

Part 3: Case Study — DeepSeek MoE Evolution (V1 → V4.1)

GenerationParams (Total / Active)Experts (Routed / $K$ / Shared)Key Architectural Advances
V1 (2024)16B / 2.8B64 (1/4) / 6 / 2Fine-grained + shared experts; softmax top-$K$; expert + device aux loss
V2 (2024)236B / 21B160 (1/10) / 6 / 2Top-$M$ device-limited routing; comm balance loss; MLA
V3 (Dec 2024)671B / 37B256 (1/14) / 8 / 1Sigmoid + renorm top-$K$; aux-loss-free bias + seq-wise aux; MLA + 1-step MTP
V4 / V4.1-Flash (2026)552B backbone / 16B decode (8B prefill)384 / 6 / 1V4: CSA + HCA, mHC residuals; V4.1-Flash: CSA2 (FP4 KV, 890 B/tok), 3 MTP layers, Engram

Systems-Aware Routing in DeepSeek V2 → V3

Device-Limited Top-$M$ Routing (V2 → V3)
  • Unrestricted Top-$K$ can send a single token to $K$ different nodes, blowing up inter-node All-to-All traffic
  • Two-stage selection: first pick the top-$M$ devices by highest expert affinity, then choose Top-$K$ experts only on those $M$ devices
  • With $M \ge 3$, quality matches unrestricted Top-$K$ while strictly bounding communication fan-out
Communication Balance & V3 Gate
  • V2 communication balance loss ($\mathcal{L}_{\text{CommBal}}$): encourages every device to both send and receive $\approx MT$ hidden states
  • V3 router equations: $$s_{i,t} = \mathrm{Sigmoid}(\mathbf{u}_t^\top \mathbf{e}_i)$$ $$g_{i,t} = \frac{g'_{i,t}}{\sum_{j=1}^{N_r} g'_{j,t}}$$ with bias-shifted Top-$K$ inside Top-$M$ devices

Next: two non-MoE architectural companions that matter in late-2026 frontier models — mHC and MTP.

Manifold-Constrained Hyper-Connections (mHC)

n = 4 Parallel Residual Streams Mix Matrix Hres Sinkhorn–Knopp (≤20 iters) Attn / MoE Sublayer F Update n Streams Doubly stochastic: rows & cols sum to 1
  • Hyper-connections widen the residual path into $n$ parallel streams (usually 4) and learn small mixing matrices before and after each layer
  • Stability problem: unconstrained mixing matrices can break the identity path that keeps deep models trainable
  • mHC (DeepSeek-V4, 2026): projects the mixing matrix toward a doubly stochastic matrix via Sinkhorn–Knopp iterations (up to 20 in DeepSeek-V4)
  • Systems cost: $n\times$ residual memory traffic + serial reductions per layer → requires fused kernels (DeepSeek self-reports 6.7% overhead of an overlapped pipeline stage)

Multi-Token Prediction (MTP)

Main Model (Next-1) Shared Head → Pi+1 Transformer × L → hi0 Shared Embedding (ti) MTP Module 1 (Next-2) Shared Head → Pi+21 1 Block + Proj (hi0, ti+1) Shared Embedding (ti+1) MTP Module 2 (Next-3) Shared Head → Pi+32 1 Block + Proj (hi1, ti+2) Shared Embedding (ti+2) hi0 hi1

$$\mathbf{h}_i^{\prime k} = M_k\big[\mathrm{RMSNorm}(\mathbf{h}_i^{k-1});\; \mathrm{RMSNorm}(\mathrm{Emb}(t_{i+k}))\big], \quad \mathbf{h}_{1:T-k}^k = \mathrm{TRM}_k(\mathbf{h}_{1:T-k}^{\prime k}), \quad P_{i+k+1}^k = \mathrm{OutHead}(\mathbf{h}_i^k)$$

Putting It Together: Late-2026 Frontier Architectures

Model (2026)AttentionMoE (Routed / Active / Shared)Notable Extras
DeepSeek-V4 / V4.1-Flash (Sept)Window 128 + CSA/HCA / CSA2 (FP4 KV)384 / 6 / 1 (552B / 16B decode)V4: mHC; V4.1: 3 MTP, Engram
Kimi K3 / K3.1 (July)3 KDA : 1 Gated MLA896 / 16 / 2 (2.8T / 104B)Stable LatentMoE, MXFP4 QAT
Qwen3.8-Flash-Next (Aug)3 GDN : 1 QSA (budget 2048)512 / 10 / 1 (125B / 6B)51B host-memory n-gram table
GLM-5.3 (2026)MLA + DSA (top-$k$ 2048)256 / 8 / 1 (78L, $d=6144$)1 MTP layer
MiniMax-M3 (June)MSA blockwise sparse GQA109B MSA evaluation model28.4× less attn FLOPs at 1M

Lecture 4 Recap

  1. Attention alternatives break $O(n^2)$ prefill and $O(n)$ KV cost along three axes:
    • Cheap local/recurrent mixers (sliding window, Mamba-2, Gated DeltaNet / KDA)
    • A minority of global layers (3:1 hybrids, gated attention)
    • Sparse and compressed global selection (MLA, DSA/QSA/MSA, CSA2 + FP4 KV at 890 B/tok)
  2. Mixtures of Experts decouple capacity from FLOPs (e.g., 552B/16B decode in DeepSeek-V4.1-Flash; 2.8T/104B in Kimi K3):
    • Fine-grained routed experts (256–896) + 1–2 shared experts
    • Sigmoid + renormalized Top-$K$ + aux-loss-free bias balancing (noaux_tc)
    • FP32 routers and router z-loss prevent BF16 exponential instabilities
  3. MoE systems & companions make sparsity fast at scale:
    • Expert parallelism + grouped/block-sparse GEMMs + LatentMoE + online expert replication (MoonEP, DeepEP V2.5)
    • mHC doubly-stochastic residuals, MTP speculative heads, and conditional memory extend the Transformer block further