Skip to content
ImagineWorld

The Landscape of Large Language Models

node_idnode-book_building-frontier-llm-from-scratch_chapter-01-the-landscape-of-large-language-models
node_typechapter-node
schema_profileworld.chapter_node.v1
statusactive
entropyhigh
manifoldworld
domainimagineworld.net
authorityinforms
layercorpus
chapter_num1
chapter_titleThe Landscape of Large Language Models
governed_byCORPUS
constitutional_citationCONSTITUTION
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.

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.

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 axisAbove the axisBelow the axis
just after 2023Llama / Llama 2 (Meta, open)
late 2023Mistral 7B — GQA+SWA
late 2023Mixtral 8x7B — open MoE
early 2024DeepSeek-V2 — MLA debut
mid 2024Llama 3 — dense, 405BGemma / Gemma 2 (Google open)
end of 2024● DeepSeek-V3/R1 — MoE+MLA, RL
early 2025Qwen3 — dense + MoELlama 4 (MoE) — Scout/Maverick
mid 2025gpt-oss — OpenAI openKimi 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.

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).

ModelDeveloperReleasedArch.Params (total / active)ContextLicenseHeadline idea
DeepSeek-V3DeepSeekDec 2024MoE671B / 37B128KMITMLA + fine-grained MoE + MTP, FP8
DeepSeek-R1DeepSeekJan 2025MoE671B / 37B128KMITRL-only reasoning (GRPO)
DeepSeek-V3.2DeepSeekDec 2025MoE671B / 37B128K+MITDeepSeek Sparse Attention
DeepSeek-V4DeepSeek2026MoE— / —~1MMIThybrid compressed attention
Qwen3-235BAlibabaApr 2025MoE235B / 22B128KApache 2.0unified think/non-think modes
Qwen3.5AlibabaFeb 2026hybrid MoE397B / 17B256K+Apache 2.0Gated-DeltaNet + sparse MoE
ModelDeveloperReleasedArch.Params (total / active)ContextLicenseHeadline idea
Llama 4 ScoutMetaApr 2025MoE109B / 17B10MLlama 416 experts, 10M context
Llama 4 MaverickMetaApr 2025MoE400B / 17B1MLlama 4128 experts, native multimodal
Llama 4 BehemothMeta2025*MoE~2T / 288B—Llama 4teacher for co-distillation
Mixtral 8×22BMistral2024MoE141B / 39B64KApache 2.0early open sparse MoE
Gemma 3 27BGoogleMar 2025dense27B / 27B128KGemmastrong small dense, distilled
gpt-oss-120bOpenAIAug 2025MoE117B / 5.1B128KApache 2.0MXFP4, 1×80GB GPU
gpt-oss-20bOpenAIAug 2025MoE21B / 3.6B128KApache 2.0runs in 16 GB
Kimi K2Moonshot2025MoE~1T / 32B128K+MIT-styletrillion-scale, agentic
GPT-5.xOpenAI2025closed——APIfrontier reasoning
Claude Opus 4.xAnthropic2025closed——APIfrontier, long context
Gemini 2.5 ProGoogle2025closed—~1M+APInatively 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.

FamilyAttentionPositionNormFFN / expertsPrecision
DeepSeek V3MLA (latent KV)RoPE (decoupled)RMSNorm, pre-normfine-grained MoE + shared expert; aux-loss-freeFP8 train
Qwen3GQA, QK-normRoPERMSNorm, pre-normdense or fine-grained MoEBF16
Qwen3.5Gated-DeltaNet + sparse attn (hybrid)partial / RoPERMSNormsparse MoEBF16/FP8
Llama 3GQARoPERMSNorm, pre-normdense, SwiGLUBF16
Llama 4GQA (+ chunked long-ctx)RoPE / NoPE mixRMSNormMoE (16 or 128 experts)FP8
Mistral / MixtralGQA + sliding-windowRoPERMSNormdense or top-2 MoEBF16
Gemma 2/3GQA, local+global interleaveRoPERMSNorm (pre+post)dense, GeGLUBF16
gpt-ossGQA + attention sinksRoPE (YaRN)RMSNormMoE, SwiGLUMXFP4 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.

SchemeWhat is cached per layerValues / tokenRelative
MHA (64 heads)K,V for all 64 heads~983,0001.00×
GQA (8 KV groups)K,V for 8 grouped heads~123,0000.13×
MLA (latent 512)one compressed latent (+ RoPE dims)~68,0000.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.

ModelTotalActiveActive fractionExperts (active / total)
Kimi K2~1000B32B3.2%8 / 384
Qwen3.5397B17B4.3%—
Llama 4 Maverick400B17B4.3%1 / 128 (+shared)
gpt-oss-120b117B5.1B4.4%4 / 128
DeepSeek-V3671B37B5.5%8 / 256 (+1 shared)
Qwen3-235B235B22B9.4%8 / 128
Llama 4 Behemoth~2000B288B14.4%—
Mixtral 8×22B141B39B27.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.

ModelAIME 2025 (math)LiveCodeBench v5CodeForces (Elo)Tool use (BFCL v3)
Qwen3-235B-A22B81.570.7205670.8
DeepSeek-R1~80~65~2000—
gpt-oss-120b (high)≈ o4-mini≈ o4-mini≈ o4-ministrong
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.

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.
CapabilityWhat is actually happeningIn the model or the system?Examples
Read image / screenshotimage encoder tokenizes pixels into the transformermodel (multimodal)GPT-4o, Gemini, Qwen-VL, Llama 4
Browse the webmodel emits actions; harness fetches pagessystem (agent + tools)ChatGPT search, Perplexity
Run a JS/Python toolmodel writes code; sandbox executes itsystem (code interpreter)Code Interpreter, Artifacts
Zip / unzip / convert filescode run in a sandboxsystem (tools)Code Interpreter, Cowork
Generate image / video / song / 3Da separate diffusion/flow model is invokedsystem (other models)DALL·E, Sora, Suno, Meshy
Reason step by steplong chain-of-thought decodingmodelDeepSeek-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.

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)ParametersNote
GPT-2 (2019)1.5 Bfluent text at scale
GPT-3 (2020)175 Bin-context learning emerges
Chinchilla (2022)70 Bcompute-optimal rebalancing
DeepSeek-V3 (2024)671 B / 37 B activesparse MoE (Chapter 45)
GLM-5.2 (2026)744 B / 40 B activesparse 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.