← Back to list

Supervised Fine-Tuning (SFT) for LLMs: Complete Guide

Large language models are impressive, but a raw pretrained model is not automatically a helpful assistant. It may know a great deal about…

QuarkAndCode · 2026-05-19 07:46 · 62 claps · 10.9 min read paywalled
#supervised-fine-tuning #sft #large-language-models #llm-training #fine-tuning-ai
Open on Medium ↗
Wiki topics: LLM · Large Language Models FT · Fine-tuning & Adaptation 📰 · Journalism & News

Supervised Fine-Tuning (SFT) for LLMs: Complete Guide

Large language models are impressive, but a raw pretrained model is not automatically a helpful assistant. It may know a great deal about language, facts, code, and patterns, yet still respond in ways that are too vague, too verbose, poorly formatted, unsafe, or simply not aligned with users’ expectations.

Supervised Fine-Tuning, usually shortened to SFT, is one of the key techniques for turning a general-purpose language model into one that follows instructions, produces answers in a desired style, and behaves more consistently in real-world applications.

Think of SFT this way: pretraining gives the model general knowledge, while supervised fine-tuning teaches it how to use that knowledge the way we want. Researchers often describe building modern language models as a step-by-step process. First, the model is trained on lots of raw text. Then it is further trained using methods such as instruction tuning, supervised fine-tuning, reinforcement learning from human feedback, or preference optimization to better match people’s needs.

What Is Supervised Fine-Tuning?

Supervised Fine-Tuning is the process of taking a pretrained language model and training it further on examples that show the model what a good response looks like. Each training example usually contains an input, such as a user prompt, and a target output, such as the ideal assistant response. Because the model is learning from labeled examples, the process is called “supervised.” Hugging Face describes SFT as a method for adapting pretrained language models to follow instructions, hold conversations, and produce specific output formats.

For example, if we want a model to be a better customer support assistant, we can train it with examples like these:

The model does not just memorize these answers. It learns patterns, such as how to reply politely, what details to include, what tone to use, how to organize the message, and what kind of behavior is expected in similar situations.

Why SFT Matters

A pretrained LLM is usually trained to predict the next word or token in a huge collection of text. That makes it good at producing language, but not necessarily good at being useful. It may complete a prompt rather than answer it. It may imitate unreliable sources. It may provide information in the wrong format. It may fail to follow instructions that seem obvious to a person.

SFT helps close this gap by teaching the model what helpful behavior looks like. In OpenAI’s InstructGPT project, researchers gathered examples of high-quality responses written by people, fine-tuned GPT-3 with supervised learning, and then used human feedback and reinforcement learning to further improve it. This led to models that followed user instructions better than the original GPT-3.

Put simply, SFT is like training a smart new employee. The person may have talent, but still needs to see examples of how your company writes emails, handles complaints, formats reports, answers tough questions, and talks to customers. SFT gives a language model this kind of guided practice.

How SFT Works

SFT usually starts with a pretrained base model. This model already knows a lot about language because it was trained on large amounts of data. Next, you prepare a supervised dataset with examples that show the behavior you want. Hugging Face points out that SFT datasets are often made of input-output pairs: a prompt, the expected response, and sometimes extra context or metadata.

A typical SFT workflow includes these steps:

  1. Choose a base model. The stronger and more suitable the base model, the better the starting point.

  2. Define the target behavior. Decide what the model should do: answer customer questions, write legal-style summaries, generate code, produce JSON, tutor students, follow a brand voice, or handle domain-specific conversations.

  3. Create or collect examples. These examples should show the model exactly what good responses look like.

  4. Format the dataset. Chat models often use message formats such as user, assistant, and system roles. Some datasets use prompt-completion pairs, while others use multi-turn conversations. Hugging Face’s SFTTrainer supports both standard and conversational formats.

  5. Train the model. The model is trained to produce the target response when given the prompt.

  6. Evaluate and refine. Developers test the model on unseen prompts, check for errors, compare it with the base model, and improve the dataset or training setup.

During training, the model’s answers are compared to the correct ones. If the model gets it wrong, its settings are adjusted. After seeing many examples, the model becomes more likely to give responses like the good examples in the dataset.

SFT and Instruction Tuning

SFT is closely related to instruction tuning. Instruction tuning is a form of supervised fine-tuning in which the dataset consists of many tasks expressed as natural-language instructions. Instead of training a model on a single narrow task, instruction tuning trains it to understand a wide variety of user requests.

The FLAN research from Google showed that fine-tuning a large model on many instruction-formatted tasks improved its performance on unseen tasks in a zero-shot setting. The FLAN paper reported that instruction-tuning a 137B-parameter model on more than 60 NLP tasks substantially improved zero-shot performance compared with the unmodified model.

Later work further scaled instruction tuning. The Flan-PaLM research studied instruction fine-tuning across 1.8K tasks and found that instruction tuning scales with both the number of tasks and the model size. The authors also reported improvements across zero-shot, few-shot, chain-of-thought, and open-ended generation evaluations.

This is why many modern chat models are not merely pretrained models. They are pretrained models that have been carefully instruction-tuned and aligned to respond naturally to human requests.

Quality Matters More Than People Think

One of the most important lessons in SFT is that data quality matters enormously. A small set of excellent examples can sometimes outperform a large set of noisy, repetitive, or poorly written examples.

The LIMA paper is a famous example. Researchers fine-tuned a 65B-parameter LLaMA model using only 1,000 carefully curated prompt-response pairs, without reinforcement learning or human preference modeling. The model showed surprisingly strong instruction-following behavior, supporting the idea that much of an LLM’s knowledge comes from pretraining, while fine-tuning often teaches the model how to surface that knowledge in a useful format.

That does not mean every SFT project only needs 1,000 examples. It means careless volume is not enough. If the examples are confusing, inconsistent, biased, outdated, or low quality, the model can learn those problems too. A fine-tuned model reflects the dataset it was trained on. If the dataset is sharp, consistent, and practical, the model has a much better chance of becoming sharp, consistent, and practical.

What Makes a Good SFT Dataset?

A good SFT dataset should be like a collection of ideal examples. It should not have just easy cases, but also realistic edge cases. For customer service, this could include refund requests, upset customers, missing information, shipping delays, policy questions, and situations that need escalation. For a coding assistant, this might include bug fixes, code explanations, refactoring, test generation, and security-conscious answers.

Good SFT data usually has several traits:

· Clear instructions: The prompt should make the task understandable.

· High-quality target responses: The answer should be accurate, helpful, and well written.

· Consistent style: The model should see the same tone, structure, and standards across examples.

· Diversity: The dataset should cover a range of topics, difficulty levels, formats, and user behaviors.

· Domain accuracy: If the model is being trained in medicine, law, finance, education, or engineering, the examples must be carefully reviewed by qualified professionals.

· Safety coverage: The model should learn how to respond when a user asks for something unsafe, impossible, private, or outside the system’s scope.

· Evaluation split: Some examples should be held out for testing to assess whether the model generalizes rather than memorizes.

A dataset should also include examples of the format you want. If the model must always return JSON, train it on clean JSON. If it must be written in a warm and friendly tone, show that tone repeatedly. If it must ask clarifying questions when information is missing, include examples where the best answer is not a confident guess, but a thoughtful follow-up question.

SFT vs Prompting vs RAG vs RLHF

SFT is powerful, but it is not always the right tool. It helps to understand how it compares with other common LLM customization methods.

Retrieval-Augmented Generation, or RAG, is often a better choice when the main problem is access to current or private knowledge. RAG connects a model to external knowledge bases, while fine-tuning trains the model on domain-specific data. The two methods can also be used together: SFT can teach the model how to behave, while RAG supplies fresh or source-backed information at response time.

RLHF and DPO are different approaches. In the InstructGPT process, SFT was first used to teach the model with examples. Then, human rankings data were used to train a reward model, which was further improved through reinforcement learning. DPO later provided a simpler way to align models using preference pairs, without needing the full reward model and reinforcement learning steps.

Full Fine-Tuning, LoRA, and QLoRA

Traditional fine-tuning updates many or all of a model’s parameters. For small models, that can be manageable. For large models, it can be expensive and difficult. This is where parameter-efficient fine-tuning methods become useful.

LoRA, or Low-Rank Adaptation, freezes the pretrained model weights and trains small additional matrices inside the model. The original LoRA paper reported that this can greatly reduce the number of trainable parameters while maintaining strong performance across several models and tasks.

QLoRA goes further by combining quantization with LoRA. It freezes a quantized, pretrained model and trains low-rank adapters on top of it. The QLoRA paper showed that this approach could fine-tune a 65B-parameter model on a single 48GB GPU while preserving strong performance compared with full 16-bit fine-tuning.

In practical terms, LoRA and QLoRA made SFT more accessible. Instead of needing enormous infrastructure to adapt a model, teams can often fine-tune open models with far fewer resources.

What SFT Is Good At

SFT is especially useful when you want a model to behave in a repeatable way. For example, it can help a model:

· Follow a company’s writing style.

· Use a specific response structure.

· Produce clean JSON, XML, SQL, or other formal outputs.

· Handle domain-specific terminology

· Follow support workflows

· Ask clarifying questions when needed.

· Refuse certain requests consistently.

· Write in a particular tone, such as friendly, concise, academic, or professional.

· Perform better on a recurring task than a general model with prompting alone.

This is why SFT is popular in customer support, coding tools, education, healthcare administration, legal operations, finance workflows, research assistance, and internal enterprise copilots. The goal is not always to create a smarter model in every possible sense. Often, the goal is to create a model that is more reliable for a specific job.

What SFT Is Not Good At

SFT is not a magic fix. It does not guarantee the model will always tell the truth or avoid mistakes. It does not replace expert review in important fields, nor does it keep a model up to date forever. It may also not teach deep new knowledge as people hope.

If a company wants a model to answer questions about a policy manual that changes every week, SFT alone is usually the wrong approach. The model may learn the old policy and keep repeating it. A RAG system connected to the latest policy documents would likely be safer and easier to maintain. SFT may still help the model answer in the right tone and format, but retrieval should provide the current facts.

SFT can also lead to overfitting. Hugging Face’s fine-tuning guide says that more training rounds can help learning but also raise the risk of overfitting. A model trained too much on a narrow dataset can become rigid, repetitive, or worse at general tasks. Good validation, early stopping, varied data, and careful checks help lower this risk.

Common SFT Mistakes

Many SFT projects fail not because the method is weak, but because the setup is careless. Some common mistakes include:

Training with messy data. If the dataset contains contradictions, poor formatting, weak answers, or mistakes, the model can learn from them too.

Using too little variety. A model trained only on easy examples may fail when users ask messy, incomplete, or adversarial questions.

Trying to use SFT as a database. Fine-tuning is not the best way to store rapidly changing facts. Use retrieval for current knowledge.

Ignoring evaluation. A fine-tuned model might look good in a demo but do worse on a real test set.

Overfitting to style. A model can learn the brand voice but may lose flexibility if every example is too similar.

Forgetting safety cases. If the dataset contains only helpful, normal answers, the model may not learn to handle harmful, private, or impossible requests.

Skipping human review. Automatic metrics help, but human checks are still important for tone, usefulness, accuracy, and safety.

How to Evaluate an SFT Model

A good evaluation plan should test the model before and after fine-tuning. It should compare the fine-tuned model with the base model and, when relevant, with a prompted version of the base model.

Useful evaluation methods include:

· Held-out test prompts: Examples the model did not see during training.

· Human preference evaluation: Reviewers compare outputs and choose the better one.

· Task-specific metrics: Accuracy, exact match, F1, pass rate, JSON validity, code execution success, or extraction accuracy.

· Robustness tests: Ambiguous prompts, incomplete prompts, adversarial prompts, and unusual edge cases.

· Safety tests: Private data requests, harmful instructions, policy violations, and refusal behavior.

· Regression tests: Checks that fine-tuning did not break important general capabilities.

The key question is not “Did the training loss go down?” The better question is: Does this model perform better for real users and the real tasks it was built for?

A Practical SFT Checklist

Before starting an SFT project, it helps to answer a few practical questions:

· What exact behavior do we want the model to learn?

· Can prompting solve the problem without fine-tuning?

· Do we need RAG because the model must use current or private information?

· Do we have enough high-quality examples?

· Who will review the data for correctness?

· What format should the model produce?

· What should the model do when the user asks a bad, unsafe, vague, or out-of-scope question?

· How will we measure improvement?

· What risks would make the fine-tuned model unacceptable?

· How will we update or retrain the model when requirements change?

SFT works best when the goal is clear and specific. “Make the model better” is too vague. A goal like “Make the model answer billing questions in a friendly tone, follow our escalation policy, ask for missing account information, and return structured case summaries” is much more effective.

The Bigger Picture

Supervised Fine-Tuning is a key step in making language models useful. It helps models act more like assistants, tutors, analysts, coding partners, or support agents, instead of just generating raw text. It lets developers teach behavior through examples rather than just prompts.

But SFT is easy to misunderstand. It is not just about giving a model more data. It is about showing the model better ways to behave. SFT is not only a technical step — it is also a design choice, a data quality challenge, and a process for improving the final product.

The best SFT projects begin with a clear goal, use carefully chosen examples, test results honestly, and combine fine-tuning with other tools when needed. Prompting, RAG, SFT, RLHF, and DPO are not rivals — they are different tools for different problems. The key is knowing when to use each one.

In the simplest terms, SFT teaches a model by example. And just as people do, models learn best from clear, consistent, thoughtful examples that are close to the work they are expected to do.


메타데이터
post_id
6d9d36ecdf98
slug
supervised-fine-tuning-sft-for-llms-complete-guide-6d9d36ecdf98
url
https://medium.com/@QuarkAndCode/supervised-fine-tuning-sft-for-llms-complete-guide-6d9d36ecdf98
canonical_url
https://medium.com/@QuarkAndCode/supervised-fine-tuning-sft-for-llms-complete-guide-6d9d36ecdf98
author_url
https://medium.com/@QuarkAndCode
status
ok
fetched_at
2026-06-13 09:11:36