Direct Preference Optimization just got a lot more accessible. This tutorial walks through a complete, end-to-end DPO pipeline using Anthropic’s HH-RLHF dataset and a Qwen2.5-0.5B-Instruct model, and the whole thing runs on a single Colab GPU. That’s notable because preference tuning has traditionally been the expensive part of the alignment stack — RLHF with PPO requires reward models, multiple policy rollouts, and days of compute. DPO strips that down to a simple classification-style loss over chosen and rejected response pairs.

The workflow is deliberately rigorous about data quality. Before any training happens, the tutorial audits the HH-RLHF subsets for structural issues and length-based preference biases — a known failure mode where models learn to simply produce longer answers rather than better ones. It then runs lexical shortcut diagnostics using TF-IDF and logistic regression to check whether surface-level patterns alone can distinguish preferred from rejected responses. If a linear classifier can separate them, the model will exploit that shortcut instead of learning real preferences. The code samples 120 training pairs and 30 test pairs from each of four subsets: helpful-base, helpful-rejection-sampled, helpful-online, and harmless-base.

The training setup uses TRL’s DPOTrainer with LoRA adaptation, a beta of 0.1, and just 30 max steps at a learning rate of 5e-6. The tutorial also handles a sneaky Colab environment issue: torchao 0.10.0 ships with peft incompatibilities that raise ImportError during import, so the code removes or patches it before training. That’s the kind of practical friction that rarely makes it into polished documentation.

What’s genuinely useful here is the evaluation plan. Rather than just reporting a single reward accuracy number, the tutorial analyzes performance across individual HH-RLHF subsets, inspects length bias in the fine-tuned policy, and generates sample responses for qualitative review. The subset breakdown matters because helpfulness and harmlessness often trade off against each other, and aggregate metrics hide that tension. The tutorial saves the final policy for further experimentation, which leaves the door open for the kind of iterative work that alignment research actually requires.