trl
AGENTS.md19k starsChanged 3 months agoApache-2.0View on GitHub
The repository is separated into main code and experimental code. Small non-invasive improvements that make experimental code more consistent with the main codebase are encouraged, but avoid large refactors. If a PR implements a method, algorithm, or training approach from a research paper, it must also add a corresponding subsection to paper_index.md. When reviewing such PRs, ensure that paper_index.md was updated. Trainers in this repository are self-contained by design. Shared logic (generation, reward computation, metric logging, weight syncing, etc.) is…
Trending
Quiet since September.about the whole repository
Who's talking about huggingface/trl
- sgl-project/sglang“Development Roadmap (2024 Q4)”GitHub · Sep 21, 2024 · 39 reactions
- unslothai/unsloth“[Feature Request] 10x faster training: Decontaminated Sample Packing”GitHub · Jan 25, 2024 · 18 reactions
- unslothai/unsloth“Support trl vllm-serve for multi-gpu vLLM inference”GitHub · Mar 24, 2025 · 7 reactions
- unslothai/unsloth“[Bug] Warning about `attn_implementation` when using `trl` with `unsloth` despite `flash_attention_2` …”GitHub · Jun 30, 2025 · 6 reactions
- vllm-project/vllm-ascend“vLLM Ascend Roadmap Q2 2025”GitHub · Mar 31, 2025 · 6 reactions
The biggest 5 of 35 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 35
Talked about on GitHub and Bluesky (35 times).
On GitHub · 33
- Sep 21, 2024Development Roadmap (2024 Q4) — sgl-project/sglang39 reactions · 27 comments
- Jan 25, 2024[Feature Request] 10x faster training: Decontaminated Sample Packing — unslothai/unslothsays it tested it18 reactions · 12 comments
- Mar 24, 2025Support trl vllm-serve for multi-gpu vLLM inference — unslothai/unsloth7 reactions · 3 comments
- Jun 30, 2025[Bug] Warning about `attn_implementation` when using `trl` with `unsloth` despite `flash_attention_2` configuration — unslothai/unsloth6 reactions · 1 comment
- Mar 31, 2025vLLM Ascend Roadmap Q2 2025 — vllm-project/vllm-ascend6 reactions · 7 comments
28 more on GitHub
- Mar 8, 2025Problem with accelerate == 1.4.0 and deepspeed ==0.16.4 when training NLP models — huggingface/accelerate5 reactions · 2 comments
- Feb 13, 2025Simplified installation requirements to support more accelerators — huggingface/open-r14 reactions · 3 comments
- Feb 3, 2025Integrate Verl with 🤗 hub — verl-project/verl4 reactions · 3 comments
- Sep 26, 2024PEP 541 Request: tri on test.pypi.org — pypi/support4 reactions · 2 comments
- Feb 22, 2024Bug in latest version of `trainer.py` leads to training not starting for making Reward Model — huggingface/transformers4 reactions · 21 comments
- Dec 27, 2023FEAT: add tagging support to axolotl — axolotl-ai-cloud/axolotl4 reactions · 5 comments
- Sep 3, 2026[httpx] Let's migrate to httpx2! — huggingface/huggingface_hub3 reactions · 7 comments
- Feb 12, 2025建议GRPOTrainer更新为trl最新代码,解决7B模型训练OOM问题 — StarsfieldAI/R1-V3 reactions · 20 comments
- Dec 13, 2024Add KTO Loss — linkedin/Liger-Kernel3 reactions · 2 comments
- Jul 17, 2024[1차 코드 완료] 내용 요약 — lion-oh/joks-llmarchi-kli3 reactions · 2 comments
- May 19, 2024RLHF with PPO — meta-pytorch/torchtune3 reactions · 12 comments
- Apr 17, 2026[book][minor] adding HF TRL to compatible frameworks for TIS — natolambert/rlhf-book2 reactions
- Sep 11, 2025Fix TrainingArguments.parallelism_config NameError with accelerate<1.10.1 — huggingface/transformers2 reactions · 2 comments
- Jul 29, 2025Adding support for apo losses, sppo_hard and nca_pair — linkedin/Liger-Kernel2 reactions
- Apr 10, 2025Tracking related fixes in other open-source projects — sail-sg/understand-r1-zero2 reactions · 1 comment
- Feb 7, 2025Use new GRPO logic — huggingface/open-r12 reactions · 1 comment
- Oct 11, 2024Models With Tied Weights Need Re-Tieing After FSDP Param Init — huggingface/accelerate2 reactions · 5 comments
- Mar 21, 2024[Research Projects] ORPO diffusion for alignment — huggingface/diffusers2 reactions · 3 comments
- Jan 8, 2024feat: enable trl's autounwrap — axolotl-ai-cloud/axolotl2 reactions · 2 comments
- Sep 18, 2023feats: Add text enviroment examples — CarperAI/trlx2 reactions
- Sep 14, 2026deps(deps): bump the workspace-dependencies group with 4 updates — JetBrains-Research/opake1 reaction
- Sep 3, 2026Clarify Python package reuse with Jobs framework images — huggingface/hub-docs1 reaction · 4 comments
- Aug 31, 2026deps(deps): bump the workspace-dependencies group across 1 directory with 4 updates — JetBrains-Research/opake1 reaction · 1 comment
- Aug 3, 2026Bump the python group across 1 directory with 10 updates — unslothai/unsloth1 reaction · 5 comments
- Jul 29, 2026Bump the python group across 1 directory with 9 updates — unslothai/unsloth1 reaction · 1 comment
- Jun 23, 2026Add CGPO-style constrained reward utilities — OpenRLHF/OpenRLHF1 reaction
- Apr 11, 2026chore(deps-dev): update trl requirement from >=0.8 to >=1.0.0 — nvandessel/hippofloop1 reaction · 1 comment
- Oct 30, 2025Providing byte level offsets for effective alignment in Cross-Tokenizer On-Policy Distillation — huggingface/tokenizers1 reaction
On Bluesky · 2
- Aug 13, 2023📦 huggingface / trl ⭐ 4,879 (+42) 🗒 Python Train transformer language models with reinforcement learning. — @github-trending.bsky.social1 likes and repost
- May 31, 2025I have successfully run a DPO with trl! Did it change anything? no it did not. But it 1) finished execution without crashing 2) created a… — @shebecoding.bsky.social0 likes and reposts · 1 reply
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository4 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- update-paper-indexSkill
- trl-trainingSkill
The file
We split this AGENTS.md into the rules it gives an agent
11 rules. About 0 are common, 7 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 9
Main code: should remain stable, consistent, and well-tested.
- Very specific: line 16
If a PR implements a method, algorithm, or training approach from a research paper, it must also add a corresponding subsection to …
- Very specific: line 18
When reviewing such PRs, ensure that paper_index.md was updated.
- Distinctive: line 43
After propagating, diff the corresponding regions to confirm they stayed aligned:
- Distinctive: line 52
When reviewing: if a PR touches duplicated logic, verify that all copies are updated consistently.
- Distinctive: line 60
Do not add layers of indirection (registries, factory patterns, plugin systems).
- Distinctive: line 61
Prefer a simple implementation that covers 90% of cases over a complex one that covers 100%.
- Distinctive: line 62
Do not add defensive code, fallback paths, or configuration options "just in case".
- Distinctive: line 64
When in doubt, prefer less code.
- Very specific: line 81
When the default is None, prefer `
(str, *optional*)instead of(str or None, *optional*, defaults to None)` - Very specific: line 116
When linking to papers, use https://huggingface.co/papers/<id> instead of https://arxiv.org/abs/<id> (same ID suffix system).
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AGENTS.md
Repository-specific guidance
Main code vs experimental code
The repository is separated into main code and experimental code.
- Main code should remain stable, consistent, and well-tested.
- Experimental code may be less stable and may contain inconsistent patterns or limited testing.
Small non-invasive improvements that make experimental code more consistent with the main codebase are encouraged, but avoid large refactors.
Paper implementations
If a PR implements a method, algorithm, or training approach from a research paper, it must also add a corresponding subsection to paper_index.md.
When reviewing such PRs, ensure that paper_index.md was updated.
Code duplication and consistency
Trainers in this repository are self-contained by design. Shared logic (generation, reward computation, metric logging, weight syncing, etc.) is deliberately duplicated across trainers rather than abstracted into a shared base class.
This is intentional: each trainer must be readable, modifiable, and evolvable in isolation. The base class (_BaseTrainer) provides only minimal utilities (model card generation). Everything else — vLLM generation paths, _get_per_token_logps_and_entropies, _calculate_rewards, _prepare_inputs, metric logging — is copied in full.
The tradeoff: duplication is accepted, but consistency is mandatory. When the same logic appears in multiple trainers, the duplicated blocks must stay aligned:
- Same variable names (
self._last_loaded_step,self._metrics[mode], …) - Same control flow structure (if/elif/else branches in the same order)
- Same comments (word-for-word when the logic is identical)
- Divergences only where the trainer's semantics require it (e.g., GRPO extracts logprobs from vLLM, RLOO discards them)
Consistency over correctness: this is a strong requirement. When duplicating code, reproduce it exactly — even if you believe the original has a bug. Do not silently fix the issue in your copy. Instead, keep your copy consistent with the source and report the problem so it can be fixed across all trainers in a dedicated PR. A correct-but-inconsistent codebase is harder to maintain than a consistently-wrong one that can be fixed in a single sweep.
When modifying duplicated code: if you change a pattern that exists in multiple trainers (e.g., the vLLM generation path in _generate_single_turn), apply the same change to all other trainers. A fix in GRPO often implies the same fix in RLOO, and vice versa. Not propagating a change is a bug.
Find every copy by grepping a distinctive line of the block:
grep -rn "self._last_loaded_step" trl/trainer/ trl/experimental/After propagating, diff the corresponding regions to confirm they stayed aligned:
diff <(sed -n '/def _generate_single_turn/,/def /p' trl/trainer/grpo_trainer.py) \
<(sed -n '/def _generate_single_turn/,/def /p' trl/trainer/rloo_trainer.py)Remaining diffs must all be semantic divergences, not drift.
When reviewing: if a PR touches duplicated logic, verify that all copies are updated consistently. A common mistake is fixing one trainer and forgetting the others.
Simplicity
This codebase values leanness and simplicity above all. Prefer straightforward, inline code over abstractions, helpers, or utilities — even at the cost of some robustness or generality.
Concretely:
- Do not add layers of indirection (registries, factory patterns, plugin systems). A contributor should be able to read a trainer top to bottom and understand the full flow.
- Prefer a simple implementation that covers 90% of cases over a complex one that covers 100%. A function that handles the common path in 20 lines is better than a catch-all that handles every edge case in 80.
- Do not add defensive code, fallback paths, or configuration options "just in case". Only handle cases that actually exist today.
- Avoid
hasattrandgetattr. Their use is almost always a symptom of overly defensive programming or a disguised version check (e.g., "this attribute was added in version X"). Instead, either drop the conditional entirely or express the version check explicitly with a version comparison. There is nearly always a cleaner alternative. - When in doubt, prefer less code. Every new function, parameter, or branch is maintenance burden. The best abstraction is often no abstraction.
Tests
Tests exercise real objects: a tiny model from trl-internal-testing, a real tokenizer, config, and dataset. Do not use SimpleNamespace, MagicMock, object.__new__ (building an instance without its __init__), or monkeypatched internals as stand-ins: they only have what the test author thought of, so the test keeps passing when the real code changes. Mock only what cannot run in the test environment, like a remote server.
Documentation
Docstrings
Docstrings must follow the repository format below. Do not convert docstrings to other styles (Google, NumPy, etc.).
Rules:
- Types appear in backticks inside parentheses: (
str) - Optional parameters are marked with
*optional* - Defaults are written as:
defaults to <value> - When the default is
None, prefer(`str`, *optional*)instead of(`str` or `None`, *optional*, defaults to `None`) - Union types use
or:strorNone - References to classes use the format: [
~transformers.PreTrainedModel] - Class docstrings may group parameters using headers such as:
> Parameters for X:
Example:
def method(self, param1: str, param2: int = 1, param3: float | None = None):
"""
Brief one-line description of what this does.
Args:
param1 (`str`):
Description of required param.
param2 (`int`, *optional*, defaults to `1`):
Description of optional param with default.
param3 (`float`, *optional*):
Description of optional param without explicit default.
Returns:
`dict` with keys:
- `key1` (`list[int]`):
Description of this key.
Examples:
```python
>>> my_func("hello")
```
"""Links to papers
When linking to papers, use https://huggingface.co/papers/<id> instead of https://arxiv.org/abs/<id> (same ID suffix system).
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

