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 with 37B active per token (DeepSeek-V3 Technical Report). Memory: every expert must still sit in GPU or system memory, so running an MoE model locally takes memory for its total size, not its active size. Load balancing: auxiliary losses keep the router from overusing a few experts. Communication: experts spread across GPUs need tokens routed between devices. Overfitting: the added parameters call for more regularization. Many frontier models use MoE; dense models remain common (Llama 3, for one). Pretraining, supervised fine-tuning and RLHF pretraining -> supervised fine-tuning (SFT) -> RLHF Pretraining: self-supervised next-token prediction on web-scale text (Common Crawl, C4 and similar), the longest and costliest phase. The result, a foundation model, only continues text. A frontier model is one of the newest and most capable; they change quickly, so check a current leaderboard such as Arena (formerly LMArena) or Artificial Analysis. Supervised fine-tuning: continued training on curated prompt-response pairs, such as questions with answers, articles with summaries, or instructions with code. General-purpose models fine-tune on many tasks at once. The risks are overfitting, worst for small models, and catastrophic forgetting of pretraining knowledge, both managed with hyperparameters such as learning rate and epochs (MLG 027). Reinforcement learning from human feedback (RLHF), as in InstructGPT (Ouyang et al., 2022): SFT model writes several responses -> humans rank them -> reward model trained on the rankings (supervised) -> LLM tuned against the reward model with RL, usually PPO The reward model is a separate network, often initialized from a copy of the LLM, that predicts a score for a prompt-response pair. Proximal Policy Optimization (PPO, MLG 029) updates the LLM to raise that score, with a penalty that keeps it close to the SFT model. Direct Preference Optimization (DPO) trains on the ranked pairs directly, with no separate reward model. Alignment and reward hacking RLHF's goal is alignment: outputs that are helpful, honest and harmless, qualities that fixed labeled data captures poorly. It costs consistent, high-quality human rankings and is harder to tune than SFT. Reward hacking, or specification gaming, is the model exploiting the reward model instead of improving, a practical case of the paperclip-maximizer thought experiment. RLHF-tuned models learned that length and a confident tone win ratings, so labs control for verbosity. Chain of thought and reasoning models Chain-of-thought (CoT) prompting: the model writes intermediate steps before its answer. Few-shot CoT gives worked examples (Wei et al., 2022); zero-shot CoT appends "Let's think step by step" (Kojima et al., 2022). It improves arithmetic, common-sense, symbolic and coding tasks, and leaves a readable trace for debugging and safety monitoring. Self-consistency: sample several chains and take the majority answer, an ensemble over reasoning paths. Tree of thoughts: generate and score several candidate next steps, search the branches breadth-first or depth-first, and backtrack from dead ends. Reasoning models (OpenAI o1 and later, DeepSeek R1) are trained with reinforcement learning to produce a long chain of thought before answering; the network architecture is unchanged. A chain of thought costs extra tokens and latency, so it pays on multi-step problems more than simple lookups. Prompt wording still changes output quality; Anthropic's Prompt Engineering Interactive Tutorial covers chain of thought among other techniques. Where to learn about LLMs The transformer resources in MLG 033. The Chinchilla and InstructGPT papers linked above. Nathan Lambert's RLHF book, free online: reward models, PPO and DPO. Next: MLG 035, on in-context learning, retrieval-augmented generation (RAG), agents and benchmarks.