Learn AI Math

Topic 4 of 20 · 39 words

Model Training & Optimization

How raw foundation models are pre-trained at scale, fine-tuned on instructions, aligned with human preferences, and compressed.

✎ Napkin Diagram · Topic 04How an AI Goes to School: 3 Steps from Bookworm to Assistant
PNG ↗
How an AI Goes to School: 3 Steps from Bookworm to Assistant Simple 3-step cartoon showing an AI 1. Reading the whole library (Pre-training) to become a Bookworm, 2. Practicing polite Q&A with a teacher (Fine-tuning), and 3. Getting thumbs-up and thumbs-down feedback from humans (RLHF). STEP 1: READ THE LIBRARY Reads billions of pages(Pre-training)Result: Know-It-All BookwormKnows facts, but rambles!Takes months & most of the computeSTEP 2: PRACTICE Q & AQ: → A:Studies helpful examples(Fine-tuning)Result: Polite HelperActually answers your questionTeaches how an assistant talksSTEP 3: HUMAN COACHING👍 Good👎 BadPeople rate its answers(RLHF / Alignment)Result: Trusted Assistant ★Clear, safe & easy to work withPolishes judgment & safety getaimath.com
First the model reads the internet to learn facts; next it practices answering questions; finally humans coach its manners.

The 39 words, in learning order

Start at 1. Each word builds on the ones before it.

  1. Pre-trainingPre-training is the first, giant training stage where a model learns general knowledge from enormous amounts of data.
  2. Fine-tuningFine-tuning is giving an already-trained AI model extra training on a smaller, focused set of examples so it gets good at a specific job.
  3. Supervised Fine-Tuning (SFT)Supervised fine-tuning trains a pre-trained model on example conversations with good answers, so it learns to respond the way we want.
  4. Instruction TuningInstruction tuning is fine-tuning a model on many examples of instructions and correct responses, so it learns to follow directions.
  5. Preference TuningPreference tuning trains a model to give answers that people prefer, using comparisons between better and worse responses.
  6. Reinforcement Learning from Human Feedback (RLHF)RLHF is a way to improve a chatbot by having people rate its answers and then training it to give the kinds of answers people prefer.
  7. Direct Preference Optimization (DPO)DPO is a simpler way to do preference tuning that trains directly on "better vs worse" answer pairs, without a separate reward model.
  8. Proximal Policy Optimization (PPO)PPO is a reinforcement learning method that improves a model in small, careful steps so it does not change too much at once.
  9. Knowledge DistillationKnowledge distillation trains a small "student" model to copy the behavior of a big "teacher" model.
  10. Model CompressionModel compression is any technique that makes an AI model smaller or faster while keeping most of its quality.
  11. PruningPruning removes parts of a neural network that contribute little, making the model smaller and faster.
  12. SparsitySparsity means that many of the numbers in a model are zero or unused, so the computer can skip them.
  13. Sparse TrainingSparse training means training a model where only a fraction of its connections are active or updated at a time.
  14. Dense TrainingDense training means every parameter in the model is used and updated for every training example.
  15. GradientA gradient is a set of numbers that tells a model which direction to change each weight to reduce its mistakes, and by how much.
  16. Gradient AccumulationGradient accumulation adds up gradients over several small batches before updating the model, to act like one big batch.
  17. Gradient ClippingGradient clipping limits how large gradients can get, so one bad batch cannot cause a huge, damaging update.
  18. OptimizerAn optimizer is the algorithm that decides exactly how to update a model's weights using the gradients.
  19. AdamAdam is a popular optimizer that adjusts the step size for each weight automatically, using its past gradients.
  20. AdamWAdamW is a version of Adam that handles weight decay in a cleaner way, which usually leads to better models.
  21. SGDSGD, or Stochastic Gradient Descent, updates a model's weights using gradients from small random batches instead of the whole dataset.
  22. MomentumMomentum is an optimizer trick that keeps a model moving in the direction it has been going, smoothing out jumpy updates.
  23. Learning Rate SchedulerA learning rate scheduler changes the learning rate during training, usually starting larger and getting smaller over time.
  24. WarmupWarmup is a short period at the start of training where the learning rate slowly rises from very small to its normal value.
  25. Weight DecayWeight decay gently shrinks a model's weights a little at every step, which helps prevent overfitting.
  26. DropoutDropout randomly turns off some neurons during training, so the network cannot rely too much on any single one.
  27. RegularizationRegularization is any technique that stops a model from overfitting by discouraging it from becoming too complex.
  28. CheckpointA checkpoint is a saved copy of a model's weights, and often its training state, at a particular moment.
  29. Training LossTraining loss is the error score a model gets on the data it is learning from.
  30. Validation LossValidation loss is the error score a model gets on held-out data it is not trained on.
  31. ConvergenceConvergence is when training settles down and the loss stops improving much, meaning the model has learned about as much as it can with that setup.
  32. Catastrophic ForgettingCatastrophic forgetting is when a model learns something new and suddenly loses skills it had before.
  33. Synthetic DataSynthetic data is training data created by computers, often by other AI models, instead of collected from the real world.
  34. Data AugmentationData augmentation creates extra training examples by slightly changing existing ones.
  35. Curriculum LearningCurriculum learning trains a model on easier examples first and harder ones later, like a school curriculum.
  36. Data ContaminationData contamination is when test or benchmark questions accidentally end up in a model's training data.
  37. Scaling LawsScaling laws are patterns showing that models get predictably better as you increase their size, data and compute.
  38. Compute-Optimal TrainingCompute-optimal training means choosing the best balance of model size and training data for a fixed computing budget.
  39. Chinchilla Scaling LawsThe Chinchilla scaling laws, from a 2022 DeepMind study, found that many big models were too large and trained on too little data.

How Model Training & Optimization fits together

Building a capable AI model happens in stages. Pre-training teaches general world knowledge by predicting trillions of tokens from raw text—burning nearly all the compute budget. Post-training (Supervised Fine-Tuning, RLHF, or DPO) turns that raw predictor into a helpful assistant that follows instructions and avoids harmful outputs.

Along the way, optimizers like AdamW, learning-rate warmup, gradient clipping, and scaling laws keep training runs stable and compute-efficient, while distillation and pruning pack large-model intelligence into smaller, faster models.