fine-tuning-with-trl

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

Updated Jun 5, 2026
One-click install
npx skills add https://github.com/xu1713/openhorse --skill fine-tuning-with-trl-xu1713
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: fine-tuning-with-trl
Source: https://github.com/xu1713/openhorse/tree/main/openhorse/openhorse/optional-skills/mlops/training/trl-fine-tuning
Command: npx skills add https://github.com/xu1713/openhorse --skill fine-tuning-with-trl-xu1713

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 involving supervised fine-tuning, reward modeling, and reinforcement learning, which are difficult to configure and debug from scratch. ## Core Features & Use Cases - Full RLHF Pipeline: Run the complete SFT → Reward Model → PPO workflow with step-by-step checklists and 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) and tuned hyperparameters. - Memory-Efficient GRPO: Train with custom reward functions using group-relative optimization, including a production-ready template and deep guidance on reward design, mode collapse, and loss behavior. - Use Case: Fine-tune Qwen2.5-1.5B on GSM8K with GRPO using correctness and format reward functions to produce structured reasoning outputs with XML-tagged answers. ## Quick Start Ask the AI to set up a DPO training run with TRL on a preference dataset using the provided configuration and trainer code.

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 passing the model, tokenizer, and dataset. A CLI alternative is available via the trl dpo command.

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 control. GRPO runs memory-efficient online RL by comparing multiple generations per prompt.

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. LoRA, gradient checkpointing, and gradient accumulation reduce memory further.

Why does loss increase during GRPO training?

Rising loss during GRPO training is expected because the loss measures KL divergence from the initial policy as the model learns. Monitor reward metrics and reward_std instead of loss to track actual training progress.

How do I fix OOM errors during DPO training?

Reduce per_device_train_batch_size to 1, lower max_length to 512, and increase gradient_accumulation_steps to maintain the effective batch size. Enabling gradient checkpointing on the model also reduces memory usage.

When should I use Axolotl or Unsloth instead of TRL?

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