trl
Train transformer language models with reinforcement learning.
What it is and what it does
TRL is a post-training library for transformer language models that wraps the Hugging Face Transformers ecosystem with specialized trainer classes for advanced alignment techniques. It implements methods like Supervised Fine-Tuning (SFT), Direct Preference Optimization (DPO), Group Relative Policy Optimization (GRPO), Kahneman-Tversky Optimization (KTO), and knowledge distillation, each exposed as a trainer class that handles distributed training, gradient accumulation, and hardware scaling automatically.
The library is designed to work with models of any size by integrating with accelerate for multi-GPU and multi-node setups, and with PEFT for parameter-efficient training on large models via quantization and LoRA. It supports a command-line interface for quick experimentation without writing code, and provides an experimental API for unstable features. All trainers are thin wrappers around the Transformers trainer, meaning they inherit its distributed training support (DDP, DeepSpeed ZeRO, FSDP) and ecosystem compatibility.
Use it for:
- Fine-tune a base language model on domain-specific instruction data using SFTTrainer to create a specialized assistant.
- Align a model with human preferences by training on paired preference data using DPOTrainer or GRPOTrainer.
- Train a reward model to score model outputs for use in reinforcement learning pipelines with RewardTrainer.
- Distill a large teacher model into a smaller student model using DistillationTrainer with memory-efficient chunked loss.
- Quickly prototype alignment techniques via the CLI without writing Python code for SFT, DPO, or KTO workflows.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
TRL provides trainer classes for post-training foundation models using techniques like supervised fine-tuning, direct preference optimization, and group relative policy optimization, built on transformers and accelerate.
Yes. TRL is actively maintained (release 1 day old), has no known vulnerabilities, low install friction, and a permissive license. It is the standard library for post-training transformer models in the Hugging Face ecosystem. Install it if you need to fine-tune, align, or distill language models with modern techniques; skip it only if you are working exclusively with inference or base model training.
Install
trl on PyPI
pip
pip install trluv
uv add trlpoetry
poetry add trlInstalling trl
Before you install
Low friction install with a pure Python wheel. Actively maintained with a release 1 day old and 19071 repository stars. Requires Python 3.10 or later and five runtime dependencies (accelerate, datasets, jinja2, packaging, transformers).
License in practice
Apache-2.0 permissive license allows commercial and private use with minimal restrictions; source code changes must be documented but derivative works are permitted.
Quickstart
pip install trl
from trl import SFTTrainer
from datasets import load_dataset
dataset = load_dataset("trl-lib/Capybara", split="train")
trainer = SFTTrainer(
model="Qwen/Qwen2.5-0.5B",
train_dataset=dataset,
)
trainer.train()
Requires Python 3.10 or later; GPU or accelerator hardware strongly recommended for practical training.
Verify before relying
- Whether DistillationTrainer's vLLM integration requires vLLM as an optional dependency or if it is bundled.
- Memory requirements and typical training time for the example models mentioned.
- Whether PEFT and Unsloth integrations are optional or required for certain trainers.
Package facts
| License | Apache-2.0 (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 5 — accelerate, datasets, jinja2, packaging, transformers |
| Maintenance | actively maintained — 1 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 3,711,636/month — #2,521 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: trl-1.10.0-py3-none-any.whl
Keywords: transformers, huggingface, language modeling, post-training, rlhf, sft, dpo, grpo
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
google-tunixTunix is a JAX-based library for post-training…
permissive · top 15,000 on PyPI
setfitSetFit fine-tunes Sentence Transformers for…
permissive · top 15,000 on PyPI
tinker_cookbookTinker Cookbook provides recipes and…
permissive · top 15,000 on PyPI
verlverl is a reinforcement learning training…
permissive · top 15,000 on PyPI
peftPEFT implements parameter-efficient fine-tuning…
permissive · top 5,000 on PyPI
transformer-smaller-training-vocabReduces transformer model vocabulary to only…
permissive · top 15,000 on PyPI
ms-swiftms-swift is a framework for training,…
permissive · top 15,000 on PyPI
verifiersVerifiers provides environments and evaluation…
permissive · top 15,000 on PyPI
coqui-tts-trainerA PyTorch model trainer framework that handles…
permissive · top 15,000 on PyPI