The Training Pipeline
Pretraining teaches the model to predict text. Alignment teaches it to follow instructions and be helpful. But why split training into phases at all?
Why not train everything at once?
Each training phase uses different data, different objectives, and different scales. Combining them would create conflicting goals — the model can't simultaneously learn grammar from trillions of web pages AND learn to refuse harmful requests from a few thousand examples. The phases build on each other:
| Pretraining | Midtraining | SFT | Reasoning RL | Alignment RL | |
|---|---|---|---|---|---|
| Loss / objective | Cross-entropy (next-token prediction) | Cross-entropy (same, curated data) | Cross-entropy (typically on response tokens only) | Policy gradient with verifiable reward (correct / incorrect) | Policy gradient with reward model (PPO) or supervised preference loss (DPO) |
| What provides the signal | The next token in the training text | The next token (higher-quality text) | Human-written gold responses | Ground-truth answers (math answers, code tests) | Human raters or AI judges ranking outputs |
| Algorithm | AdamW (most common; also Adafactor, Muon) | AdamW (lower learning rate) | AdamW (fine-tuning LR) | GRPO, PPO, or REINFORCE | PPO, DPO, or GRPO |
| Learning rate | 0.0001 – 0.0003 aggressive — big steps | 0.00001 – 0.00005 10× slower — careful refinement | 0.00001 – 0.00002 gentle — don't break what pretraining built | 0.000001 – 0.000005 100× slower — nudge, don't overwrite | 0.000001 – 0.000005 same — tiny adjustments to behavior |
| Parameters trained | All weights initialized randomly | All weights continuing from pretrained checkpoint | All weights frontier labs use full fine-tuning; LoRA is used for API/customer fine-tuning only | All weights full model update (confirmed by DeepSeek-R1, LLaMA 3/4) | All weights full fine-tuning for flagship models |
| Data scale | 1-40T+ tokens | 100B-5T tokens | 10K-1M+ examples | ~50K-100K problems | ~50K-1M+ comparisons |
| Cost (estimated) | $100M-$1B+ | $10M-$50M | $10M-$100M+ for frontier models (large human-annotation + synthetic-data pipelines) | ||
| What it changes | Everything — builds the model from scratch | Sharpens skills, extends context | Activates the Q&A format (capability already exists in base model) | Teaches "think before answering" | Steers toward helpful, harmless, honest |
The Alignment Pipeline
The InstructGPT / ChatGPT three-step process that launched the alignment era.
The three-step alignment pipeline (InstructGPT / ChatGPT)
Modern Post-Training Approaches
The InstructGPT pipeline was the 2022 breakthrough. Since then, several approaches have largely supplanted PPO for post-training.
DPO (Direct Preference Optimization)
Eliminates the reward model entirely. Reparameterizes the RLHF objective so the preference loss is computed directly from the policy model. Uses simple binary cross-entropy on preferred vs. dispreferred responses.
Used by: LLaMA 3/4 (iterative DPO over 6 rounds), Zephyr, many open-source models.
GRPO (Group Relative Policy Optimization)
Generates multiple responses per prompt, scores them with verifiable rewards (math/code correctness), and updates the model using group-relative advantages. Eliminates the critic model, halving memory vs PPO.
Used by: DeepSeek-R1, Qwen3, Llama-Nemotron. The dominant algorithm for reasoning RL.
Constitutional AI (Claude)
Two phases: (1) SFT with AI self-critique guided by a written "constitution" of principles. (2) RLAIF — the AI itself generates preference rankings, replacing human labelers.
Used by: Anthropic (Claude). Scales better than human feedback. The constitution makes values explicit and auditable.
Full Fine-Tuning vs PEFT
Full fine-tuning updates every weight. PEFT methods update only a tiny fraction. The visual difference is dramatic.
Interactive: What gets updated?
Each cell represents a block of model parameters. Green = updated during training. Blue/dim = frozen.
| Aspect | Full Fine-Tuning | PEFT (LoRA, etc.) |
|---|---|---|
| Params updated | All (100%) | 0.1-2% of total |
| GPU memory | Very high (full model + optimizer states) | Low (base frozen, only adapters in optimizer) |
| Training speed | Slower (more gradients) | Faster (fewer gradients) |
| Task adaptation | Maximum | Very good (surprisingly close) |
| Catastrophic forgetting | Higher risk | Lower risk (base weights preserved) |
| Multi-task serving | One model per task | Swap adapters (same base model) |
| Storage per variant | Full model copy (~7B = ~14GB in FP16) | ~10-50 MB adapter file |
LoRA Explained Visually
Low-Rank Adaptation freezes the original weight matrix and learns a small bypass: two tiny matrices that approximate a weight update.
The LoRA bypass: W + BA
Why "low rank" works
Research shows that the weight updates during fine-tuning have low intrinsic dimensionality. The change in weights can be well-approximated by a rank-16 or rank-64 matrix, even though the weight matrix itself is 4096x4096. LoRA exploits this by only learning the low-rank factors.
Interactive: Rank trade-off
Which layers to target?
LoRA is typically applied to the attention projection matrices. The most common configuration targets q_proj and v_proj, though targeting all projection layers (q_proj, k_proj, v_proj, o_proj) can yield better results.
QLoRA
QLoRA combines quantized base weights with LoRA adapters, making it possible to fine-tune 65B+ models on a single GPU.
LoRA
QLoRA
Key insight: QLoRA quantizes the frozen base model to 4-bit but keeps the LoRA adapters in full precision (FP16). During training, the 4-bit weights are temporarily dequantized for computation. The gradients only flow through the small LoRA matrices. This is why QLoRA can fine-tune a 65B model on a single 48GB GPU (Dettmers et al., 2023).
Model Distillation
Train a smaller student to imitate a larger teacher. The student learns from the teacher's soft probabilities, not just hard labels.
Teacher-Student Pipeline
"kitten": 0.30
"feline": 0.15
"dog": 0.05
"pet": 0.03
...
"kitten": 0.28
"feline": 0.17
...
Why soft labels are better than hard labels
Loses all information about word relationships.
Preserves semantic similarity -- "kitten" is close to "cat."
Distillation vs PEFT: Distillation creates a new, smaller model entirely. PEFT adapts an existing model more cheaply. Distillation is for deployment efficiency; PEFT is for task adaptation.
When Fine-Tuning Is Worth It
Fine-tuning is not automatically the next step after a weak prompt. Show restraint.
Decision Framework
Fine-tune when:
Don't fine-tune when:
Key insight: Fine-tuning is not automatically the next step after a weak prompt. Sometimes the real issue is poor data, bad chunking, or missing tools.
Dataset Quality Checklist
A small, clean dataset is often more valuable than a large noisy one. The model will faithfully learn your inconsistencies too.
Interactive Checklist: Is your dataset ready?
Click each item to check it off. A good dataset should pass all of these.
Each example has one obvious correct label. No "it depends" cases without clear resolution rules.
The data covers the same topics, styles, and edge cases the model will see in production -- not just "easy" examples.
Includes rare but important cases: short inputs, long inputs, multilingual, adversarial, out-of-scope queries.
All examples follow the same format template. The model learns format from examples -- inconsistency teaches inconsistency.
Training and evaluation sets are truly separate. Near-duplicates and paraphrases of eval examples are removed from training.
The outputs in training match what you actually want the model to say in production -- not just technically correct but also in the right style, length, and tone.
Simple format tasks: ~100-500 examples. Complex reasoning: 1000+. More data helps but returns diminish after the model has seen the pattern.
The golden rule: Data quality defines the ceiling. Fine-tuning amplifies the pattern in the data; it does not invent a better target than the one you provide.
Catastrophic Forgetting
When fine-tuning pushes the model so hard toward a new task that it loses its general capabilities.
Visual: Capabilities over fine-tuning time
Symptoms
Mitigations
Evaluation Before Release
Evaluate both target-task gains and unintended regressions. Compare against the baseline and the cheapest non-fine-tuned alternative.
Evaluation Matrix
Task Performance
Regression Checks
Comparison Baselines
Model
accuracy, format
Suite
safety, general
vs baseline
Iterate
Key principle: A mature evaluation compares the fine-tuned model against the baseline model and the cheapest non-fine-tuned alternative. Otherwise you cannot tell whether fine-tuning truly earned its complexity.
Cost Tradeoffs & When to Avoid Fine-Tuning
Fine-tuning has both upfront and lifecycle costs. Teams sometimes focus on training cost and forget the long-term burden.
Interactive: Total Cost of Fine-Tuning
The full cost picture
The discipline of not fine-tuning
A team should avoid fine-tuning when the task changes rapidly, the dataset is weak, the behavior is mostly knowledge retrieval rather than skill adaptation, or the product can be solved with better prompting, retrieval, or tool use. Fine-tuning can add complexity without solving the actual bottleneck. Good engineers do not optimize the wrong layer of the stack.