Foundation Models and Finetuning
The more trainable parameters a model has, the higher its memory footprint during finetuning. Reducing the number of parameters that are updated is therefore a direct route to lower finetuning memory. This reasoning is the motivation for PEFT.
Why Large Models Strain Memory
Foundation models are very large, and that size is where the trouble starts. Because of their scale, memory is a bottleneck for working with them. This is true in two situations: when you run a model to produce outputs, which is called inference, and when you adjust a model for a specific task, which is called finetuning.
Keep both situations in mind as you read. The goal of this article is to trace where memory goes, why finetuning asks for much more of it than inference, and which two techniques, parameter-efficient finetuning and quantization, are designed to reduce it.
Tracing Memory Through Inference and Finetuning
A model's memory footprint is the amount of memory it occupies.
Inference uses a model to produce outputs. Finetuning uses a model as a starting point and adjusts it for a specific task. The source is clear that finetuning typically needs much more memory than inference for the same model. So when you move from running a model to finetuning it, the memory question changes from whether the model fits to whether the extra work of adjusting it also fits.
This difference is the core of the memory bottleneck. The model itself is the same in both cases. What differs is the additional state that finetuning needs, and the next section names the three factors that drive the total.
The Three Contributors to the Footprint
During finetuning, the source identifies three key contributors to a model's memory footprint. The first is the number of parameters, which describes the model itself. The second is the number of trainable parameters, which describes how many of those parameters are adjusted during finetuning. The third is the numerical representations, which describe how many bits are used to store each value.
The three contributors are not interchangeable, and that is what makes them useful to reason about. The number of parameters is a property of the model. The number of trainable parameters is a property of the finetuning process, because it counts how many parameters are adjusted. The numerical representations are a property of storage, because they set how many bits each value uses. Each one feeds into the total, so reducing any one of them can reduce the footprint.
The more trainable parameters a model has, the higher its memory footprint during finetuning. Reducing the number of parameters that are updated is therefore a direct route to lower finetuning memory. This reasoning is the motivation for PEFT.
How PEFT Cuts Trainable Parameters
Parameter-efficient finetuning, usually called PEFT, reduces the memory needed for finetuning by reducing the number of trainable parameters. It leaves the model's overall parameter count where it is. What it changes is how many of those parameters are adjusted when the model is finetuned.
Read the diagram as a split. Most of the pretrained model stays fixed, and only a reduced set of parameters is adjusted. Because the memory cost of finetuning grows with the number of trainable parameters, shrinking that set shrinks the cost. The model still has the same number of parameters, so PEFT is aimed at the second contributor, not the first.
How Quantization Shrinks Each Value
Quantization targets the third contributor, the numerical representations. It reduces memory by converting a model to fewer bits per value. The source gives 16 bits, 8 bits, and even 4 bits as examples of the lower widths used. Fewer bits per value means each stored number occupies less space, so the whole model takes up less memory without changing how many parameters it has.
Halving the size of a 13 billion parameter model
A 13 billion parameter model occupies 52 GB when stored in its original numerical format. After quantization to fewer bits per value, it occupies 26 GB. Explain what the change tells you.
- 1Identify the starting size
The model starts at 52 GB. This is the footprint before quantization.
- 2Identify the ending size
After converting the model to fewer bits per value, the footprint is 26 GB.
- 3Compare the two sizes
The footprint drops from 52 GB to 26 GB, which is half the original size.
- 4Connect the change to bits
The number of parameters stays at 13 billion. Only the bits used per value change, so the reduction comes from the numerical representation, which is the third contributor.
Quantization reduced the footprint from 52 GB to 26 GB by storing each value in fewer bits, while the parameter count stayed the same.
Inference Precision Versus Training Precision
Quantization fits inference most naturally. The source explains that inference is typically done using as few bits as possible. Training is different. It is more sensitive to numerical precision, which makes it harder to train a model in lower precision. The table below sets the two side by side.
| Aspect | Inference | Training |
|---|---|---|
| Typical precision | As few bits as possible, such as 16, 8, or 4 bits | Mixed precision: some operations in higher precision such as 32-bit, others in 16-bit or 8-bit |
| Sensitivity to precision | Lower, so quantization fits well | Higher, which makes lower precision harder to train with |
| Main memory lever | Storing values in fewer bits | Keeping higher precision where needed while using fewer bits elsewhere |
Numerical precision in inference and training, as described in the source
Training is typically done in mixed precision. Some operations run in higher precision, such as 32-bit, and others run in lower precision, such as 16-bit or 8-bit. The mix lets training use fewer bits in places while keeping higher precision where the source says it is needed for stability of training.
Predicting the Footprint After Quantization
What do you think happens?
A 13 billion parameter model takes 52 GB at its original precision. If it is quantized from 32-bit values to 16-bit values and the parameter count stays the same, what is its new footprint?
Reveal answer
26 GB
Halving the bits per value halves the stored size, and the number of parameters does not change. The source gives this exact move from 52 GB to 26 GB for a 13 billion parameter model.
A team finetunes a model using PEFT so that far fewer parameters are trainable, and separately quantizes the model to fewer bits per value. Name which contributor each technique targets, and say whether either one changes the total number of parameters in the model.
Hints
- Recall the three contributors: number of parameters, number of trainable parameters, and numerical representations.
- PEFT reduces the number of trainable parameters. Quantization converts the model to fewer bits per value.
- The source says PEFT reduces memory by reducing trainable parameters, and it does not say it removes parameters from the model.
Mistakes Beginners Make With Memory and Precision
Common mistake Assuming finetuning needs about the same memory as inference
Why it failsThe source states that finetuning typically needs much more memory than inference for the same model, because finetuning adds the trainable parameters and their numerical handling to the footprint.
Do this insteadEstimate finetuning memory separately, and consider the number of trainable parameters as well as the size of the model.
Common mistake Thinking PEFT reduces the number of parameters in the model
Why it failsPEFT reduces the number of trainable parameters, which is the second contributor. The model's overall parameter count is the first contributor, and PEFT targets the trainable subset.
Do this insteadDescribe PEFT as reducing how many parameters are adjusted during finetuning.
Common mistake Treating quantization and PEFT as targeting the same contributor
Why it failsQuantization changes the numerical representations, which is the third contributor. PEFT changes the number of trainable parameters, which is the second.
Do this insteadMatch each technique to its contributor: PEFT to trainable parameters, quantization to bits per value.
Common mistake Assuming lower precision works equally well for training and inference
Why it failsThe source says inference is typically done with as few bits as possible, while training is more sensitive to numerical precision.
Do this insteadUse aggressive low-bit storage naturally for inference, and use mixed precision for training.
Key Takeaways
- Memory is a bottleneck for foundation models during both inference and finetuning, and finetuning typically needs much more memory than inference.
- During finetuning, a model's memory footprint is driven by its number of parameters, its number of trainable parameters, and its numerical representations.
- PEFT reduces the memory needed for finetuning by reducing the number of trainable parameters, which is the motivation behind it.
- Quantization reduces memory by converting a model to fewer bits per value, as shown by the move from 52 GB to 26 GB for a 13 billion parameter model.
- Inference typically uses as few bits as possible, while training is more sensitive to precision and is typically done in mixed precision.