openlair/dr-claw/trl-fine-tuning
Claude Code and agent skill by openlair/dr-claw
- community
Checking that the SKILL.md file is still in the repository.
Fine-tune LLMs using reinforcement learning with TRL - SFT for instruction tuning, DPO for preference alignment, PPO/GRPO for reward optimization, and reward model training. Use when need RLHF, align model with preferences, or train from human feedback. Works with HuggingFace Transformers. Also covers GRPO with TRL and SimPO (guides in references/).
Install
npx vskill@latest install openlair/dr-claw/trl-fine-tuningSKILL.md
The same SKILL.md was published earlier as openlair/dr-claw/trl-fine-tuning.
TRL - Transformer Reinforcement Learning
Quick start
TRL provides post-training methods for aligning language models with human preferences.
Installation:
Supervised Fine-Tuning (instruction tuning):
DPO (align with preferences):
Common workflows
Workflow 1: Full RLHF pipeline (SFT → Reward Model → PPO)
Complete pipeline from base model to human-aligned model.
Copy this checklist:
Step 1: Supervised fine-tuning
Train base model on instruction-following data:
Step 2: Train reward model
Train model to predict human preferences:
Step 3: PPO reinforcement learning
Optimize policy using reward model:
Step 4: Evaluate
Workflow 2: Simple preference alignment with DPO
Align model with preferences without reward model.
Copy this checklist:
Step 1: Prepare preference dataset
Dataset format:
Load dataset:
Step 2: Configure DPO
Step 3: Train with DPOTrainer
CLI alternative:
Workflow 3: Memory-efficient online RL with GRPO
Train with reinforcement learning using minimal memory.
Copy this checklist:
Step 1: Define reward function
Or use a reward model:
Step 2: Configure GRPO
Step 3: Train with GRPOTrainer
CLI:
When to use vs alternatives
Use TRL when:
- Need to align model with human preferences
- Have preference data (chosen/rejected pairs)
- Want to use reinforcement learning (PPO, GRPO)
- Need reward model training
- Doing RLHF (full pipeline)
Method selection:
- SFT: Have prompt-completion pairs, want basic instruction following
- DPO: Have preferences, want simple alignment (no reward model needed)
- PPO: Have reward model, need maximum control over RL
- GRPO: Memory-constrained, want online RL
- Reward Model: Building RLHF pipeline, need to score generations
Use alternatives instead:
- HuggingFace Trainer: Basic fine-tuning without RL
- Axolotl: YAML-based training configuration
- LitGPT: Educational, minimal fine-tuning
- Unsloth: Fast LoRA training
Common issues
Issue: OOM during DPO training
Reduce batch size and sequence length:
Or use gradient checkpointing:
Issue: Poor alignment quality
Tune beta parameter:
Issue: Reward model not learning
Check loss type and learning rate:
Ensure preference dataset has clear winners:
Issue: PPO training unstable
Adjust KL coefficient:
Advanced topics
SFT training guide: See references/sft-training.md for dataset formats, chat templates, packing strategies, and multi-GPU training.
DPO variants: See references/dpo-variants.md for IPO, cDPO, RPO, and other DPO loss functions with recommended hyperparameters.
Reward modeling: See references/reward-modeling.md for outcome vs process rewards, Bradley-Terry loss, and reward model evaluation.
Online RL methods: See references/online-rl.md for PPO, GRPO, RLOO, and OnlineDPO with detailed configurations.
Hardware requirements
- GPU: NVIDIA (CUDA required)
- VRAM: Depends on model and method
- SFT 7B: 16GB (with LoRA)
- DPO 7B: 24GB (stores reference model)
- PPO 7B: 40GB (policy + reward model)
- GRPO 7B: 24GB (more memory efficient)
- Multi-GPU: Supported via
accelerate - Mixed precision: BF16 recommended (A100/H100)
Memory optimization:
- Use LoRA/QLoRA for all methods
- Enable gradient checkpointing
- Use smaller batch sizes with gradient accumulation
Resources
- Docs: https://huggingface.co/docs/trl/
- GitHub: https://github.com/huggingface/trl
- Papers:
- "Training language models to follow instructions with human feedback" (InstructGPT, 2022)
- "Direct Preference Optimization: Your Language Model is Secretly a Reward Model" (DPO, 2023)
- "Group Relative Policy Optimization" (GRPO, 2024)
- Examples: https://github.com/huggingface/trl/tree/main/examples/scripts
Related tools (merged into this skill)
These were separate skills. Their full guides now live under references/; read the one you need when the user asks for that tool or it fits the task better.
| Tool | Guide | What it covers | |
|---|---|---|---|
| GRPO with TRL | references/grpo-rl-training/overview.md | Expert guidance for GRPO/RL fine-tuning with TRL for reasoning and task-specific model training | |
| SimPO | references/simpo/overview.md | Simple Preference Optimization for LLM alignment. |
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/post-training/trl-fine-tuning/SKILL.md
Popularity
- Repository stars
- 1,139
- Repository forks
- 131
- 7-day trend score
- 35
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/openlair/dr-claw/trl-fine-tuning)