Log-Probability Building Blocks
Numerically stable softmax/log-softmax, token log-prob gathering, and masked sequence log-probabilities used everywhere downstream.
Implement log-prob utilities, Bradley–Terry preferences, DPO gradients, IPO variants, and a full evaluation pipeline.
Every source step is its own lesson with intuition, concepts, correctly rendered MathJax mathematics, implementation, tests, mistakes, and a checkpoint.
Numerically stable softmax/log-softmax, token log-prob gathering, and masked sequence log-probabilities used everywhere downstream.
Initialize policy parameters, compute token logits, sequence log-probs, and their gradients w.r.t. the policy.
Bradley–Terry pairwise loss, reward accuracy, and utilities to build and sample preference pairs.
Frozen reference log-probs, policy–reference log-ratios, pair margins, the DPO objective, and its gradient.
A single DPO train step and the outer training loop over preference batches.
Length-normalized log-probs, IPO loss, implicit rewards, preference accuracy, KL to reference, and reward-margin statistics.
Aggregate DPO evaluation metrics and wire everything into a complete train-and-evaluate pipeline.