Sub topic 2
Why full fine-tuning is expensive
This chapter explains where the cost of full fine-tuning comes from, so the savings from LoRA in later chapters make sense. It assumes you can run a Hugging Face model for inference, know basic PyTorch training loops, and understand that a transformer is made of large weight matrices. No linear algebra beyond matrix shapes is needed here.
What "full fine-tuning" means
Full fine-tuning continues training a pretrained model with every parameter set to trainable. Each step runs a forward pass, computes the loss, backpropagates, and lets the optimizer update all the weights. The result is a new copy of the entire model.
This works well and is the quality baseline for adaptation. The problem is that training a parameter costs far more than storing it.
Memory: the bytes per parameter
Running inference needs the weights and some activation memory. Training needs three more things for every trainable parameter:
- Gradients. One gradient value per weight, produced by backpropagation.
- Optimizer state. AdamW keeps two running statistics per weight: the first moment (mean of gradients) and the second moment (mean of squared gradients).
- Master weights. In mixed-precision training, the forward and backward passes use bf16 or fp16 weights. The optimizer updates a separate fp32 copy, because small updates get lost in 16-bit arithmetic.
A common mixed-precision AdamW setup uses these bytes per parameter:
| Component | Precision | Bytes per parameter |
|---|---|---|
| Working weights | bf16 | 2 |
| Gradients | bf16 | 2 |
| Master weights | fp32 | 4 |
| Adam first moment | fp32 | 4 |
| Adam second moment | fp32 | 4 |
| **Total** | **16** |
Training everything in fp32 also costs 16 bytes per parameter (4 weights, 4 gradients, 8 Adam state). Inference in bf16 needs only 2 bytes per parameter, so training takes about eight times the memory of serving the same model.
A worked estimate
The following script computes the numbers for a 7-billion-parameter model. It also estimates a LoRA run on the same model, using the shapes of a Llama-2-7B-style network (hidden size 4096, 32 layers, adapters on four attention projections).
def gb(n_bytes: float) -> float:
return n_bytes / 1e9
def full_finetune_bytes(n_params: float) -> dict:
parts = {
"weights (bf16)": 2 * n_params,
"gradients (bf16)": 2 * n_params,
"master weights (fp32)": 4 * n_params,
"adam state (fp32)": 8 * n_params,
}
parts["total"] = sum(parts.values())
return parts
def lora_trainable_params(hidden: int, layers: int, r: int, n_proj: int = 4) -> int:
# Each adapted square projection adds A (r x hidden) and B (hidden x r).
return layers * n_proj * r * 2 * hidden
n_params = 7e9
for name, value in full_finetune_bytes(n_params).items():
print(f"full {name:24s} {gb(value):7.1f} GB")
trainable = lora_trainable_params(hidden=4096, layers=32, r=16)
frozen_base = 2 * n_params # bf16, no gradients or optimizer state
adapter_state = 16 * trainable # fp32 adapters with full training state
print(f"\nLoRA trainable params: {trainable:,}")
print(f"LoRA frozen base: {gb(frozen_base):7.1f} GB")
print(f"LoRA adapter state: {gb(adapter_state):7.2f} GB")
print(f"LoRA total: {gb(frozen_base + adapter_state):7.2f} GB")Running it prints:
full weights (bf16) 14.0 GB
full gradients (bf16) 14.0 GB
full master weights (fp32) 28.0 GB
full adam state (fp32) 56.0 GB
full total 112.0 GB
LoRA trainable params: 16,777,216
LoRA frozen base: 14.0 GB
LoRA adapter state: 0.27 GB
LoRA total: 14.27 GBFull fine-tuning of a 7B model needs about 112 GB before counting activations. That exceeds a single 80 GB GPU. The LoRA estimate is about 14.3 GB, because gradients and optimizer state exist only for 16.8 million adapter parameters, about 0.24% of the model.
Both numbers exclude activations, covered next.
Activations are a separate cost
Backpropagation needs the intermediate outputs of the forward pass, called activations. Their size depends on batch size, sequence length, hidden size and layer count, not on how many parameters are trainable. For long sequences they can rival the weight memory.
Two consequences matter in practice:
- LoRA does not remove activation memory. The backward pass still flows through every frozen layer to reach the adapters in early layers.
- Gradient checkpointing trades compute for memory. It discards most activations and recomputes them during the backward pass, typically costing about 20–35% more step time. You will meet it again with QLoRA.
Compute: LoRA saves less than you might expect
A rule of thumb for dense transformers is that training costs about 6 FLOPs per parameter per token. That splits into 2 for the forward pass, 2 for gradients with respect to activations, and 2 for gradients with respect to weights.
LoRA skips the weight-gradient part for the frozen matrices. The cost drops to roughly 4 FLOPs per parameter per token, about a third less. It does not drop by 99%.
The practical benefit of LoRA is therefore memory, not speed. A LoRA run on a 7B model processes tokens at roughly the same order of speed as a full run. What changes is that it fits on hardware you can actually get, and it avoids the communication overhead of sharding a 112 GB training state across several GPUs.
Distributed training raises the bar
If the model does not fit on one GPU, full fine-tuning needs a sharding strategy such as DeepSpeed ZeRO or PyTorch FSDP. These split gradients, optimizer state and optionally weights across devices. They work, but add:
- Multi-GPU or multi-node hardware, with fast interconnects for good throughput.
- More configuration surface: sharding stage, offloading, mixed-precision policy.
- More failure modes, such as out-of-memory on one rank, hangs on collective operations, and checkpoints that must be gathered before saving.
A single-GPU LoRA script avoids all of this. That difference in operational complexity often matters as much as the raw memory figure.
Storage and deployment costs
Full fine-tuning produces a complete model per task. Suppose you serve five customer-specific variants of a 7B model:
| Approach | Artifacts to store | Approximate size |
|---|---|---|
| Full fine-tuning | 5 complete bf16 models | 5 × 14 GB = 70 GB |
| LoRA | 1 base model + 5 adapters | 14 GB + 5 × ~34 MB (bf16 adapters) ≈ 14.2 GB |
The adapter size follows from the parameter count above: 16.8 million parameters at 2 bytes is about 34 MB in bf16, or about 67 MB in fp32.
Full-model checkpoints during training are larger still. A resumable checkpoint includes optimizer state, so saving one every few hundred steps can fill a disk quickly. Serving also changes. Each full model needs its own GPU memory when loaded, while adapters on a shared base can be swapped per request. The serving chapter returns to this.
Risk: forgetting and overfitting
Updating every weight lets the model drift far from its pretrained behavior. With a small, narrow dataset, full fine-tuning can overfit and lose general abilities, a problem called catastrophic forgetting. Large learning rates make it worse.
LoRA does not eliminate this risk, but it constrains the update to a low-dimensional change added to frozen weights. That limits how far the model can move. The next chapters explain why.
Summary of the cost components
| Cost | Full fine-tuning | LoRA |
|---|---|---|
| Gradients and optimizer state | For all parameters | Only for adapter parameters |
| Frozen weights | None | Stored once, no training state |
| Activations | Required | Still required |
| Compute per token | About 6 FLOPs per parameter | About 4 FLOPs per parameter |
| Multi-GPU sharding | Often necessary at 7B+ | Often unnecessary |
| Artifact per task | Whole model | Small adapter |
Remember that memory is the main bottleneck in training, and that most of it goes to training state, not to the weights.
Exercise
You want to fully fine-tune a 3-billion-parameter model with AdamW, using mixed precision with fp32 master weights (16 bytes per parameter). (a) How much memory do the weights, gradients, master weights and optimizer state need, ignoring activations? (b) If you instead freeze the base in bf16 and train LoRA adapters with 12 million parameters (16 bytes each), what is the approximate total? (c) Does LoRA reduce the activation memory?
Show answer
(a) 3e9 × 16 bytes = 48 GB. (b) The frozen base takes 3e9 × 2 = 6 GB, and the adapters take 12e6 × 16 = 0.192 GB, so the total is about 6.2 GB. (c) No. Activations depend on batch size, sequence length and model shape, and the backward pass still passes through every frozen layer, so you need gradient checkpointing or a smaller batch to reduce them.
Exercise
Why does LoRA reduce training compute by only about a third, even though it trains under 1% of the parameters?
Show answer
The forward pass (about 2 FLOPs per parameter per token) and the gradient with respect to activations (about 2) still run through all the frozen weights. LoRA only skips the weight-gradient computation (about 2) for the frozen matrices, which takes the total from roughly 6 to roughly 4 FLOPs per parameter per token.