SFTTrainer is the right Trainer for instruction tuning
trl.SFTTrainer wraps Trainer with conveniences for chat-format data:
- Accepts datasets with a
messagescolumn directly. - Applies the tokenizer's chat template automatically.
- Sets up
DataCollatorForCompletionOnlyLMby default if you give it aresponse_template. - Plugs into PEFT for LoRA / QLoRA in two extra args.
The dataset format
Either of these works:
- Conversational: each row has
messages: [{"role":"user","content":...}, {"role":"assistant","content":...}]. - Single-turn text: each row has a
textcolumn already containing the formatted prompt + response.
Conversational is the modern default. The trainer applies the model's chat template; you don't hand-format strings.