United Stateshuggingface/trl
Train transformer language models with reinforcement learning.
⚡ Post-train transformer models with TRL
A single toolkit for SFT, preference tuning and reinforcement learning on foundation models.
TRL (Transformers Reinforcement Learning) is a library for post-training foundation models using advanced methods like Supervised Fine-Tuning (SFT), Group Relative Policy Optimization (GRPO), and Direct Preference Optimization (DPO). Built on top of the 🤗 Transformers ecosystem, it wraps each method in a dedicated trainer class while keeping compatibility with distributed training and parameter-efficient fine-tuning.
✨ Highlights
- Trainers for common methods: Access
SFTTrainer,GRPOTrainer,DPOTrainer,RewardTrainerand more with a similar API to the 🤗 Transformers trainer. - GRPO without heavy PPO code:
GRPOTrainerimplements Group Relative Policy Optimization, which is more memory-efficient than PPO and was used to train Deepseek AI's R1. - Preference-based post-training:
DPOTrainerimplements Direct Preference Optimization for tuning models from pairwise preference data. - Efficient and scalable: Leverages 🤗 Accelerate for DDP and DeepSpeed across single GPU to multi-node setups, and integrates 🤗 PEFT for training large models with LoRA/QLoRA on modest hardware.
- Faster training kernels: Integrates 🦥 Unsloth for accelerating training using optimized kernels.
- CLI access: A command-line interface lets you fine-tune models without writing training code.
- Harbor support: TRL now supports Harbor to train agents against sandboxed task suites via
GRPOTrainer'senvironment_factory.
💡 Why it matters
TRL brings standard post-training algorithms into one place without forcing users to re-implement each one from scratch. By building directly on Transformers, Accelerate, PEFT and Unsloth, it keeps distributed and parameter-efficient training native while making methods like GRPO and DPO easier to apply to custom datasets. With TRL v1 and additions like Harbor, it also extends beyond text fine-tuning toward agent training in sandboxed environments.
#RL #PostTraining #FineTuning #LLM #TiniX