fine-tuning-with-trl

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

13.0k|930|Updated Nov 3, 2025
One-click install
npx skills add https://github.com/Orchestra-Research/AI-research-SKILLs --skill fine-tuning-with-trl-orchestra-research
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: fine-tuning-with-trl
Source: https://github.com/Orchestra-Research/AI-research-SKILLs/tree/main/06-post-training/trl-fine-tuning
Command: npx skills add https://github.com/Orchestra-Research/AI-research-SKILLs --skill fine-tuning-with-trl-orchestra-research

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 prompt-completion pairs, chat templates, packing, and LoRA support. - Preference Alignment (DPO): Align models with chosen/rejected preference pairs using 10+ loss variants including IPO, hinge, and robust DPO, without needing a reward model. - Online RL (PPO/GRPO): Optimize policies with reward models or custom reward functions, with GRPO offering memory-efficient training. - Reward Model Training: Train models to score completions using Bradley-Terry loss for RLHF 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 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.

Does TRL support LoRA fine-tuning?▼

Yes, TRL trainers accept a peft_config parameter with LoraConfig from the peft library. This enables memory-efficient LoRA and QLoRA training for SFT, DPO, and other methods, reducing VRAM requirements significantly.

Why does DPO training run out of memory?▼

DPO stores both policy and reference models, roughly doubling memory usage. Reduce per_device_train_batch_size to 1, lower max_length to 512, increase gradient_accumulation_steps, or enable gradient checkpointing to fit in available VRAM.

How do I train a reward model for RLHF?▼

Use RewardTrainer with an AutoModelForSequenceClassification loaded with num_labels=1 and a preference dataset with chosen/rejected pairs. The default Bradley-Terry loss learns 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 or Unsloth for fast LoRA training when you do not need reinforcement learning. TRL is specifically for RLHF, preference alignment, and reward model training workflows.