evalstate
commited on
Commit
·
d70ac03
1
Parent(s):
6527162
enhance eval instructions
Browse files
trl/references/training_patterns.md
CHANGED
|
@@ -2,79 +2,6 @@
|
|
| 2 |
|
| 3 |
This guide provides common training patterns and use cases for TRL on Hugging Face Jobs.
|
| 4 |
|
| 5 |
-
## Quick Demo (5-10 minutes)
|
| 6 |
-
|
| 7 |
-
Test setup with minimal training:
|
| 8 |
-
|
| 9 |
-
```python
|
| 10 |
-
hf_jobs("uv", {
|
| 11 |
-
"script": "https://raw.githubusercontent.com/huggingface/trl/main/examples/scripts/sft.py",
|
| 12 |
-
"script_args": [
|
| 13 |
-
"--model_name_or_path", "Qwen/Qwen2.5-0.5B",
|
| 14 |
-
"--dataset_name", "trl-lib/Capybara",
|
| 15 |
-
"--dataset_train_split", "train[:50]", # Only 50 examples
|
| 16 |
-
"--max_steps", "10",
|
| 17 |
-
"--output_dir", "demo",
|
| 18 |
-
"--push_to_hub",
|
| 19 |
-
"--hub_model_id", "username/demo"
|
| 20 |
-
],
|
| 21 |
-
"flavor": "t4-small",
|
| 22 |
-
"timeout": "15m",
|
| 23 |
-
"secrets": {"HF_TOKEN": "$HF_TOKEN"}
|
| 24 |
-
})
|
| 25 |
-
```
|
| 26 |
-
|
| 27 |
-
**Note:** The TRL maintained script above doesn't include Trackio. For production training with monitoring, see `scripts/train_sft_example.py` for a complete template with Trackio integration.
|
| 28 |
-
|
| 29 |
-
## Production with Checkpoints
|
| 30 |
-
|
| 31 |
-
Full training with intermediate saves. Use this pattern for long training runs where you want to save progress:
|
| 32 |
-
|
| 33 |
-
```python
|
| 34 |
-
hf_jobs("uv", {
|
| 35 |
-
"script": """
|
| 36 |
-
# /// script
|
| 37 |
-
# dependencies = ["trl>=0.12.0", "peft>=0.7.0", "trackio"]
|
| 38 |
-
# ///
|
| 39 |
-
|
| 40 |
-
from datasets import load_dataset
|
| 41 |
-
from peft import LoraConfig
|
| 42 |
-
from trl import SFTTrainer, SFTConfig
|
| 43 |
-
import trackio
|
| 44 |
-
|
| 45 |
-
trackio.init(project="production-training", space_id="username/my-dashboard")
|
| 46 |
-
|
| 47 |
-
dataset = load_dataset("trl-lib/Capybara", split="train")
|
| 48 |
-
|
| 49 |
-
config = SFTConfig(
|
| 50 |
-
output_dir="my-model",
|
| 51 |
-
push_to_hub=True,
|
| 52 |
-
hub_model_id="username/my-model",
|
| 53 |
-
hub_strategy="every_save", # Push each checkpoint
|
| 54 |
-
save_strategy="steps",
|
| 55 |
-
save_steps=100,
|
| 56 |
-
save_total_limit=3,
|
| 57 |
-
num_train_epochs=3,
|
| 58 |
-
report_to="trackio",
|
| 59 |
-
)
|
| 60 |
-
|
| 61 |
-
trainer = SFTTrainer(
|
| 62 |
-
model="Qwen/Qwen2.5-0.5B",
|
| 63 |
-
train_dataset=dataset,
|
| 64 |
-
args=config,
|
| 65 |
-
peft_config=LoraConfig(r=16, lora_alpha=32),
|
| 66 |
-
)
|
| 67 |
-
|
| 68 |
-
trainer.train()
|
| 69 |
-
trainer.push_to_hub()
|
| 70 |
-
trackio.finish()
|
| 71 |
-
""",
|
| 72 |
-
"flavor": "a10g-large",
|
| 73 |
-
"timeout": "6h",
|
| 74 |
-
"secrets": {"HF_TOKEN": "$HF_TOKEN"}
|
| 75 |
-
})
|
| 76 |
-
```
|
| 77 |
-
|
| 78 |
## Multi-GPU Training
|
| 79 |
|
| 80 |
Automatic distributed training across multiple GPUs. TRL/Accelerate handles distribution automatically:
|
|
@@ -116,18 +43,24 @@ trackio.init(project="dpo-training", space_id="username/my-dashboard")
|
|
| 116 |
|
| 117 |
dataset = load_dataset("trl-lib/ultrafeedback_binarized", split="train")
|
| 118 |
|
|
|
|
|
|
|
|
|
|
| 119 |
config = DPOConfig(
|
| 120 |
output_dir="dpo-model",
|
| 121 |
push_to_hub=True,
|
| 122 |
hub_model_id="username/dpo-model",
|
| 123 |
num_train_epochs=1,
|
| 124 |
beta=0.1, # KL penalty coefficient
|
|
|
|
|
|
|
| 125 |
report_to="trackio",
|
| 126 |
)
|
| 127 |
|
| 128 |
trainer = DPOTrainer(
|
| 129 |
model="Qwen/Qwen2.5-0.5B-Instruct", # Use instruct model as base
|
| 130 |
-
train_dataset=
|
|
|
|
| 131 |
args=config,
|
| 132 |
)
|
| 133 |
|
|
@@ -169,26 +102,66 @@ hf_jobs("uv", {
|
|
| 169 |
|
| 170 |
| Use Case | Pattern | Hardware | Time |
|
| 171 |
|----------|---------|----------|------|
|
| 172 |
-
|
|
| 173 |
-
| Small dataset (<1K) | Production w/ Checkpoints | t4-medium | 30-60 min |
|
| 174 |
-
| Medium dataset (1-10K) | Production w/ Checkpoints | a10g-large | 2-6 hours |
|
| 175 |
| Large dataset (>10K) | Multi-GPU | a10g-largex2 | 4-12 hours |
|
| 176 |
| Preference learning | DPO Training | a10g-large | 2-4 hours |
|
| 177 |
| Online RL | GRPO Training | a10g-large | 3-6 hours |
|
| 178 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
## Best Practices
|
| 180 |
|
| 181 |
-
1. **
|
| 182 |
-
2. **
|
| 183 |
-
3. **
|
| 184 |
-
4. **
|
| 185 |
-
5. **
|
| 186 |
6. **Use multi-GPU for large models** - 7B+ models benefit significantly
|
| 187 |
|
| 188 |
## See Also
|
| 189 |
|
| 190 |
-
- `scripts/train_sft_example.py` - Complete SFT template with Trackio
|
| 191 |
- `scripts/train_dpo_example.py` - Complete DPO template
|
| 192 |
- `scripts/train_grpo_example.py` - Complete GRPO template
|
| 193 |
- `references/hardware_guide.md` - Detailed hardware specifications
|
| 194 |
- `references/training_methods.md` - Overview of all TRL training methods
|
|
|
|
|
|
| 2 |
|
| 3 |
This guide provides common training patterns and use cases for TRL on Hugging Face Jobs.
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
## Multi-GPU Training
|
| 6 |
|
| 7 |
Automatic distributed training across multiple GPUs. TRL/Accelerate handles distribution automatically:
|
|
|
|
| 43 |
|
| 44 |
dataset = load_dataset("trl-lib/ultrafeedback_binarized", split="train")
|
| 45 |
|
| 46 |
+
# Create train/eval split
|
| 47 |
+
dataset_split = dataset.train_test_split(test_size=0.1, seed=42)
|
| 48 |
+
|
| 49 |
config = DPOConfig(
|
| 50 |
output_dir="dpo-model",
|
| 51 |
push_to_hub=True,
|
| 52 |
hub_model_id="username/dpo-model",
|
| 53 |
num_train_epochs=1,
|
| 54 |
beta=0.1, # KL penalty coefficient
|
| 55 |
+
eval_strategy="steps",
|
| 56 |
+
eval_steps=50,
|
| 57 |
report_to="trackio",
|
| 58 |
)
|
| 59 |
|
| 60 |
trainer = DPOTrainer(
|
| 61 |
model="Qwen/Qwen2.5-0.5B-Instruct", # Use instruct model as base
|
| 62 |
+
train_dataset=dataset_split["train"],
|
| 63 |
+
eval_dataset=dataset_split["test"], # IMPORTANT: Provide eval_dataset when eval_strategy is enabled
|
| 64 |
args=config,
|
| 65 |
)
|
| 66 |
|
|
|
|
| 102 |
|
| 103 |
| Use Case | Pattern | Hardware | Time |
|
| 104 |
|----------|---------|----------|------|
|
| 105 |
+
| SFT training | `scripts/train_sft_example.py` | a10g-large | 2-6 hours |
|
|
|
|
|
|
|
| 106 |
| Large dataset (>10K) | Multi-GPU | a10g-largex2 | 4-12 hours |
|
| 107 |
| Preference learning | DPO Training | a10g-large | 2-4 hours |
|
| 108 |
| Online RL | GRPO Training | a10g-large | 3-6 hours |
|
| 109 |
|
| 110 |
+
## Critical: Evaluation Dataset Requirements
|
| 111 |
+
|
| 112 |
+
**⚠️ IMPORTANT**: If you set `eval_strategy="steps"` or `eval_strategy="epoch"`, you **MUST** provide an `eval_dataset` to the trainer, or the training will hang.
|
| 113 |
+
|
| 114 |
+
### ✅ CORRECT - With eval dataset:
|
| 115 |
+
```python
|
| 116 |
+
dataset_split = dataset.train_test_split(test_size=0.1, seed=42)
|
| 117 |
+
|
| 118 |
+
trainer = SFTTrainer(
|
| 119 |
+
model="Qwen/Qwen2.5-0.5B",
|
| 120 |
+
train_dataset=dataset_split["train"],
|
| 121 |
+
eval_dataset=dataset_split["test"], # ← MUST provide when eval_strategy is enabled
|
| 122 |
+
args=SFTConfig(eval_strategy="steps", ...),
|
| 123 |
+
)
|
| 124 |
+
```
|
| 125 |
+
|
| 126 |
+
### ❌ WRONG - Will hang:
|
| 127 |
+
```python
|
| 128 |
+
trainer = SFTTrainer(
|
| 129 |
+
model="Qwen/Qwen2.5-0.5B",
|
| 130 |
+
train_dataset=dataset,
|
| 131 |
+
# NO eval_dataset but eval_strategy="steps" ← WILL HANG
|
| 132 |
+
args=SFTConfig(eval_strategy="steps", ...),
|
| 133 |
+
)
|
| 134 |
+
```
|
| 135 |
+
|
| 136 |
+
### Option: Disable evaluation if no eval dataset
|
| 137 |
+
```python
|
| 138 |
+
config = SFTConfig(
|
| 139 |
+
eval_strategy="no", # ← Explicitly disable evaluation
|
| 140 |
+
# ... other config
|
| 141 |
+
)
|
| 142 |
+
|
| 143 |
+
trainer = SFTTrainer(
|
| 144 |
+
model="Qwen/Qwen2.5-0.5B",
|
| 145 |
+
train_dataset=dataset,
|
| 146 |
+
# No eval_dataset needed
|
| 147 |
+
args=config,
|
| 148 |
+
)
|
| 149 |
+
```
|
| 150 |
+
|
| 151 |
## Best Practices
|
| 152 |
|
| 153 |
+
1. **Use train/eval splits** - Create evaluation split for monitoring progress
|
| 154 |
+
2. **Enable Trackio** - Monitor progress in real-time
|
| 155 |
+
3. **Add 20-30% buffer to timeout** - Account for loading/saving overhead
|
| 156 |
+
4. **Test with TRL official scripts first** - Use maintained examples before custom code
|
| 157 |
+
5. **Always provide eval_dataset** - When using eval_strategy, or set to "no"
|
| 158 |
6. **Use multi-GPU for large models** - 7B+ models benefit significantly
|
| 159 |
|
| 160 |
## See Also
|
| 161 |
|
| 162 |
+
- `scripts/train_sft_example.py` - Complete SFT template with Trackio and eval split
|
| 163 |
- `scripts/train_dpo_example.py` - Complete DPO template
|
| 164 |
- `scripts/train_grpo_example.py` - Complete GRPO template
|
| 165 |
- `references/hardware_guide.md` - Detailed hardware specifications
|
| 166 |
- `references/training_methods.md` - Overview of all TRL training methods
|
| 167 |
+
- `references/troubleshooting.md` - Common issues and solutions
|
trl/references/troubleshooting.md
CHANGED
|
@@ -2,6 +2,49 @@
|
|
| 2 |
|
| 3 |
Common issues and solutions when training with TRL on Hugging Face Jobs.
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
## Job Times Out
|
| 6 |
|
| 7 |
**Problem:** Job terminates before training completes, all progress lost.
|
|
@@ -208,5 +251,6 @@ If issues persist:
|
|
| 208 |
- `references/hub_saving.md` - Hub authentication issues
|
| 209 |
- `references/hardware_guide.md` - Hardware selection and specs
|
| 210 |
- `references/uv_scripts_guide.md` - UV script format issues
|
|
|
|
| 211 |
|
| 212 |
4. **Ask in HF forums:** https://discuss.huggingface.co/
|
|
|
|
| 2 |
|
| 3 |
Common issues and solutions when training with TRL on Hugging Face Jobs.
|
| 4 |
|
| 5 |
+
## Training Hangs at "Starting training..." Step
|
| 6 |
+
|
| 7 |
+
**Problem:** Job starts but hangs at the training step - never progresses, never times out, just sits there.
|
| 8 |
+
|
| 9 |
+
**Root Cause:** Using `eval_strategy="steps"` or `eval_strategy="epoch"` without providing an `eval_dataset` to the trainer.
|
| 10 |
+
|
| 11 |
+
**Solution:**
|
| 12 |
+
|
| 13 |
+
**Option A: Provide eval_dataset (recommended)**
|
| 14 |
+
```python
|
| 15 |
+
# Create train/eval split
|
| 16 |
+
dataset_split = dataset.train_test_split(test_size=0.1, seed=42)
|
| 17 |
+
|
| 18 |
+
trainer = SFTTrainer(
|
| 19 |
+
model="Qwen/Qwen2.5-0.5B",
|
| 20 |
+
train_dataset=dataset_split["train"],
|
| 21 |
+
eval_dataset=dataset_split["test"], # ← MUST provide when eval_strategy is enabled
|
| 22 |
+
args=SFTConfig(
|
| 23 |
+
eval_strategy="steps",
|
| 24 |
+
eval_steps=50,
|
| 25 |
+
...
|
| 26 |
+
),
|
| 27 |
+
)
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
+
**Option B: Disable evaluation**
|
| 31 |
+
```python
|
| 32 |
+
trainer = SFTTrainer(
|
| 33 |
+
model="Qwen/Qwen2.5-0.5B",
|
| 34 |
+
train_dataset=dataset,
|
| 35 |
+
# No eval_dataset
|
| 36 |
+
args=SFTConfig(
|
| 37 |
+
eval_strategy="no", # ← Explicitly disable
|
| 38 |
+
...
|
| 39 |
+
),
|
| 40 |
+
)
|
| 41 |
+
```
|
| 42 |
+
|
| 43 |
+
**Prevention:**
|
| 44 |
+
- Always create train/eval split for better monitoring
|
| 45 |
+
- Use `dataset.train_test_split(test_size=0.1, seed=42)`
|
| 46 |
+
- Check example scripts: `scripts/train_sft_example.py` includes proper eval setup
|
| 47 |
+
|
| 48 |
## Job Times Out
|
| 49 |
|
| 50 |
**Problem:** Job terminates before training completes, all progress lost.
|
|
|
|
| 251 |
- `references/hub_saving.md` - Hub authentication issues
|
| 252 |
- `references/hardware_guide.md` - Hardware selection and specs
|
| 253 |
- `references/uv_scripts_guide.md` - UV script format issues
|
| 254 |
+
- `references/training_patterns.md` - Eval dataset requirements
|
| 255 |
|
| 256 |
4. **Ask in HF forums:** https://discuss.huggingface.co/
|