skillfed

trl

Train transformer language models with reinforcement learning.

trl v1.10.0 3.7M downloads/30d#2,521 on PyPI19,071
Permissive license Apache-2.0 Active released

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 trl

uv

uv add trl

poetry

poetry add trl

Installing 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

Development Status :: 2 - Pre-AlphaIntended Audience :: DevelopersIntended Audience :: Science/ResearchNatural Language :: EnglishOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14

Tags

fine-tune language models with reinforcement learningDPO trainer for preference optimizationsupervised fine-tuning transformersRLHF post-training frameworkmodel alignment with preference dataGRPO group relative policy optimizationknowledge distillation trainer
language-model-trainingreinforcement-learningmodel-alignment

More Artificial Intelligence packages

Further reading