Post-training: instruction tuning, preferences and reinforcement learning
From text continuer to assistant and reasoner
Chapter 17 of 21 · V. Training · about 50 minutes. Builds on: 4. Probability, softmax and next-token prediction, 16. Pretraining at scale.
Pretrained models are not assistants
Section titled “Pretrained models are not assistants”A model that has only been pretrained (Chapter 9) is a text continuer. Given “What is the capital of France?” it may continue with another quiz question. Post-training turns it into an assistant that follows instructions, refuses some requests, and reasons step by step. It uses far less compute than pretraining but determines most of the behavior users see, and most of the safety behavior.
Stage 1: supervised fine-tuning (SFT)
Section titled “Stage 1: supervised fine-tuning (SFT)”Collect example conversations (a prompt and an ideal response, written by people or generated and filtered by models). Render each with the chat template and continue training with the usual next-token loss, computed only on the response tokens (the prompt is context, not target). A few thousand to a few million examples are enough to shift the style dramatically. Training on instructions across many tasks also improves zero-shot performance on unseen tasks .
Stage 2: learning from preferences (RLHF)
Section titled “Stage 2: learning from preferences (RLHF)”Writing perfect answers is hard; comparing two answers is easy. So collect pairs (, , ): a prompt, a response people preferred and one they did not. The pipeline of , applied to text by and has three steps.
Reward model
Section titled “Reward model”Train a network that outputs a scalar score. Model the probability that beats as a function of the score difference (the Bradley–Terry model), and minimize the negative log-likelihood:
Policy optimization
Section titled “Policy optimization”Treat the language model as a policy that generates a response one token at a time and receives the reward-model score at the end. Maximize the expected reward while staying close to the SFT model , so the policy cannot drift into text that merely fools the reward model:
The optimizer used is PPO . Its key device is a clipped objective that limits how far one update can move the policy. With the probability ratio and advantage (how much better than average this token’s outcome was):
When the advantage is positive, there is no incentive to raise beyond ; when negative, none to lower it below . In standard PPO a separate value network estimates the baseline used to compute advantages. InstructGPT found labelers preferred outputs of a 1.3B RLHF-tuned model over the 175B GPT-3 base model, evidence that alignment tuning matters as much as scale for perceived quality .
Direct preference optimization (DPO)
Section titled “Direct preference optimization (DPO)”RLHF needs a reward model and a reinforcement-learning loop. noticed the KL-regularized objective above has a closed-form optimal policy:
Substitute this expression for into the Bradley–Terry loss. The terms cancel because both responses share the prompt, leaving a loss that depends only on the policy and the reference:
It is plain supervised training on preference pairs: no reward model, no sampling loop. Both losses in one widget:
Reinforcement learning with verifiable rewards, and GRPO
Section titled “Reinforcement learning with verifiable rewards, and GRPO”For problems with checkable answers (math, code that passes tests, formats) no learned reward model is needed: reward 1 if the final answer is correct, else 0. Group Relative Policy Optimization (GRPO), introduced in DeepSeekMath , removes PPO’s value network. For each prompt, sample a group of responses from the old policy, score each ( … ), and use the group itself as the baseline:
Every token of response shares this advantage. The objective is
where is PPO’s clipped term ( is the probability ratio between the new and old policy) and the KL term uses a per-token estimator that is always non-negative:
The KL term is added to the loss directly rather than folded into the reward. Notice what the normalization does: a response is pushed up only if it beat its siblings. If every sample is right (or every one wrong), all advantages are zero and the prompt teaches nothing.
Reasoning models and test-time compute
Section titled “Reasoning models and test-time compute”Chain-of-thought prompting (Chapter 19) showed that writing out intermediate steps improves answers. Reasoning models are trained to do this by themselves using reinforcement learning against verifiable rewards. DeepSeek-R1 reports that applying RL directly to a base model (R1-Zero) made long reasoning, self-checking and revision emerge, and that a multi-stage recipe with some SFT data produced the final model; it also reports distilling the reasoning into smaller models (Chapter 18).
This opens a second axis of scaling. show that, for some problems, giving a smaller model more computation at inference (sampling many solutions and verifying them, or reasoning longer) can beat a much larger model. Process reward models that score each step, trained on step-level human labels, outperformed outcome-only reward models for selecting correct math solutions . The gpt-oss models use chain-of-thought RL in post-training and expose low, medium and high reasoning effort settings .
Safety training and the instruction hierarchy
Section titled “Safety training and the instruction hierarchy”- Constitutional AI : the model critiques and revises its own outputs against written principles, and AI-generated preference labels (RLAIF) replace some human labels.
- Instruction hierarchy. gpt-oss is trained to rank instruction sources: system, then developer, then user, then assistant, then tool output. The model card reports its instruction-hierarchy scores trail OpenAI’s o4-mini; for example system-prompt extraction resistance scored 0.832 (120b) versus 0.993 for o4-mini . The hierarchy is a trained behavior, not a mechanism, and its robustness is measured, not guaranteed.
- Chain of thought. The gpt-oss card says no direct optimization pressure was applied to the reasoning text, so that it stays an honest signal for monitoring, and advises developers not to show raw reasoning to users without filtering .
Check yourself
Section titled “Check yourself”Why is the SFT loss computed on response tokens only?
The goal is to model what the assistant should say given the prompt. Training to predict the prompt’s own tokens would waste capacity and teach the model to write user messages.
In DPO, what does the reference model do?
It anchors the implicit reward: the policy is rewarded for raising the chosen answer’s probability relative to the reference, so it cannot reduce loss simply by assigning arbitrary probabilities; it acts like the KL penalty in RLHF.
Four of six sampled answers are correct (reward 1). What are the GRPO advantages?
mean , std . Correct answers: ; wrong answers: .
Papers
Section titled “Papers”- , , The RLHF lineage; start with InstructGPT.
- PPO.
- DPO; the derivation in section 4 is short.
- GRPO (section 4.1).
- Reasoning via RL.
- , Test-time compute and process supervision.
- Constitutional AI.
- A model card with unusually concrete safety and instruction-hierarchy evaluations.