Overview

4 Instruction Fine-tuning

Instruction fine-tuning is presented as the practical bridge between pretrained language models and the RLHF pipeline. Early models could continue text well, but they were not naturally organized to follow explicit user requests, so a question like “What is the boiling point of water?” might produce an irrelevant continuation instead of a direct answer. Instruction tuning addresses this by training models on instruction-response examples, teaching them to treat prompts as tasks to complete rather than text to extend, which makes them more useful and sets up the later stages of preference learning and reinforcement optimization.

The chapter explains that this approach became widespread because two trends converged: NLP research moved toward unified text-to-text and instruction-style training, and scaling plus in-context learning showed that general models could transfer across many tasks. Once instruction following was shown to improve when it was explicitly trained, large collections of prompts and responses became the standard way to adapt models. The result is a supervised fine-tuning stage, often called SFT or instruction tuning, that produces a model better aligned with the format and behavior expected in conversational and assistant settings.

A major focus is on how instruction-tuned systems are formatted in practice. Conversations are encoded with chat templates that assign roles such as system, user, and assistant, then serialize them into token sequences the model can learn from. The chapter also highlights best practices: use high-quality data, focus on prompts similar to downstream use, and recognize that around a million prompts can be enough for strong post-training performance, with diminishing returns beyond that. Implementation details differ from pretraining by using smaller batch sizes, masking prompt tokens, handling multi-turn data carefully, and using much smaller learning rates, all of which help the model learn responses without overwriting the general knowledge gained during pretraining.

Summary

  • Instruction fine-tuning (IFT/SFT) teaches pretrained language models to respond in an instruction-response format, and is the foundation that all later post-training stages – from preference data collection to RLHF optimization – depend on.
  • Chat templates define how user queries, system prompts, and assistant responses are formatted into token sequences using special tokens, and are the standard interface between users and instruction-tuned models.
  • Successful instruction tuning depends on high-quality data, prompt distributions that match downstream tasks, and choosing scale appropriately within the broader post-training pipeline.
  • Implementation details include smaller batch sizes than pretraining, prompt masking so the model learns responses rather than queries, and multi-turn masking strategies that control which assistant turns are trained on.

FAQ

What is instruction fine-tuning, and why is it important before RLHF?Instruction fine-tuning (IFT), also called supervised fine-tuning (SFT), trains a pretrained language model to follow instructions in a question-answer format. It is important because RLHF assumes the model already has basic instruction-following ability; without it, later stages like preference data collection and online RLHF optimization are much harder or impossible.
How is an instruction-tuned model different from a base pretrained model?A base pretrained model mainly continues text based on next-token prediction, often producing related but unhelpful continuations. An instruction-tuned model is trained to respond directly to the user’s request, so it learns to produce relevant answers instead of just continuing the prompt.
Why did instruction fine-tuning become popular?It became popular because two trends converged: NLP moved toward unified text-to-text and instruction-based task framing, and scaling plus in-context learning showed that a single model could generalize across many tasks. Fine-tuning on large instruction datasets made that generalization more reliable and practical.
What is a chat template?A chat template is the formatting scheme used to structure conversations for a language model. It defines how system, user, and assistant messages are converted into tokens so the model can read the interaction consistently during training and generation.
What roles are commonly used in chat-formatted training data?The traditional roles are system, user, and assistant. The system role provides hidden or top-level instructions, the user role contains the input query, and the assistant role contains the model’s response.
Why is prompt masking used during instruction tuning?Prompt masking prevents the model from learning to predict the user’s questions. Instead, the loss is applied mainly to the response tokens, so the model learns to generate answers rather than imitate prompts.
What are the two common approaches to masking in multi-turn conversations?The first is final-turn only, where only the last assistant response is trained on and earlier context is masked. The second is mask user turns only, where all user messages are masked but every assistant message contributes to the loss.
How do batch sizes in instruction tuning compare to pretraining?Instruction tuning usually uses much smaller batch sizes than pretraining. This is because post-training operates on a narrower data distribution and often uses fewer training tokens, so smaller batches are sufficient and can help keep optimization stable.
Why is the learning rate usually smaller for SFT than for pretraining?SFT typically uses a learning rate one to two orders of magnitude smaller because the model starts from a strong pretrained initialization and is trained on smaller datasets with smaller batches. Conservative updates help avoid destabilizing the model while adapting it to instruction-following behavior.
What makes good instruction-tuning data?High-quality completions matter most, since the model learns primarily from the responses. It also helps if the prompts resemble the downstream tasks the model will later face, and around one million prompts can already support very strong post-training performance in many settings.

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
  • Reinforcement Learning from Human Feedback 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
  • Reinforcement Learning from Human Feedback 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
  • Reinforcement Learning from Human Feedback ebook for free