Anthropic has released a workflow for auditing preference biases and fine-tuning language models using Direct Preference Optimization on its HH-RLHF dataset via TRL and LoRA.
In this article
Setup and environment checks
The process begins by establishing a Colab environment. The script installs required packages including trl, transformers, accelerate, datasets, peft, and scikit-learn in a single pip call to ensure compatibility. It then removes torchao, a dependency that conflicts with the peft library version used here. The system reports the installed versions of Python, PyTorch, and transformers, along with the available device type and precision modes. If CUDA is not available, the setup defaults to CPU training.
Dataset preparation
The tutorial loads the Anthropic/hh-rlhf dataset from Hugging Face. It splits the data into four subsets: helpful-base, helpful-rejection-sampled, helpful-online, and harmless-base. From each subset, it samples 120 rows for training and 30 for testing. The code parses the raw conversation transcripts into structured user and assistant messages. It validates that chosen and rejected responses share the same conversational prefix before including them in the final dataset.
Biases and diagnostics
Before training, the script audits the data for structural and length-based preference biases. It calculates the difference in word count between chosen and rejected responses for every pair. A bar chart visualises the mean length delta across the different source subsets. The analysis also checks for identical completion pairs within the training set to ensure the data contains genuine preference examples rather than duplicates.
Training configuration
The model being fine-tuned is Qwen2.5-0.5B-Instruct. Training parameters include a beta value of 0.1, a maximum of 30 steps, and a learning rate of 5e-6. The batch size is set to one with gradient accumulation over eight steps. LoRA adaptation is enabled for the fine-tuning process. The code configures the DPOTrainer class through the TRL library to apply these settings.
What it means
This workflow provides a method for researchers to inspect the quality of RLHF data before training. By checking for length bias and identical pairs, teams can avoid reinforcing superficial patterns in their models. The use of LoRA allows for efficient adaptation of the base model without altering the full weights, making the process more practical for smaller teams.




