Chapter 5: Foundation Models and Architectures
Before about 2020, you trained a model per task: one for sentiment, another for translation, another for image classification. Foundation models invert this. A foundation model is pretrained once on broad, internet-scale data to learn general representations, and then adapted, by prompting, retrieval, or fine-tuning, to thousands of downstream tasks. Chip Huyen calls the resulting discipline AI engineering, building with models, in contrast to ML engineering, building models. The transformer is the substrate because it scales predictably and is modality-agnostic: give it a sequence of tokens, any tokens, and it learns their structure.
Concepts from other sections (11)
This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.
- foundation model: a model pretrained on broad data at scale and then adapted to many downstream tasks. Read more: 5.3 Model landscape and lifecycle
- KV cache: per-layer storage of past keys and values, so each decode step processes only the new token. Read more: 21.2 The KV cache, incremental decoding, and generate
- Retrieval-augmented generation (RAG): retrieving relevant evidence at query time and placing it in the context window, so a model answers from fresh, private, citable facts instead of only its parametric memory. Read more: Chapter 27: Retrieval and RAG
- adaptation ladder: the sequence of increasingly expensive ways to specialize a model, from prompting through RAG and fine-tuning to continued pretraining. Read more: 5.3 Model landscape and lifecycle
- RMSNorm: divides a vector by its root mean square plus eps (inside the root) and multiplies by a learned gain; no mean subtraction, no bias. Read more: 13.1 Pre-LN and RMSNorm
- RoPE: rotary position embedding, which rotates queries and keys by position to encode relative position. Read more: 5.3 Model landscape and lifecycle
- SwiGLU: a gated MLP, , that replaced the ReLU feed-forward block. Read more: 5.3 Model landscape and lifecycle
- GQA / MLA: attention variants that shrink the KV cache by sharing K/V heads across groups of query heads, or by compressing K/V into a low-rank latent. Read more: 5.3 Model landscape and lifecycle
- Mixture of experts (MoE): a layer of many expert MLPs of which a router picks per token. Read more: 13.8 Mixture of Experts
- Multi-query attention (MQA): all query heads share one key/value head. Read more: 13.5 Grouped-Query Attention with a Cache Hook, Windows, and Sinks
- classifier-free guidance: combining conditional and unconditional denoising predictions with weight to trade diversity for prompt adherence. Read more: 5.3 Model landscape and lifecycle
This chapter surveys that landscape, and nearly all of it is variations on three questions: how do we tokenize the input, how do we attend over it, and do we generate autoregressively or by denoising? We start with what makes a model a foundation model and how practitioners adapt one. We then trace how the 2018 transformer converged to a single recipe, why attention became an architectural battleground over the KV cache, and how text, images, and audio all became tokens. Diffusion models, the other foundation-model family, get their own treatment, followed by a tour of the 2026 model landscape. The chapter closes with the deepest mental-model shift of all: building an LLM is not the software development lifecycle. You do not write the behavior; you grow it from data.
Learning objectives
- Define a foundation model and place prompting, RAG, parameter-efficient fine-tuning, full fine-tuning, and continued pretraining on the adaptation ladder.
- Describe the modern decoder-only recipe (pre-norm, RMSNorm, RoPE, SwiGLU, GQA, optionally MoE) and why each component replaced its predecessor.
- Compare MHA, MQA, GQA, and MLA by KV-cache size and quality, and explain how text, images, and audio are tokenized.
- Explain the DDPM, latent diffusion, classifier-free guidance, DiT, and flow-matching objectives.
- Map the four learning paradigms onto the stages of the LLM lifecycle, and contrast that lifecycle with the software SDLC.
Before you begin
Section titled “Before you begin”This chapter builds on Deep Learning, especially its treatment of transformers, attention, and generative models, and on Linear Algebra and Probability and Statistics from Mathematics.
The optional paid reference is Chip Huyen’s AI Engineering: Building Applications with Foundation Models (O’Reilly, 2025). Its official companion repository has free supporting materials, but not the full book, so follow the free papers and documentation listed under Further reading alongside it; see the source register. Read Huyen for the engineering view (adaptation, evaluation, serving cost) and the original papers for the architecture view. Build a tiny GPT from scratch with Karpathy so the transformer recipe is concrete rather than vocabulary. For each model family, read its model card and tech report, which is where the real architectural choices and their justifications live. And treat text, audio, vision, and diffusion as four instantiations of one idea, sequence modeling, rather than four separate fields.
In this chapter
Section titled “In this chapter”- Foundation models and transformer families: Distinguish model architecture from training signal and deployment role.
- Modalities and diffusion: Explain why modality and generation objective change the serving workload.
- Model landscape and lifecycle: Read model examples as architecture and training decisions rather than a fixed leaderboard.