Skip to main content

What this is

This guide walks through DPO (Direct Preference Optimization) training using the cookbook. DPO learns from preference pairs (chosen vs. rejected responses) without a separate reward model.

How DPO differs from GRPO

Architecture

Using the recipe

Dataset format

DPO expects preference pairs. Supported formats: Format 1 — chosen/rejected messages:
Format 2 — input/output split:

Loss and reference

DPO increases the chosen-versus-rejected policy margin relative to a frozen reference. It trains with -log(sigmoid(beta * margin)), using summed logprobs over the response tokens. Reference scores are cached and reused; keep the base model, tokenizer, and rendering consistent with that cache. LoRA DPO normally shares a frozen reference within the policy trainer. Full-parameter DPO uses a separate reference trainer. DPO and ORPO retain controlled dataset batches and need no rollout streaming. Loss and cache implementation details live in the recipe and training skill.

Operational guidance

  • Set trainer.training_shape_id when you need an explicit policy shape — otherwise supported recipes auto-select a validated policy shape.
  • Leave trainer.reference_training_shape_id unset unless you need a specific reference shape — full-parameter DPO auto-selects the model’s validated LoRA shape as the reference; LoRA DPO uses a shared-session reference by default.
  • DPO does not provision a deployment — there are no rollout samples or deployment weight syncs in the recipe.
  • Keep a versioned reference cache tied to tokenizer + base model revision. If the base model changes, recompute reference logprobs.
  • Monitor margin statistics: increasing margins indicate the policy is learning preferences.
  • Periodic checkpoints are disabled by default (dcp_save_interval=0); successful runs save final state by default. Set a positive interval on dpo_loop.Config for recovery during a run.

Common pitfalls

  • Mismatched formatting between chosen/rejected sequences corrupts preference signals — ensure identical prompt prefixes.
  • Stale reference cache: If you warm-start from a different model, cached reference logprobs are invalid.
  • ORPO (training.recipes.orpo_loop) — Odds Ratio Preference Optimization. Combines an SFT-style negative-log-likelihood term on the chosen response with a margin term on the odds ratio between chosen and rejected. Unlike DPO, ORPO does not require a reference trainer (no cached reference logprobs), so the recipe runs with a single trainer + dataset of preference pairs. See training.recipes.orpo_loop in the public cookbook repo for the full configuration.