Fine-Tuning and Customization
12.1 What Is Fine-Tuning
After pre-training, the model has general knowledge about language, but may not behave as desired for specific tasks. Fine-tuning is the process of continuing to train the model on a smaller, more specific dataset, steering its behavior toward a particular domain or application.
Fine-tuning is considerably cheaper than pre-training, as it requires far less data and compute. While pre-training can take weeks or months, fine-tuning can be completed in hours or days. This makes it possible to adapt large models to specific applications even with limited computational resources.
12.2 Supervised Fine-Tuning
The most direct form of fine-tuning is supervised fine-tuning (SFT), in which the model is trained on a set of desired input-output examples. For instance, to create a programming assistant, we could fine-tune the model with pairs of programming questions and correct answers.
During SFT, the model’s parameters are updated to maximize the probability of generating the desired answers given the input prompt. The model learns the format and style of the example answers, acquiring new behaviors without completely forgetting the knowledge from pre-training.
In instruction tuning, the examples are organized as instruction, optional context, and response. This change teaches the model to interpret requests and produce useful formats, instead of merely continuing raw text. The quality, diversity, and consistency of the supervised responses matter more than repeating nearly identical examples many times.

12.3 Reinforcement Learning from Human Feedback (RLHF)
A particularly influential technique is reinforcement learning from human feedback (RLHF). RLHF combines supervised fine-tuning with reinforcement learning to align the model with human preferences.
The RLHF process typically involves three steps. First, reward models are trained on human comparisons of pairs of responses. Second, the language model is optimized using the reward model as the objective function through reinforcement learning algorithms such as PPO (Proximal Policy Optimization). Third, the cycle can be repeated to continuously refine the preferences.
RLHF was fundamental in creating models such as ChatGPT, which demonstrate behavior more aligned with user intentions and generate more helpful and less problematic responses than models that are only pre-trained.
12.4 LoRA and Other Efficiency Techniques
Before comparing efficient methods, it is useful to separate three goals. Instruction tuning teaches format and behavior from instruction-response pairs; domain adaptation brings vocabulary and patterns closer to a given field; preference alignment favors comparatively desired responses. None of them guarantees correct facts or eliminates the need for evaluation.
Full fine-tuning of large models is prohibitively expensive for many use cases, since it involves updating billions of parameters. Computational-efficiency techniques were developed to solve this problem.
LoRA (Low-Rank Adaptation) is a technique that adds small trainable matrices to the model’s layers while keeping the original parameters frozen. This drastically reduces the number of parameters that need to be optimized during fine-tuning, while maintaining results comparable to full fine-tuning.
Other techniques include QLoRA, which combines LoRA with quantization to reduce memory requirements even further, and adapter methods, which introduce small, trainable modules at strategic points in the architecture.
12.4.1 What Really Changes in LoRA
For a frozen matrix , LoRA learns a low-rank update , with rank much smaller than the original dimensions. The forward pass then uses . Thus, we train few variables without discarding the knowledge of the base model.
Avoid evaluation leakage
Split training, validation, and test sets by document or source when similar examples can repeat. A random split by row can place near-duplicates in all three sets and produce an overly optimistic estimate.
12.5 Deciding What to Adapt
Full fine-tuning offers maximum freedom, but requires memory for the gradients and optimizer states of all weights. PEFT restricts the update to a small fraction. Before choosing, ask whether the goal is to teach a format, incorporate terminology, change preferences, or introduce updatable factual knowledge. For the latter, external retrieval may be easier to correct and audit.
In LoRA, the rank controls the capacity of the update. Very small values may limit adaptation; larger values consume more memory and may make overfitting easier. The scaling factor regulates the contribution of , and dropout on the LoRA path can help with small datasets.
After training, the adapters can remain separate or be merged into . Keeping them separate makes it easy to swap specializations; merging them simplifies inference. In both cases, the exact base model and the target modules must be recorded.
12.6 Knowledge Distillation
In distillation, a student model learns from the outputs of a teacher model. Instead of receiving only the correct token, the student can approximate the teacher’s entire smoothed distribution. Relationships among alternatives — for example, two tokens that are almost equally plausible — carry information that a hard label discards.
An objective function can combine the supervised loss with a divergence between distributions:
where is the temperature used to smooth the logits. Distillation can produce smaller and cheaper models, but it also transmits the teacher’s errors and biases. Transfer data, coverage, and independent evaluation remain essential.
Tuning does not replace safety
Desired behavior on the training set does not guarantee robustness outside it. Evaluate conflicting instructions, long inputs, different languages, and attempts to circumvent policies.