StackMap
Subscribe
Explore / trl
huggingface

trl

Hugging Face's post-training library: SFT, DPO, GRPO, KTO and reward-model trainers on top of Transformers — from a Colab LoRA run to multi-GPU deployments.

18,852 2,845 Python Apache-2.0updated today
Curator's take

The on-ramp for post-training: if your model is on the Hub and your job fits SFT/DPO/GRPO/KTO, a Trainer class gets you a running job in an afternoon — and nothing else scales down to a free Colab as gracefully. PEFT/LoRA, quantized training and accelerate multi-GPU come along for free. NOT for frontier-scale RL dataflows (that's verl/slime territory — no Megatron, no disaggregated rollout engines), and the trainer abstraction that makes it easy also hides the loss mechanics: when results surprise you, read the trainer source before blaming the data.

Mapped by ShipWithAI editors · links verified
README.md

TRL - Transformers Reinforcement Learning

TRL Banner


A comprehensive library to post-train foundation models

License Documentation GitHub release Hugging Face Hub

🎉 What's New

🌍 Multi-environment agentic RL: GRPOTrainer now supports per-example environment selection and environment-owned rewards — mix multiple sandboxed task suites in one run and let each environment define its own scoring, with Harbor and OpenEnv.

🎯 KTO is now stable: KTOTrainer graduates to the stable API after a full alignment pass with DPOTrainer.

Overview

TRL is a cutting-edge library designed for post-training foundation models using advanced techniques like Supervised Fine-Tuning (SFT), Group Relative Policy Optimization (GRPO), and Direct Preference Optimization (DPO). Built on top of the 🤗 Transformers ecosystem, TRL supports a variety of model architectures and modalities, and can be scaled-up across various hardware setups.

Highlights

  • Trainers: Various fine-tuning methods are easily accessible via trainers like SFTTrainer, GRPOTrainer, DPOTrainer, KTOTrainer and more.

  • Efficient and scalable:

    • Leverages 🤗 Accelerate to scale from single GPU to multi-node clusters using methods like DDP and DeepSpeed.
    • Full integration with 🤗 PEFT enables training on large models with modest hardware via quantization and LoRA/QLoRA.
    • Integrates 🦥 Unsloth for accelerating training using optimized kernels.
  • Command Line Interface (CLI): A simple interface lets you fine-tune with models without needing to write code.

Installation

Python Package

Install the library using pip:

pip install trl

From source

If you want to use the latest features before an official release, you can install TRL from source:

pip install git+https://github.com/huggingface/trl.git

Repository

If you want to use the examples you can clone the repository with the following command:

git clone https://github.com/huggingface/trl.git

Quick Start

For more flexibility and control over training, TRL provides dedicated trainer classes to post-train language models or PEFT adapters on a custom dataset. Each trainer in TRL

Continue your stack

What teams reach for next — and why each earns a place beside trl. Ranked by curator confidence.