Policy model (trainable)
Reference model (frozen)
Reward model (frozen)
Value head (trainable)
You will rarely hand-write a full PPO trainer — libraries like TRL exist for this. But understanding the two functions below (reward shaping with KL, and the clipped surrogate loss) demystifies what those libraries do under the hood.