model_finetuning

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

Updated Jan 14, 2026
One-click install
npx skills add https://github.com/jvsandhu/agentic-skills --skill model-finetuning-jvsandhu
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: model_finetuning
Source: https://github.com/jvsandhu/agentic-skills/tree/main/skills/model_finetuning
Command: npx skills add https://github.com/jvsandhu/agentic-skills --skill model-finetuning-jvsandhu

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires trl, transformers, datasets, peft, accelerate, torch, and includes references (resource) components.

What problem does it solve? Aligning a base language model with human preferences requires navigating a complex post-training pipeline—supervised fine-tuning, reward modeling, and reinforcement learning—where misconfigured hyperparameters or memory limits frequently derail training runs. ## Core Features & Use Cases - Full RLHF Pipeline: Step-by-step checklists covering SFT, reward model training, and PPO optimization with working code for each stage. - Preference Alignment with DPO: Train directly on chosen/rejected pairs without a separate reward model, including beta tuning guidance. - Memory-Efficient Online RL: GRPO workflows with custom reward functions for GPU-constrained environments. - Use Case: You have a Qwen2.5-0.5B base model and a dataset of user preference pairs. Follow the DPO workflow to align the model, then evaluate it and merge LoRA adapters for deployment. ## Quick Start Fine-tune the Qwen2.5-0.5B model on my instruction dataset using TRL's SFTTrainer with LoRA and show me the training configuration.

Frequently Asked Questions about model_finetuning

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 dataset, configure SFTConfig with output directory and learning rate, then pass everything to SFTTrainer and call train(). The skill provides complete working code for this workflow.

What is the difference between DPO, PPO, and GRPO for alignment?

DPO trains directly on preference pairs without a reward model and is simplest. PPO uses a trained reward model for maximum control but needs more memory. GRPO performs online RL with lower memory usage by generating multiple completions per prompt.

How much GPU VRAM do I need for fine-tuning a 7B model?

With LoRA, SFT needs about 16GB, DPO about 24GB since it stores a reference model, PPO about 40GB for policy plus reward model, and GRPO about 24GB. Gradient checkpointing and QLoRA reduce requirements further.

Why does DPO training run out of memory?

DPO holds both policy and reference models in memory. Reduce per_device_train_batch_size to 1, lower max_length, increase gradient_accumulation_steps, and enable gradient checkpointing on the model to fit within available VRAM.

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.