trl
Reference for the TRL (Transformer Reinforcement Learning) library codebase.
Skill by benchflow-ai
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/benchflow-ai-trl
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Use cases: data, writing
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions
What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.
- Tools
- No tools found
- Secrets
- None asked for
- Install scripts
- None found
Network hosts it talks to 1
codeload.github.com· found in install command
Files it touches
~/.claude/skills/trl
What's inside
- Skill name
trl- Description
- Reference for the TRL (Transformer Reinforcement Learning) library codebase. Use proactively before reading or editing any file under `trl/` so you have the intended contracts and invariants in mind, not just what the current code says. Covers trainer hierarchy (SFT, DPO, GRPO, KTO), shared utility functions (selective_log_softmax, decode_and_strip_padding, padding helpers), configuration system, model wrappers, and how data flows through any TRL trainer.
- License
- Apache-2.0
- Instructions
- 81 lines in SKILL.md · view on GitHub
Files (2)
- SKILL.md
- trl-codebase.md · references/
SKILL.md (first lines)
# TRL Library Reference ## Package Structure TRL is organized around a trainer hierarchy that extends Hugging Face `transformers.Trainer`. ``` trl/ ├── trainer/ │ ├── grpo_trainer.py # GRPOTrainer │ ├── grpo_config.py # GRPOConfig │ ├── sft_trainer.py # SFTTrainer (supervised fine-tuning) │ ├── dpo_trainer.py # DPOTrainer (direct preference optimization) │ ├── kto_trainer.py # KTOTrainer (Kahneman-Tversky optimization) │ ├── online_dpo_trainer.py # OnlineDPOTrainer │ ├── utils.py # Shared utilities (log probs, decoding, padding) │ └── ... ├── models/ │ └── modeling_value_head.py # Value head for PPO-style trainers ├── data_utils.py ├── commands/ # CLI entry points └── ... ``` ## Trainer Hierarchy All TRL trainers extend `transformers.Trainer`: ``` transformers.Trainer ├── SFTTrainer # Supervised fine-tuning ├── DPOTrainer # Direct preference optimization ├── GRPOTrainer # Group relative policy optimization ├── KTOTrainer # Kahneman-Tversky optimization └── OnlineDPOTrainer # Online DPO ``` Each trainer overrides `compute_loss` with its specific objective, and RL-based trainers (GRPO, OnlineDPO) additionally override `training_step` to add a generation phase before the optimization step. ## Shared Utility Functions (trainer/utils.py) These utilities are used across multiple trainers. Read the source before modifying; the contracts below are what callers rely on. ### `selective_log_softmax(logits, index)` Memory-efficient per-token log-probability. Equivalent in value to `F.log_softmax(logits, dim=-1).gather(...)` at the selected token positions, but avoids materializing the full vocab-sized tensor. **Contract:** - Input: `logits [B, T, V]`, `index [B, T]` - Output: `log_probs [B, T]`, each entry a valid log-probability (i.e. non-positive) - Must agree with `F.log_softmax` to within numerical tolerance on the same inputs ### `decode_and_strip_padding(input_ids, tokenizer)` Converts a batch of token ID tensors into the cleaned text strings that the reward function will score. **Contract:** - Input: `input_ids [B, T]`, tokenizer - Output: `list[str]` of length `B` - Strips padding and decoder artefacts - Handles any reasoning-block conventions the library supports; the exact policy for complete, incomplete, and absent reasoning markers is defined in the implementation ### Other Utilities - `pad` / `pad_to_length` — Pad tensors to equal or specific lengths - Various tokenizer helpers for batch processing ## Configuration System All TRL configs extend `transformers.TrainingArguments`. Each trainer adds its own fields: | Config | Trainer | Key fields | |--------|---------|------------| | `SFTConfig` | SFTTrainer | `max_seq_length`, `packing`, `dataset_text_field` | | `DPOConfig` | DPOTrainer | `beta`, `loss_type`, `reference_free` | | `GRPOConfig` | GRPOTrainer | `num_generations`, `beta`, `epsilon`, `reward_functions` | | `KTOConfig` | KTOTrainer | `beta`, `desirable_weight`, `undesirable_weight` | ## Available References | File | Contents | When to load | |------|----------|-------------| | `references/trl-codebase.md` | Module-by-module guide to TRL source: detailed breakdown of each trainer, model wrappers, data utilities, and CLI commands | When navigating unfamiliar parts of TRL beyond the trainer layer, or when you need details about a specific non-GRPO trainer |
From benchflow-ai/skillsbench, Apache-2.0.
More from benchflow-ai/skillsbench
- 0.552score
hex-grid-spatial
benchflow-ai
Hex grid spatial utilities for offset coordinate systems.
SkillCFreshness: C★ 1.9KClaude Code +9 - 0.552score
grpo
benchflow-ai
Reference for the GRPO (Group Relative Policy Optimization) algorithm.
SkillCFreshness: C★ 1.9KClaude Code +9 - 0.552score
mesh-analysis
benchflow-ai
Analyzes 3D mesh files (STL) to calculate geometric properties (volume, components) and extract attribute data.
SkillCFreshness: C★ 1.9KClaude Code +9 - 0.552score
task-review
benchflow-ai
SkillsBench task PR review — classifies the task track (standard / research / multimodal), runs static policy checks against the track-specific rubric…
SkillCFreshness: C★ 1.9KClaude Code +9 - 0.552score
civ6lib
benchflow-ai
Civilization 6 district mechanics library.
SkillCFreshness: C★ 1.9KClaude Code +9 - 0.552score
d3-visualization
benchflow-ai
Build deterministic, verifiable data visualizations with D3.js (v6).
SkillCFreshness: C★ 1.9KClaude Code +9 - 0.552score
modal-gpu
benchflow-ai
Run Python code on cloud GPUs using Modal serverless platform.
SkillCFreshness: C★ 1.9KClaude Code +9 - 0.552score
mhc-algorithm
benchflow-ai
Implement mHC (Manifold-Constrained Hyper-Connections) for stabilizing deep network training.
SkillCFreshness: C★ 1.9KClaude Code +9 - 0.552score
transaction-concurrency-control-foundations
benchflow-ai
Provides database transaction concurrency-control background.
SkillCFreshness: C★ 1.9KClaude Code +9 - 0.552score
search-accommodations
benchflow-ai
Lookup accommodations by city from the bundled dataset.
SkillCFreshness: C★ 1.9KClaude Code +9 - 0.552score
search-attractions
benchflow-ai
Retrieve attractions by city from the bundled dataset.
SkillCFreshness: C★ 1.9KClaude Code +9 - 0.552score
rl-post-training
benchflow-ai
Diagnostic guide for RL-based post-training of language models (GRPO, PPO, REINFORCE, DPO).
SkillCFreshness: C★ 1.9KClaude Code +9
Signals
- Stars
- 1,870
- Forks
- 372
- Open issues
- 50
- Last commit (this folder)
- May 4, 2026 (5 months ago)
- Last release
- Jun 14, 2026 (4 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- Apache-2.0
- Repository
- github.com/benchflow-ai/skillsbench
- Website
- www.skillsbench.ai
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
More from benchflow-ai
- 0.552score
modal-gpu
benchflow-ai
Run Python code on cloud GPUs using Modal serverless platform.
SkillCFreshness: C★ 1.9KClaude Code +9 - 0.552score
task-review
benchflow-ai
SkillsBench task PR review — classifies the task track (standard / research / multimodal), runs static policy checks against the track-specific rubric…
SkillCFreshness: C★ 1.9KClaude Code +9 - 0.552score
transaction-concurrency-control-foundations
benchflow-ai
Provides database transaction concurrency-control background.
SkillCFreshness: C★ 1.9KClaude Code +9 - 0.552score
search-attractions
benchflow-ai
Retrieve attractions by city from the bundled dataset.
SkillCFreshness: C★ 1.9KClaude Code +9 - 0.552score
search-accommodations
benchflow-ai
Lookup accommodations by city from the bundled dataset.
SkillCFreshness: C★ 1.9KClaude Code +9 - 0.552score
mhc-algorithm
benchflow-ai
Implement mHC (Manifold-Constrained Hyper-Connections) for stabilizing deep network training.
SkillCFreshness: C★ 1.9KClaude Code +9
Cite this page
trl skill. Agent Mart. https://agentmart.dev/skills/benchflow-ai-trl (last updated 2026-10-24)