fine-tuning-with-trl

Fine-tune LLMs with TRL using SFT, DPO, PPO, GRPO, and reward model training.

1|Updated Mar 5, 2026
One-click install
npx skills add https://github.com/Clay-HHK/claude-skills --skill fine-tuning-with-trl-clay-hhk
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: fine-tuning-with-trl
Source: https://github.com/Clay-HHK/claude-skills/tree/main/trl-fine-tuning
Command: npx skills add https://github.com/Clay-HHK/claude-skills --skill fine-tuning-with-trl-clay-hhk

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires trl, transformers, datasets, peft, accelerate, torch, and includes references (resource) components.

What problem does it solve? Aligning language models with human preferences requires complex RLHF pipelines involving supervised fine-tuning, reward modeling, and reinforcement learning, which are difficult to implement correctly from scratch. ## Core Features & Use Cases - Supervised Fine-Tuning (SFT): Train base models on instruction-following data with support for chat templates, sequence packing, LoRA, and multi-GPU training. - Preference Alignment (DPO): Align models using chosen/rejected preference pairs without a reward model, with 10+ loss variants including IPO, hinge, and robust DPO. - Online RL (PPO/GRPO): Optimize policies with reward models or custom reward functions, with GRPO offering memory-efficient training. - Reward Model Training: Train Bradley-Terry reward models on preference data for use in PPO pipelines. - Use Case: Take a base Qwen model, run SFT on instruction data, train a reward model on UltraFeedback preferences, then apply PPO to produce a human-aligned chat model. ## Quick Start Fine-tune Qwen2.5-0.5B with DPO on the trl-lib/ultrafeedback_binarized preference dataset using TRL.

Frequently Asked Questions about fine-tuning-with-trl

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fine-tune an LLM with DPO using TRL?▼

Use DPOTrainer with a preference dataset containing prompt, chosen, and rejected fields. Configure DPOConfig with beta (default 0.1), learning rate around 5e-7, and max lengths, then call trainer.train() with your model and tokenizer.

What is the difference between DPO, PPO, and GRPO in TRL?▼

DPO aligns models directly from preference pairs without a reward model. PPO uses a trained reward model for maximum control but needs about 40GB VRAM for 7B models. GRPO is memory-efficient online RL needing about 24GB for 7B models.

How much GPU memory does TRL training require?▼

For 7B models: SFT needs about 16GB with LoRA, DPO about 24GB since it stores a reference model, PPO about 40GB for policy plus reward model, and GRPO about 24GB. Use LoRA, gradient checkpointing, and gradient accumulation to reduce memory.

Why does DPO training run out of memory?▼

DPO stores both policy and reference models, doubling memory usage. Reduce per_device_train_batch_size to 1, lower max_length to 512, increase gradient_accumulation_steps, or enable gradient checkpointing on the model.

What dataset format does TRL reward model training need?▼

RewardTrainer expects preference data with prompt, chosen, and rejected fields, such as trl-lib/ultrafeedback_binarized. The model is loaded with num_labels=1 and trained with the Bradley-Terry loss to score chosen responses higher than rejected ones.

When should I use Axolotl or Unsloth instead of TRL?▼

Use Axolotl for YAML-based training configuration, Unsloth for fast LoRA training, or plain HuggingFace Trainer for basic fine-tuning without RL. TRL is the right choice when you need RLHF, preference alignment, or reward model training.