Skip to content
ImagineWorld

Supervised Fine-Tuning and Parameter-Efficient Methods

node_idnode-book_llm-systems-engineering_module-28-supervised-fine-tuning-and-parameter-efficient-methods
node_typechapter-node
schema_profileworld.chapter_node.v1
statusactive
entropyhigh
manifoldworld
domainimagineworld.net
authorityinforms
layercorpus
chapter_num28
chapter_titleSupervised Fine-Tuning and Parameter-Efficient Methods
governed_byCORPUS
constitutional_citationCONSTITUTION
local graph

Module 28 — Supervised Fine-Tuning and Parameter-Efficient Methods

Section titled “Module 28 — Supervised Fine-Tuning and Parameter-Efficient Methods”

Fine-tuning success depends as much on the configuration of the training loop as on the quality of the data consumed. Parameter-efficient methods have made fine-tuning feasible on hardware that cannot accommodate updates to every weight in a large model. Among these methods, Low-Rank Adaptation has emerged as the most widely adopted, expressing weight changes in a compressed form that preserves expressive power while reducing memory footprint substantially. The choice between full fine-tuning and efficient alternatives carries consequences for training cost and for the preservation of prior capabilities. This module examines the fine-tuning loop and the methods used to perform it efficiently.

The supervised fine-tuning loop resembles pretraining in its outer structure, yet the configuration of each component is tuned to a different objective. During pretraining, the model minimizes next-token prediction loss across every token in the sequence, teaching the network to model the full distribution of natural language. During supervised fine-tuning, the loss is computed only over the tokens corresponding to the assistant response, with instruction tokens masked out so that the gradient does not push the model to generate prompts of its own (Wang et al., 2023b). This response-only masking is implemented at the level of the loss function by setting label values of prompt tokens to a sentinel index that the loss routine ignores.

Pretraining
┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐
│ The │ │ cat │ │ sat │ │ on │ │ the │ │warm │ │ mat │
└──┬──┘ └──┬──┘ └──┬──┘ └──┬──┘ └──┬──┘ └──┬──┘ └──┬──┘
↓ ↓ ↓ ↓ ↓ ↓ ↓
┌───────────────────────────────────────────────────────┐
│ Next-token loss across all 7 tokens │
└───────────────────────────────────────────────────────┘
Supervised fine-tuning
┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐
│User:│ │Name │ │a cat│ │ A: │ │ Try │ │ Mr. │ │ Pip │
└─────┘ └─────┘ └─────┘ └──┬──┘ └──┬──┘ └──┬──┘ └──┬──┘
↓ ↓ ↓ ↓
┌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┐ ┌───────────────────────────────┐
╎ Masked ╎ │ Loss on 4 response tokens only│
└╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┘ └───────────────────────────────┘

Figure 5-4. Loss Coverage in Pretraining vs. Supervised Fine-Tuning

Learning rates in fine-tuning are set one or two orders of magnitude below pretraining values. A rate that worked well during pretraining, say 3e-4 (a learning rate of 0.0003), will overwrite pretrained representations too aggressively when applied to the smaller, more targeted fine-tuning corpus. Practitioners commonly use values between 1e-5 and 2e-4 depending on model size and on whether adapters are being trained in place of full weights. Warmup is usually brief, since the starting point is already a well-conditioned network and only a short ramp is needed to prevent early instability.

Epoch counts are another area where fine-tuning differs sharply. Pretraining typically sees data once or close to once across the full corpus. Fine-tuning datasets are much smaller, often containing between a few thousand and a few hundred thousand examples, and models commonly traverse them two or three times. Running many more epochs tends to cause overfitting, where the model memorizes specific responses and loses the generality inherited from pretraining.

Full Fine-Tuning and Selective Layer Updates

Section titled “Full Fine-Tuning and Selective Layer Updates”

When engineers decide how to fine-tune, the first question is whether every weight in the model should receive gradient updates or whether only a subset should. Full fine-tuning updates all parameters simultaneously and provides the greatest capacity for the model to adapt. It also demands optimizer state memory proportional to the full parameter count, which for a 70 billion-parameter model can exceed half a terabyte when AdamW moments are held in 32-bit precision. This memory footprint prices full fine-tuning out of reach for most organizations that do not have access to multi-node training clusters.

Selective layer updates restrict gradient flow to a chosen subset of transformer blocks. Common choices are the final few decoder layers, which are thought to encode the most task-relevant representations, or the embedding and output projection layers when vocabulary adaptation is desired. Freezing the remaining layers reduces optimizer memory and stabilizes training when the fine-tuning dataset is small, because the preserved layers cannot drift away from their pretrained configuration. Updating only the top quarter of layers can recover most of the performance gain of full fine-tuning on narrow task suites, though the gap widens on tasks that require broader behavioral change.

Model size interacts strongly with this decision. For a 1 billion-parameter model, full fine-tuning on a single high-memory GPU is feasible, and the additional capacity is often worth the cost. For a 13 billion-parameter model, full fine-tuning typically requires multiple GPUs with tensor parallelism or a more memory-efficient approach. Dataset scale also matters. When only a few thousand examples are available, updating all weights tends to overfit, and selective updates or parameter-efficient methods yield better generalization. Available compute is the final practical consideration. Teams working with a single A100 or H100 card will find that selective updates keep runs within hours, while full fine-tuning of a mid-size model can stretch into days of continuous training.

Low-Rank Adaptation addresses the memory constraints of fine-tuning by changing what is trained. LoRA freezes the pretrained weights and introduces a pair of smaller matrices, AA and BB, whose product approximates the weight update that would otherwise be applied. The original matrix WW has dimensions dd by kk. Inside LoRA, AA has dimensions dd by rr while BB has dimensions rr by kk, where rr is the chosen rank and is typically much smaller than either dd or kk.

During training, only AA and BB receive gradient updates. The pretrained WW remains frozen throughout. At inference time, the effective weight can be reconstructed as WW plus the product BABA, which means a trained LoRA adapter can be merged back into the base model with no additional latency cost. A typical LoRA configuration for a 7 billion-parameter model trains only around 0.1 to 1 percent of the total parameters, depending on which matrices are targeted and the chosen rank.

Rank selection governs the balance between expressive capacity and efficiency. A rank of 8 is a common default for language modeling tasks and offers a small parameter footprint while still capturing most of the behavioral change induced by fine-tuning. Higher values such as 32 or 64 provide more capacity and are useful for broader adaptation tasks including learning a new domain vocabulary or accommodating a style change across many response types. Higher ranks provide diminishing returns on most supervised fine-tuning benchmarks, with rank 16 often performing within a fraction of a percentage point of full fine-tuning while reducing trainable parameters by two orders of magnitude.

An important property of LoRA is that its weight update can be merged back into the base model once training is complete. This produces a final model whose inference cost is identical to the original. A further advantage is that multiple LoRA adapters can be trained independently on the same base and swapped at serving time, enabling a single deployment to serve several specialized variants without maintaining separate full-model copies.

Before LoRA gained dominance, adapter-based methods were the most widely used form of parameter-efficient fine-tuning. Adapters insert small projection blocks between transformer layers. Each adapter compresses the hidden state to a lower dimension, applies a nonlinearity, and projects back up to the original dimension (Houlsby et al., 2019). Only the adapter parameters are trained, and the surrounding transformer layers are frozen. Adapter layers introduce a small additional latency at inference time because they add sequential operations to every forward pass. This serial overhead is the main reason LoRA has overtaken adapters in most production settings, since merged LoRA weights impose no runtime cost at all.

Prefix tuning takes a different approach. It leaves the model weights entirely unchanged and prepends a sequence of trainable vectors to the key and value states at each transformer layer (Li & Liang, 2021). These learned prefixes condition the model’s behavior without modifying its weights. Prefix tuning is extremely lightweight in parameter terms, often training fewer than 0.1 percent of the total parameters, and it is attractive in settings where many specialized variants must coexist. Its main limitation is that capacity is bounded by the prefix length, and it often underperforms LoRA on tasks that require substantial behavioral adaptation.

Choosing among these methods depends on the interaction between hardware limits and the scope of adaptation required by the task. LoRA is the default choice for most supervised fine-tuning work on modern language models because it combines strong adaptation capacity with negligible inference overhead once adapters are merged. Adapters remain useful when the training framework does not support low-rank decompositions cleanly or when the practitioner wants to retain and swap adapters at runtime without merging. Prefix tuning is best suited to settings where many lightweight variants of the same base model must be maintained and where each variant requires only a modest behavioral change.

Quantized variants such as QLoRA combine LoRA with 4-bit base-model quantization, allowing fine-tuning of models as large as 65 billion parameters on a single consumer GPU (Dettmers et al., 2023). This has broadened access to fine-tuning substantially, making it possible for small teams to adapt frontier-scale models on hardware previously considered inadequate. The cost is a small reduction in precision during the forward pass, which empirical work has shown to be recoverable through slightly higher LoRA rank or longer training. The practical workflow for most teams begins with LoRA at a modest rank. Only if that initial run fails to meet the target behavior does the engineer escalate to higher ranks or to full fine-tuning, matching the method to the actual difficulty of the adaptation task.