Skip to content

Chapter 15 — Pretraining at Scale: Data, Scaling Laws, and Training Runs

Part IV — Transformers and LLMs · 6–8 weeks

What you will learn

This chapter covers the differences between the small model of Chapter 14 and a released open large language model (LLM): the data, the model size, and the length and cost of the training run. It describes how a pretraining corpus is built from web crawls and curated sources by text extraction, filtering, deduplication, and mixing, and how small ablation models are used to choose among data recipes. It presents the scaling laws of Kaplan et al. and of Hoffmann et al. (Chinchilla), which relate the loss to parameters, tokens, and compute, and the estimate C ≈ 6ND, which converts a parameter count N and a token count D into floating-point operations (FLOPs), GPU-hours, and cost. It also covers the configuration of a long training run — batch size, learning-rate schedule, checkpointing, and recovery from loss spikes — as documented in the reports of open models such as OLMo 2, Llama 3, and SmolLM3.

Topics

  • Sources of pretraining text: Common Crawl, code, books, papers, and curated corpora
  • Legal and privacy constraints on training data: licenses, copyright, and removal of personal information
  • Corpus construction: text extraction, language identification, quality filtering, deduplication, and removal of benchmark data (decontamination)
  • Open corpora: The Pile, RefinedWeb, Dolma, FineWeb, and FineWeb-Edu
  • Data mixtures, synthetic data, and ablations on small models to choose among them
  • Training compute: C ≈ 6ND, FLOPs, GPU-hours, model FLOPs utilization (MFU), and cost
  • Scaling laws (Kaplan, Chinchilla) and compute-optimal training
  • Token budgets in practice: training beyond the compute-optimal point to reduce inference cost
  • Hyperparameters at scale: batch size, learning rate, and schedules (cosine, warmup-stable-decay)
  • Training stability: loss spikes, their mitigations, checkpointing, and restarts
  • The effect of data quality on downstream evaluation results

Resources

Suggested path. Start with The Smol Training Playbook, which follows one open training run from the decision to pretrain through ablations, data mixing, and failure recovery; it is book-length, so read it over several weeks alongside the other material. In parallel, watch CS336 lectures 9 and 11 with the Kaplan and Chinchilla papers, then lectures 13 and 14 with the FineWeb paper; Transformer Math 101 supplies the compute formulas for the milestone, and the final part of Karpathy's "Let's reproduce GPT-2 (124M)", listed in Chapter 14, shows a complete run on 10B tokens of FineWeb-Edu. Of the model reports, read at least the pretraining sections of OLMo 2 and Llama 3. When time is short, omit CS324, the DeepLearning.AI short course, Raschka's bonus material, The Pile, RefinedWeb, Dolma, and DeepSeek-V3.

University courses

  • Stanford — CS336: Language Modeling from Scratch by Tatsunori Hashimoto and Percy Liang (free; Spring 2026 lecture videos and assignments; start here: lectures 9 and 11 "Scaling laws", lecture 13 "Data (sources, datasets)", and lecture 14 "Data (filtering, deduplication, mixing, synthetic data)"; lecture 2, first assigned in Chapter 14, supplies the FLOPs accounting; Assignment 3 (Scaling) has instructions for non-students, because its hosted training API is reserved for enrolled students; the filtering and deduplication parts of Assignment 4 (Data) run offline, and its final 8-GPU training run can be omitted).
  • Stanford — CS324: Large Language Models by Percy Liang, Tatsunori Hashimoto, and Christopher Ré (free; Winter 2022 lecture notes; optional: the notes on Data, Training, and Scaling laws are a short written summary of the same topics, without the developments after 2022).

Online courses (MOOCs)

  • DeepLearning.AI and Upstage — Pretraining LLMs by Sung Kim and Lucy Park (free; 1h29m; optional: notebooks on data preparation, packing of token sequences, model initialization, a short training run, and evaluation).

Books

Lectures, papers and articles

Milestone

Write a two-page training plan for a 1B-parameter open model: data sources and mixture, token budget (one compute-optimal and one over-trained variant), compute in FLOPs from C ≈ 6ND, GPU-hours and cost on a named GPU at a stated MFU, and the loss predicted by the Chinchilla parametric fit. Validate the arithmetic against published figures: reproduce the 3.8 × 10²⁵ FLOPs that the Llama 3 report states for its 405B model, and compute the MFU implied by the GPU count and training duration reported for SmolLM3.

Estimated time

6–8 weeks.