Bookmarks

SFT — supervised fine-tuning

A training stage in which a model learns from ready-made pairs of a prompt and a model answer, turning a base model into an instruction-following one.

Also: supervised fine-tuning, training on example dialogues, instruction tuning

checked 18 Nov

All terms

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 parameterWhat it does
assistant_only_loss=Truethe loss is computed only on the assistant’s messages; requires a chat template with {% generation %} markers
completion_only_lossthe same for prompt–completion data: the loss is computed only on the completion; enabled by default for such data
packing=Trueseveral 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.

python
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 pages

Verified 18 Nov

Not to be confused with

what it is mixed up with and how it differs

  • pretraining

    Pretraining uses huge amounts of unlabelled text and produces a base model, whereas SFT uses small datasets of conversations.

  • DPOdirect preference optimisation

    DPO trains the model on pairs of a better and a worse answer, whereas SFT trains it on a single model answer.

In depth in the references

where the topic is covered in detail