fine-tuning-with-trl

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

1|Updated Mar 12, 2026
One-click install
npx skills add https://github.com/kaminocorp/hermes-alpha-hunter --skill fine-tuning-with-trl-kaminocorp
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: fine-tuning-with-trl
Source: https://github.com/kaminocorp/hermes-alpha-hunter/tree/main/skills/mlops/training/trl-fine-tuning
Command: npx skills add https://github.com/kaminocorp/hermes-alpha-hunter --skill fine-tuning-with-trl-kaminocorp

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 implement correctly from scratch. ## Core Features & Use Cases - Supervised Fine-Tuning (SFT): Train base models on instruction-following datasets with prompt-completion or conversational formats, including LoRA and packing support. - Preference Alignment (DPO): Align models with chosen/rejected preference pairs using 10+ loss variants without needing a separate reward model. - Online Reinforcement Learning: Run PPO with a trained reward model or memory-efficient GRPO with custom reward functions. - Use Case: Take a base model like Qwen2.5-0.5B, 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 call trainer.train(). 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 offers 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 needs 24GB since it stores a reference model, PPO needs 40GB for policy plus reward model, and GRPO needs about 24GB. LoRA, gradient checkpointing, and gradient accumulation reduce memory further.

Why does DPO training run out of memory?▼

DPO stores both policy and reference models, 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 within available VRAM.

Can I use LoRA with TRL trainers?▼

Yes, pass a peft LoraConfig to SFTTrainer via the peft_config parameter. Typical settings use r=16, lora_alpha=32, and target_modules set to all-linear. LoRA works with other TRL methods as well to reduce memory requirements.

When should I use Axolotl or Unsloth instead of TRL?▼

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