Skip to content

5.3 Model landscape and lifecycle

This part of Foundation Models and Architectures develops the mechanisms below. Work the numerical examples or trace the code before checking the answer.

Concepts from other sections (18)

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.

Learning objectives

  • Read model examples as architecture and training decisions rather than a fixed leaderboard.

With the architectures in hand, you can read the current models as combinations of these choices. These are the main open-weight families; for each, read the tech report and model card:

FamilyNotable variantsArchitectural notes
Gemma (Google)3 (270M/1B/4B/12B/27B), 3n (E2B/E4B, MatFormer + per-layer embeddings, edge), 4 (E2B/E4B/26B-MoE/31B-dense, native audio + video), PaliGemma, MedGemma, CodeGemma, ShieldGemma, RecurrentGemmamultimodal, local+global attention, single-GPU focus
Llama (Meta)3.x, 4 (MoE)the reference open decoder-only recipe
Qwen (Alibaba)dense + MoE, VL, audiostrong multilingual + multimodal
DeepSeekV3/R1 (MLA + fine-grained MoE)MLA attention, reasoning (RL)
Mistral7B, Mixtral (MoE), sliding-windowefficiency-focused
Phi (Microsoft)small, data-curated“textbooks” data quality over scale

The closed, frontier models, GPT (OpenAI), Claude (Anthropic), and Gemini (Google), are API-only, larger, and multimodal.

To read any model, check its size and active parameters (dense or MoE), its context length, its attention type (GQA, MLA, or sliding-window), its modality support, its license, and the availability of quantized GGUF or other checkpoints, which decides whether you can actually run it; see Quantization: Math to Code.

The architecture tells you what a model is. The final question is how one comes to exist, and here the right mental model departs sharply from ordinary software. In traditional software you write the behavior: a human encodes rules as deterministic code. In an LLM you grow the behavior: a pipeline of learning paradigms turns a corpus into weights, and the behavior is whatever statistically emerged. Behavior is emergent rather than specified, which is why “testing” becomes evals and “bug fixes” become more data and more alignment. This is the deepest shift in the chapter, so treat the two lifecycles as genuinely different engineering disciplines, not the same one with a neural network swapped in. The account here draws on Karpathy’s State of GPT, Huyen’s AI Engineering, and the Llama 3 tech report.

The paradigms differ only in where the training signal comes from, and each owns a stage of the lifecycle:

ParadigmWhere the label comes fromLifecycle stageDeeper treatment
Unsupervisedno labels: structure in the data itself (clustering, dedup, topic balance)Corpus curation & data engineeringUnsupervised learning
Self-supervisedlabels derived from the data (predict the next token / a masked span / a held-out view)Pretraining (the expensive 99%)Representation learning
Supervisedcurated human input→output pairsSFT / instruction tuningStatistical Learning
RL from feedback (RLHF / RLAIF / DPO / GRPO)a preference or reward signal over whole outputsPreference optimization / alignmentRLHF and alignment, Reinforcement Learning

Self-supervision is the engine. It is what let pretraining escape the labeling bottleneck and consume the internet. Two families are worth naming specifically, because they show that self-supervision is broader than next-token prediction.

Siamese or joint-embedding networks use two weight-sharing encoder towers to map two views of the same datum to embeddings; the loss pulls matching pairs together and pushes non-matching pairs apart. This is the backbone of contrastive learning (SimCLR, MoCo, CLIP’s dual encoder) and of metric learning (face verification, retrieval). The classic failure mode is representation collapse, in which everything maps to one point, and the fixes define the field: negative pairs (SimCLR), a momentum target encoder (BYOL, MoCo), stop-gradient plus a predictor (SimSiam), and redundancy-reduction objectives (Barlow Twins, VICReg).

JEPA (Joint-Embedding Predictive Architecture) is LeCun’s non-generative self-supervision. Instead of reconstructing pixels or tokens, which is generative and wastes capacity on noise, it predicts the representation of a masked target from a context, in embedding space. I-JEPA (images) and V-JEPA and V-JEPA 2 (video, a step toward world models) avoid collapse with an asymmetric context and target encoder, an EMA target, and a predictor. The thesis is to model the world in an abstract latent space, not pixel by pixel. Contrast this with generative pretraining and with diffusion, both of which do reconstruct the input.

The paradigms are applied in a fixed order, looping back on every iteration: data curation, pretraining, mid-training, SFT, preference optimization, evaluation, deployment, and monitoring.

  1. Data curation (unsupervised): crawl, deduplicate, filter, decontaminate against evals, and balance the mixture. Data is the source code now; most of the quality lives here.
  2. Pretraining (self-supervised): next-token loss over trillions of tokens. This stage dominates compute and is governed by scaling laws, such as Chinchilla-optimal data-to-parameter ratios.
  3. Mid-training or continued pretraining: long-context extension, up-weighting of domain or code data, and annealing on high-quality data.
  4. SFT (supervised): a smaller, curated set of instruction-response demonstrations teaches the format of being helpful.
  5. Preference optimization (RL from feedback): RLHF with a reward model and PPO; or DPO, which skips the reward model; or RLAIF and Constitutional AI, with AI-generated preferences; or GRPO for reasoning. This is where helpfulness, harmlessness, and style are dialed in.
  6. Evaluation: not pass/fail tests but distributional evals (MMLU, GPQA, SWE-bench, LMArena) and behavioral red-teaming, where a regression means a benchmark score dropping. The Statistical Learning chapter covers honest evaluation.
  7. Deployment: the artifact is the weights. Quantize them (Quantization: Math to Code), pick a runtime (Inference Frameworks), and serve with a KV cache (LLM Systems & Inference).
  8. Monitoring and iteration: watch for drift, jailbreaks, and regressions; collect production preferences; and feed them back into the next SFT or preference round.

The LLM lifecycle versus the software SDLC

Section titled “The LLM lifecycle versus the software SDLC”

Set side by side, the two lifecycles share stage names but differ in almost every stage’s content:

StageTraditional software SDLCLLM development lifecycle
Requirementsspecs, user storiescapability target + evals defined first
Designarchitecture, modules, interfacesdata mixture, tokenizer, model architecture
Implementationhumans write deterministic codepretraining grows weights from data (self-supervised)
Refinement(none)SFT (supervised) + preference optimization (RLHF/DPO)
Testingunit/integration/e2e, deterministic pass/failevals: statistical, behavioral, red-team; “regression” = score drop
Build artifacta versioned binarya set of weights (+ tokenizer + config)
DeploymentCI/CD, blue-greenquantize → serve; same weights, many quantizations
Maintenancepatch the buggy linecan’t patch a line: mitigate with more data, more alignment, guardrails, or a retrain
Version controlgit over sourcegit over source + data + weights + eval provenance

Four differences matter most. First, behavior is specified versus emergent: code does exactly what is written, while a model does what the data made statistically likely, so you debug a distribution, not a line. Second, fixes are deterministic versus probabilistic: a software bug has a root-cause fix, while a model failure is reduced, by more SFT data, a preference pass, or a guardrail, and rarely eliminated. Third, “it compiles” has no analog: the closest signal is a loss curve plus eval scores, and success is graded, not binary. Fourth, the source of truth moved: in software the code is canonical, while for an LLM the data and the eval set are canonical and the weights are a build output. Reproducibility means versioning data and experiments, not just code, and the Pragmatic Programmer’s principles of DRY and reversibility from Software Engineering still apply, to your data and pipeline.

The engineering practices of the right-hand column, review, testing as evals, reproducible builds, and deprecation, are exactly Software Engineering applied to ML. The two lifecycles diverge in what you build but converge on how to build it responsibly. For a contrast with the classic software lifecycle, read Software Engineering at Google.

This chapter sits between the foundations and the systems. The architecture foundations, transformers, attention, scaling laws, and VAE and diffusion basics, come from Deep Learning, which also covers the self-supervised, Siamese, contrastive, and JEPA objectives behind pretraining and the RLHF and DPO methods for post-training. Running these models, with KV caches, GQA and MLA, FlashAttention, and serving, is the subject of LLM Systems & Inference; making them fit with GGUF, AWQ, and FP8 is Quantization: Math to Code; and the candle, diffusers, and transformers runtimes where they execute are mapped in Inference Frameworks. The pipeline from pretraining through post-training is worked out in detail in Training and Post-Training. The KL divergence, score, and entropy in the diffusion and VAE objectives come from Information Theory in Mathematics, and building responsibly across the LLM lifecycle connects to Software Engineering.

This material appears throughout the industry: in Gemma and Gemini architecture, multimodality, and diffusion (Imagen, Veo) at Google DeepMind; in GPT architecture, multimodality, and scaling at OpenAI; in transformer internals, interpretability, and post-training at Anthropic; in the Llama recipe and open-weight strategy at Meta; in the Transformers and Diffusers open ecosystem at Hugging Face; and in Flux and Stable Diffusion, with flow matching and MMDiT, at Black Forest Labs and Stability.

  • foundation model: a model pretrained on broad data at scale and then adapted to many downstream tasks.
  • adaptation ladder: the sequence of increasingly expensive ways to specialize a model, from prompting through RAG and fine-tuning to continued pretraining.
  • RoPE: rotary position embedding, which rotates queries and keys by position to encode relative position.
  • SwiGLU: a gated MLP, (Swish(xW)⊙xV)W2(\text{Swish}(xW) \odot xV)W_2, that replaced the ReLU feed-forward block.
  • 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.
  • patchify: cutting an image into a grid of patches, each embedded as one token.
  • classifier-free guidance: combining conditional and unconditional denoising predictions with weight ww to trade diversity for prompt adherence.
  • flow matching: training a velocity field along straight paths between noise and data, giving fewer, straighter sampling steps.
  • JEPA: a non-generative self-supervised architecture that predicts the embedding of a masked target rather than reconstructing it.
  • representation collapse: the failure of joint-embedding training in which all inputs map to the same point.
  • A foundation model is pretrained once and adapted many times; most practitioners now build with models, with latency and cost as first-class constraints.
  • The transformer has converged to a recipe, decoder-only with pre-norm, RMSNorm, RoPE, SwiGLU, and GQA, optionally MoE, and the major open families differ mostly at the margins.
  • Attention is the architectural battleground: MHA, MQA, GQA, and MLA trade quality for KV-cache size, while sliding-window and sparse variants trade global context for linear cost.
  • Everything is tokens: text subwords, image patches, and audio codec codes or spectrogram frames all feed one architecture, which is how models went multimodal.
  • Diffusion generates by denoising, and modern diffusion is a transformer (DiT) trained with flow matching, converging with the LLM stack.
  • Building an LLM is not the software SDLC: behavior is grown from data through self-supervised pretraining, SFT, and preference optimization, so tests become evals and fixes become more data and alignment.
  1. Why did foundation models shift most practitioners from training models to adapting them, and what is the cheapest-to-most-expensive order of adaptation methods?
    AnswerPretraining on internet-scale data yields general representations and emergent capabilities, such as in-context learning, that a per-task model cannot match, and pretraining is expensive enough that few teams repeat it. Adaptation, in order of cost, is prompting, few-shot prompting, RAG, PEFT such as LoRA, full fine-tuning, and continued pretraining.
  2. List the components of the modern decoder-only recipe and say what each replaced and why.
    AnswerPre-norm replaced post-norm for stable deep training; RMSNorm replaced LayerNorm because it is cheaper; RoPE replaced learned or sinusoidal positions because it encodes relative position and extrapolates; SwiGLU replaced the ReLU FFN for better quality per parameter; GQA replaced MHA for a smaller KV cache; and MoE optionally replaces the dense MLP to add parameters without adding per-token FLOPs.
  3. Why is attention called a fight over the KV cache, and how do MQA, GQA, and MLA differ?
    AnswerDuring decoding every token reads all previous keys and values, so the number and size of K/V heads set the cache size and therefore how many concurrent users fit in memory. MQA shares a single K/V head across all query heads (tiny cache, some quality loss), GQA uses a few shared groups (the standard compromise), and MLA compresses K/V into a low-rank latent (DeepSeek's large cache savings).
  4. Why does audio need a codec or spectrogram front end while text does not?
    AnswerText is discrete and low-rate, so subword tokens are already a manageable sequence. Audio is continuous and high-rate, at 16,000 or more samples per second, so it must be converted to spectrogram frames or quantized into discrete codec codes (for example EnCodec or SoundStream with RVQ) to reach a token rate a transformer can handle, and streaming latency matters more.
  5. State the DDPM training loss and the flow-matching loss, and explain the practical advantage of flow matching.
    AnswerDDPM trains $\epsilon_\theta(x_t, t)$ to predict the added noise, minimizing $\mathbb{E}\lVert \epsilon - \epsilon_\theta(x_t, t) \rVert^2$. Flow matching learns a velocity field along the straight path $x_t = (1 - t)x_0 + t x_1$, minimizing $\mathbb{E}\lVert v_\theta - (x_1 - x_0) \rVert^2$. Straighter paths need fewer sampling steps.
  6. How does JEPA differ from contrastive Siamese learning and from generative pretraining?
    AnswerContrastive Siamese networks pull embeddings of two views of the same datum together and push other pairs apart, guarding against collapse with negatives, momentum encoders, or stop-gradients. Generative pretraining reconstructs tokens or pixels. JEPA predicts the embedding of a masked target from a context, entirely in representation space, avoiding collapse with asymmetric encoders, an EMA target, and a predictor, so it spends no capacity modeling unpredictable detail.
  7. Give the four differences between the LLM lifecycle and the software SDLC that matter most.
    AnswerBehavior is emergent rather than specified, so you debug a distribution; failures are reduced probabilistically rather than fixed at a root cause; there is no "it compiles", only graded loss curves and eval scores; and the source of truth is the data and eval set, with weights as a build output, so reproducibility requires versioning data, weights, and eval provenance as well as code.

Chapter contents