fix: add formatting_func for SFTTrainer compatibility#19
Conversation
Newer unsloth/trl requires a formatting_func when passing raw datasets. Use tokenizer.apply_chat_template to convert the messages list to a chat-formatted string. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Greptile SummaryThis PR adds a However, the PR bundles a second unrelated change: replacing
Confidence Score: 4/5Safe to merge if the warmup_ratio silent-drop is addressed; the formatting_func fix itself is correct. One P1 finding: the configured warmup_ratio is silently discarded in favour of a hardcoded warmup_steps=50, while TrainingConfig still requires warmup_ratio to be specified in the YAML. This is a present defect that will cause incorrect training warmup schedules without any warning. src/hippofloop/training/trainer.py (line 79) and configs/default.yaml / src/hippofloop/training/config.py for the warmup_ratio vs warmup_steps inconsistency.
|
| Filename | Overview |
|---|---|
| src/hippofloop/training/trainer.py | Adds correct formatting_func for SFTTrainer, but hardcodes warmup_steps=50 while warmup_ratio is still required in config — silently ignored. |
| notebooks/train-hippofloop.ipynb | Mirrors the trainer.py changes in notebook form; formatting_func addition is correct, warmup_ratio→warmup_steps change has the same silent-drop issue. |
Sequence Diagram
sequenceDiagram
participant YAML as configs/default.yaml
participant CFG as TrainingConfig
participant TR as UnslothTrainer.train()
participant SFT as SFTTrainer
YAML->>CFG: load warmup_ratio=0.03 (required)
CFG->>TR: self._config.warmup_ratio (never read)
Note over TR: warmup_steps=50 hardcoded ❌
TR->>SFT: formatting_func=formatting_func ✅
TR->>SFT: warmup_steps=50 (ignores config)
SFT-->>TR: trainer instance
TR-->>TR: trainer.train()
Reviews (3): Last reviewed commit: "fix: formatting_func receives batched ex..." | Re-trigger Greptile
Unsloth expects formatting_func to return a list of strings, not a single string. Also replace deprecated warmup_ratio with warmup_steps. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When batched=True (unsloth default), formatting_func gets a dict of lists. Iterate over examples["messages"] and return a list of formatted strings. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
formatting_functo SFTTrainer calls (notebook + trainer.py)tokenizer.apply_chat_template()to convert messages to chat-formatted stringsPrevious run failed with:
RuntimeError: Unsloth: You must specify a formatting_funcTest plan
🤖 Generated with Claude Code