TRL logo

TRL

Free

TRL is a full stack library where we provide a set of tools to train transformer language models with Reinforcement Learning, from the Supervised Fine-tuning step (SFT), Reward Modeling step (RM) to the Proximal Policy Optimization (PPO) step.

FreeFree tier
Type
Open Source
Company
Hugging Face

About TRL

TRL is a full-stack library by Hugging Face that provides a comprehensive set of tools for training transformer language models using reinforcement learning and related methods. It supports the entire pipeline from supervised fine-tuning (SFT), reward modeling, and direct preference optimization (DPO) to advanced online methods like GRPO and PPO. The library is deeply integrated with the Hugging Face Transformers ecosystem, offers experimental support for multi-environment agentic RL with per-example environment selection, and includes stable implementations of KTO. It also integrates with DeepSpeed, Liger Kernel, and PEFT for efficient training. TRL is open-source and used for post-training alignment of LLMs, including vision-language models.

Key Features

Supports Supervised Fine-Tuning (SFT), Group Relative Policy Optimization (GRPO), Direct Preference Optimization (DPO), Reward Modeling, and more
Integrated with Hugging Face Transformers for seamless model handling
Includes experimental online methods like PPOTrainer, RLOOTrainer, NashMDTrainer, and XPOTrainer
Stable KTO trainer with full alignment pass
Multi-environment agentic RL support via GRPOTrainer with per-example environment selection and environment-owned rewards
Integrations with DeepSpeed, Liger Kernel, PEFT, and vLLM for efficient training and inference
Provides tools for knowledge distillation (GKDTrainer, MiniLLMTrainer)
Full pipeline coverage from supervised fine-tuning to final RLHF training

Pros & Cons

Pros
  • Open-source and freely available under the Hugging Face ecosystem
  • Comprehensive coverage of modern RL and alignment training methods in one library
  • Strong integration with Transformers, making it easy to use with thousands of pretrained models
  • Active development with regular updates and new features (e.g., multi-environment RL, stable KTO)
  • Supports memory- and compute-efficient training via integrations with DeepSpeed, vLLM, and PEFT
  • Backed by an active community and extensive documentation with examples and tutorials
  • Enables fine-tuning of very large models on limited hardware (e.g., 20B parameters on 24GB GPU)
Cons
  • RLHF training pipeline is inherently complex and may require expertise to set up correctly
  • Some trainers (e.g., PPOTrainer, OnlineDPOTrainer, NashMDTrainer) are still marked as experimental
  • Documentation primarily targets users already familiar with Hugging Face Transformers and RL concepts
  • Requires significant computational resources for training large models, though optimizations exist

Best For

Fine-tuning large language models with reinforcement learning from human feedback (RLHF)Aligning models with human preferences using DPO, KTO, or other preference optimization methodsTraining reward models for use in RLHF pipelinesPost-training alignment of vision-language modelsKnowledge distillation from larger teacher models to smaller student modelsExploring multi-environment agentic RL with sandboxed task suitesEfficiently training 20B+ parameter LLMs on consumer GPUs using memory reduction techniques

FAQ

What is TRL?
TRL (Transformers Reinforcement Learning) is a full-stack library by Hugging Face that provides tools to train transformer language models with reinforcement learning, including methods like Supervised Fine-Tuning (SFT), Group Relative Policy Optimization (GRPO), Direct Preference Optimization (DPO), and Reward Modeling.
How do I install TRL?
Installation instructions are provided in the 'Getting Started' section of the TRL documentation, which includes pip installation and quickstart guides.
What training methods does TRL support?
TRL supports a wide range of methods: online methods (GRPO, RLOO, OnlineDPO, NashMD, PPO, XPO), reward modeling (RewardTrainer, PRMTrainer), offline methods (SFT, DPO, KTO, BCO, CPO, ORPO), and knowledge distillation (GKD, MiniLLM). Some methods are experimental.
Is TRL free to use?
Yes, TRL is open-source and free to use. It is released under the Hugging Face ecosystem with an open license.
Can I use TRL with vision-language models?
Yes, TRL supports alignment of vision-language models, as highlighted in blog posts about Vision Language Model Alignment in TRL.