AI From Scratch/Phase 19/Lesson 40/~90 minutes

Capstone Lesson 40: Direct Preference Optimization from Scratch

BuildPython (torchnumpy)No prerequisites

Reward models and PPO are the classical RLHF stack. DPO collapses that stack into a single supervised loss that fits a policy directly against preference pairs. This lesson derives the DPO loss from the reward-difference identity, ships a...

Loading lesson page...