Why RLHF After SFT: Aligning LLMs with On-Policy and Off-Policy Optimization
This article explains why Supervised Fine-Tuning (SFT) alone is not enough for LLM alignment and why reinforcement learning from human feedback is introduced afterward. It covers the structural limitations of SFT, a practical criterion for distinguishing on-policy methods such as PPO from off-policy methods such as DPO, the three main sources of reward signals, and key practices for building a reproducible alignment pipeline. Readers will learn how to choose a technical route based on verifiability, compute budget, and iteration speed.
1. The Starting Point: What SFT Solves and What It Leaves Behind
Supervised Fine-Tuning (SFT) is the first key step in making a general-purpose language model capable of following instructions. It does something straightforward: prepare a batch of “instruction–ideal answer” pairs, have the model perform token-by-token next-word prediction given a prefix, and drive down the cross-entropy loss.
# SFT training objective (illustrative): compute loss only on the answerprompt_ids = tokenizer(prompt, return_tensors="pt").input_idsanswer_ids = tokenizer(answer, return_tensors="pt").input_idsinput_ids = torch.cat([prompt_ids, answer_ids], dim=1)labels = input_ids.clone()labels[:, :prompt_ids.shape[1]] = -100 # mask out the prompt portionloss = cross_entropy(model(input_ids).logits[:, :-1], labels[:, 1:])
This process is efficient, stable, and memory-friendly; one forward pass plus one backward pass completes a single update. But it also plants three structural problems, and these three problems are exactly the fundamental motivation for introducing reinforcement-learning-style alignment later.
First, the training objective is inconsistent with inference. SFT optimizes “predicting the next word under a human-written prefix,” while during online inference the prefix is generated by the model itself. Once the first few steps produce a deviation, the model enters a state distribution it never saw during training, and errors accumulate along the sequence. This is the classic exposure bias problem.
Second, the supervision signal is only “imitation,” with no “evaluation.” SFT tells the model “this is what a correct answer looks like,” but never tells it “how much worse your answer is than that one.” Human preferences are naturally relative and graded: answer A is more helpful than answer B, but A itself may not be perfect either. Compressing continuous quality differences into a single ground-truth answer loses a great deal of information.
Third, good answers are hard to enumerate but easy to recognize. Having annotators write a long answer that is safe, detailed, and well-formatted is extremely costly; having annotators choose between two answers costs an order of magnitude less. This creates an asymmetry of “hard to generate, easy to judge,” and preference learning is precisely the means of turning that asymmetry into a training signal.
2. On-Policy vs. Off-Policy: A Practical Criterion for Distinguishing Routes
Current mainstream alignment methods can be roughly divided into two categories, and a memorable criterion is: whether the model needs to generate samples on the spot during training. Methods that require on-the-spot generation are on-policy; methods that directly use an existing offline dataset are off-policy.
PPO-based methods belong to the former: the model first samples answers for a batch of prompts, then a reward model scores them, and a clipped policy gradient update is performed using the advantage function together with the probability ratio between the new and old policies. DPO-based methods belong to the latter: they use a mathematical transformation to rewrite the objective of “reward + policy optimization” into a classification-style loss computed directly on preference pairs, requiring no generation at all during training.
# Core DPO loss (illustrative): no online generation, one forward passpi_logp = policy_logprob(model, x, y_w) - policy_logprob(model, x, y_l)ref_logp = policy_logprob(ref_model, x, y_w) - policy_logprob(ref_model, x, y_l)loss = -F.logsigmoid(beta * (pi_logp - ref_logp)).mean()
The difference in engineering cost between the two is very intuitive. On-policy requires the model to autoregressively decode at every step, emitting one token at a time; the sampling stage often takes up most of the wall-clock time of an entire training run, and it also requires extra memory to keep the policy model, reference model, and reward model resident simultaneously. Off-policy degenerates into a forward–backward process similar to SFT, with high throughput, simple implementation, and more forgiving hyperparameters.
But the cost buys a higher performance ceiling. The reason goes back to exposure bias in Section 1: only when the model runs on its own current distribution does the reward signal act on the mistakes it will actually make. Imagine an athlete learning a competitive game, with two possible coaching approaches: one is to have him repeatedly watch recordings of high-level play, with explanations of which moves are brilliant and which are mistakes; the other is to have him play in person, where pushing down a tower earns approval and getting killed in return gets pointed out as a problem. The former has high information density, but the athlete may not be able to turn “understanding” into “doing,” because the situations in the recordings are not the situations he will actually reach; the latter provides feedback that covers his real decision boundary, so correction is more efficient. This also explains why the “slower” methods usually have an advantage in open-ended generation and long-answer quality.
3. Where the Reward Signal Comes From: Three Options
Whichever route you take, you must answer “how to quantify good and bad.” Three common approaches in industrial practice:
- Reward models: train a scoring model on preference pairs that takes a prompt and an answer as input and outputs a scalar score, serving as dense feedback for policy optimization. Its advantage is cheap and reusable scoring; the risk is that the policy may “game” it, producing reward hacking where the score rises while true quality drops, so it needs to be combined with KL constraints and periodic retraining.
- Rules and verifiable rewards: whether a math answer is correct, whether code passes unit tests, whether the format meets constraints—these scenarios can be judged directly by a program, and the signal is objective and hard to fake, making it an important means of improving reasoning and tool-use capabilities today.
- Model-based feedback: another strong model gives an evaluation and improvement suggestions according to a rubric, suitable for dimensions that are hard to formalize, such as “helpfulness, clarity, and tone,” but watch out for evaluation bias and position preference; prompt design and calibration on human evaluations are needed.
A more robust engineering combination is layering: hand the verifiable parts to rules, the subjective parts to a preference model or model-based review, and keep a small-scale human spot-check as the final arbiter.
4. Putting It into Practice: Building a Stable Alignment Pipeline
A reproducible alignment pipeline usually consists of four stages: SFT as the foundation → preference data collection and reward modeling → reinforcement-learning-style optimization → evaluation and regression. A few lessons worth emphasizing in practice:
- Data quality comes before algorithm choice. If the consistency of preference annotation (inter-annotator agreement) is low, no sophisticated algorithm can save it. First do small-scale annotation, compute agreement, iterate on the annotation guidelines, and then scale up.
- The KL constraint is a safety valve. Limiting how far the new policy deviates from the reference model can both suppress output degradation and repetition and delay reward hacking.
- Offline first, online later. Getting a stable baseline with offline preference optimization and then adding online sampling for refinement can significantly reduce the risk of hyperparameter tuning and compute.
- Evaluation must be independent of the training signal. Use an evaluation set from a source different from the reward model, including adversarial prompts and long-tail scenarios, to avoid “score-chasing illusions.”
- Compute elasticity comes from platformization. Online sampling requires large amounts of concurrent decoding and frequent weight synchronization; you can leverage container platforms for elastic scaling, object storage to archive samples and checkpoints, message queues to decouple sampling from training, and logging services with monitoring and alerting to track reward curves and throughput fluctuations. Baidu AI Cloud has general-purpose capabilities for resource orchestration of such mixed training and inference workloads, which can be combined as needed.
5. Conclusion: Not Replacement, but Division of Labor
SFT and reinforcement-learning-style alignment are not either/or. SFT is responsible for pulling the model’s output space into a region that “sounds like human speech and follows instructions,” at extremely low cost, and is a necessary prerequisite; preference optimization is responsible for reshaping the relative ordering within that region, pushing “acceptable” toward “more reliable, more useful, and more rule-abiding.” Which technical route to choose depends on the verifiability of the task, the compute budget, and the iteration speed: when the objective can be judged programmatically and the performance ceiling is the priority, prefer online methods; when resources are tight and a quick launch is needed, start with offline preference optimization and gradually introduce online sampling. Understanding the single main thread of “whether the training distribution equals the inference distribution” can self-consistently answer the vast majority of route-selection questions.
