Why train fewer parameters
9 min read
The cost of updating every weight
Full fine-tuning updates every weight, as Fitting training into memory showed. Each trainable weight needs a gradient and optimiser state next to it, so a 7 billion weight model can need over 100 GB of GPU memory before any activations are counted. A single consumer card does not have that, and renting a larger one costs more for every experiment.
Storage is the second cost. Every fully tuned model is a complete copy of the weights. If you serve five tasks, five copies of a 14 GB file take 70 GB, and each one has to be loaded, versioned and kept in step with its tokenizer.
Freeze the base, train an adapter
The idea is to freeze the base model, which means the optimiser never changes its weights, and add a small set of new weights that does change. The forward pass uses both. Only the new weights need gradients and optimiser state. The frozen weights are still loaded, still used in every forward pass, and still take memory, but they carry no extra training state.
The new weights are called an adapter. They live in their own small file, and you attach them to the matching base model at load time.
Count what you save
The program below counts the attention weights of a 7 billion parameter style model with 32 layers and a width of 4,096. It compares training all four attention projections in full with training a LoRA adapter of rank 8 on the same four. The next Lesson explains what rank means. For now it is the size of the adapter.
hidden, layers, projections, rank = 4096, 32, 4, 8
bytes_per_value = 2
full = layers * projections * hidden * hidden
adapter = layers * projections * 2 * hidden * rank
print(f"attention weights, full: {full:,} ({full * bytes_per_value / 1e9:.2f} GB at 16-bit)")
print(f"adapter, rank {rank}: {adapter:,} ({adapter * bytes_per_value / 1e6:.1f} MB)")
print(f"trainable share: {adapter / full:.2%}")
tasks, base_gb = 5, 14
adapter_gb = adapter * bytes_per_value / 1e9
print(f"{tasks} tasks as full copies: {tasks * base_gb} GB")
print(f"{tasks} tasks as one base plus adapters: {base_gb + tasks * adapter_gb:.2f} GB")It prints:
attention weights, full: 2,147,483,648 (4.29 GB at 16-bit)
adapter, rank 8: 8,388,608 (16.8 MB)
trainable share: 0.39%
5 tasks as full copies: 70 GB
5 tasks as one base plus adapters: 14.08 GBThe adapter has about 8.4 million numbers, 0.39% of the 2.1 billion attention weights, and its file is about 17 MB. Five tasks that would take 70 GB as full copies fit in about 14 GB of base model plus five small adapter files. The saving in training memory follows from the same count: gradients and optimiser state are needed only for the adapter's weights, not for the whole model.
These numbers cover attention weights only, and a real model also has feed-forward layers and embeddings. The shape of the result holds anyway: the trainable part is a small fraction of the whole.
What else changes
- Sharing. Many adapters can sit on one base model, so you can keep one adapter per task, customer or language.
- Experiments. A small adapter is quick to save, copy and compare, which makes it cheap to try several settings.
- Reset. Detach the adapter and you have the original behaviour back, which helps with Catastrophic forgetting because the base weights never moved.
- Dependencies. An adapter only works with the base model it was trained on. Keep the base model identity, tokenizer and adapter settings together as one record.
What you give up
An adapter limits how the model can change. For many tasks that is enough, and it often matches full fine-tuning on narrow, well-defined jobs. For a large shift, such as teaching a model a new language or a very different domain, a small adapter can fall short.
Methods also differ in speed. The forward and backward passes still run through the full model, so training is not always much faster. The main savings are in memory and storage, and the speed you get depends on the setup.
So the rule is the usual one. Train an adapter first, evaluate it on held-out cases with the same measures as the base model, and move to more trainable weights only if the results show you need them. Evaluating a fine-tuned model covers that comparison.
The main methods
The rest of this module covers them in turn.
| What it trains | Why use it | |
|---|---|---|
| LoRA | Two small matrices beside chosen layers | LoRA keeps the base frozen and trains the adapter |
| QLoRA | A LoRA adapter on a 4-bit frozen base | Fits large models on one GPU |
| Prompt, prefix and adapter layers | Learned inputs or small modules | Fewest trained numbers |
The Lessons How LoRA works and LoRA in code come first, then Quantisation and QLoRA and Other efficient methods. For the library that implements these methods, see the Hugging Face PEFT overview.
What is the main saving of parameter-efficient tuning?
Full tuning of a 7B model needs a large cluster.
Only a small number of new weights are trained and saved.
What stays frozen?
You use LoRA.
The base weights do not change, so one base can serve many adapters.
What can efficient methods not promise?
A team assumes the result will match full tuning.
Quality is usually close but should be measured on your task.
Your reading position is saved
0 of 36 complete
Lesson complete
Why train fewer parameters
Up next