The same loss, on a different distribution
- : the positions belonging to the completion.
Supervised fine-tuning is next-token prediction again, run on curated pairs of a prompt and the response you want.
Nothing about the objective changes from pretraining. What changes is that the text is chosen rather than scraped, and that only part of it is scored.
Masking the prompt is the detail that matters
The loss on the prompt tokens is zero.
The prompt is context, not output. Training the model to predict the user's question teaches it to generate questions, which is not the behaviour being bought.
In practice this is a label mask: the prompt positions are set to an ignore index and contribute no gradient.
Get the mask wrong and the model repeats the instruction back.
That failure is common enough to be worth checking directly, by printing the first batch's labels and confirming the prompt region is masked.
The template is part of the model
A template looks like "<|user|> ... <|assistant|> ... <|end|>".
Special tokens mark who is speaking, and the model learns to emit the end token to stop.
The exact template used in training must be used at inference, character for character.
A mismatched template is the single most common cause of a fine-tuned model behaving strangely in production.
One run, in order
- Build pairs of prompt and ideal response, formatted with the chat template.
- Tokenise, mask the prompt positions, and pack sequences to fill the context.
- Train for one to three epochs at a learning rate one or two orders below pretraining.
- Evaluate on held-out prompts by reading the outputs, not only the loss.
- Keep the adapter or the weights, and pin the template alongside them.
The rate is small because the model is already good. A pretraining rate erases the pretrained behaviour in a few hundred steps.
Data quality decides the outcome
A thousand excellent examples beat a hundred thousand mediocre ones.
This is the most reliably reproduced result in the area.
A small, carefully written set beats a large scraped one, and the failure mode of the large set is that the model learns its average quality.
Past about 3 epochs it starts to memorise.
The dataset is small and the model is enormous, so it will memorise rather than generalise if given the chance, and the sign is a training loss that collapses towards zero.
What it cannot do
SFT teaches the model what a good answer looks like. It never shows it a bad one, so it has no signal about what to avoid.
That is the gap preference tuning fills. A ranked pair says this response is better than that one, which is information the maximum likelihood objective structurally cannot express.
It also does not add knowledge reliably. A fact stated in a hundred examples is learned as a phrasing pattern, and the model will produce the same confident shape for facts it does not have.