Part 2 · Train LLMs Chapter 5
Pre-training
The training pipeline, data engineering (filtering, deduplication, mixing), scaling laws, the compute and memory ledger and distributed parallelism: the engineering and scientific decisions that turn raw text into usable weights for a base model.
After this chapter you will be able to
- Draw the training pipeline from data to a base model, say what each stage optimizes, and reproduce its key experiments on a laptop.
- Name the lossy steps that turn web pages into training tokens, design near-duplicate removal with MinHash and banded LSH, and know its blind spots.
- Use scaling laws to split a compute budget between parameters and training tokens, and state their assumptions and known corrections.
- Estimate the FLOPs, GPU hours and memory (model states and activations) of a training run, and check the numbers a paper reports.
- Tell data, tensor and pipeline parallelism and ZeRO apart, and judge which to use under which conditions.
Pre-training sets the ceiling of a model’s ability and is the most expensive step in the whole pipeline. This chapter answers five questions: what stages a complete training pipeline consists of; how raw web pages become a training corpus (extraction, filtering, deduplication and mixing); how to split parameters and training data for a given compute budget; how many FLOPs, GPU hours and bytes of memory a run needs, and how to check the numbers papers report; and how a model that does not fit on one GPU is trained with parallelism.
The chapter builds on Compute and Systems: every number in the compute and memory ledgers comes from the hardware limits explained there. Once a base model is trained, the next chapter, Post-training and Alignment, turns it into a useful assistant.
Related paper explainers: Scaling Laws, the GPT series, LLaMA, FineWeb and Llama 3.
Chapter roadmap
- 5.1
The LLM Training Pipeline: From Data to Deployment
A map of the pipeline from data preparation, pretraining, SFT and preference alignment to evaluation and release, with the public data scale of each stage, plus a 0.86M-parameter byte-level GPT that trains on a laptop CPU to test data mixture, resuming and leakage.
Prerequisites3.2Attention Basics2.2From Language Modeling to Next-Token Prediction
- 5.2
Pretraining Data Engineering: Filtering, Deduplication and Mixing
A pretraining corpus is filtered, deduplicated and mixed step by step, and every step throws data away. This page shows what FineWeb, Gopher, DCLM and Llama 3 drop and why, then runs MinHash near-duplicate removal on a demo corpus: how many words may change before a copy stops counting.
Prerequisites5.1The LLM Training Pipeline2.5Tokenizers and Embeddings
- 5.3
Scaling Laws: How to Split Compute Between Parameters and Data
From Kaplan to Chinchilla: why loss falls as a power law in parameters, data and compute, how to split a compute budget between parameters and tokens, and why today's models are trained on far more data than the compute-optimal amount.
Prerequisites5.1The LLM Training Pipeline
- 5.4
The Compute and Memory Ledger of Training: FLOPs, MFU and Memory Budgets
How many FLOPs, GPU hours and bytes of memory does training a model need? This page works out where 6ND comes from, what MFU measures, why model states cost 16 bytes per parameter, how activation memory scales, and how to sanity-check reported GPU hours.
Prerequisites5.3Scaling Laws3.5Modern LLM Architecture
- 5.5
Distributed Training: Data, Tensor and Pipeline Parallelism
Data parallelism splits the batch, tensor parallelism the matrices inside a layer, pipeline parallelism the stack of layers; ZeRO and FSDP shard optimizer state, gradients and parameters. Runnable checks verify gradient averaging, ring all-reduce traffic, the Megatron split and the bubble formula.
Prerequisites5.1The LLM Training Pipeline