Trackio Integration for TRL Training
Trackio is a local-first experiment tracking library that provides real-time metrics visualization via a Gradio dashboard.
β οΈ IMPORTANT: Trackio is local-first, which means:
- It runs a dashboard on the machine where training happens
- For Jobs training, sync to a Hugging Face Space to view metrics
- Without a Space, metrics are only accessible during the job (then lost)
Setting Up Trackio for Jobs
Step 1: Add trackio dependency
# /// script
# dependencies = [
# "trl>=0.12.0",
# "trackio", # Required!
# ]
# ///
Step 2: Create a Trackio Space (one-time setup)
Option A: Let Trackio auto-create (Recommended)
Pass a space_id to trackio.init() and Trackio will automatically create the Space if it doesn't exist.
Option B: Create manually
- Create Space via Hub UI at https://huggingface.co/new-space
- Select Gradio SDK
- OR use command:
huggingface-cli repo create my-trackio-dashboard --type space --space_sdk gradio
Step 3: Initialize Trackio with space_id
import trackio
trackio.init(
project="my-training",
space_id="username/my-trackio-dashboard", # CRITICAL for Jobs!
config={
"model": "Qwen/Qwen2.5-0.5B",
"dataset": "trl-lib/Capybara",
"learning_rate": 2e-5,
}
)
Step 4: Configure TRL to use Trackio
SFTConfig(
report_to="trackio",
# ... other config
)
Step 5: Finish tracking
trainer.train()
trackio.finish() # Ensures final metrics are synced
What Trackio Tracks
Trackio automatically logs:
- β Training loss
- β Learning rate
- β GPU utilization
- β Memory usage
- β Training throughput
- β Custom metrics
How It Works with Jobs
- Training runs β Metrics logged to local SQLite DB
- Every 5 minutes β Trackio syncs DB to HF Dataset (Parquet)
- Space dashboard β Reads from Dataset, displays metrics in real-time
- Job completes β Final sync ensures all metrics persisted
Viewing the Dashboard
After starting training:
- Navigate to the Space:
https://huggingface.co/spaces/username/my-trackio-dashboard - The Gradio dashboard shows all tracked experiments
- Filter by project, compare runs, view charts with smoothing
Alternative: TensorBoard (Simpler for Jobs)
For simpler setup without needing a Space:
SFTConfig(
report_to="tensorboard", # Logs saved with model to Hub
)
TensorBoard logs are automatically saved with the model and viewable via TensorBoard locally after downloading.
Recommendation
- Trackio: Best for real-time monitoring during long training runs
- TensorBoard: Best for post-training analysis, simpler setup
- Weights & Biases: Best for team collaboration, requires account