fine-tuning-with-trl

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

1|Updated May 10, 2026
One-click install
npx skills add https://github.com/Tgoldi/claude-skills --skill fine-tuning-with-trl-tgoldi
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: fine-tuning-with-trl
Source: https://github.com/Tgoldi/claude-skills/tree/main/fine-tuning-with-trl
Command: npx skills add https://github.com/Tgoldi/claude-skills --skill fine-tuning-with-trl-tgoldi

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 post-training pipelines (RLHF) that are difficult to configure correctly. This Skill provides ready-to-use workflows for supervised fine-tuning, preference alignment, reward model training, and online reinforcement learning using HuggingFace TRL. ## Core Features & Use Cases - Full RLHF Pipeline: Step-by-step checklists for SFT → reward model → PPO training with working code for each stage. - Preference Alignment with DPO: Train on chosen/rejected pairs without a reward model, with 10+ loss variants (IPO, hinge, robust, APO) documented in references. - Memory-Efficient Online RL: GRPO training with custom reward functions for GPU-constrained environments. - Use Case: You have a dataset of preferred vs. rejected chatbot responses. Use the DPO workflow to align a Qwen2.5 model with those preferences, tune the beta parameter, and evaluate the aligned model. ## Quick Start Fine-tune Qwen2.5-0.5B with DPO on the ultrafeedback preference dataset using TRL and show me the training configuration.

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?

Load a preference dataset with prompt, chosen, and rejected fields, configure DPOConfig with beta and learning rate, then train with DPOTrainer. TRL also offers a CLI: trl dpo --model_name_or_path <model> --dataset_name <dataset>.

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

SFT trains on prompt-completion pairs for instruction following. DPO aligns with preference pairs without a reward model. PPO uses a trained reward model for maximum RL control. GRPO provides online RL with lower memory usage than PPO.

How much GPU memory does TRL training require?

For a 7B model: 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. LoRA, gradient checkpointing, and gradient accumulation reduce memory further.

Why does DPO training run out of memory?

DPO holds both policy and reference models in memory, so OOM is common. Reduce per_device_train_batch_size to 1, lower max_length, increase gradient_accumulation_steps, or enable gradient checkpointing on the model.

How do I train a reward model for RLHF with TRL?

Load a model with AutoModelForSequenceClassification and num_labels=1, prepare a chosen/rejected preference dataset, and train with RewardTrainer. The Bradley-Terry loss teaches the model to score chosen responses higher than rejected ones.

When should I use Axolotl or Unsloth instead of TRL?

Use Axolotl for YAML-driven 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.