[RFC] Moving Most TRL Trainers to the experimental Submodule to Streamline the Core
Context
TRL currently includes 15 trainers, which vary significantly in usage and maintenance requirements.
Key points:
- Maintaining all trainers in their current state imposes a high maintenance cost and reduces our ability to quickly respond to user feature requests.
- As we prepare the library for V1, we need to clearly define which trainers are considered stable versus experimental, with the latter receiving less/no attention from maintainers.
- Some trainers have required bug fixes and refactoring for a while but have received limited attention due to low usage. Currently, these trainers remain in the codebase but are largely ignored in practice. While this works for rapid alpha development, it is not sustainable for a stable V1 release.
Proposal
We suggest a radical approach: remove most of the trainers from the main codebase.
~Some may still live in trl.experimental module based on feedback from the community.~
EDIT: We will first move most trainers in trl.experimental, and discuss later which one should be promoted, which one should stay in experimental, and which one should be removed.
Goal
- Reduce maintenance overhead
- Allow maintainers to focus on the stable core of the library and new features
- Provide a clearer distinction between stable and experimental trainers
- Simplify the codebase
Questions / Discussion
- Which trainers do you think should remain in the stable codebase?
- Any other suggestions or concerns regarding this plan?
Current plan (edited based on feedback)
| Trainer | Plan for v1 | Ready for v1? | Plan for after v1 (to be discussed later) |
|---|---|---|---|
| BCO | π§ͺ Moving to trl.experimental |
N/A | May be removed |
| CPO | π§ͺ Moving to trl.experimental |
N/A | May be removed |
| DPO | β
Stay in trl |
β Requires refactoring | |
| Online DPO | π§ͺ Moving to trl.experimental |
N/A | May be removed |
| GKD | π§ͺ Moving to trl.experimental |
N/A | May be removed |
| GRPO | β
Stay in trl |
β Yes | |
| KTO | π§ͺ Moving to trl.experimental |
N/A | The reference to KTO will stay in trl; Priority for having it stable after v1 |
| Nash-MD | π§ͺ Moving to trl.experimental |
N/A | May be removed |
| ORPO | π§ͺ Moving to trl.experimental |
N/A | May stay in trl.experimental |
| PPO | π§ͺ Moving to trl.experimental |
N/A | May stay in trl.experimental because it's an important baseline but requires heavy refactor |
| PRM | π§ͺ Moving to trl.experimental |
N/A | May be removed |
| Reward | β Yes | β Yes | |
| RLOO | β Yes | β Yes | |
| SFT | β Ready for v1 | β Yes | |
| XPO | π§ͺ Moving to trl.experimental |
N/A | May be removed |
Another data point, issues per trainer
I would keep at least one method that supports unpaired and imbalanced feedback, which is much more common in IRL problems than paired and balanced feedback. To that end, I would recommend keeping KTO, whose usage (as measured by citations) is still growing 2x YoY.
I'm in agreement with @kawine I'd keep ORPO since it allows for alignment without having a frozen reference model. I'd keep KTO since it supports aligning models without needing a preference dataset. I'd keep PPO too since it is often used as a baseline in a number of papers.
Thanks for the feedback. I agree that all of these trainers have their place and should not be removed entirely. However, given their current usage, I donβt think they justify being considered "first-class citizens" in the library. But the major factor IMO is maintainability. Here is the current status of these trainers:
| Trainer | Ease of Maintenance | Comments |
|---|---|---|
| RLOO | Easy | Thanks to recent refactoring; closely aligned with GRPO |
| ORPO | Hard | Needs refactoring to be closer to SFT |
| KTO | Hard | Needs refactoring to be closer to SFT |
| PPO | Very Hard | Needs refactoring to be closer to RLOO and GRPO |
Thus, it could make sense to move these trainers to trl.experimental. ORPO, KTO, and PPO will have to be refactored to be more aligned with the stable trainers; otherwise, they have a high risk of becoming obsolete.
I can't speak for the other losses, but KTO could be implemented as an option within DPOTrainer. The user would just have to format the dataset such that for every input, there is one non-empty string and one empty string completion among "chosen" and "rejected", but this is a fairly easy change to make on the user's end and to enforce.
IMO just supporting DPO for offline alignment is over-indexing on academic users, who are happy to work with clean paired preference data for their experiments, because that satisfies reviewers. Companies aligning a model for some practical purpose (e.g., are customers responding to my messaging campaign?) are often working with data that is noisy, heavily imbalanced, and unpaired. Even if these aren't always the type to open a Github issue when something's wrong, they still use TRL for a reference implementation of KTO for example (speaking from my experience interacting with them).
Part of why TRL is great is that both academics working with one of a handful of datasets and companies / startups working with rough real-world data can use it. I understand the need to streamline the repo, but treating paired preferences as a first-class citizen while demoting unpaired/imbalanced data disadvantages the latter group.
Is CPO hard to maintain alongside DPO?
Especially for translation (as proposed in the original paper) CPO offers a lot of value to improve models, as you can take okay-ish outputs from a model and then post-edit them and use this directly as feedback for the model. As this is how professional linguists work with model-generated translations, it offers a very nice feedback loop to improve translation models, and I'd imagine this also holds true for other usecases.
Would it be possible to at least keep in in trl.experimental?
I think by only analyzing what's open source in the Hub you have a clear bias... People only open source and do tutorials on tasks that:
- Are not an economic oportunity.
- There are some (or several) well-known and established datasets for that.
- Goes in line with the hype and thus has the possibility to reward them with likes and shares on LinkedIn --> LLMs optimized with RL for math and code everywhere, like no other task was possible with LLMs and RL.
That's why I think that you are getting the actual picture wrong; and this proposal is based on the idea that the main usage of this library is solely for open sourcing new models. That would be absurd: we are training the same model on the same dataset thousand times, just for "tutorial" purposes. And each of those "Llama3" or "Qwen3" trained on math problems etc counts as a unique model, while actually they don't provide any novelty, benefit or value to the open source community.
Some companies, like mine, aren't lucky enough to have the financial support of a partner that can afford to spend thousands on AI training and then open source them. We need to extract economic value from those investments, otherwise the business model is not sustainable. So keep in mind that this action would precisely damage the most small companies trying to do AI products that deliver real value to users (and society), which they cannot open source or disclose too much because they deserve to eat, too. And those are companies making huge economic efforts (for their size) to try to provide that value, which wouldn't be possible without open source libraries like TRL.
So please, don't look at the misguiding big picture you provided at the top message @qgallouedec ; it's clearly biased, doesn't represent all users of the library, and would go against the small businesses that cannot affort to invest on AI and then give up those assets for free.
Please keep KTO & PPO in core, since they are widely used RLHF baselines for implicit/binary feedback and reward-model training, and moving them risks breaking reproducibility and tutorials. Advanced variants can live in trl.experimental and need not be heavily maintained.
thanks @avacaondata, that's an interesting point. Without asking you to reveal any confidential details, can you share what method you use?
Thanks for the feedback. I agree that all of these trainers have their place and should not be removed entirely. However, given their current usage, I donβt think they justify being considered "first-class citizens" in the library. But the major factor IMO is maintainability. Here is the current status of these trainers:
Trainer Ease of Maintenance Comments RLOO Easy Thanks to recent refactoring; closely aligned with GRPO ORPO Hard Needs refactoring to be closer to SFT KTO Hard Needs refactoring to be closer to SFT PPO Very Hard Needs refactoring to be closer to RLOO and GRPO Thus, it could make sense to move these trainers to
trl.experimental. ORPO, KTO, and PPO will have to be refactored to be more aligned with the stable trainers; otherwise, they have a high risk of becoming obsolete.
I agree with this table, highlighting that the implementation of RLOO is now close to that of GRPO and is easy to maintain. As @northern-64bit and @kawine mentioned, retaining PPO and OPRO is also very beneficial. We are here to assist in refactoring the library to simplify the maintenance process for these trainers.
I think by only analyzing what's open source in the Hub you have a clear bias... People only open source and do tutorials on tasks that:
- Are not an economic oportunity.
- There are some (or several) well-known and established datasets for that.
- Goes in line with the hype and thus has the possibility to reward them with likes and shares on LinkedIn --> LLMs optimized with RL for math and code everywhere, like no other task was possible with LLMs and RL.
That's why I think that you are getting the actual picture wrong; and this proposal is based on the idea that the main usage of this library is solely for open sourcing new models. That would be absurd: we are training the same model on the same dataset thousand times, just for "tutorial" purposes. And each of those "Llama3" or "Qwen3" trained on math problems etc counts as a unique model, while actually they don't provide any novelty, benefit or value to the open source community.
Some companies, like mine, aren't lucky enough to have the financial support of a partner that can afford to spend thousands on AI training and then open source them. We need to extract economic value from those investments, otherwise the business model is not sustainable. So keep in mind that this action would precisely damage the most small companies trying to do AI products that deliver real value to users (and society), which they cannot open source or disclose too much because they deserve to eat, too. And those are companies making huge economic efforts (for their size) to try to provide that value, which wouldn't be possible without open source libraries like TRL.
So please, don't look at the misguiding big picture you provided at the top message @qgallouedec ; it's clearly biased, doesn't represent all users of the library, and would go against the small businesses that cannot affort to invest on AI and then give up those assets for free.
I apologize for the interruption, but I would like to suggest that your company consider forking TRL and hiring a dedicated individual to implement the necessary models and losses at your own expense. If your intention is to solely benefit from the open-source ecosystem, it might prove challenging to maintain such a large project under the current conditions. I believe that forking and developing on your own repository may have more advantages than engaging the TRL maintainers to assist you in this regard. Thank you for considering this perspective.
I too think removing KTO would be a mistake and push adoption away from TRL. In my testing, anecdotes from others, and several papers it outperforms DPO. DPO, while an innovation for the time, has problems with brittleness and coherence. I understand the use of current adoption as a metric but it may be providing a flawed analysis of the situation and best path forward. KTO was released over a year later than DPO with necessities like liger kernels coming even later than that. As I see it lower adoption makes perfect sense in this context but does not speak to its performance or future usage. Personally I find KTO to be an amazing tool, possibly the best of the bunch, and would be very bummed out if it got cut from TRL.
Keep RLOO! Based on this post I think it's important to have an algorithm that is not biased (i.e. does not learn from random rewards).
Along with seconding that KTO and RLOO, in specific should be kept maintained if this is still the route chosen (anecdotally they perform much better than alternatives like DPO/PPO), I think this is more indicative than anything that TRL should be refactored.
It is indeed an untenable situation to have to maintain 20 trainer variants that are all mostly the same pairwise code (especially, ie CPO, ORPO). Is there anything stopping there being, for example, an overarching PairwiseTrainer class that handles all the loss-agnostic data handling and only requiring subclassing and maintenance of a specific loss function given the final hidden states? It would reduce most maintenance burden on the specific methods in question, here, and deduplicate some pieces of the codebase as well; a similar method could be applied to the rest of the codebase (one OnlineTrainer that handles PPO/GRPO/RLOO, for example).
I recommend full support for KTO, it outperforms offline DPO and can use unpaired data. Its one of the easiest ways for people to RL their model as the data is the easiest to obtain.
I think by only analyzing what's open source in the Hub you have a clear bias... People only open source and do tutorials on tasks that:
- Are not an economic oportunity.
- There are some (or several) well-known and established datasets for that.
- Goes in line with the hype and thus has the possibility to reward them with likes and shares on LinkedIn --> LLMs optimized with RL for math and code everywhere, like no other task was possible with LLMs and RL.
That's why I think that you are getting the actual picture wrong; and this proposal is based on the idea that the main usage of this library is solely for open sourcing new models. That would be absurd: we are training the same model on the same dataset thousand times, just for "tutorial" purposes. And each of those "Llama3" or "Qwen3" trained on math problems etc counts as a unique model, while actually they don't provide any novelty, benefit or value to the open source community.
Some companies, like mine, aren't lucky enough to have the financial support of a partner that can afford to spend thousands on AI training and then open source them. We need to extract economic value from those investments, otherwise the business model is not sustainable. So keep in mind that this action would precisely damage the most small companies trying to do AI products that deliver real value to users (and society), which they cannot open source or disclose too much because they deserve to eat, too. And those are companies making huge economic efforts (for their size) to try to provide that value, which wouldn't be possible without open source libraries like TRL.
So please, don't look at the misguiding big picture you provided at the top message @qgallouedec ; it's clearly biased, doesn't represent all users of the library, and would go against the small businesses that cannot affort to invest on AI and then give up those assets for free.
I apologize for the interruption, but I would like to suggest that your company consider forking TRL and hiring a dedicated individual to implement the necessary models and losses at your own expense. If your intention is to solely benefit from the open-source ecosystem, it might prove challenging to maintain such a large project under the current conditions. I believe that forking and developing on your own repository may have more advantages than engaging the TRL maintainers to assist you in this regard. Thank you for considering this perspective.
Thank you for your answer and for your work with trl. This is just about business models actually, HF gets lots of VC πΆ, among other things (and because you guys are awesome π€), because of all of the resources you develop for the open source community. The way to monetize is clearly first years with huge losses and then slowly introduce the obvious costs for the storage and usage of the Hub, which I'm a huge fan of by the way (and would've been happy to pay since the beginning - I'm a big follower since PyTorch-transformers). But the best way to keep all the people working around that ecosystem you've created and to keep it growing is to use part of the VC + progressively incoming income to maintain the core libraries everybody uses (from students to ultra small to ultra big companies). That's also the spirit and mission that has the whole AI community (including myself) in love.
Sadly, we have a different reality. We're developing TerapIA, a mental health app with our own models (for privacy + clinically polished), which is completely free for the moment - released 1st version a year ago. But we have no external funding. We are a group of experts in AI, Psychology and Software Development with passion to help people and fight the mental health crisis and lack of affordable resources available at least in Spain and LatAm. And we are developing something beautiful which is helping many people out there deal with suffering and emotional pain. We're normal people (no rich founders) using their savings to financially support the project.
Obviously, we would be completely unable to do such a thing without the incredible support of the open source community, and I get your point of "hire a developer yourself". I wish I could do such a thing, really. And that's why me, as probably many others (and looking at the comments it seems so) have a similar situation.
Many startups (most, actually, not-so-visible-to-all though) are really small, self-funded, and with good intentions. I know it's unfair to ask the maintainers of a library part of the HF suite to keep support for artifacts just because it's beneficial to (at least) my case. I apologize for that if I crossed (or am crossing) the line when giving my opinion.
But as I see it, and with all of my respects, this point of view (both the will to remove most trainers and the "hire a developer") is a little bit classist. It disregards all agents in the beautiful diverse economy that cannot afford to lose open source support. Some make economic profit (people typically have the dangerous addiction of eating and sleeping - if possible every day - and not all have a VC daddy to feed them). Others not. But most try to deliver something good for people.
I'd love you to consider this perspective also, which I can understand can be less common in your context and thus it's hard to get in our shoes. I'm not saying any of this to you personally, this is a general message to the (again, very lovedπ₯°π€) HF team.
Requesting you to please keep BCO for a few more months (at least till end of 2025). We are using it for experiments for a research work.
Reason being - DPO, GRPO, etc require both preferred and rejected responses for a single prompt, while BCO requires only one and a label (True/False). It's very helpful for particular finetuning data formats (unpaired preference ones) (we are operating with only a single response per prompt), so this is a crucial part of our project.
Thank you.
@qgallouedec
trl has always been good because it has broad support for a wide range of online/offline RL methods, such as KTO, ORPO, and Online DPO. I really don't want to lose them, because then there won't be many reasons to choose trl over other frameworks.
As noted above, it is indeed worth keeping KTO because of the lack of need to use preference datasets. Moving it to the unsupported trl.experimental is a bad decision.
Maybe the best way (IMO) out of the current situation would be to introduce support tiers for trainers, like in projects such as Debian or FreeBSD, instead of complete removal.
I have already commented on π, but let me shortly expand.
I agree that TRLβs trainer list has become hard to maintain, and I see the root issue being duplication. Of course there is another philosophical question whether HF should maintain all of these algorithm implementations, but let's disregard this for one moment. Most of the trainers share a lot of their structure and only differ in small algorithmic details. Instead of removing them, they could be merged by structure, while strategies and hooks allow for a clean implementation without too much code duplication.
Two Core Families
Please take what I say about Offline methods with a grain of salt, as I have no practical experience with them, so I may be wrong on the specficis there.
-
Offline / Preference-Based Trainer (
OfflinePrefTrainer)
Covers DPO, KTO, ... β all fundamentally βcontrastive preferenceβ losses.
The base could handle data flow, reference model evaluation, batching, etc.
Differences come from:- how pairs are built (paired vs unpaired, weighting, etc.)
- how the contrastive loss is defined
β Both can be implemented as strategies or plug-ins.
-
Policy-Gradient Trainer (
PGTrainer)
Covers PPO, GRPO, RLOO and could (should) include vanilla REINFORCE and variants, such as REINFORCE - baseline⦠all share rollout sampling, and the same optimization loop.
Variants differ in:- how the advantage is computed (returns, baseline-adjusted-returns, group leave-one-out, etc.)
- how the loss/objective scales or clips ratios
β Could be strategies, configurable or overridable.
This would also easily open the door to multi-turn in a configurable way, as there are many ways to define advantage and such for multi-turn, using the same algorithm (remember that GRPO specifically was engineered to work well for contextual bandits).
With this structure, algorithms become presets or configs, not separate classes.
Example (purely illustrative):
trainer = PGTrainer(
advantage_strategy="group_relative",
objective_strategy="clipped",
group_size=8,
)
That would effectively behave like GRPO. There could even be presets, such that a user can simply enter "grpo", which would automatically route to the correct strategies under the hood. On the other hand, you could change advantage_strategy to be something like value_model and you get PPO.
Closing words
Happy to discuss this direction further if you are interested in exploring this. I think it could significantly reduce maintenance overhead while keeping TRL useful for amateurs, yet hackable.
About duplication being the issue
see the root issue being duplication
In a way, but with one slight nuance: duplicated code is actually simple to maintain. The problem is more standardization.
E.g: Now RLOO and GRPO are very similar (lot of duplicated code), and every change in GRPO is easy to reproduce in RLOO.
The main issue actually is that trainers do a lot of similar things, but in a different way. Ideally we would have to refactor some trainers to maximize standardization and allow easy maintenance. The major and main question is: are these refactoring worth the effort?
About generic trainer
Having an approach based on trainers inheritance is actually not a good idea in my opinion. We tried to do it in the past with
- RLOO and PPO (OnlineTrainer); and
- GKDTrainer which inherits from SFTTrainer
- KTO being a special case of DPO
In fact, it creates far more complexity than it helps with maintenance. It actually makes maintenance more complicated (example here https://github.com/huggingface/trl/pull/2863#discussion_r1958707025). I would strongly advocate against this approach.