SFT teaches a model what good outputs look like; it never shows the model what bad looks like. When your tuned model is correct but ranks poorly on judgment calls — verbose when it should be terse, hedging when it should commit, picking the plausible-but-wrong framing — you need preference optimization.
Tier: Advanced · Workflow area: Fine-tuning & Model Adaptation
DPO (Direct Preference Optimization) does this without training a separate reward model, and GRPO-style methods now appear by name in Indian job postings. This playbook runs DPO on a small preference set, on the same free-GPU budget as pb-29.
Skip if SFT-stage problems remain (wrong facts, broken format) — DPO polishes preferences, it does not repair correctness; fix the SFT dataset first.
(prompt, chosen, rejected) — quality bar as in pb-28, decontaminated against evals.DPOTrainer, plus the pb-29 GPU setup (Kaggle 16GB, 4-bit base + LoRA for 7–8B).Mine preference pairs from reality first. Best sources: production A/B outputs with user choices, reviewer edit history (pre-edit = rejected, post-edit = chosen), and side-by-side ratings from pb-36's annotation workflow. Synthetic fallback: sample two responses at temperature 0.9 from your SFT model, have a strong judge pick chosen/rejected with your rubric, and human-review 20% of verdicts before trusting the rest.
Audit the pairs for degenerate patterns. Check length statistics: if "chosen" is systematically longer than "rejected", DPO will learn verbosity, not quality — length-match or subsample until the chosen/rejected length ratio averages ~1.0. Same check for format artifacts (markdown headers, bullet density).
Configure DPO conservatively.
from trl import DPOConfig, DPOTrainer
cfg = DPOConfig(
beta=0.1, # KL strength: raise to 0.3 if drifting, lower to 0.05 if not moving
learning_rate=5e-6, # 10-40x smaller than SFT — this is not a typo
per_device_train_batch_size=1,
gradient_accumulation_steps=16,
num_train_epochs=1,
max_length=1024, max_prompt_length=512,
)
Train a fresh LoRA adapter on top of the merged SFT model (or stack adapters); with PEFT, TRL uses the frozen base as the implicit reference model, saving the second model's VRAM — that is what keeps 7–8B DPO inside 16GB.
Monitor the DPO-specific metrics. rewards/accuracies (how often the model prefers chosen over rejected) should climb toward 0.7–0.9; rewards/margins should grow steadily. Accuracy pinned at ~0.5 means your pairs are indistinguishable or mislabeled; accuracy at 1.0 within an epoch means pairs are trivially separable (often the length artifact from step 2).
Evaluate three ways. (a) Preference accuracy on the held-out triples. (b) Win-rate: calibrated judge (pb-36) compares DPO-model vs SFT-model outputs on fresh prompts, order-randomized. (c) Regression: re-run the pb-33 correctness suite — DPO must not have traded correctness for likability.
Decide SFT-only vs SFT+DPO with numbers. Ship DPO only if the win-rate improves meaningfully (e.g., ≥ 60% with confidence interval clearing 50%) and correctness regressions are within your tolerance. Record the verdict and configs in the model card.
DPO learns whatever separates chosen from rejected — if that separator is length or formatting rather than quality, you have trained a longer model, not a better one. The pair audit in step 2 is the whole game.
DPOTrainer: the reference implementation; pairs directly with the pb-29 PEFT stack.Preference data often encodes who was preferred, not just what — check pairs for names, org references, and reviewer identities before they leave the boundary.