trl-fine-tuning

Train and align language models using TRL SFT, DPO, GRPO, and RLOO methods.

Updated Aug 22, 2026
One-click install
npx skills add https://github.com/vivekgoquest/hermes-agent-stable --skill trl-fine-tuning-vivekgoquest
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: trl-fine-tuning
Source: https://github.com/vivekgoquest/hermes-agent-stable/tree/main/optional-skills/mlops/training/trl-fine-tuning
Command: npx skills add https://github.com/vivekgoquest/hermes-agent-stable --skill trl-fine-tuning-vivekgoquest

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 navigating multiple post-training methods, dataset formats, and hyperparameter choices, and mistakes like using removed APIs (PPO in TRL 1.x) or misconfigured reward functions waste GPU hours. ## Core Features & Use Cases - Full RLHF Pipelines: Step-by-step checklists for SFT, reward model training, and RLOO reinforcement learning with working code for each stage. - Preference Alignment with DPO: Train on chosen/rejected pairs without a reward model, with guidance on beta tuning and 10+ loss variants (IPO, hinge, robust, APO). - Memory-Efficient GRPO: Design custom reward functions for verifiable tasks like math and structured output, with a production-ready training template and deep-dive reference on training dynamics. - Use Case: Fine-tune Qwen2.5-1.5B-Instruct on GSM8K with GRPO using correctness and format reward functions, monitoring reward progression and avoiding mode collapse. ## Quick Start Fine-tune Qwen/Qwen2.5-0.5B with supervised fine-tuning on the trl-lib/Capybara dataset using TRL's SFTTrainer.

Frequently Asked Questions about trl-fine-tuning

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

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

Load a model with AutoModelForCausalLM, prepare a prompt-completion or conversational dataset, configure SFTConfig with output directory and learning rate, then pass everything to SFTTrainer and call train(). Enable packing for 2-3x faster training.

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

DPO aligns models directly on preference pairs without a reward model. RLOO uses a trained reward model for online RL and replaces the removed PPO in TRL 1.x. GRPO is the memory-efficient option that compares groups of completions using custom reward functions.

Was PPO removed from TRL?▼

Yes, PPOTrainer, PPOConfig, and the ppo CLI script were removed in TRL 1.x. Use RLOOTrainer or the trl rloo command as the drop-in replacement for reward-model-driven RLHF, or GRPO for memory-efficient online RL.

How much GPU memory does TRL training need?▼

For 7B models: SFT needs about 16GB with LoRA, DPO needs 24GB since it stores a reference model, RLOO needs 40GB for policy plus reward model, and GRPO needs about 24GB. Reduce memory with LoRA/QLoRA and gradient checkpointing.

Why does GRPO loss increase during training?▼

Increasing loss is expected behavior in GRPO because the loss measures KL divergence from the initial policy as the model learns. Monitor reward metrics and reward_std instead; reward should rise while reward_std stays above 0.1 to avoid mode collapse.

How do I fix OOM errors during DPO training?▼

Reduce per_device_train_batch_size to 1, lower max_length from 1024 to 512, and increase gradient_accumulation_steps to maintain effective batch size. You can also enable gradient checkpointing on the model to trade compute for memory.