# Trl

> Trl is an Agent Skill for agent building published in the mkurman/zorai repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.

Transformer Reinforcement Learning library (TRL). Supervised fine-tuning (SFT), reward modeling, PPO, DPO, KTO, GRPO for RLHF. Process reward models and language model alignment.

- Skill name: `trl`
- Category: [Agent Building](https://www.openparable.com/skill/agent-building/1)
- Source: https://github.com/mkurman/zorai/blob/HEAD/skills/scientific-skills/trl/SKILL.md
- Repository: mkurman/zorai (320 GitHub stars when collected)

## SKILL.md

## Overview

TRL (Transformer Reinforcement Learning) is Hugging Face's library for RLHF — SFT, reward modeling, PPO, DPO, KTO, and GRPO. It's the standard post-training toolkit for aligning language models with human preferences.

## Installation

```bash
uv pip install trl
```

## SFT

```python
from trl import SFTTrainer
from transformers import AutoModelForCausalLM, AutoTokenizer

model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-1.5B-Instruct")
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-1.5B-Instruct")

trainer = SFTTrainer(
    model=model, tokenizer=tokenizer,
    train_dataset=dataset,
    args=dict(per_device_train_batch_size=4, learning_rate=2e-5, max_seq_length=2048),
)
trainer.train()
```

## DPO

```python
from trl import DPOTrainer

dpo = DPOTrainer(
    model=model, ref_model=ref_model, tokenizer=tokenizer,
    train_dataset=preference_dataset,
    args=dict(per_device_train_batch_size=4, max_length=2048),
)
dpo.train()
```

## References
- [TRL docs](https://huggingface.co/docs/trl)
- [TRL GitHub](https://github.com/huggingface/trl)

---

Source: https://www.openparable.com/skill/agent-building/trl (OpenParable). Cite the canonical URL above.
