Chapter 4 Concept Guides

2 min read Original article ↗

Chapter 4 is where the main modern decoder variations start to matter: KV-cache compression, local attention, sparse feed-forward layers, and linear-attention hybrids.

These pages turn the local temp/LLMs-from-scratch/ch04 bonus chapters into quick website guides, with figures and examples pulled from the corresponding chapter scripts, later LLMs-from-scratch notebooks, and linked architecture articles.

RMSNorm figure

RMSNorm

A cheaper alternative to LayerNorm that keeps activation magnitudes stable without explicitly subtracting the mean.

SiLU / Swish figure

SiLU / Swish

The smooth activation behind modern SwiGLU feed-forward blocks, favored largely for efficiency and optimization stability.

QK-Norm figure

QK-Norm

Applies RMSNorm to queries and keys inside attention before RoPE, helping stabilize large-model training.

Grouped-Query Attention (GQA) figure

Grouped-Query Attention (GQA)

Multiple query heads share the same key-value projections, reducing KV-cache size without changing the overall decoder pattern.

Mixture of Experts (MoE) figure

Mixture of Experts (MoE)

A sparse feed-forward setup where only a few experts are active per token, even though total model capacity is much larger.

Gated Attention figure

Gated Attention

A tuned attention block that keeps content-based attention but adds an output gate and a few stabilizing tweaks.

Hybrid Attention figure

Hybrid Attention

A broader family of architectures that replaces most full-attention layers with cheaper linear or state-space sequence modules while keeping a smaller number of heavier retrieval layers.

DeepSeek Sparse Attention figure

DeepSeek Sparse Attention

A learned sparse attention mask used to reduce long-context costs in DeepSeek V3.2- and GLM-5-style models.