The Landscape of Large Language Models
local graph
Chapter 1 — The Landscape of Large Language Models
Section titled “Chapter 1 — The Landscape of Large Language Models”Part I — The Landscape and the Foundations
In the span of a few years, the large language model went from a research curiosity to the most consequential artifact in software. The pace has been disorienting: the flagship open model of one quarter is a footnote by the next. This book takes the opposite of a snapshot approach. Rather than teach one model, it teaches the machinery that every modern model shares, using the best open implementations as worked examples. To do that well, you first need a map of the territory — who builds these systems, how their designs differ, and which numbers actually mean something. That is the job of this chapter.
We will keep returning to a single comparative lens: a modern LLM is a stack of choices — how it attends, where it puts position, how it normalizes, whether it is dense or sparse, how it is trained and aligned — and different labs make different choices for different reasons. By the end of the book you will be able to make every one of those choices yourself. Here, we simply lay them on the table.
1.1 Open-Source, Open-Weight, and Closed
Section titled “1.1 Open-Source, Open-Weight, and Closed”Three release models coexist, and the difference matters for anyone who wants to learn.
-
Closed / API-only. The weights never leave the provider. You send tokens and receive tokens. GPT-5, Claude, and Gemini are the canonical examples. You can study their behavior but not their internals.
-
Open-weight. The trained parameters are published, usually under a permissive or quasi-permissive license, often with inference code — but the full training data and recipe are typically withheld. This is where most of the frontier-adjacent readable work lives: DeepSeek, Qwen, Llama, Mistral, Gemma, and the OpenAI gpt-oss models.
- Open-source (in the strict sense). Weights, code, and enough of the data and method to reproduce the model, under an OSI-style license. Fully open efforts (for example the OLMo and some research lines) are rarer but invaluable for teaching.
This book centers on open-weight models because they are the ones you can download, read, run, and modify. DeepSeek is our primary reference: its technical reports and code are unusually transparent, and its architecture (Multi-head Latent Attention plus a fine-grained Mixture-of-Experts) has become a template that other labs now follow. But we deliberately compare DeepSeek against every other major family at each step, because the disagreements between them are where the real understanding lives.
1.2 A Family Tree of Modern Models
Section titled “1.2 A Family Tree of Modern Models”Five lineages dominate the open-weight world, with a long tail of strong challengers. Figure 1.1 sketches the milestones that matter for this book.
[!visual-conversion] Timeline, PDF 024 (printed 26): a horizontal axis with ticks at 2023, 2024, 2025 and 2026, and labelled boxes above and below it. Given here left to right, with the side of the axis each box sits on; positions between ticks are as drawn, not exact dates. The two boxes drawn with darker borders are marked ●.
| Position on the axis | Above the axis | Below the axis |
|---|---|---|
| just after 2023 | Llama / Llama 2 (Meta, open) | |
| late 2023 | Mistral 7B — GQA+SWA | |
| late 2023 | Mixtral 8x7B — open MoE | |
| early 2024 | DeepSeek-V2 — MLA debut | |
| mid 2024 | Llama 3 — dense, 405B | Gemma / Gemma 2 (Google open) |
| end of 2024 | ● DeepSeek-V3/R1 — MoE+MLA, RL | |
| early 2025 | Qwen3 — dense + MoE | Llama 4 (MoE) — Scout/Maverick |
| mid 2025 | gpt-oss — OpenAI open | Kimi K2 · GLM — trillion-class MoE |
| early 2026 | ● DeepSeek V3.2/V4 — sparse / hybrid; Qwen3.5 hybrid |
Figure 1.1. A simplified timeline of open-weight milestones. Boxes nearer the axis with darker borders mark the DeepSeek line that anchors this book; Mixtral popularized open MoE, DeepSeek-V2 introduced MLA, and by 2025–2026 the field converged on sparse Mixture-of-Experts with increasingly exotic attention.
The story in one paragraph: Meta’s Llama releases made capable weights freely available and seeded an ecosystem. Mistral showed a small team could ship efficient models and put Mixture-of-Experts (MoE) into open hands with Mixtral. DeepSeek pushed architecture forward — Multi-head Latent Attention in V2, then the 671-billion-parameter V3 and the R1 reasoning model — at a training cost low enough to rattle the industry. Alibaba’s Qwen matched the frontier across an enormous range of sizes and, with Qwen3.5, moved to a hybrid attention/state-space design. Google’s Gemma brought distilled, license-friendly small models. And in 2025 OpenAI returned to open weights with gpt-oss, its first since GPT-2. A cluster of Chinese labs — Moonshot (Kimi), Zhipu (GLM), Xiaomi (MiMo) — now ships trillion-parameter MoE models that trade the open lead month to month.
1.3 The Field at a Glance
Section titled “1.3 The Field at a Glance”Table 1.1 collects the headline specifications of the models we will refer to most. Two patterns jump out immediately: the convergence on MoE for flagship models, and the decoupling of total parameters (what the model knows) from active parameters (what it costs to run a token).
| Model | Developer | Released | Arch. | Params (total / active) | Context | License | Headline idea |
|---|---|---|---|---|---|---|---|
| DeepSeek-V3 | DeepSeek | Dec 2024 | MoE | 671B / 37B | 128K | MIT | MLA + fine-grained MoE + MTP, FP8 |
| DeepSeek-R1 | DeepSeek | Jan 2025 | MoE | 671B / 37B | 128K | MIT | RL-only reasoning (GRPO) |
| DeepSeek-V3.2 | DeepSeek | Dec 2025 | MoE | 671B / 37B | 128K+ | MIT | DeepSeek Sparse Attention |
| DeepSeek-V4 | DeepSeek | 2026 | MoE | — / — | ~1M | MIT | hybrid compressed attention |
| Qwen3-235B | Alibaba | Apr 2025 | MoE | 235B / 22B | 128K | Apache 2.0 | unified think/non-think modes |
| Qwen3.5 | Alibaba | Feb 2026 | hybrid MoE | 397B / 17B | 256K+ | Apache 2.0 | Gated-DeltaNet + sparse MoE |
| Model | Developer | Released | Arch. | Params (total / active) | Context | License | Headline idea |
|---|---|---|---|---|---|---|---|
| Llama 4 Scout | Meta | Apr 2025 | MoE | 109B / 17B | 10M | Llama 4 | 16 experts, 10M context |
| Llama 4 Maverick | Meta | Apr 2025 | MoE | 400B / 17B | 1M | Llama 4 | 128 experts, native multimodal |
| Llama 4 Behemoth | Meta | 2025* | MoE | ~2T / 288B | — | Llama 4 | teacher for co-distillation |
| Mixtral 8×22B | Mistral | 2024 | MoE | 141B / 39B | 64K | Apache 2.0 | early open sparse MoE |
| Gemma 3 27B | Mar 2025 | dense | 27B / 27B | 128K | Gemma | strong small dense, distilled | |
| gpt-oss-120b | OpenAI | Aug 2025 | MoE | 117B / 5.1B | 128K | Apache 2.0 | MXFP4, 1×80GB GPU |
| gpt-oss-20b | OpenAI | Aug 2025 | MoE | 21B / 3.6B | 128K | Apache 2.0 | runs in 16 GB |
| Kimi K2 | Moonshot | 2025 | MoE | ~1T / 32B | 128K+ | MIT-style | trillion-scale, agentic |
| GPT-5.x | OpenAI | 2025 | closed | — | — | API | frontier reasoning |
| Claude Opus 4.x | Anthropic | 2025 | closed | — | — | API | frontier, long context |
| Gemini 2.5 Pro | 2025 | closed | — | ~1M+ | API | natively multimodal |
Table 1.1 — Representative open-weight models (and closed frontier, for context)
Italic rows are closed/API-only and listed only for orientation; their internals are undisclosed. *Behemoth was announced as a teacher model and, at the time of writing, was not released as open weights. “Context” is the advertised maximum; usable context is often shorter. Figures are as reported by developers.
Read the active column carefully — it is the single most important number for cost. A MoE model with 671B total but 37B active runs, per token, at roughly the cost of a 37B dense model while carrying the knowledge of something far larger. This is the trick that made trillion-parameter open models practical, and Section 1.5 quantifies it.
1.4 Architectural Methodologies, Side by Side
Section titled “1.4 Architectural Methodologies, Side by Side”Strip away branding and a model is a set of answers to a handful of recurring questions. Table 1.2 lines up those answers for the major families. Every term in the header is the subject of a later chapter; for now, read it as a periodic table of design choices.
| Family | Attention | Position | Norm | FFN / experts | Precision |
|---|---|---|---|---|---|
| DeepSeek V3 | MLA (latent KV) | RoPE (decoupled) | RMSNorm, pre-norm | fine-grained MoE + shared expert; aux-loss-free | FP8 train |
| Qwen3 | GQA, QK-norm | RoPE | RMSNorm, pre-norm | dense or fine-grained MoE | BF16 |
| Qwen3.5 | Gated-DeltaNet + sparse attn (hybrid) | partial / RoPE | RMSNorm | sparse MoE | BF16/FP8 |
| Llama 3 | GQA | RoPE | RMSNorm, pre-norm | dense, SwiGLU | BF16 |
| Llama 4 | GQA (+ chunked long-ctx) | RoPE / NoPE mix | RMSNorm | MoE (16 or 128 experts) | FP8 |
| Mistral / Mixtral | GQA + sliding-window | RoPE | RMSNorm | dense or top-2 MoE | BF16 |
| Gemma 2/3 | GQA, local+global interleave | RoPE | RMSNorm (pre+post) | dense, GeGLU | BF16 |
| gpt-oss | GQA + attention sinks | RoPE (YaRN) | RMSNorm | MoE, SwiGLU | MXFP4 weights |
Table 1.2 — How the major families answer the core architectural questions
Simplified; configurations vary across sizes and revisions within a family. “NoPE” = no positional encoding on some layers. QK-norm normalizes queries and keys before the dot product.
The attention axis is the most consequential. Vanilla multi-head attention (MHA) stores a full set of keys and values per head, which makes the KV cache — the dominant memory cost at inference — enormous. The field’s answer has been a steady march toward storing less:
- GQA / MQA share key/value heads across query heads, cutting cache size by the grouping factor. This is the workhorse of Llama, Qwen, Mistral, and Gemma.
- MLA (DeepSeek) compresses keys and values into a small shared latent vector, then reconstructs them on the fly — a different and often more favorable point on the quality-versus-memory curve.
- Sparse attention (DeepSeek V3.2, Qwen3.5, Llama 4 long-context) attends to only a selected subset of past tokens, trading exactness for sub-quadratic cost at very long context.
The numbers make the stakes concrete. Consider a 60-layer model with 128-dimensional heads. Table 1.3 shows the per-token KV cache each scheme stores, normalized to MHA.
| Scheme | What is cached per layer | Values / token | Relative |
|---|---|---|---|
| MHA (64 heads) | K,V for all 64 heads | ~983,000 | 1.00× |
| GQA (8 KV groups) | K,V for 8 grouped heads | ~123,000 | 0.13× |
| MLA (latent 512) | one compressed latent (+ RoPE dims) | ~68,000 | 0.07× |
Table 1.3 — Relative KV-cache footprint per token (illustrative, 60 layers, head dim 128)
Order-of-magnitude figures to build intuition; exact values depend on head count, latent rank, and RoPE dimensions. The point is the ~15× spread from MHA to MLA, which translates directly into longer context and cheaper serving.
1.5 The Defining Split: Dense versus Sparse
Section titled “1.5 The Defining Split: Dense versus Sparse”If one decision separates the 2025–2026 flagships from their predecessors, it is the move from dense models (every parameter participates in every token) to sparse Mixture-of-Experts (a router sends each token to a few experts). Figure 1.2 contrasts the two forward passes.
[!visual-conversion] Two-panel diagram, PDF 029 (printed 31). Left panel “Dense FFN”, right panel “Mixture-of-Experts”. In print the active experts E2 and E3 are shaded and the idle experts E1 and E4 are drawn dashed. The relation sign in the two cost notes is too small to read with certainty; it is given as ∝.
flowchart TB
subgraph D["Dense FFN — cost ∝ total parameters"]
dt["token"] --> dffn["one big FFN<br/>all params active"] --> dout["output"]
end
subgraph M["Mixture-of-Experts — cost ∝ active parameters only"]
mt["token"] --> r["router (top-k)"]
r --> e2["E2"]
r --> e3["E3"]
e1["E1 (idle)"]
e4["E4 (idle)"]
e2 --> mout["output"]
e3 --> mout
end
classDef idle stroke-dasharray: 4 3
classDef active fill:#999
class e1,e4 idle
class e2,e3 active
Figure 1.2. Dense versus sparse computation. The dense block runs every parameter for every token; the MoE block routes each token to a small subset of experts (here 2 of 4), so only the shaded experts do work. Total capacity grows with the number of experts while per-token cost stays low.
Table 1.4 quantifies how aggressively current models exploit this. The “active fraction” is the share of parameters touched per token — and therefore, roughly, the inference cost relative to the model’s apparent size.
| Model | Total | Active | Active fraction | Experts (active / total) |
|---|---|---|---|---|
| Kimi K2 | ~1000B | 32B | 3.2% | 8 / 384 |
| Qwen3.5 | 397B | 17B | 4.3% | — |
| Llama 4 Maverick | 400B | 17B | 4.3% | 1 / 128 (+shared) |
| gpt-oss-120b | 117B | 5.1B | 4.4% | 4 / 128 |
| DeepSeek-V3 | 671B | 37B | 5.5% | 8 / 256 (+1 shared) |
| Qwen3-235B | 235B | 22B | 9.4% | 8 / 128 |
| Llama 4 Behemoth | ~2000B | 288B | 14.4% | — |
| Mixtral 8×22B | 141B | 39B | 27.6% | 2 / 8 |
Table 1.4 — Sparsity of leading MoE models
Expert counts are approximate and exclude always-on “shared” experts where used. The trend over time is toward more, smaller experts and a lower active fraction — the “fine-grained MoE” idea introduced by DeepSeek and now widespread.
Sparsity is not free. It complicates training (experts can collapse or overload — Chapter 11) and serving (tokens must be routed and gathered across devices — Chapter 19). The reason every major lab pays that price is the table above: capacity that would be ruinously expensive as a dense model becomes routine as a sparse one.
Key point Total parameters measure capability; active parameters measure cost. The defining engineering move of the current generation is to pull those two numbers as far apart as the training and serving systems can bear.
1.6 Reading Benchmarks Without Fooling Yourself
Section titled “1.6 Reading Benchmarks Without Fooling Yourself”You will see leaderboards everywhere, and you should treat them with structured suspicion. Table 1.5 gives a few reported figures for flagship open models, chosen because their developers published them. Even so, read the caveats below the table before you read the table.
| Model | AIME 2025 (math) | LiveCodeBench v5 | CodeForces (Elo) | Tool use (BFCL v3) |
|---|---|---|---|---|
| Qwen3-235B-A22B | 81.5 | 70.7 | 2056 | 70.8 |
| DeepSeek-R1 | ~80 | ~65 | ~2000 | — |
| gpt-oss-120b (high) | ≈ o4-mini | ≈ o4-mini | ≈ o4-mini | strong |
| Llama 4 Maverick | — | — | — | — |
Table 1.5 — Selected reported scores for flagship open models (reasoning mode where applicable)
Qwen figures are from the Qwen3 technical report. DeepSeek-R1 values are approximate ranges from its report. gpt-oss is reported by OpenAI as near-parity with o4-mini on core reasoning; exact cross-model numbers are not directly comparable. Llama 4 emphasized non-reasoning and multimodal benchmarks and is left blank here rather than mixing incomparable metrics.
Why single numbers mislead (1) Thinking vs non-thinking. Most 2025+ models can emit long chains of thought; scores with reasoning enabled are far higher and not comparable to scores without it. (2) Contamination. Popular benchmarks leak into training data, inflating scores in ways that do not generalize. (3) Prompt and format sensitivity. Few-shot count, chat template, and parsing can swing results several points. (4) Version drift. “Qwen3” or “DeepSeek” names a moving target; numbers attach to a specific checkpoint and date. (5) Metric cherry-picking. Every lab leads with the benchmarks it wins. Treat any table — including this one — as a starting point for your own evaluation (Chapter 29), never as a verdict.
1.7 What Modern LLMs Can Actually Do
Section titled “1.7 What Modern LLMs Can Actually Do”Ask a 2026 assistant to “look at this screenshot, find the bug, browse the docs, and build me a calculator,” and it will — yet almost none of that lives in the language model itself. It is worth being precise about this from the start, because the distinction between the core model and the system around it organizes the whole book.
-
Reading images and screenshots. Vision-language models fuse an image encoder with the transformer so the model “sees” pixels as tokens. This is a genuine model capability. Examples: GPT-5 and GPT-4o (vision), Gemini 2.5, Claude, Qwen-VL, DeepSeek-VL, and Llama 4’s native early-fusion multimodality.
-
Browsing the web. The model emits a search or click action; an agent harness executes it and feeds results back. The “browsing” is tool use, not the network stack living inside the weights. Examples: ChatGPT with search, Gemini, Perplexity, and Claude’s computer-use agents.
-
Compiling and running tools. Given a task, the model writes code and a sandbox runs it — for instance, generating an HTML form that performs a Monte Carlo simulation in JavaScript and renders the histogram live, or running Python to crunch a spreadsheet. Examples: ChatGPT Code Interpreter/Canvas, Claude Artifacts and code execution, Gemini.
- Handling files. Reading a PDF, zipping or unzipping an archive, converting formats — again the work of a code sandbox the model drives, not the model itself.
- Generating images, video, songs, and 3D. These are produced by separate generative models the assistant calls, usually diffusion or flow-matching systems rather than autoregressive LLMs. Images: DALL·E 3, Imagen, Midjourney, Stable Diffusion, FLUX. Video: Sora, Veo, Kling, Runway. Music: Suno, Udio. 3D meshes: Meshy, Tripo, Hunyuan3D.
| Capability | What is actually happening | In the model or the system? | Examples |
|---|---|---|---|
| Read image / screenshot | image encoder tokenizes pixels into the transformer | model (multimodal) | GPT-4o, Gemini, Qwen-VL, Llama 4 |
| Browse the web | model emits actions; harness fetches pages | system (agent + tools) | ChatGPT search, Perplexity |
| Run a JS/Python tool | model writes code; sandbox executes it | system (code interpreter) | Code Interpreter, Artifacts |
| Zip / unzip / convert files | code run in a sandbox | system (tools) | Code Interpreter, Cowork |
| Generate image / video / song / 3D | a separate diffusion/flow model is invoked | system (other models) | DALL·E, Sora, Suno, Meshy |
| Reason step by step | long chain-of-thought decoding | model | DeepSeek-R1, o-series, Qwen thinking |
Table 1.6 — Capability vs. mechanism: what is the model, and what is the system around it
The pattern is consistent: text understanding and reasoning are the model; perception of new modalities is added at the input; actions and media are delegated to tools and other models. This book builds the core engine and shows where each bolt-on attaches.
This framing is freeing. You do not need to learn ten different systems — you need to learn the one engine they all wrap, plus the small set of interfaces (tokenized images, tool calls, function schemas) through which the rest is attached. Multimodal input is covered in Chapter 31; tool use and agents are introduced there as well; and the reasoning that powers step-by-step problem solving is built directly, in Part VI.
1.8 How This Book Is Organized, and Why It Is Different
Section titled “1.8 How This Book Is Organized, and Why It Is Different”The remainder of the book follows the natural order of building a model.
- Part I finishes the foundations: the mathematics, automatic differentiation, and PyTorch fluency every later chapter assumes, plus the language-modeling objective itself.
- Part II builds a tokenizer and a pretraining data pipeline from scratch.
- Part III derives the transformer piece by piece and trains a working GPT — the first capstone.
- Part IV is the heart of the book: it upgrades that plain GPT into a frontier-class architecture — Mixture-of-Experts, Multi-head Latent Attention, multi-token prediction, and modern attention — reading DeepSeek’s code and comparing it with Qwen, Llama, and the rest at every step.
- Part V trains at scale: FP8, distributed parallelism, the infrastructure that makes a large run affordable, and continued pre-training — adapting an existing base model to new domains or languages by training further on fresh data before any fine-tuning, the most cost-effective way for a small team to specialize a frontier model.
- Part VI aligns the model: supervised fine-tuning, preference optimization, and reinforcement learning for reasoning (GRPO and the R1 recipe), plus distillation and quantization for cheap local deployment.
- Part VII serves and evaluates it, including the economics of inference.
- Part VIII is the second capstone — your own small DeepSeek-style model, end to end — followed by multimodal systems, agents, and the research frontier.
What makes this book different Most introductions stop at a plain GPT and a diagram of attention. This one goes further on purpose: (1) it reads real frontier source code — DeepSeek’s models and its open-infrastructure stack (FlashMLA, DeepEP, DeepGEMM, DualPipe) — rather than toy re-implementations; (2) it compares every design numerically across families (Qwen, Llama, Mistral, Gemma, gpt-oss, Kimi) instead of teaching one model in isolation; (3) it builds the genuinely modern pieces other books skip — fine-grained Mixture-of-Experts, Multi-head Latent Attention, FP8 training, and reinforcement-learned reasoning; (4) it treats systems and economics as first-class — distributed training, continued pre-training, distillation, quantization, KV-cache math, and the cost per token — so you can not only build a model but afford to run it; and (5) it is honest about evaluation, so you leave able to measure a model rather than trust a leaderboard.
Wherever a real implementation exists, we point to it by repository and file, and reproduce the parts worth reading closely. Code that we write from scratch is the book’s own; code we quote belongs to its authors and is used under the licenses listed in Appendix E. With the map in hand, we begin where every model begins: with the mathematics and the code that turn text into tensors.
1.9 The Scaling Hypothesis, Quantified
Section titled “1.9 The Scaling Hypothesis, Quantified”The central bet that organized the last several years of progress is the scaling hypothesis: that capability grows predictably as model size, training data, and compute increase together, with no obvious ceiling in sight. It is worth seeing the trajectory in numbers, because the sheer rate of growth is the story:
| Model (year) | Parameters | Note |
|---|---|---|
| GPT-2 (2019) | 1.5 B | fluent text at scale |
| GPT-3 (2020) | 175 B | in-context learning emerges |
| Chinchilla (2022) | 70 B | compute-optimal rebalancing |
| DeepSeek-V3 (2024) | 671 B / 37 B active | sparse MoE (Chapter 45) |
| GLM-5.2 (2026) | 744 B / 40 B active | sparse MoE (Chapter 44) |
Table 1.7 — A trajectory of scale (representative, approximate)
Two patterns in the table matter more than the raw numbers. The first is the pace: from a billion-parameter model that impressed in 2019 to hundred-billion-parameter models a year later, the growth was not incremental but explosive, and it was driven by the empirical finding that bigger reliably meant better. The second is the bend in the trajectory toward the end. The latest entries report two numbers — a large total and a much smaller active count — because the field discovered (Chapter 11) that you can keep growing the total parameter count, and thus capacity, while holding the active compute per token nearly flat through sparsity. The scaling hypothesis did not stop; it changed shape, decoupling capacity from cost. The scaling laws of Chapter 17 formalize the relationship the table only sketches, and the rest of this book is, in effect, an account of the engineering that made each step on this curve possible.
Bigger reliably meant better — then got sparse The scaling hypothesis drove an explosive rise in model size because capability tracked scale predictably. The recent split between total and active parameters shows it did not end but changed shape: grow capacity, hold per-token cost via sparsity.