19.4 Choosing post-training signals
This part of Choosing Training and Adaptation Methods develops the mechanisms below. Work the numerical examples or trace the code before checking the answer.
Concepts from other sections (22)
This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.
- DPO: preference optimization that uses the closed-form optimum of KL-constrained RLHF so the reward model and partition function drop out. Read more: 19.7 The training step and validation
- verifiable reward: a reward computed by a deterministic checker rather than a learned model. Read more: 18.3 Group relative policy optimization with verifiable rewards
- GRPO: a PPO-style RL method that replaces the critic with the group-normalized reward of several samples of the same prompt. Read more: 19.7 The training step and validation
- LoRA: fine-tuning a frozen matrix through a trainable low-rank update initialized to zero. Read more: 19.7 The training step and validation
- Cosine decay: half a cosine period from to over a fixed horizon . Read more: 16.4 Learning-rate schedules (cosine, WSD, Noam) and gradient clipping in Mathematics
- clipped surrogate: the minimum of and , which removes the incentive to move a sample’s probability beyond the clip range. Read more: 18.3 Group relative policy optimization with verifiable rewards
- GAE: an exponentially weighted combination of temporal-difference residuals. Read more: 18.6 PPO with a critic and generalized advantage estimation
- Bradley-Terry model: , a pairwise preference probability from scalar rewards. Read more: 18.2 Direct preference optimization and IPO
- Likelihood: , the probability of the observed data as a function of the parameter. Read more: 13.10 Probability problem set, part b: joint distributions, covariance, MLE in Mathematics
- Regularization: penalizing model complexity to trade bias for lower variance. Read more: Chapter 1: Statistical Learning
- Verbosity bias: an LLM judge’s tendency to rate longer answers higher regardless of quality. Read more: Chapter 29: LLM Evaluation
- IPO: regressing the margin to the target with a squared loss. Read more: 18.2 Direct preference optimization and IPO
- PPO: a policy gradient method that clips the new-to-old probability ratio to keep updates small. Read more: 4.4 World models, multiple agents, and RLHF
- k3 estimator: with , an unbiased, nonnegative per-sample estimate of . Read more: 17.1 Entropy, cross-entropy, KL, JS, and the k3 estimator in Mathematics
- forward KL: , weighted by the teacher; mass-covering. Read more: 18.4 Distillation with forward and reverse KL
- Value function: the expected discounted return from a state (or state-action pair) under a policy. Read more: 4.4 World models, multiple agents, and RLHF
- Standard deviation: , the typical distance of a random variable from its mean, in the same units as the variable itself. Read more: Chapter 13: Probability and Statistics in Mathematics
- Mixture of experts (MoE): a layer of many expert MLPs of which a router picks per token. Read more: 13.8 Mixture of Experts
- Reinforcement fine-tuning (RFT): tuning a model against an evaluator that returns a reward from 0 to 1 for each output, with gold completions optional; it fits tasks that are verifiable but lack reference answers. Read more: 24.5 Routing implementations and selection
- ZeRO / FSDP: sharding optimizer states, gradients, and (at stage 3) parameters across data-parallel ranks instead of replicating them. Read more: 19.7 The training step and validation
- On-policy / off-policy: learning about the policy being followed versus learning about a different policy. Read more: 4.4 World models, multiple agents, and RLHF
- logits: unnormalized log-scores that softmax turns into probabilities; here the table stores . Read more: 6.1 Byte bigram: counts, logits, safetensors v0
Learning objectives
- Match demonstrations, preferences, rewards, and teacher distributions to objectives.
Post-training
Section titled “Post-training”Post-training adapts a base model to particular response, preference, reward, or deployment goals. Base-model capability, data coverage, retrieval, and serving behavior remain relevant. The three main tools need three different kinds of data: SFT teaches format from demonstrations, preference optimization such as DPO teaches taste from comparisons, and RL with verifiable rewards such as GRPO teaches skills that a grader can check. The key papers are InstructGPT, DPO, DeepSeekMath, DeepSeek-R1, and Tulu 3.
Supervised fine-tuning
Section titled “Supervised fine-tuning”SFT is next-token training on demonstrations, with one important change: loss masking. You train only on the response tokens , labeling prompt and system positions -100 (the ignore_index), so the loss is
Training on prompts would waste capacity on imitating users. train_step_torch.py implements the masking.
The model also learns the exact special-token format of its chat template (<|start_header_id|>, <|im_start|>, and so on). Train and serve with the same template, taken from the tokenizer via apply_chat_template.
Warning: Template mismatch between training and serving can silently degrade a fine-tune. Nothing crashes; the model just behaves worse.
To avoid wasting compute on padding, packing concatenates short examples into full-length sequences. Pair it with document masking, a position-ID reset plus block-diagonal attention (for example FlashAttention’s varlen kernels), so packed examples do not attend to each other.
Typical hyperparameters are 1-3 epochs, a learning rate around 1e-5 for full fine-tuning and 1e-4 to 2e-4 for LoRA, with cosine decay and warmup. Quality beats quantity: LIMA got strong results from 1,000 curated examples.
RLHF with PPO
Section titled “RLHF with PPO”Classic RLHF, as in InstructGPT, has three parts. First, train a reward model on preference pairs with the Bradley-Terry loss, where is the preferred response and the rejected one:
Second, use RL to maximize that reward with a KL penalty that keeps the policy near the SFT reference:
In practice the KL term is applied per token as , with added at the final token.
Third, optimize with PPO (Schulman et al.), whose clipped surrogate uses the ratio :
with advantages computed by GAE from a learned value model, the critic.
Count the actual resident tensors and optimizer state: actor, reference, reward function, and critic are distinct roles but can share a backbone, cache scores, or be swapped. Generation sits inside the learning loop. The PPO and GAE part derives the masks, targets, and controls needed to evaluate this design.
Deriving DPO
Section titled “Deriving DPO”DPO is RLHF with the reward model solved away. Start from the same KL-constrained objective. Its optimum has a closed form, a Gibbs distribution:
Solve it for the reward:
Now substitute this into the Bradley-Terry model, . The intractable appears in both terms and cancels. Parametrize by the policy and maximize the likelihood of the observed preferences:
Call the bracketed margin . The gradient is
The weight is what makes DPO sensible: it focuses learning on pairs that the implicit reward currently ranks wrongly. And at initialization, when , the margin is zero and the loss is exactly . Both facts are asserted in dpo_loss.py, which checks the gradient against central finite differences.
The practical consequences follow from the derivation. DPO is offline: no reward model, no sampling, and only two models, the policy and a frozen reference whose log-probs can be precomputed. Its memory cost is that of SFT plus one forward pass. The coefficient changes the preference-loss parameterization inherited from reference regularization; it does not enforce a hard measured-KL bound. Tune it against held-out behavior and drift. Its known failure modes are likelihood displacement, where both the chosen and the rejected log-probs fall, and verbosity bias. Variants include IPO, KTO (which works on unpaired thumbs up/down), ORPO, and SimPO (reference-free). Online or iterative preference collection can reduce mismatch between the dataset and the current model, but its benefit depends on label quality, coverage, and cost. Compare it with fixed-pair training on the same held-out suite.
GRPO and RL with verifiable rewards
Section titled “GRPO and RL with verifiable rewards”DPO removes the reward model; GRPO (DeepSeekMath) keeps the RL loop but removes the critic. For each prompt, sample a group of outputs (8-64), score each, and use the group itself as the baseline. Every token of output gets the same advantage:
The objective is the PPO surrogate averaged per output and per token, with a KL penalty:
The per-token penalty can use the pointwise nonnegative k3 estimator below. Its expectation is forward KL when actions are sampled from the current policy with matching support; stale or old-policy samples need the stated correction or approximation:
The group baseline avoids learning a value function. Inclusive group means and sampled standard deviations affect the gradient estimator; they are not generally an unbiased action-independent baseline. Memory savings depend on critic sharing, group size, reward scoring, and generation layout. See rollout systems and variants.
GRPO pairs naturally with RLVR, RL with verifiable rewards (named in Tulu 3), where the reward is a program rather than a model: the math answer matches, the unit tests pass, the JSON validates against a schema, the format regex matches. Removing a learned reward model removes one source of reward-model error, while incomplete tests, parser bugs, and format shortcuts remain exploitable. DeepSeek-R1 (2501.12948) is the landmark result. R1-Zero ran GRPO with rule-based accuracy and format rewards directly on the base model, and long chain-of-thought and self-verification emerged. R1 itself added a cold-start SFT, then RL, then rejection-sampling SFT, then a final RL stage, and was distilled into small dense models.
Three follow-ups are worth naming: DAPO (2503.14476), with clip-higher, dynamic sampling, and a token-level loss; Dr. GRPO (2503.20783), which removes the length and std normalization biases; and GSPO (2507.18071), which uses sequence-level ratios and is stabler for MoE. Fireworks and others sell this as RFT, reinforcement fine-tuning, where the customer supplies the grader.
The hard part of RL is a systems problem: RL is mostly generation. Rollouts run in vLLM or SGLang, training runs in FSDP or Megatron, and weights sync between them every step. Asynchronous, off-policy rollouts trade staleness for throughput.
Distillation
Section titled “Distillation”The last post-training tool trains a student on a teacher’s outputs. Sequence-level distillation is SFT on teacher generations, which is how R1’s distilled models were built, and needs only text. Logit-level distillation minimizes KL to the teacher’s distribution (Hinton et al.) and needs a shared tokenizer and the teacher’s logits. On-policy distillation (GKD) scores the student’s own samples with the teacher. For a customer, “distill a frontier model’s behavior on your task into an 8B” is often the best cost play, subject to the teacher’s license terms.
Learner and inference runtime responsibilities
Section titled “Learner and inference runtime responsibilities”A trainer owns differentiation, optimizer state, objective masks/reductions, data scheduling, and checkpoints. A rollout runtime such as vLLM or SGLang owns generation and its behavior probabilities. The orchestration layer owns revision-consistent weight transfer, scoring, queueing, and policy-lag limits. Some packages bundle several roles, but the contracts remain separate.
Use a trainer only after checking that its installed version implements the intended objective and normalization. The versioned TRL GRPO reference illustrates how the same trainer exposes several recipe choices. Distributed and adapter support must be verified with the actual model and topology. The local lab starts with the shared training-to-serving validation loop.
Summary
Section titled “Summary”Match demonstrations, preferences, rewards, and teacher distributions to objectives. State the assumptions before applying the result to a different workload.
Review questions
Section titled “Review questions”-
What does a falling reward loss fail to establish?
Answer
It does not establish better held-out task behavior, calibrated rewards, or a policy that serves correctly.