The Problem with Full Fine-Tuning
Training every weight of a large model needs huge memory for the weights, gradients and optimizer states. Many people cannot afford that hardware.
The LoRA Idea
LoRA (Low-Rank Adaptation) freezes the original weights. For a weight matrix of size d x k it adds two small matrices, A and B, with a small rank r. Only these are trained. The update is their product, which is added to the original output.
rank 4 -> trainable 32768 = 0.2 % of full matrix | rank 8 -> trainable 65536 = 0.39 % of full matrix | rank 16 -> trainable 131072 = 0.78 % of full matrix | rank 64 -> trainable 524288 = 3.12 % of full matrix
At rank 8 the adapter trains well under 1% of that matrix. The saved adapter file is small and can be swapped for different tasks on the same base model.
QLoRA
QLoRA goes further. It loads the frozen base model in 4-bit precision to save memory, then trains LoRA adapters in higher precision on top. The Hugging Face PEFT documentation shows this with the bitsandbytes library and the nf4 4-bit data type.
16 bit weights for a 7B model ~ 14.0 GB | 8 bit weights for a 7B model ~ 7.0 GB | 4 bit weights for a 7B model ~ 3.5 GB
This counts only the weights. Training also needs memory for activations, adapters and optimizer states, so real usage is higher.
Typical Settings (Shape of the Code)
Key Settings
| Setting | Meaning |
|---|---|
| r (rank) | Adapter size. Higher can learn more but costs more |
| lora_alpha | Scaling of the adapter's effect |
| target_modules | Which layers get adapters |
| lora_dropout | Helps against overfitting |
| learning rate and epochs | Start small, watch validation loss |
Practice
- Compute adapter size for d = 2048, k = 8192, r = 16
- Compare 4-bit and 16-bit weight size for a 13B model
- Write why you must keep a validation set
Conclusion
LoRA trains small adapters and QLoRA also compresses the base model, so large models can be tuned on modest hardware.

