huggingface/trl
Train transformer language models with reinforcement learning.
https://skillcdn.ai/gh/huggingface/trlConnect this address to your AI to use these skills. How to connect
- Unverified
- Default branch
main - Commit
7d2b4d5 - License
Apache-2.0 - Searchwords
Showing commit 7d2b4d5
The newest commit, a7dd73c, is being indexed. Until it is ready, this page and every agent are served the last indexed commit.
Explore this repository
Searches the original text of skills and documents, and the translations of skills when you search in their language.
Documents
- _redirects.ymldocs/source/_redirects.yml
- _toctree.ymldocs/source/_toctree.yml
- A2POTRL supports A\-PO (Optimal Advantage Regression) as described in the paper Accelerating RL for LLM Reasoning with Optimal Advantage Regression by Kianté Brantley, Mingyu Chen, Zhaolin Gao, Jason D.…docs/source/a2po_trainer.md
- Training on AMD GPUsTRL trainers run on AMD Instinct GPUs without code changes. PyTorch's ROCm build exposes them as cuda devices, so the commands in the rest of the documentation work as they are.docs/source/amd_gpus.md
- Async Distillation[experimental.async_distillation.AsyncDistillationTrainer] is the async counterpart to [DistillationTrainer], architected like [AsyncGRPOTrainer]: a background rollout worker generates the student's…docs/source/async_distillation_trainer.md
- Asynchronous GRPO Trainer[AsyncGRPOTrainer] implements the same GRPO algorithm but decouples rollout generation from training. A background worker continuously streams completions from a vLLM server while the training loop c…docs/source/async_grpo_trainer.md
- Training on AWS TrainiumAWS Trainium runs PyTorch natively through the torch-neuronx package, which registers the neuron device. TRL trainers run on it without code changes. Neuron compiles a graph for each input shape it s…docs/source/aws_trainium.md
- BEMA for Reference ModelThis feature implements the BEMA algorithm to update the reference model during DPO training.docs/source/bema_for_reference_model.md
- Callbacks[[autodoc]] RichProgressCallbackdocs/source/callbacks.md
- Chat template utilitiesFor an overview of the chat templates bundled with TRL and the rationale behind the training patches, see Chat Templates.docs/source/chat_template_utils.md
- Chat TemplatesA chat template is a Jinja2 snippet that formats messages into the string a model was trained on. For example:docs/source/chat_templates.md
- Command Line Interfaces (CLIs)TRL provides a powerful command-line interface (CLI) to fine-tune large language models (LLMs) using methods like Supervised Fine-Tuning (SFT), Direct Preference Optimization (DPO), and more. The CLI…docs/source/clis.md
- Community TutorialsCommunity tutorials are made by active members of the Hugging Face community who want to share their knowledge and expertise with others. They are a great way to learn about the library and its featu…docs/source/community_tutorials.md
- CPO TrainerContrastive Preference Optimization (CPO) as introduced in the paper Contrastive Preference Optimization: Pushing the Boundaries of LLM Performance in Machine Translation by Haoran Xu, Amr Sharaf, Yu…docs/source/cpo_trainer.md
- Training customizationTRL is designed with modularity in mind so that users are able to efficiently customize the training loop for their needs. Below are examples on how you can apply and test different techniques.docs/source/customization.md
- Data Utilities[[autodoc]] is_conversationaldocs/source/data_utils.md
- Dataset formats and typesThis guide provides an overview of the dataset formats and types supported by each trainer in TRL.docs/source/dataset_formats.md
- DeepSpeed IntegrationTRL supports training with DeepSpeed, a library that implements advanced training optimization techniques. These include optimizer state partitioning, offloading, gradient partitioning, and more.docs/source/deepspeed_integration.md
- Distillation TrainerThe Distillation Trainer implements on-policy knowledge distillation as described in On-Policy Distillation of Language Models: Learning from Self-Generated Mistakes by Rishabh Agarwal, Nino Vieillar…docs/source/distillation_trainer.md
- Distributing TrainingThe trainers in TRL are launched with torchrun, PyTorch's distributed launcher. It starts one process per GPU:docs/source/distributing_training.md
- DPO TrainerTRL supports the Direct Preference Optimization (DPO) Trainer for training language models, as described in the paper Direct Preference Optimization: Your Language Model is Secretly a Reward Model by…docs/source/dpo_trainer.md
- ExamplesThe examples/ directory contains a collection of self-contained examples that demonstrate how to use the TRL library for various applications. Each example lives in its own folder named after the met…docs/source/example_overview.md
- ExperimentalThis directory contains a minimal, clearly separated space for fast iteration on new ideas.docs/source/experimental_overview.md
- Generalized Knowledge Distillation TrainerGeneralized Knowledge Distillation (GKD) was proposed in On-Policy Distillation of Language Models: Learning from Self-Generated Mistakes by Rishabh Agarwal, Nino Vieillard, Yongchao Zhou, Piotr Stan…docs/source/gkd_trainer.md
- GMPOIn the paper Geometric-Mean Policy Optimization, the authors propose a GRPO variant that maximizes the geometric mean of the token-level importance ratios instead of the arithmetic mean. Because the…docs/source/gmpo.md
- General Online Logit Distillation (GOLD) TrainerGeneral Online Logit Distillation (GOLD) is an extension of Universal Logit Distillation (ULD) that supports student/teacher pairs with different tokenizers. It aligns the textual spans produced by b…docs/source/gold_trainer.md
- GRPO TrainerTRL supports the GRPO Trainer for training language models, as described in the paper DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models by Zhihong Shao, Peiyi Wang, Q…docs/source/grpo_trainer.md
- TRL - Transformers Reinforcement LearningTRL is a full stack library where we provide a set of tools to train transformer language models with methods like Supervised Fine-Tuning (SFT), Group Relative Policy Optimization (GRPO), Direct Pref…docs/source/index.md
- InstallationYou can install TRL either from PyPI or from source:docs/source/installation.md
- IW-OPDIn the paper On the Position Bias of On-Policy Distillation, the authors introduce Importance-Weighted On-Policy Distillation (IW-OPD). IW-OPD addresses position bias in on-policy distillation by rew…docs/source/iw_opd_trainer.md
- Training with JobsHugging Face Jobs runs your training on Hugging Face GPUs. You pick the hardware for each run and pay only for the seconds it runs. With --push_to_hub, the trained model is uploaded to the Hub at the…docs/source/jobs_training.md
- Kernels Hub Integration and UsageThe kernels library allows optimized compute kernels to be loaded directly from the Hub. You can find kernels in dedicated orgs or by searching for the kernel tag within the Hub.docs/source/kernels_hub.md
- KTO TrainerTRL supports the Kahneman-Tversky Optimization (KTO) Trainer for training language models, as described in the paper KTO: Model Alignment as Prospect Theoretic Optimization by Kawin Ethayarajh, Winni…docs/source/kto_trainer.md
- Training Beyond 1M TokensAn agent is capable of working on a task for hours: reading files, running commands, and carrying every turn of the session forward. That accumulated session runs to hundreds of thousands of tokens,…docs/source/long_context_training.md
- LoRA Without RegretRecent research from the team at Thinking Machines Lab (Schulman et al., 2025) shows that LoRA can match full fine-tuning performance when configured correctly, while using only ~67% of the compute.…docs/source/lora_without_regret.md
- MergeModelCallback[[autodoc]] experimental.merge_model_callback.MergeModelCallbackdocs/source/merge_model_callback.md
- Online DPO TrainerOnline DPO was proposed in Direct Language Model Alignment from Online AI Feedback by Shangmin Guo, Biao Zhang, Tianlin Liu, Tianqi Liu, Misha Khalman, Felipe Llinares, Alexandre Rame, Thomas Mesnard…docs/source/online_dpo_trainer.md
- OpenEnv Integration for Training LLMs with EnvironmentsOpenEnv is an open-source framework for defining, deploying, and interacting with environments in reinforcement learning (RL) and agentic workflows. It provides standardized APIs for environment inte…docs/source/openenv.md
- OpenReward Integration for Training LLMs with EnvironmentsOpenReward is an open ecosystem for RL environments built on the Open Reward Standard (ORS) — a public, language-agnostic HTTP/SSE protocol for how an environment exposes its tasks, tools, sessions,…docs/source/openreward.md
- ORPO TrainerOdds Ratio Preference Optimization (ORPO) was introduced in ORPO: Monolithic Preference Optimization without Reference Model by Jiwoo Hong, Noah Lee, and James Thorne.docs/source/orpo_trainer.md
- Paper IndexPapers relating to the [GRPOTrainer].docs/source/paper_index.md
- PEFT IntegrationTRL supports PEFT (Parameter-Efficient Fine-Tuning) methods for memory-efficient model training. PEFT enables fine-tuning large language models by training only a small number of additional parameter…docs/source/peft_integration.md
- QuickstartTRL is a comprehensive library for post-training foundation models using techniques like Supervised Fine-Tuning (SFT), Group Relative Policy Optimization (GRPO), Direct Preference Optimization (DPO).docs/source/quickstart.md
- RapidFire AI IntegrationRapidFire AI is an open-source experiment execution framework that integrates with TRL to turn "train one configuration at a time" into real-time, side-by-side comparison of many configurations on th…docs/source/rapidfire_integration.md
- Reducing Memory UsageTraining workflows can often be optimized to reduce memory consumption, and TRL provides several built-in features to help achieve this.docs/source/reducing_memory_usage.md
- Reward ModelingTRL supports the Outcome-supervised Reward Modeling (ORM) Trainer for training reward models.docs/source/reward_trainer.md
- Reward FunctionsThis module contains some useful reward functions, primarily intended for use with the [GRPOTrainer] and [RLOOTrainer].docs/source/rewards.md
- RLOO TrainerTRL supports the RLOO Trainer for training language models, as described in the paper Back to Basics: Revisiting REINFORCE Style Optimization for Learning from Human Feedback in LLMs by Arash Ahmadia…docs/source/rloo_trainer.md
- Scripts Utilities[[autodoc]] ScriptArgumentsdocs/source/script_utils.md
- SDFTSelf-Distilled Fine-Tuning (SDFT) is described in the paper Self-Distillation Enables Continual Learning by Idan Shenfeld, Mehul Damani, Jonas Hübotter, and Pulkit Agrawal.docs/source/sdft_trainer.md
Skipped (28)
These manifests were not served. Fix them and push: the next commit is indexed again.
docs/source/async_grpo_trainer.mdlink_missing11 links name no file of the repository (grpo_trainer, dataset_formats#conversational, grpo_trainer#option-1-colocate-mode, ...)docs/source/chat_template_utils.mdlink_missinga link names no file of the repository (chat_templates)docs/source/chat_templates.mdlink_missinga link names no file of the repository (chat_template_utils)docs/source/clis.mdlink_missinga link names no file of the repository (vllm_integration)docs/source/cpo_trainer.mdlink_missing3 links name no file of the repository (dataset_formats#preference, dataset_formats#conversational, dataset_formats#standard)docs/source/distillation_trainer.mdlink_missing12 links name no file of the repository (async_distillation_trainer, reducing_memory_usage, dataset_formats#prompt-only, ...)docs/source/distributing_training.mdlink_missing2 links name no file of the repository (deepspeed_integration, long_context_training)docs/source/dpo_trainer.mdlink_missing8 links name no file of the repository (dataset_formats#preference, dataset_formats#standard, dataset_formats#conversational, ...)docs/source/example_overview.mdlink_missing3 links name no file of the repository (clis, openenv, openreward)docs/source/experimental_overview.mdlink_missinga link names no file of the repository (paper_index)docs/source/gold_trainer.mdlink_missing3 links name no file of the repository (dataset_formats#conversational, dataset_formats#language-modeling, dataset_formats#vision-datasets)docs/source/grpo_trainer.mdlink_missing14 links name no file of the repository (paper_index#masked-importance-sampling, paper_index#sequence-level-importance-sampling, reducing_memory_usage#vllm-sleep-mode, ...)docs/source/index.mdlink_missing20 links name no file of the repository (async_grpo_trainer, grpo_trainer, rloo_trainer, ...)docs/source/jobs_training.mdlink_missing4 links name no file of the repository (trackio_integration, example_overview#index, clis, ...)docs/source/kto_trainer.mdlink_missing6 links name no file of the repository (dataset_formats#unpaired-preference, dataset_formats#standard, dataset_formats#conversational, ...)docs/source/online_dpo_trainer.mdlink_missing4 links name no file of the repository (dataset_formats#prompt-only, dataset_formats#preference, dataset_formats#conversational, ...)docs/source/openenv.mdlink_missing4 links name no file of the repository (openreward, grpo_trainer#agent-training, grpo_trainer#using-a-custom-reward-function, ...)docs/source/openreward.mdlink_missinga link names no file of the repository (openenv)docs/source/orpo_trainer.mdlink_missing3 links name no file of the repository (dataset_formats#preference, dataset_formats#conversational, dataset_formats#standard)docs/source/paper_index.mdlink_missing9 links name no file of the repository (gmpo, grpo_trainer#loss-types, a2po_trainer, ...)docs/source/peft_integration.mdlink_missinga link names no file of the repository (lora_without_regret)docs/source/quickstart.mdlink_missing7 links name no file of the repository (sft_trainer, dpo_trainer, grpo_trainer, ...)docs/source/reducing_memory_usage.mdlink_missinga link names no file of the repository (peft_integration)docs/source/reward_trainer.mdlink_missing4 links name no file of the repository (dataset_formats#preference, dataset_formats#standard, dataset_formats#conversational, ...)docs/source/rloo_trainer.mdlink_missing6 links name no file of the repository (grpo_trainer, reducing_memory_usage#vllm-sleep-mode, speeding_up_training#vllm-for-fast-generation-in-online-methods, ...)docs/source/sft_trainer.mdlink_missing12 links name no file of the repository (dataset_formats#language-modeling, dataset_formats#prompt-completion, dataset_formats#standard, ...)docs/source/speeding_up_training.mdlink_missing3 links name no file of the repository (index#online-methods, vllm_integration, kernels_hub)docs/source/vllm_integration.mdlink_missinga link names no file of the repository (reducing_memory_usage#vllm-sleep-mode)