LLM training — pretraining, SFT, RLHF, DPO, RLAIF
**Pretraining** — next-token prediction over trillions of tokens (web + code + books + synthetic). Scaling laws (Chinchilla, Hoffmann et al. 2022): compute-optimal D ≈ 20 × N parameters. Modern frontier models train to D >> 20N for inference-time efficiency (Llama 3: 15T tokens on 8B/70B/405B).
**Post-training alignment pipeline** typically has three stages:
1. **Supervised fine-tuning (SFT)** on high-quality instruction-response pairs. Teaches format and basic helpfulness. ~10k-1M examples.
2. **Preference optimization:** • **RLHF (Christiano et al. 2017, InstructGPT — Ouyang et al. 2022)** — train reward model on human preferences (A > B), then PPO against RM with KL penalty to reference policy. • **DPO (Rafailov et al. 2023)** — direct preference optimization; closed-form optimal policy under Bradley-Terry assumption, no explicit RM needed. Cheaper, simpler, widely adopted. • **RLAIF (Bai et al. 2022 Constitutional AI)** — use an LLM as judge to generate preferences from a constitution. Enables scaling beyond human annotation throughput. • **KTO, IPO, SimPO** — DPO variants with different loss parameterizations.
3. **Online/iterative RL** — best-of-N rejection sampling, rubric-based rewards, test-time compute (o1/o3-style chain-of-thought with outcome rewards on math/code/science).
**Data quality > data quantity** past a threshold. Deduplication, toxicity filtering, language balance, synthetic data (model-generated with filtering) all crucial. Textbooks are high-signal (Phi family, Gunasekar et al.).
**Tokenization** — byte-pair encoding (BPE) dominant. SentencePiece, tiktoken (GPT), tokenizers crate. Context windows grew from 2K (GPT-3) to 128K (GPT-4) to 1M-10M (Gemini 1.5, Claude Opus 4.7) via long-context training and retrieval augmentation.