What supervised fine-tuning is
A pretrained language model continues text. Given a question, it is about as likely to write another question, a forum reply or a list as an answer, because that is what follows questions on the web. Supervised fine-tuning (SFT) turns it into an assistant by training it further, with the same next-token loss it was pretrained with, on conversations in which a user asks and an assistant answers. Only the data and the choice of which tokens are scored change.
This page puts two released checkpoints side by side: SmolLM2-135M, the base, and SmolLM2-135M-Instruct, whose SFT set is smol-smoltalk. Both have 134.5 M parameters, 30 layers and a 49,152-token vocabulary, and both read the same held-out conversation from smol-smoltalk's test split (row 1820: three user turns about breakfast and three assistant replies). The strip under the board then runs 12 real SFT steps from the base on that conversation.
The chat template
A conversation is a list of messages with roles. The tokenizer's chat template, a small Jinja program shipped with the model, flattens it into one string: each message becomes <|im_start|>, the role, a newline, the content and <|im_end|>. This conversation has no system message, so the template adds SmolLM's default one, "You are a helpful AI assistant named SmolLM, trained by Hugging Face". The Chat template panel shows the result: 133 tokens, in which <|im_start|> and <|im_end|> are single special tokens.
To ask for a reply, the template ends with <|im_start|>assistant and a newline, and the model writes until it emits <|im_end|>. A model fine-tuned on one template has to be prompted with that template. The base model never saw it during pretraining, which is part of why its replies run on past where an answer should end.
The loss mask
SFT minimises the mean cross-entropy of the tokens it scores. With a mask over the conversation's tokens ,
The Loss mask · cross-entropy per token panel draws of every token under both models and hatches the tokens the mask leaves out. The mask is 1 on the 56 tokens of the three assistant replies, each with its closing <|im_end|>, and 0 on the system and user turns, the role headers and the newlines between turns. In code those positions get the label −100, which PyTorch's cross-entropy ignores. Masked tokens are still read as context, so the model learns to answer given the user's message without being trained to write it. Scoring each reply's closing <|im_end|> is how the model learns to stop.
On these 56 tokens the base's loss is 2.452 nats per token and the instruct model's 1.261. Switching the toolbar to every token scores all 132 predicted tokens instead: 3.559 against 1.781, a gap that now includes the template and the user turns, which the instruct model has also learned to expect. Whether to score the prompt is a real design choice. Shi et al. found that also training on the instruction helps most when instructions are long and outputs short, or when there are few training examples. The released recipe's config sets no assistant-only option; the steps on this page use the mask.
What fine-tuning changed
The Next token at #… panel opens one position: the six tokens of context before it and each model's most likely next tokens, with the real next token marked. The three buttons jump to the first token of each reply, where the difference is largest. Before the first reply's "Hello" the base spreads its bets (entropy 5.34 nats; "Hey" 16 %, "Hello" 4.9 %), while the instruct model puts 80 % on "Hello" (entropy 0.95 nats).
Fine-tuning makes the model more certain, not always more right. Before the second reply, which starts "Oatmeal", the instruct model puts 64 % on "A" and pays 7.98 nats for the real token, more than the base's 5.99. Over all 56 scored tokens its loss is still about half the base's. The same panel also shows the base after the SFT steps below, at whichever step the stepper is on.
Twelve steps from the base
The strip runs SFT itself: AdamW at a constant learning rate of , betas 0.9 and 0.999, no weight decay, all 134.5 M weights trained, float32 on the CPU, and a batch of this one conversation with the mask above. Each step computes by backpropagation and lets AdamW move every weight.
The SFT from the base · 12 real steps chart shows the masked loss falling from 2.452 to 0.155, far below the released instruct model's 1.261 (the dashed line), while the gradient norm falls from 15.07 to 2.27. The Loss of each assistant token, step by step heatmap shows where the loss went: one row per step, one column per scored token. In Greedy reply to the second user turn, the base at step 0 answers "A healthy breakfast option is a good choice." and runs on into fragments of other turns. After 12 steps it writes the dataset's reply word for word and stops on <|im_end|>.
That is memorising one conversation, not learning to chat, as the page says. The released model was trained differently: a learning rate of with a cosine schedule and 10 % warm-up, for 2 epochs over the whole set. It has never seen this test conversation, which is why its loss on it stays well above the memorising run's.
Where SFT came from
FLAN (Wei et al., 2022) showed that fine-tuning a 137 B model on more than 60 NLP datasets, each rephrased as natural-language instructions, made it follow instructions for tasks it had not seen. InstructGPT (Ouyang et al., 2022) made SFT on human-written demonstrations the first of three stages, before a reward model and reinforcement learning (see the RLHF tab). LIMA (Zhou et al., 2023) fine-tuned a 65 B model on only 1,000 curated examples and argued that alignment mostly teaches the style and format of answers, while the knowledge comes from pretraining.
Chat models today usually follow SFT with preference tuning, as the DPO, SimPO and ORPO tabs show; ORPO folds the two into one loss. LoRA, QLoRA and DoRA make the same fine-tuning cheaper by training far fewer weights.
Papers
- Finetuned Language Models Are Zero-Shot Learners FLAN: instruction tuning on many NLP tasks phrased as instructions, which makes a model follow instructions for unseen tasks.
- Training language models to follow instructions with human feedback InstructGPT: SFT on labellers’ demonstrations as the first stage of the recipe behind chat models, followed by a reward model and PPO.
- SmolLM2: When Smol Goes Big -- Data-Centric Training of a Small Language Model The SmolLM2 family this page records, base and instruct, with its training data and post-training recipe.
- Instruction Tuning With Loss Over Instructions Compares scoring only the outputs with also scoring the instructions, the choice the page’s loss-mask toggle shows.
- LIMA: Less Is More for Alignment SFT on 1,000 curated examples, and the hypothesis that fine-tuning mostly teaches format while pretraining supplies the knowledge.
- Instruction Tuning for Large Language Models: A Survey A survey of instruction-tuning data sets, methods and evaluations.