← govind p lal
AI and ML Bootcamp · Lecture 15 · lecture notes

Preference Tuning: RLHF, PPO and DPO

In short — An SFT model follows instructions but cannot tell which of two valid answers a human likes more. This lecture covers preference tuning, which fixes that using reinforcement learning. It builds RL vocabulary with a dog-training analogy, walks through the InstructGPT pipeline (SFT, reward model, PPO), and ends with DPO, which drops the reward model.

Why SFT is not enough

builds on Lecture 14: Week 13 - AI&ML | Fine-tuning - Part 2 | 11/04/2026, Lecture 14: Week 13 - AI&ML | Fine-tuning - Part 2 | 11/04/2026, Lecture 13: Week 12 - AI&ML | Fine-tuning | 04/04/2026

Same base model, different behaviour. GPT-3 vs GPT-3.5 (ChatGPT): GPT-3.5 had more fine-tuning and human preference optimization. Paper -> InstructGPT.

Industry order: pre-training -> SFT -> preference tuning -> reasoning.

The Problem

The Solution Preference tuning - tune the model on human preferences. Data = two answers A and B, plus which one the human picked.

Analogy: SFT is learning from a textbook with the right answer. Preference tuning is learning which way of writing the answer people like more.

!

SFT is not obsolete. Without a structured response from SFT, you cannot compare two responses. SFT first, then preference tuning.

Why negative examples matter

builds on Lecture 13: Week 12 - AI&ML | Fine-tuning | 04/04/2026
Example

Teaching a circle. Method A: draw 1000 perfect circles (SFT style). The learner may draw a near-circle oval and think it fits. Method B: show circle, oval, circle, rectangle, circle, hexagon (preference style). The boundary is clear.

SFT memorizes, RL generalizes

Reinforcement learning basics

builds on Lecture 2: Week 1 - AI and ML | Fast-tracking the course of AI | 18/01/2026, Lecture 2: Week 1 - AI and ML | Fast-tracking the course of AI | 18/01/2026

Reinforcement learning - learn by trying, getting a reward, and adjusting. Like learning to ride a bicycle. Old field (robots, Go, Atari).

Objective: maximise the expected reward. A second part keeps updates small so the model does not drift far from where it started (safety).

Example

Dog fetching a ball. No loss function to optimise in a dog. Dog explores, moves toward the ball, gets a treat. Later picks up the ball and returns, gets another treat. Nobody gave rules. It discovered them through rewards.

RL termDog trainingLLM
AgentDogLanguage model
EnvironmentParkChat window
StateWhere the ball isThe prompt
ActionRun, catch, sitGenerate a response
PolicyDog's brain / habitsModel weights
RewardTreatScore for the response
EpisodeThrow, fetch, returnOne prompt-response cycle

Policy - strategy of choosing an action given a state. Optimising the policy = updating the weights = fine-tuning.

Example

Chess: state = piece positions, action = move, environment = board/game, episode = full game.

Reward and reward model

The Problem Robot picks a can: success or fail, +1 or -1. For LLMs both responses look right. We must define what is good.

The Solution

InstructGPT pipeline and PPO

builds on Lecture 14: Week 13 - AI&ML | Fine-tuning - Part 2 | 11/04/2026
SFTresponses to ratescoresstart policyBase modelSFT modelfollow instructionsReward modeltrained on preferencesPPOoptimise policyAligned model
InstructGPT three-step flow.

Step 1: SFT. Step 2: collect preference data and train a reward model. Step 3: optimise with PPO (Proximal Policy Optimization).

Preference data

Example

Prompt: explain a stock dividend. Response A: shareholders get extra shares instead of cash. Response B: same plus a concrete example (5% dividend, 100 shares -> 5 extra, total value unchanged). Human prefers B.

Reward model - the final layer changes from next-token probabilities to a score (e.g. 0.73 vs 0.9). Learns from chosen vs rejected.

PPO loop

Online training - new data is generated during training (PPO). Offline training - a fixed dataset, nothing generated during training.

Why PPO is hard for LLMs, and reward hacking

builds on Lecture 13: Week 12 - AI&ML | Fine-tuning | 04/04/2026
ModelRole
Active (policy)Being trained, updated every step
ReferenceFrozen copy of the SFT model; keeps updates from drifting far
RewardScores responses
Value (critic)Predicts reward to compute advantage

All four sit in memory at once. Plus gradients and Adam optimizer states. Not feasible for most people. (7B parameters at 16-bit = 56 GB just for weights.)

Reward hacking - the model finds a shortcut to a high score without doing the real task.

DPO - Direct Preference Optimization

builds on Lecture 13: Week 12 - AI&ML | Fine-tuning | 04/04/2026

The Insight The preference dataset already says which response is better. So the reward is implicit. No reward model needed.

Per example DPO asks two things

Loss compares how much more likely chosen vs rejected has become now, compared to the reference. Push chosen up, push rejected down.

Why contrasting beats imitation

!

DPO is sensitive and needs a much lower learning rate than SFT. It must learn very small differences.

PPODPO
Models in memory42
TrainingOnlineOffline
Reward modelNeededNot needed
ComputeHighLower
DataPreference pairsSame preference pairs

Practical run: DPO on SmolLM 135M Instruct with prompt/chosen/rejected data. PPO was not run because it does not fit on Colab. Next topic: reasoning with GRPO (Group Relative Policy Optimization).

Glossary

Preference tuning
Tuning a model on human choices between two responses.
Policy
Strategy for choosing an action given a state; for an LLM, the model weights.
Reward model
A model trained to score a prompt-response pair like a human would.
PPO
Proximal Policy Optimization; RL algorithm that updates the policy with clipped steps.
DPO
Direct Preference Optimization; trains on chosen vs rejected pairs with no reward model.
Reward hacking
Model exploits the reward signal without doing the real task.
Contrastive learning
Learning from contrasting good and bad examples.