fine-tuning-with-trl

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

14|5|Updated Apr 9, 2026
One-click install
npx skills add https://github.com/MLT-OSS/hermes-agent-go --skill fine-tuning-with-trl-mlt-oss
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: fine-tuning-with-trl
Source: https://github.com/MLT-OSS/hermes-agent-go/tree/main/skills/mlops/training/trl-fine-tuning
Command: npx skills add https://github.com/MLT-OSS/hermes-agent-go --skill fine-tuning-with-trl-mlt-oss

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 model training, and reinforcement learning, which are difficult to configure and stabilize without guidance. ## Core Features & Use Cases - Supervised Fine-Tuning (SFT): Train base models on instruction-following datasets with prompt-completion or conversational formats, 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 Reinforcement Learning: Run PPO with a trained reward model or memory-efficient GRPO with custom reward functions for online RL training. - Use Case: Take a base model like Qwen2.5-0.5B, run SFT on the Capybara dataset, 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 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 full RL control. GRPO runs online RL with lower memory by sampling multiple completions per prompt.

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 large batch sizes and sequence lengths cause OOM. Reduce per_device_train_batch_size to 1, lower max_length to 512, increase gradient_accumulation_steps, and enable gradient checkpointing.

Can I train a reward model with TRL for RLHF?

Yes, RewardTrainer trains a sequence classification model with num_labels=1 on chosen/rejected preference pairs using the Bradley-Terry loss. The saved reward model can then be passed to PPO training via reward_model_path.

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.