Define supervised fine-tuning (SFT) in one breath.
SFT is continued next-token training on curated (prompt, response) demos, with loss masked to response tokens, to install assistant behaviour on a pretrained base.
Imagine a brilliant student who has read every book in the library but has never been to a job interview. They know everything but they ramble, they speak out of turn, they cite obscure sources when a one-line answer would do. SFT is a weekend with a tutor who shows the student a few hundred good interview answers. The tutor never teaches new facts; the student already knows the material. What changes is style and shape, when to be concise, when to elaborate, when to refuse, when to ask. By Monday the student answers in the right format. Same knowledge, brand new presentation. That polish is exactly what SFT installs on top of a pretrained base.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Supervised fine-tuning, SFT, is the gateway step between a pretrained base model and any modern alignment pipeline. It is also one of the most commonly misunderstood operations in the entire LLM stack. Beginners assume SFT teaches new facts. It does not, primarily. Beginners assume SFT runs a special loss. It does not. The loss is the same next-token cross-entropy as pretraining. What changes is everything around the loss.
This deep dive walks through what SFT actually does. We start with the mechanical definition (same loss, different data, different masking, different learning rate), explain why prompt loss masking matters, lay out the behaviour versus knowledge distinction that decides when SFT is the right tool, and survey the production recipe that has converged across the open ecosystem.
The headline is concise. SFT runs masked next-token cross-entropy on curated chat-format demonstrations at a much lower learning rate than pretraining, in order to install behaviour and format on top of a pretrained base. It excels at teaching the model how to follow the chat template, when to answer, how to structure replies, how to refuse, and how to invoke tools. It is poor at teaching genuinely new factual knowledge; that is the job of retrieval or continued pretraining.
Getting this distinction right reshapes how teams think about post-training. A team that treats SFT as a knowledge-injection tool will collect 100k facts in chat format, spend a week training, and watch the model produce mediocre answers that hallucinate facts in the same shape as the demonstrations. A team that treats SFT as behaviour installation will collect 1k high-quality format demonstrations, finish training in hours, and ship a sharply better assistant.
What SFT actually runs under the hood
The loss
SFT runs the same loss as pretraining: next-token cross-entropy on a causal-LM forward pass. For a sequence of tokens x_1, x_2, ..., x_T, the model predicts each token from the ones before it:
Notice the sum is restricted to response token positions. This is the prompt loss masking discussed below; the loss function itself is identical to pretraining.
The data
SFT data is curated (prompt, response) pairs, typically formatted as multi-turn chat conversations with system, user, and assistant roles. A single example might be a one-turn instruction-response pair (Alpaca-style) or a long multi-turn dialogue with tool calls embedded (modern agentic SFT).
Volume ranges from 1k (LIMA) to a few hundred k examples. Past a few thousand high-quality examples, more data offers diminishing returns; quality and diversity dominate.
The learning rate
Full SFT uses 1e-5 to 2e-5. LoRA SFT uses 1e-4 (most weights frozen, larger steps on the small trainable slice are safe). Both are roughly ten times smaller than pretraining LRs.
The reason is geometric. Pretraining ended in a sharp loss basin built over trillions of tokens. SFT takes small steps inside that basin. A pretraining-scale LR pushes the weights out of the basin, the small SFT dataset cannot rebuild the pretraining distribution, and the model rapidly loses its general capabilities. This is catastrophic forgetting, and using too high a fine-tuning LR is the fastest way to cause it.
The training duration
Typical SFT runs are hours to a few days on a single node or a few nodes. Compare to pretraining (weeks to months on thousands of GPUs). The 100x to 1000x cost reduction is what made SFT economically central to modern LLM development.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
| Dimension | Pretraining | SFT |
|---|---|---|
| Data shape | Raw text, no labels | Curated chat-format demos |
| Data volume | Trillions of tokens | Thousands to low millions |
| Loss | Next-token CE, every token | Next-token CE, assistant only |
| Learning rate | 1e-4 to 6e-4 | 1e-5 to 2e-5 |
| What changes | World knowledge | Format and behaviour |
Real products, models, and research that use this idea.
- Llama 4 Maverick's post-training begins with a large SFT stage on curated demonstrations before any preference optimisation.
- DeepSeek V4 publishes an SFT recipe using around 2e-5 learning rate on a multi-million example chat dataset.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy does prompt loss masking matter so much in practice?
Without masking the model learns to predict user tokens too, which means it sometimes generates fake user turns mid-response or refuses to respond because it just wrote a user message. Masking aligns gradients with what you want the model to produce, not with what it observes.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Treating SFT as a way to inject new factual knowledge. SFT primarily reshapes behaviour and format; for genuinely new facts you usually need retrieval or continued pretraining.
60 second bullets to scan on the way to the call.
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.