Skip to main content
TRL provides dedicated trainer classes for every stage of the post-training pipeline. Each trainer is a lightweight wrapper around the Hugging Face Trainer and supports distributed training out of the box.

Install TRL

Trainers

1

Supervised Fine-Tuning with SFTTrainer

SFTTrainer is the starting point for most post-training workflows. It fine-tunes a model on a dataset of demonstrations.
See the SFT Trainer docs for options like dataset packing, chat templates, and LoRA.
2

Reinforcement learning with GRPOTrainer

GRPOTrainer implements Group Relative Policy Optimization (GRPO) — a memory-efficient RL algorithm used to train DeepSeek-R1. It generates groups of completions and optimizes them against a reward function.
For reasoning models, use the reasoning_accuracy_reward() function for better results.
See the GRPO Trainer docs for reward function configuration and vLLM integration.
3

Preference alignment with DPOTrainer

DPOTrainer implements Direct Preference Optimization (DPO), which trains the model directly on preference pairs without a separate reward model. DPO was used to post-train Llama 3 and many other models.
See the DPO Trainer docs for reference model configuration and loss variants.
4

Reward modeling with RewardTrainer

RewardTrainer trains a scalar reward model on preference data. Reward models are used as the reward signal for online RL methods like GRPO and RLOO.
See the Reward Trainer docs for dataset format and evaluation.

Command Line Interface

The trl CLI lets you run fine-tuning jobs directly from your terminal without writing any Python code. SFT — supervised fine-tuning:
DPO — preference alignment:
Reward modeling:
Run trl --help or any subcommand with --help to see all available options. See the CLI docs for the full reference.

Troubleshooting

Out of memory

Reduce batch size and accumulate gradients to maintain an effective batch size:
For more aggressive memory reduction, install PEFT and enable LoRA:
See the memory optimization guide and PEFT integration for details.

Loss not decreasing

A learning rate that is too high or too low is a common cause. A good starting point for fine-tuning:
For more help, open an issue on GitHub.

Next steps

SFT Trainer

Full guide to supervised fine-tuning: packing, chat templates, and LoRA

GRPO Trainer

Group Relative Policy Optimization for reasoning and RL alignment

Distributed training

Scale to multi-GPU and multi-node with DeepSpeed and FSDP

PEFT integration

Train large models on consumer hardware with LoRA and QLoRA