RLHF and Reward Modeling
Everything in the next four pages is defined by what it deletes from this pipeline. So it is worth building the pipeline first, even though almost nobody runs it in full any more.
Example folder: 03_llms/04_reward_model/ — RewardTrainer + DeepSpeed, plus reward_modeling.py (the Bradley-Terry objective on plain tensors, no GPU).
TRL trainers: RewardTrainer, PPOTrainer
1. Why Alignment Needs More Than SFT
Supervised fine-tuning maximises the likelihood of a reference answer. That works when there is a reference answer. It breaks down for the questions people actually ask a chat model:
- "Is this reply helpful?" — no single correct token sequence
- "Is this reply safe?" — defined by what it must not say
- "Is this reply the right length?" — a property of the whole response
SFT can only tell the model "this output was good". It has no way to say "this output was better than that one", and it can never say "this output was bad" — a maximum-likelihood objective has no mechanism for pushing probability down.
Minimising NLL on good responses raises their likelihood without ever lowering the likelihood of bad ones. Every method in this section exists to add the missing downward force. They differ only in how expensively they get it.