Skip to content

Commit e3642f6

Browse files
abidlabsclaudeqgallouedec
authored
docs: add TRL integration guide (#537)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: Quentin Gallouédec <45557362+qgallouedec@users.noreply.github.com>
1 parent 0b9d4d0 commit e3642f6

3 files changed

Lines changed: 91 additions & 2 deletions

File tree

docs/source/_toctree.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@
3636
title: How-to guides
3737
- sections:
3838
- local: transformers_integration
39-
title: Transformers Trainer
39+
title: Running with Transformers
40+
- local: trl_integration
41+
title: Running with TRL
4042
- local: rapidfireai_integration
41-
title: RapidFire AI
43+
title: Running with RapidFire AI
4244
title: Integration
4345
- sections:
4446
- local: api

docs/source/trl_integration.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# TRL Integration
2+
3+
Trackio integrates natively with [TRL](https://github.com/huggingface/trl) so you can log metrics from any TRL trainer (`SFTTrainer`, `DPOTrainer`, `GRPOTrainer`, etc.) with minimal setup. Ensure you have the latest version of `trl` installed (version 1.2.0 or higher).
4+
5+
```python
6+
from datasets import Dataset
7+
from trl import SFTConfig, SFTTrainer
8+
9+
# Create a small fake dataset
10+
prompts = ["The capital of France is", "Hamlet was written by"] * 12
11+
completions = [" Paris.", " Shakespeare."] * 12
12+
dataset = Dataset.from_dict({"prompt": prompts, "completion": completions})
13+
14+
# Train a model using the TRL SFTTrainer API
15+
trainer = SFTTrainer(
16+
model="Qwen/Qwen3-0.6B",
17+
args=SFTConfig(report_to="trackio", run_name="Qwen3-0.6B-sft"),
18+
train_dataset=dataset,
19+
)
20+
trainer.train()
21+
```
22+
23+
## Configuring Project and Space
24+
25+
Set the project and space ID directly in your TRL config (e.g. [`~trl.SFTConfig`], [`~trl.DPOConfig`], [`~trl.GRPOConfig`]):
26+
27+
```python
28+
from trl import SFTConfig
29+
30+
args = SFTConfig(
31+
report_to="trackio",
32+
run_name="my-run",
33+
project="my-project",
34+
trackio_space_id="username/space_id",
35+
)
36+
```
37+

examples/trl-integration.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# /// script
2+
# dependencies = [
3+
# "trackio>=0.23.0",
4+
# "trl>=1.2.0",
5+
# ]
6+
# ///
7+
8+
import random
9+
10+
from datasets import Dataset
11+
from trl import SFTConfig, SFTTrainer
12+
13+
suffix = random.randint(100000, 999999)
14+
project_name = f"trackio-trl-demo-{suffix}"
15+
16+
prompts = [
17+
[{"role": "user", "content": "What is the capital of France?"}],
18+
[{"role": "user", "content": "Who wrote Hamlet?"}],
19+
[{"role": "user", "content": "What is 2 + 2?"}],
20+
[{"role": "user", "content": "What color is the sky?"}],
21+
[{"role": "user", "content": "Name a primary color."}],
22+
[{"role": "user", "content": "What is the largest planet?"}],
23+
] * 4
24+
completions = [
25+
[{"role": "assistant", "content": "Paris."}],
26+
[{"role": "assistant", "content": "Shakespeare."}],
27+
[{"role": "assistant", "content": "4."}],
28+
[{"role": "assistant", "content": "Blue."}],
29+
[{"role": "assistant", "content": "Red."}],
30+
[{"role": "assistant", "content": "Jupiter."}],
31+
] * 4
32+
dataset = Dataset.from_dict({"prompt": prompts, "completion": completions})
33+
34+
trainer = SFTTrainer(
35+
model="Qwen/Qwen3-0.6B",
36+
args=SFTConfig(
37+
output_dir="./model_output",
38+
num_train_epochs=1,
39+
per_device_train_batch_size=4,
40+
learning_rate=2e-5,
41+
logging_steps=1,
42+
report_to="trackio",
43+
project=project_name,
44+
),
45+
train_dataset=dataset,
46+
)
47+
48+
trainer.train()
49+
50+
print(f"Run complete. Open with: trackio show --project {project_name}")

0 commit comments

Comments
 (0)