A base model only continues text; it does not answer questions. SFT shows it thousands of examples of what a good answer to a prompt looks like, and it learns to answer in the same way. After this stage you have an instruction-following model that you can hold a conversation with.
How it works
The training is the same as in pretraining: the model predicts the next token, and the loss is computed in the same way. The difference is in the data: each example is a conversation recorded in the model’s chat template, with the roles system, user and assistant. The loss is often computed only on the assistant’s replies, and the prompt is ignored.
| SFTConfig parameter | What it does |
|---|---|
assistant_only_loss=True | the loss is computed only on the assistant’s messages; requires a chat template with {% generation %} markers |
completion_only_loss | the same for prompt–completion data: the loss is computed only on the completion; enabled by default for such data |
packing=True | several short examples are packed into one sequence, so training runs faster |
Example with TRL
A minimal run from the TRL documentation: the Qwen3-0.6B model and the trl-lib/Capybara dataset of conversations. For a base model, such as Qwen/Qwen3-0.6B-Base, you also set the chat template chat_template_path in SFTConfig.
from trl import SFTTrainerfrom datasets import load_dataset trainer = SFTTrainer( model="Qwen/Qwen3-0.6B", train_dataset=load_dataset("trl-lib/Capybara", split="train"),)trainer.train()SFT can be done as full fine-tuning or with LoRA adapters. To align answers with human preferences, SFT is usually followed by RLHF or DPO. In InstructGPT (2022) this was the first stage: about 13,000 examples with answers written by human labellers.
Sources
the term is written from these pagesVerified 18 Nov