~/satyajit

Architectures

jsonmcp

The building-block architectures behind modern models — attention, MoE, state-space, positional, diffusion — each rated on how interesting and how unique it is, and many drawn as detailed distill-style diagrams.

sort19 of 19
AttentionEssentialinterest 5/5 · unique 5/5

A hybrid block — KDA (gated delta-rule linear attention) interleaved with Gated MLA (full attention) and Stable LatentMoE — plus Block Attention Residuals: each residual add reads a gated mix of every earlier block.

The full explainer, with a narrated film
Kimi K3 · hybrid KDA / MLA / LatentMoE block + Block Attention Residuals (AttnRes)
OutputresidualbusKDAlinear attention+αStable LatentMoEsparse FFN+αGated MLAfull attention+αStable LatentMoEsparse FFN+α⋮earlier blocksEmbeddingAttnRes: each α reads a gated mix of every earlier block on the bus

Read bottom‑to‑top. Kimi K3 stacks a hybrid block — KDA (linear‑time attention), Gated MLA (full attention for exact recall) and Stable LatentMoE (shared + routed experts) — into the residual stream. The twist is Block Attention Residuals: every residual add pulls a gated read (α) off a bus carrying every earlier block’s output, not just the layer below — a learnable skip across the whole depth.

linear-attention · hybrid · cross-depth-residualarticle
SSM / RNNEssentialinterest 5/5 · unique 5/5

A selective state-space model: a fixed-size state carried by a linear-time recurrence whose transition parameters depend on the input, giving content-based routing of information — a leading attention-free alternative.

The full explainer, with a narrated film
selective state space model (mamba) · recurrent scan
state  hₜ = Āₜ hₜ₋₁ + B̄ₜ xₜoutput  yₜ = Cₜ hₜh₀=0ĀₜĀₜĀₜx₁selectΔ, B, Ch₁y₁x₂selectΔ, B, Ch₂y₂x₃selectΔ, B, Ch₃y₃x₄selectΔ, B, Ch₄y₄Δ, B, C ← xₜ(input-selective)linear-time recurrence · input-selective · attention-free

Instead of attending over the whole sequence, Mamba scans it: a single fixed-size state is carried step to step by a linear recurrence, and the transition parameters (Δ, B, C) are computed from the input — so the model can selectively remember or forget while staying linear in length.

recurrent · selective · linear-time · attention-freepaper
TransformerEssentialinterest 5/5 · unique 5/5

The self-attention block that replaced recurrence: pre-norm → multi-head self-attention → residual, then pre-norm → MLP → residual, stacked N deep with a causal mask. Every architecture below is a variation on it.

The full explainer, with a narrated film
pre-norm decoder-only transformer block
Inputtokens + positions → vectorsMixingtokens attend to the pastThinkingper-token MLP · d→4d→dstacked x N layersThecatsatoninput tokensToken Embedding + Positional EncodingLayerNormpre-normMulti-Head Self-Attentionh1h2h3h4causal (masked) attention over past tokensLayerNormFeed-Forward (MLP)d to 4d to d, per-tokenresidualresidualFinal LayerNormLM Headlogits over the vocabulary

Each block refines the token stream twice — self-attention lets positions mix, the MLP thinks per-token — and both sub-layers are wrapped in a normalize → transform → add residual, so the original signal (and its gradient) flows straight up through all N stacked layers.

self-attention · residual · foundationalarticle paper
OtherEssentialinterest 4/5 · unique 5/5

Hash the last few tokens, reduce the hash modulo a different prime per head, and fetch one row per head from a table of hundreds of millions of rows; the rows are gated into the residual stream. Parameters that cost a lookup, not a matmul, and can live on the CPU or an SSD.

The full explainer, with a narrated film
hashed n-gram memory · a lookup table beside the layers, read by hashing the last few tokens
thecatsaton2-gram3-gramhash the token idsfixed odd multipliersmod p₁mod p₂mod p₃⋮one prime per head:unrelated collisionsthe tablemillions of rowsindexed, never multipliedcan sit in CPU RAM or on NVMeconcatenated rows egateby the hidden stateresidual streamlayer ℓ+hidden stateparameters that cost a gather, not a matmul

The last few token ids are hashed, and each head reduces the hash modulo its own prime to pick one row of a very large table. Two n-grams that collide under one prime almost never collide under another, so the concatenated rows still identify the phrase. A gate computed from the hidden state decides how much of that memory enters the residual stream, at one layer or a few.

lookup-table · hashing · conditional-memory · offloadarticle paper
AttentionEssentialinterest 5/5 · unique 4/5

How the Key/Value side collapses to shrink the KV cache: MHA (one KV per query head) → MQA (one shared) → GQA (a few groups) → MLA (a single compressed latent up-projected on the fly), at near-equal quality.

The full explainer, with a narrated film
KV-head sharing · MHA → MQA → GQA → MLA
8 query heads (blue) share ever-fewer Key/Value heads (salmon) — shrinking the KV cacheMHA8 Q, 8 KV (1:1)8 query heads8 KV headsKV cache size8x cacheMQA8 Q, 1 KVKV8 query heads1 shared KVKV cache size1x cacheGQA8 Q, 2 KV groupsKV g1KV g28 query heads2 KV groupsKV cache size2x cacheMLA8 Q, latent KVc8 query headscompressed latent cup-projected to K, VKV cache sizetiny (latent)

The queries never change — only the Key/Value side collapses. Going MHA → MQA → GQA → MLA folds many KV heads into few, or into a single compressed latent, shrinking the per-token KV cache that dominates memory at long context while keeping quality nearly intact.

kv-cache · kv-sharing · mla · inferencearticle
SSM / RNNEssentialinterest 5/5 · unique 4/5

Three layers in four swap attention for Gated DeltaNet: a fixed-size matrix memory per head that decays, erases what it held for the current key and writes the new value. Every fourth layer keeps full attention for exact recall. The 3:1 shape of Qwen3.8 and of small models like KLM.

The full explainer, with a narrated film
gated deltanet hybrid · three recurrent layers, then one that attends in full
one block, read bottom to topfull attentionKV cache growsGated DeltaNetfixed stateGated DeltaNetfixed stateGated DeltaNetfixed statehidden state from the block belowto the next block×None Gated DeltaNet head, one tokenSₜ = αₜ (I − βₜ kₜkₜᵀ) Sₜ₋₁ + βₜ kₜvₜᵀSₜ₋₁dₖ × dᵥ per headdecay× αₜ (0 to 1)erase along kₜ− βₜ kₜ (kₜᵀ S)write along kₜ+ βₜ kₜ vₜᵀSₜreadSₜᵀqₜthe row along kₜ now holds vₜtoken xₜ→ qₜ, kₜ, vₜ, αₜ, βₜfixed memory on three layers in four · exact lookup left to the fourth

A Gated DeltaNet layer keeps a matrix of fixed size per head instead of a cache. Each token first shrinks it by a decay α, then reads what the matrix already stores for its key and replaces it with the new value, at a strength β the token picks. Three such layers share each block with one full-attention layer, whose cache still grows and does the exact retrieval a summary cannot.

linear-attention · delta-rule · hybrid · fixed-statearticle paper
AttentionEssentialinterest 5/5 · unique 4/5

A small, low-precision indexer scores every cached token for each query, and the real attention reads only the top k, 2,048 in DeepSeek-V3.2. The cache keeps everything; what shrinks is what each query reads. Most open models without full attention are this.

The full explainer, with a narrated film
index-selected sparse attention · a cheap indexer picks which keys the real attention reads
score  Iₜ,ₛ = Σⱼ wₜ,ⱼ · ReLU(qₜ,ⱼ · kₛ)  for every cached s, then attend over the top knew tokenhₜlightning indexerfew heads, low precision, scores all None score per cached positiontop k(5 here)cache: all Nentries keptmain attention over k entries onlysoftmax and values as usual, on the gathered rowsqueryoutputkeeps every key, reads only k · the indexer still scans all N, cheaply

The indexer is a second, much smaller attention: a few heads in low precision whose ReLU scores rank every cached position. The top k positions are the only ones the main attention gathers and reads. Nothing is evicted, so the cache is as large as a dense layer’s; what shrinks is how much of it each query reads.

sparse-attention · indexer · top-k · long-contextarticle paper
MoEEssentialinterest 5/5 · unique 4/5

Replace the dense FFN with many expert FFNs and a router that sends each token to only a few (plus an optional always-on shared expert). Parameters scale up while per-token compute stays flat.

The full explainer, with a narrated film
mixture-of-experts FFN layer · router picks top-2
shared (always-on)routed, top-2idle (not selected)MoE outputgated weighted sumexperts (each a small FFN)SharedFFNalways onE1FFNidleE2FFNg = 0.66E3FFNidleE4FFNidleE5FFNg = 0.34E6FFNidleRouterlinear → softmax → keep top-2h · token

Only the top-2 routed experts (plus an always-on shared expert) fire for any given token, so a layer can hold a huge pile of parameters while each token pays the compute of just a few small FFNs.

sparse · router · conditional-computearticle
DiffusionHighinterest 4/5 · unique 4/5

A diffusion denoiser that is a Transformer over image latent patches, conditioned on the timestep and text through adaptive LayerNorm; MMDiT carries text and image tokens in separate streams that attend jointly.

The full explainer, with a narrated film
transformer denoiser · adaln conditioning · joint text+image attention
conditioningadaLN MLPpool(t, caption) → γ, βtimestep tcaptiontext promptadaLN γ,βDiT blockstacked × Nimage tokensown projtext tokensown projadaLN-Norm · scale γ, shift βJoint Self-Attentionimage + text tokens attend togetherMLPper-tokenMLPper-tokento next blockpredicted noise= ε (output)Patchify + Embedpatches → tokenscaption tokensnoisy latent z_t(3×3 patches)

A Diffusion Transformer denoises image latents by treating patches as tokens: a stack of blocks predicts the noise ε, while the timestep and caption are pooled through a small MLP that adaptively modulates each block’s norm (adaLN). In the MMDiT variant, image and text tokens keep separate projections but mix through one joint self-attention.

diffusion · adaln · joint-attention · image-genarticle

Hyper-connections (HC / mHC)

2024
TransformerHighinterest 4/5 · unique 4/5

Widen the residual stream into N parallel streams with three small learned maps around each sublayer: a weighted read, a weighted write and a stream mixer. DeepSeek's mHC keeps the mixer doubly stochastic so its product over depth cannot blow up.

hyper-connections · N residual streams, three small maps around each sublayer
Xₗ₊₁ = Hʳᵉˢ Xₗ + Hᵖᵒˢᵗ F( Hᵖʳᵉ Xₗ )x₁x₂x₃x₄N = 4 streams, each the model’s widthHᵖʳᵉ readF: attention or MLPruns once, on one vectorHᵖᵒˢᵗ writeHʳᵉˢ mixes streamsan N × N matrixmHC: Hʳᵉˢ doubly stochastic0.70.10.10.10.10.60.20.10.10.20.60.10.10.10.10.7rows and columns each sum to 1Plain HC leaves Hʳᵉˢ free, so its product across many layerscan grow or shrink geometrically. A doubly stochastic matrixcannot amplify, and neither can any product of them.

The residual stream becomes N streams, but each sublayer still runs once on one vector, so its cost does not change. What is new is three tiny maps around it: a weighted read, a weighted write, and a stream mixer. mHC constrains the mixer so that rows and columns sum to one, which restores the stability the identity path of a plain residual gave for free.

residual · multi-stream · sinkhorn · stabilityarticle paper
TransformerHighinterest 4/5 · unique 4/5

Reuse the same block for several passes to buy effective depth (and latent reasoning) without adding parameters — depth paid in FLOPs, not weights.

The full explainer, with a narrated film
looped transformer · weight-tied recurrent depth
LM head → outputexit after ×KTransformer Blockself-attention + MLPweight-tied · sharedmergeinput embeddingslatent reasoning loop× K passes(same weights every pass)shared weights · depth paid in FLOPs, not parameters

A looped Transformer runs one shared block over and over — the output of a pass is fed back as the next pass’s input — so it gets the effective depth of a much taller model while storing the parameters of just a single layer. The extra reasoning is paid for in compute, not weights.

weight-sharing · recurrent-depth · latent-reasoningarticle
DiffusionHighinterest 4/5 · unique 4/5

A non-autoregressive language model that generates by iteratively unmasking tokens under bidirectional attention — denoising a fully masked sequence over several steps instead of left-to-right.

The full explainer, with a narrated film
non-autoregressive · bidirectional · denoise a masked sequence over T steps
[M] maskedfilledjust unmaskedstep 0[M][M][M][M][M][M]all [M]step 1the[M][M]on[M][M]4× [M]step 2thecat[M]on[M]mat2× [M]step Tthecatsatonthemattext ✓unmask a fewre-predictunmask a fewre-predictunmask a fewre-predictbidirectional attentionthecatsatontheeach token attends both left & right (not causal)

Unlike a left-to-right autoregressive model that commits one token at a time, a masked-diffusion LM starts from an all-[M] sequence and, under bidirectional attention, unmasks a few tokens each step and re-predicts the rest — refining the whole sentence in parallel over T steps.

diffusion · non-autoregressive · bidirectionalarticle
PositionalHighinterest 4/5 · unique 4/5

Encode position by rotating each query/key vector by an angle proportional to its index, so the attention score depends only on the relative offset. The de-facto positional scheme in modern LLMs.

The full explainer, with a narrated film
rotary position embedding (rope) · position = rotation
position m rotates the query/key vector by an angle ∝ mthe rotation grows with position — here θ = m · 25°m = 1 · 25°m = 2 · 50°m = 3 · 75°+25°+25°the dot product of two rotated vectors depends only on (m − n)50°k · pos nq · pos mattention sees only relative distance⟨ q(m), k(n) ⟩ = g(q, k, m − n)the score depends only on the relative offset(m − n) — never on absolute position m or n.

RoPE encodes a position by rotating each pair of feature dimensions by an angle proportional to that position. Because a dot product only cares about the angle between two vectors, attention ends up reading the relative distance (m − n) for free.

relative · rotation · positionalarticle
OtherNotableinterest 3/5 · unique 4/5

A per-layer router lets each token either pass through the block or skip it via the residual, so compute is spent only where needed and effective depth becomes token-dependent under a fixed budget.

The full explainer, with a narrated film
mixture-of-depths · per-token skip routing
tokens123456sequencerouter 1top-2 of 6skip · residual (bypass)block 1self-attn + MLPprocessedrouter 2top-2 of 6skip · residualblock 2self-attn + MLPprocessedrefined tokens123456outputsselected → through block (pays FLOPs)skipped → residual bypass (free)per-token, per-layer compute — only selected tokens pay

A router at every layer keeps only a fixed fraction of tokens for the block; the rest skip it through the residual connection. Because the selected set changes layer to layer, each token gets a different effective depth — and the network spends compute only where it helps.

conditional-compute · token-routing · dynamic-depthpaper
TransformerNotableinterest 4/5 · unique 3/5

An encoder-only stack with full (non-causal) attention, pretrained by masking tokens and predicting them — so every position sees the whole sequence. Still the default for embeddings and classification.

The full explainer, with a narrated film
bidirectional encoder (bert) · masked language model
predict [MASK]→ “sat”MLM Headsoftmax over vocabularyencoder block × NAdd & NormFeed-Forward (MLP)per-token · d → 4d → dAdd & NormMulti-Head Self-Attentionbidirectional · no causal maskresidualresidualToken + Positional Embeddingsbidirectional — every token sees the whole sequence (no causal mask)thecat[MASK]onmat

BERT is a Transformer encoder: with no causal mask, every position attends to the whole sequence at once, so the hidden state for [MASK] is built from context on both sides. The MLM head then reads that position and predicts the missing word.

masked-lm · bidirectional · representationspaper
TransformerNotableinterest 4/5 · unique 3/5

Two stacks: an encoder that reads the source bidirectionally, and a decoder that generates while cross-attending into the encoder's representations. The seq2seq form behind translation, T5 and BART.

The full explainer, with a narrated film
encoder–decoder transformer (seq2seq) · t5 / bart
encoder × Ndecoder × NAdd & NormFeed-ForwardAdd & NormSelf-Attentionbidirectionalinput embedding + posderHundbelltsource · GermanAdd & NormFeed-ForwardAdd & NormCross-AttentionK,V from encoderAdd & NormMasked Self-Attentioncausal · past onlyoutput embedding + pos[BOS]thedogtarget · shifted rightLinear → Softmaxoutput: barksencoder output → K,V

The encoder reads the whole source at once and produces a set of vectors; the decoder generates the target left-to-right, and at each step its cross-attention queries that encoder output — the one wire that turns two stacks into a translator.

cross-attention · seq2seq · translationarticle

Multi-token prediction modules

2024
TrainingNotableinterest 4/5 · unique 3/5

Extra modules that predict tokens further ahead: DeepSeek-V3's each take the previous depth's hidden state and the next token's embedding, run one block and share the output head. They add training signal, then draft tokens for self-speculative decoding.

multi-token prediction · sequential modules that each look one token further
main modeltᵢ₊₁output headtransformer × Lembeddingt₁ … tᵢMTP module 1tᵢ₊₂output headshared1 transformer blockconcat, project M2d → dRMSNormRMSNormembeddingsharedtᵢ₊₁MTP module 2tᵢ₊₃output headshared1 transformer blockconcat, project M2d → dRMSNormRMSNormembeddingsharedtᵢ₊₂h⁰h¹training: a loss at every depth · inference: drop the modules, or let them draft for the main model

Each module sees the hidden state of the depth before it and the real next token, so its guess one step further is conditioned on everything to its left. That keeps the causal chain that independent parallel heads give up. During training each depth adds a loss; at inference the modules either go away or propose tokens the main model checks in one pass.

mtp · speculative-decoding · draft-modelarticle paper
AttentionNotableinterest 4/5 · unique 3/5

Most layers attend only to the last W tokens, so their cache stops growing; a global layer every few layers reads the whole past. Stacked windows reach further than one, and many models keep an attention sink. The pattern in Gemma, gpt-oss and MiMo.

The full explainer, with a narrated film
sliding-window attention · local layers with a global layer every few
local layereach query sees the last W = 4 keysglobal layereach query sees every earlier keykeys →keys →queries →queries →sink: position 0 stays visible(in models that keep one)reads grow with position:the cost window layers avoidone block, read bottom to topcached at long contextgloballocalW tokens, then flatlocalW tokens, then flatlocalW tokens, then flatlocalW tokens, then flatlocalW tokens, then flatevery token, growing×N blocksa window caps memory by position · the global layers carry everything older

A local layer attends over a fixed window of recent keys, so its cache stops growing once the context passes W tokens. Stacking windows widens what the top of the stack can reach, and a global layer every few layers reads the whole past. Some models also keep the first tokens visible to every query as an attention sink.

local-attention · kv-cache · attention-sink · hybridarticle paper

Latent mixture-of-experts

2026
MoESolidinterest 3/5 · unique 3/5

The router reads the full-width token, but routed experts work in a narrower latent: one shared down-projection before them, one up-projection after. Each expert gets smaller, so a layer can hold and route to more of them, at the price of two dense projections every token pays for.

latent mixture-of-experts · route at full width, compute the experts in a narrower latent
y = shared(x) + W↑ RMSNorm( Σᵢ pᵢ Eᵢ( W↓ x ) )token xwidth drouterreads all d, picks kW↓d → ℓrouted experts, each ℓ → f → ℓΣW↑ℓ → dafter RMSNormshared expertfull width d, every token+yexpert weights and dispatch traffic scale with ℓ, not d

The router still sees the whole token, but the routed experts never do: one down-projection, shared by all of them, maps the token into a narrower latent of width ℓ, and one up-projection maps the weighted sum back. A routed expert shrinks from 3·d·f weights to 3·ℓ·f, so a layer can hold and route to more of them. The price is the two projections, which are dense and run for every token.

moe · latent-projection · expert-sizearticle paper