The LLM lifecycle and model landscape
From trillions of web tokens to a chat assistant — and how to pick one
Every decision you make with LLMs — which model to call, whether to fine-tune (8.2 Fine-tuning and PEFT), how to prompt (8.4 Prompting as programming), what to expect from a "reasoning" model (8.6 Reasoning models and test-time compute) — depends on understanding how these models are actually produced. This lesson gives you the full pipeline (data → pretraining → post-training) and the late-2026 landscape of closed and open-weight models, so that model cards, pricing pages and technical reports stop being noise.
You'll be able to
- Describe the three training stages (pretraining, supervised fine-tuning, preference/RL) and what each contributes
- Explain how pretraining corpora are built, filtered and deduplicated, and why data quality matters more than raw size
- Estimate training compute from parameters and tokens and relate it to GPU-hours and cost
- Distinguish base, instruct and reasoning models and pick the right one for a task
- Choose a model using capability, cost, latency, context, modality, privacy and license criteria
Key ideas
- An assistant is one transformer trained in three stages: pretraining (knowledge), SFT (format), preference/RL (behavior and reasoning).
- Pretraining data is mostly filtered web crawl plus code, books and synthetic text; quality filtering and deduplication matter as much as scale.
- Training compute is C ≈ 6ND; production models are trained far past Chinchilla's D ≈ 20N because inference cost scales with N.
Show 4 more key ideas
- Base models complete text, instruct models follow a chat template, reasoning models think before answering at higher cost.
- Frontier closed models (Claude, GPT, Gemini) and open-weight families (Llama, Qwen, DeepSeek, Mistral, Gemma) coexist; open weights are not the same as open source.
- Choose models by your own eval, then cost, latency, context/modality, privacy and license — in that order.
- Model cards and technical reports should be read for what they omit as much as for what they report.
Suggested path through this lesson
Three stages, one model
A modern assistant is the same transformer (7.6 Decoder-only: GPT and autoregressive generation) trained in three stages. Pretraining teaches it to predict the next token on trillions of tokens of text and code; the result is a base model — a superb autocomplete with broad knowledge but no notion of being helpful. Supervised fine-tuning (SFT) continues training on a much smaller set of (prompt, ideal response) pairs so the model learns the format of being an assistant. Preference optimization and RL (RLHF, DPO, RL with verifiable rewards — 8.3 Alignment: RLHF, PPO, DPO, GRPO and Constitutional AI) then shape behavior: helpfulness, honesty, refusals, and — for reasoning models — the habit of thinking before answering (8.6 Reasoning models and test-time compute).
Intuition. Andrej Karpathy's analogy: pretraining is reading every textbook; SFT is studying worked examples; RL is doing practice problems and learning from whether you got them right.
| stage | data | scale | what it gives |
|---|---|---|---|
| pretraining | web, code, books, papers | –+ tokens | knowledge, language, in-context learning |
| SFT / instruction tuning | curated (prompt, response) pairs | – examples | assistant format, instruction following |
| preference / RL | comparisons, verifiers, rubrics | –+ prompts | behavior, safety, reasoning |
Where the tokens come from
The bulk of pretraining data is filtered web crawl (Common Crawl snapshots), plus code repositories, books, Wikipedia, scientific papers, and increasingly synthetic data written by other models. Turning a crawl into training data is a pipeline of its own:
- Text extraction from HTML (boilerplate removal).
- Language identification and quality filtering — heuristics (document length, symbol ratios, repeated lines) and learned classifiers that score "educational value" or similarity to trusted sources.
- Deduplication at document and near-document level (MinHash/LSH on shingles) — duplicates waste compute and increase memorization.
- Safety and PII filtering, and decontamination: removing benchmark test sets so evaluations stay meaningful (8.7 Evaluating LLMs).
- Mixing: choosing proportions of web/code/math/multilingual data, often with a final annealing phase that up-weights the highest-quality data.
Open pipelines such as FineWeb (about 15 trillion tokens of filtered Common Crawl) and fully open efforts like OLMo document every step; most frontier labs publish only summaries. Two empirical facts drive the field: data quality filtering buys as much as several times more raw data, and when data is scarce, repeating it for up to roughly four epochs costs little — beyond that, returns fall off.
Tokens, compute and money
From 7.9 Scaling laws and compute-optimal training: training FLOPs for parameters and tokens. Chinchilla's compute-optimal rule is , but production models are over-trained far beyond it because inference cost depends on , not : Llama 3's 8B model was trained on about 15 trillion tokens — nearly 2,000 tokens per parameter.
Math check. 8B parameters × 15T tokens: FLOPs. An H100 sustaining about FLOP/s in bf16 (roughly 40% utilization) needs GPU-seconds, i.e. about half a million GPU-hours before counting failures and restarts. The Llama 3 report gives the actual figures — it is on the order of a million GPU-hours, consistent with this estimate.
At cloud prices of a few dollars per GPU-hour, that is millions of dollars for a small model; frontier runs use tens of thousands of accelerators for months. This is why almost nobody pretrains from scratch and why fine-tuning (8.2 Fine-tuning and PEFT) and retrieval (9.1 Why RAG, and the canonical pipeline) matter so much.
Base vs instruct vs reasoning
| kind | how it behaves | when to use |
|---|---|---|
| base | continues text; needs few-shot formatting; will happily continue a question with more questions | research on pretraining, custom post-training, few-shot classification pipelines |
| instruct / chat | follows instructions, uses a chat template with special tokens, refuses some requests | nearly all applications |
| reasoning | produces (often hidden) chains of thought before the answer, trained with RL on verifiable tasks | math, code, planning, hard analysis; slower and costlier per answer |
The chat template matters in practice: an instruct model expects its conversation serialized with the exact special tokens it was trained on; feeding it raw text degrades it. Libraries apply the template for you, but when you fine-tune (8.2 Fine-tuning and PEFT) you must match it.
The landscape in late 2026
Two tiers coexist. Frontier closed models are served through APIs by a handful of labs — Anthropic's Claude, OpenAI's GPT and o-series, Google DeepMind's Gemini families — and lead on the hardest reasoning, agentic and multimodal tasks. Open-weight models you can download and run include Meta's Llama, Alibaba's Qwen, DeepSeek, Mistral, Google's Gemma, plus families such as Microsoft's Phi, NVIDIA's Nemotron and the fully open OLMo. The capability gap between the best open and closed models has narrowed to months on many benchmarks, and open reasoning models exist since DeepSeek-R1 (January 2025).
A few distinctions worth keeping straight:
- Open weights ≠ open source. Most releases publish weights under a license (Apache-2.0 or MIT for some Qwen, DeepSeek and Mistral models; custom community licenses for Llama and Gemma) but not the training data or full code. OLMo-style projects release everything.
- Model families ship in sizes (e.g. 1B–400B+) and variants (base, instruct, reasoning, vision, long-context). Smaller models are distilled from or trained alongside bigger siblings.
- Trends that are settled: natively multimodal inputs, context windows of hundreds of thousands of tokens, reasoning modes with adjustable effort, tool use as a first-class capability (10.2 Tool use and function calling), and price tiers that differ by 50–100× between flagship and small models.
Exact version numbers and leaderboard positions change every few months; the way to stay current is a leaderboard (e.g. LMArena, Artificial Analysis) plus your own evaluation (8.7 Evaluating LLMs).
Choosing a model
Decide in this order:
- Capability on your task — measured on your own eval set, not a public benchmark.
- Cost — priced per million tokens, with output tokens typically 3–5× input and cached input often much cheaper. Estimate tokens per request × requests per day.
- Latency — time to first token and tokens per second; reasoning modes add seconds to minutes.
- Context window and modality — do you need long documents, images, audio?
- Privacy and deployment — API with data-retention terms vs self-hosting open weights (needs GPUs and an inference server such as vLLM, 7.10 Efficient inference: KV cache, GQA, FlashAttention, speculative decoding, quantization).
- License and ecosystem — commercial use, fine-tuning rights, tooling support.
A practical workflow: establish a ceiling with the strongest model you can afford, build the eval, then test cheaper and smaller models (and routing between them) until quality drops below what you need.
Reading a model card or technical report
Look for: training data description and cutoff, parameter count and architecture, tokens trained, post-training method, evaluation tables (with the exact prompting setup), safety evaluations, known limitations, license, and intended use. Treat missing information as information.
Where this shows up later
- Fine-tuning and PEFT build on the SFT stage — 8.2 Fine-tuning and PEFT; preference optimization and RL on verifiable rewards are the third stage — 8.3 Alignment: RLHF, PPO, DPO, GRPO and Constitutional AI, 8.6 Reasoning models and test-time compute.
- Benchmarks and model cards only mean something once you can evaluate — 8.7 Evaluating LLMs.
- Retrieval (9.1 Why RAG, and the canonical pipeline) and agents (10.1 What is an agent? Loops, autonomy and workflows vs agents) are built around model choice, cost and context limits introduced here.
Common pitfalls (4)
- Judging a model by a public leaderboard alone — benchmark gains often do not transfer to your task.
- Feeding an instruct model raw text without its chat template, then concluding it is 'bad'.
- Comparing prices per million tokens without accounting for the input/output asymmetry and for how many tokens a reasoning model actually emits.
- Assuming 'open weights' means you may use the model for anything; read the license.
Recap: all 7 key points
- An assistant is one transformer trained in three stages: pretraining (knowledge), SFT (format), preference/RL (behavior and reasoning).
- Pretraining data is mostly filtered web crawl plus code, books and synthetic text; quality filtering and deduplication matter as much as scale.
- Training compute is C ≈ 6ND; production models are trained far past Chinchilla's D ≈ 20N because inference cost scales with N.
- Base models complete text, instruct models follow a chat template, reasoning models think before answering at higher cost.
- Frontier closed models (Claude, GPT, Gemini) and open-weight families (Llama, Qwen, DeepSeek, Mistral, Gemma) coexist; open weights are not the same as open source.
- Choose models by your own eval, then cost, latency, context/modality, privacy and license — in that order.
- Model cards and technical reports should be read for what they omit as much as for what they report.
Watch
The definitive end-to-end tour: pretraining data, tokenization, SFT, RLHF and reasoning. Watch in two sittings.
Read
Exercises
- Compute and cost estimate
For a hypothetical 3B-parameter model trained on 6T tokens, compute , convert to H100-hours at FLOP/s sustained, and price it at $2.50 per GPU-hour. Repeat for a Chinchilla-optimal token count (). Expected: the over-trained run costs about 100× the compute-optimal one.
- Base vs instruct, side by side
Using the Hugging Face
transformerspipeline (or a hosted playground), send the same three prompts to a base model and its instruct sibling from one family (e.g. a small Qwen or Llama). Note how the base model continues rather than answers, and how the instruct model changes once you wrap the prompt in the correct chat template withtokenizer.apply_chat_template. - Read a model card like a reviewer
Pick one recent open-weight release and fill in a one-page template: data sources and cutoff, parameter count, tokens trained, post-training method, three headline eval numbers with their exact setup, license terms, stated limitations. Mark every field the card leaves unspecified.
- Cost model for an app
Sketch a customer-support assistant handling 10,000 conversations/day with 2,000 input and 400 output tokens each. Compute monthly cost for a flagship model and for a small model at current list prices, then estimate the saving from caching a 1,500-token system prompt. Expected: the output-token line and caching dominate the answer.
Quiz
Flashcards
These cards are now in your spaced-repetition queue. Review all due cards →