Overview

6 Supervised fine-tuning: Maximum expressiveness

Supervised fine-tuning is presented as the step up from LoRA when a small adapter can no longer fully reshape a model’s behavior. Unlike LoRA, full SFT updates every parameter, which gives the optimizer much more freedom to learn rigid output formats, domain vocabulary, and multi-step response patterns, but also increases memory use, training time, and the risk of overfitting or forgetting. The chapter’s running example builds an IT support assistant from a cleaned, reformatted Stack Exchange-based dataset mixed with a small general-purpose slice, then trains a Qwen3-4B model with conservative hyperparameters and gradient checkpointing so the run fits on modest hardware.

The training workflow emphasizes discipline in preparation and monitoring. Data is transformed into chat-style JSONL with a consistent house format, then split into train, validation, and held-out test sets so performance can be measured honestly. During training, the most important signals are training loss, validation loss, and gradient norm: healthy runs show loss falling, validation loss flattening rather than rising, and gradient norms stabilizing after early spikes. The chapter also recommends smoke tests before long runs, continuous metric tracking with tools like TensorBoard or W&B, and simple scripts that inspect the saved training log for early signs of overfitting or instability.

Evaluation is treated as both quantitative and behavioral. For the IT support example, the fine-tuned model improves Token-F1 only modestly over the base model, which the chapter warns may understate the real benefit because open-ended generation is poorly captured by overlap metrics. More revealing are behavioral checks: the SFT model reliably follows the desired structured-answer format, retains general knowledge, and still passes basic safety tests, though a separate safety regression suite shows that harmful-request refusal can weaken after fine-tuning. The chapter’s broader takeaway is that SFT is worth the extra cost when a task needs consistent structure, deeper domain behavior, or stronger control than LoRA can provide, but it should be chosen only after simpler methods fall short, with careful attention to data quality, validation, and ongoing maintenance.

The IT support data-preparation pipeline: source real questions and answers from Stack Exchange, mix and balance with a Dolly slice, then normalize each answer to the house format.
Training metrics for the SFT run (Qwen3-4B, 450 IT support examples, 3 epochs, two 24 GB test GPUs): training loss falls steadily while validation loss stays flat near 2.14, the gradient norm settles into the 3 to 4 range, and the learning rate follows a cosine decay.
The four training loss patterns encountered during fine-tuning.
SFT decision tree

Summary

  • Full-parameter SFT updates every weight in the model, giving the optimizer maximum freedom to reshape behavior at the cost of higher compute, greater overfitting risk, and harder rollback than LoRA.
  • SFT excels at complex structured output, multi-step domain reasoning, and strict behavioral consistency; for simpler tasks, LoRA provides nearly equivalent quality at lower cost.
  • Fine-tuning changes how a model behaves, not what it knows; use RAG for knowledge gaps and fine-tuning for behavior gaps.
  • Data quality dominates outcomes: 500 curated examples outperform 5,000 noisy ones, and 300 to 1,500 well-curated examples suffice for moderate tasks.
  • The training pipeline uses TRL’s SFTTrainer with gradient checkpointing; the only difference from LoRA training is omitting the PEFT configuration and lowering the learning rate.
  • Monitor validation loss as the primary health signal; a widening gap between training and validation loss indicates overfitting.
  • Catastrophic forgetting, overfitting, and distribution mismatch are the three primary risks; run safety regression tests after every training run.
  • Always compare fine-tuned performance against the base model, not against an absolute standard, and define success thresholds before training begins.
  • Tune one hyperparameter at a time in order of impact: learning rate, then epochs, then batch size; stop tuning when gains fall below one percentage point per run.
  • SFT is the foundation for preference optimization: the SFT checkpoint becomes the starting model for DPO or GRPO training in chapter 8.
  • The decision to fine-tune is also a decision to maintain; factor the full lifecycle cost (retraining, evaluation, serving infrastructure) into the ROI calculation.

FAQ

What is supervised fine-tuning (SFT), and how is it different from LoRA?SFT updates all model parameters, giving the optimizer full freedom to reshape behavior across attention, norms, and feed-forward layers. LoRA only trains small adapter matrices on top of a frozen base model, which is cheaper and lighter but less expressive.
Why would you choose full SFT instead of just increasing LoRA rank?If LoRA improvements plateau and the model still cannot reliably learn a rigid format, deeper reasoning pattern, or consistent behavior, full SFT can help because it is not limited by a low-rank adapter constraint. It is the next step when LoRA falls measurably short of the target.
What dataset structure does this chapter use for SFT training?The training data is converted into chat-formatted JSONL examples with system, user, and assistant messages. The assistant response is the only part trained on directly; system and user messages condition the model but are masked from loss.
Why does the chapter mix IT support data with a slice of general-purpose data?The general-purpose slice helps preserve broad capabilities and reduces the risk of catastrophic forgetting. It also prevents the model from becoming too narrow or overly specialized in one style.
Why are the SFT training hyperparameters so conservative?Full SFT updates every parameter, so it is more sensitive to instability and overfitting than LoRA. That is why the chapter recommends a low learning rate, small micro-batch size, gradient accumulation, warmup, weight decay, and gradient checkpointing.
Why is gradient checkpointing important for full SFT?It reduces activation memory by discarding most intermediate activations and recomputing them during backpropagation. This makes full SFT feasible on smaller GPUs, at the cost of extra compute time.
What training signals should you monitor during SFT?The main signals are training loss, validation loss, and gradient norm. Training loss should fall steadily, validation loss should stay flat or improve, and gradient norm should stabilize rather than spike wildly or collapse toward zero.
What does it mean if validation loss stops improving while training loss keeps dropping?That is a classic overfitting pattern. The model is memorizing the training set rather than learning transferable behavior, so you should stop training at the checkpoint with the lowest validation loss.
Does SFT usually improve performance a lot over LoRA?Usually not by a huge amount. The chapter describes SFT’s advantage as real but modest, often only a few percentage points over a well-tuned LoRA adapter, while costs in memory, storage, and maintenance are much higher.
What is the biggest safety risk after full SFT?Catastrophic forgetting and safety regression. A model trained only on helpful examples may become less likely to refuse harmful prompts or acknowledge uncertainty, so the chapter recommends running explicit safety regression tests before deployment.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • LLM Customization and Fine-Tuning ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • LLM Customization and Fine-Tuning ebook for free