Machine Learning GuideOCDevelAll episodes
MLG 034 Large Language Models 1
Large language models (LLMs) train compute-optimally at about 20 tokens per parameter (Chinchilla), often past that for cheaper inference, then align through supervised fine-tuning and RLHF, where human rankings train a reward model and PPO tunes the LLM against it. Also covers emergent abilities, mixture of experts, reward hacking, chain of thought and reasoning models.
Links • Notes and resources at ocdevel.com/mlg/34
- Join the free MLG group: listen to my other AI shows, ask me questions, and talk with other listeners
LLMs are scaled-up transformers Large language models (LLMs) are transformers (MLG 033): stacks of self-attention and feed-forward layers that train in parallel, which recurrent neural networks (RNNs) could not. The classical NLP background is in MLG 018 to 020, and RNNs and embeddings in 022 and 023.
Scaling laws: Kaplan vs Chinchilla • Scaling Laws for Neural Language Models (Kaplan et al., 2020): test loss (cross-entropy) falls as a power law in parameters, training tokens and compute, over more than seven orders of magnitude. The network's shape, depth against width, matters far less than scale. Growing parameters with data fixed brings diminishing returns from overfitting; the penalty depends on N^0.74/D (N parameters, D tokens), so data need only grow sublinearly with model size.
- Training Compute-Optimal Large Language Models (Hoffmann et al., DeepMind, 2022), the Chinchilla paper: for a fixed compute budget, scale parameters and tokens together, about 20 tokens per parameter. Earlier large models were undertrained: the 70B-parameter Chinchilla beat the 280B Gopher and the 175B GPT-3.
GPT-2 had 1.5 billion parameters and GPT-3 175 billion. OpenAI never published GPT-4's size; outside estimates run near 1.8 trillion, as a mixture of experts.
Training-optimal vs inference-optimal Chinchilla's ratio minimizes training cost. A model serving many users can spend more on inference over its lifetime than on training, so labs train smaller models well past that ratio: Llama 2 on 2 trillion tokens, Llama 3 on 15 trillion. Test-time compute is the other lever: more computation per query for reasoning steps, sampled answers and self-critique, at higher latency and cost per query.
Emergent abilities Emergent Abilities of Large Language Models (Wei et al., 2022) describes abilities absent in small models that appear sharply past a scale threshold:
- In-context learning (ICL): doing a new task from examples in the prompt (one-shot or few-shot).
- Instruction following: carrying out instructions for tasks not seen in training.
- Multi-step reasoning: arithmetic, common-sense and symbolic tasks, helped by chain of thought.
Are Emergent Abilities of Large Language Models a Mirage? (Schaeffer et al., 2023) argues many are artifacts of all-or-nothing metrics; scored with continuous metrics, the same abilities improve smoothly.
Mixture of experts (MoE) An MoE layer replaces a transformer block's feed-forward layer with many expert feed-forward networks plus a router, usually a linear layer and a softmax. For each token, in each MoE layer, the router picks the top-k experts (Mixtral: 2 of 8) and sums their outputs weighted by its scores; the rest sit idle for that token. This is sparse activation, or conditional computation. What each expert specializes in is learned and opaque, rarely a topic a person would name.
- Gain: many parameters for little compute per token. DeepSeek-V3 and R1 have 671B parameters wit