C.W.K.
Stream
Lesson 05 of 06 · published

Alignment: DPO, ORPO, SimPO

~22 min · dpo, orpo, simpo, alignment, preference

Level 0Observer
0 XP0/43 lessons0/11 achievements
0/120 XP to next level120 XP to go0% complete

Beyond supervised fine-tuning

SFT teaches the model what to say. Alignment teaches it to prefer better responses over worse ones. Use alignment when your data is preference pairs (preferred / rejected) rather than instruction → response.

DPO (Direct Preference Optimization)

Train with pairs of (preferred, rejected) responses. Simpler than RLHF — no separate reward model needed. Requires a reference model (frozen base) for the KL constraint.

ORPO (Odds Ratio Preference Optimization)

Combines SFT and alignment into a single training step — no reference model. Faster and more memory-efficient than DPO. In TRL v1.0, available under trl.experimental.orpo.

SimPO (Simple Preference Optimization)

Uses average log probability as the implicit reward (no reference model). Reported to outperform DPO by ~6.4 points on AlpacaEval 2 with 20% less compute. Available via CPOTrainer with loss_type="simpo".

Method comparison

MethodData formatReference model?Best for
SFTinstruction → responseNoTeaching specific behaviors
DPOpreferred / rejected pairsYesImproving response quality
ORPOpreferred / rejected pairsNoSingle-stage alignment
SimPOpreferred / rejected pairsNoBest quality, efficient

Code

DPO training in TRL·python
from trl import DPOConfig, DPOTrainer

# Data format: {"prompt": "...", "chosen": "...", "rejected": "..."}
dpo_config = DPOConfig(
    output_dir="./dpo-results",
    beta=0.1,                    # KL penalty strength
    learning_rate=5e-5,
    num_train_epochs=1,
    per_device_train_batch_size=2,
    gradient_accumulation_steps=4,
    bf16=True,
)

trainer = DPOTrainer(
    model=model,                 # the SFT-fine-tuned model
    ref_model=None,              # None = use frozen base for KL
    args=dpo_config,
    train_dataset=preference_dataset,
    processing_class=tokenizer,
    peft_config=peft_config,
)
trainer.train()

External links

Exercise

Take an SFT-fine-tuned model from a previous lesson. Build a small (50-pair) preference dataset by generating two responses per prompt with different temperatures, then ranking them. Run DPO on top of the SFT model. Compare base, SFT, and SFT+DPO outputs on 10 held-out prompts.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.