What it is
PEFT (parameter-efficient fine-tuning) is a family of methods that adapt a model by training a small number of new weights while the original ones stay frozen. LoRA (Low-Rank Adaptation), introduced by Hu et al. in 2021, is the most widely used. It rests on one observation: the change fine-tuning needs to make to a large weight matrix can be described with far fewer numbers than the matrix itself. In mathematical terms, the change has low rank.
How it works
Take one linear layer with weight matrix W of shape d × k. Full fine-tuning would learn a change ΔW of the same shape: d × k new numbers. LoRA instead learns that change as the product of two thin matrices. A (r × k) squeezes the layer's input down to r numbers, and B (d × r) expands them back. The rank r is small, typically 4–64, while d and k are in the thousands.
h = W·x + (α / r) · B·A·x
W : d × k frozen
A : r × k trainable, random at the start
B : d × r trainable, zero at the start → B·A = 0 at step 0
trainable weights per adapted layer = r × (d + k)- Initialisation. A starts random and B starts at zero, so B·A = 0 and the adapted model is exactly the base model at step 0. Training moves it away gradually.
- Scaling. The adapter's output is multiplied by alpha ÷ r. This keeps the size of its effect roughly stable when r changes, so the learning rate doesn't need re-tuning for every rank. A variant, rank-stabilised LoRA (rsLoRA), divides by the square root of r instead, which behaves better at high ranks.
- Merging. After training, B·A can be multiplied out and added into W. The merged model has the original shape and runs at the original speed, with no added latency. Or the adapter is kept as a small separate file and loaded on top of the base, which lets one base model serve several adapters.
- One 4096 × 4096 attention projection: 16.8 million weights in W.
- LoRA at rank 8: A is 8 × 4096 and B is 4096 × 8, so 2 × 4096 × 8 = 65,536 trainable weights, 0.4% of the layer.
- A Llama-style 7B model at rank 16 on all linear layers (four attention and three MLP projections in each of 32 layers): about 40 million trainable weights, roughly 0.6% of the model.
- Training memory: those 40 million weights need about 0.6 GB for gradients and AdamW state, against about 112 GB for full fine-tuning of all 7 billion.
- The saved adapter in 16-bit is about 80 MB, against 14 GB for a full copy of the model.
- In the original paper, on GPT-3 175B, LoRA reduced trainable parameters by up to 10,000× and GPU memory by about 3× compared with full fine-tuning with Adam.
The settings
The inner dimension of A and B, and so the adapter's capacity: how many independent directions of change it can learn in each layer. Trainable weights grow in proportion to r. Low ranks are enough for tone, style and format; larger, knowledge-heavy datasets benefit from more. Once the adapter has enough capacity for the data, a higher rank adds cost without improving results. Some providers call this the adapter size.
A scaling factor: the adapter's output is multiplied by alpha ÷ r. A larger alpha makes every update count for more, much like a higher learning rate, which is why many setups fix alpha and tune the learning rate instead. Common conventions are alpha equal to r, alpha equal to twice r, or a fixed value such as 16 or 32. Pick one convention and keep it: changing r while alpha stays fixed also changes the scale.
- Target modules decide which layers get an adapter. The original paper adapted only the attention query and value projections. Later work, including QLoRA and a 2025 study by Thinking Machines, found that adapting all linear layers, especially the MLP (feed-forward) layers, is needed to match full fine-tuning. Libraries usually offer an ‘all linear layers’ option.
- LoRA dropout randomly zeroes part of the adapter's input during training, a mild guard against overfitting on small datasets. Common values are 0 to 0.1.
- Learning rate. LoRA usually needs a higher learning rate than full fine-tuning: about ten times higher in the Thinking Machines study, which also found the best rate changes little across ranks.
- Batch size. The same study found LoRA tolerates very large batches less well than full fine-tuning, so moderate batch sizes are the safer choice.
QLoRA: adapters on a 4-bit base
QLoRA (Dettmers et al., 2023) trains ordinary 16-bit LoRA adapters but stores the frozen base model in a 4-bit format designed for normally distributed weights (NF4). It adds double quantisation, which compresses the quantisation constants themselves, and paged optimizers that absorb memory spikes. The paper fine-tuned a 65B-parameter model on a single 48 GB GPU while preserving the task performance of 16-bit fine-tuning. The trade-off is speed: the 4-bit weights are unpacked on the fly, so each step is somewhat slower.
When LoRA is the right choice
| Situation | Usually prefer |
|---|---|
| Tone, format or domain phrasing, from hundreds to thousands of examples | LoRA |
| Limited GPU memory or budget | LoRA, or QLoRA |
| Several task-specific variants of one base model | LoRA: one small adapter each |
| Keeping the base model's general abilities matters | LoRA, which forgets less |
| Very large datasets teaching substantial new skills, such as code or maths | Full fine-tuning may learn more |
Common mistakes
- Adapting only the attention layers. On most fine-tuning data this underperforms adapters on all linear layers, including the MLP.
- Reusing a full fine-tuning learning rate. LoRA typically needs one around ten times higher, or it barely learns.
- Changing the rank while alpha stays fixed, without noticing that alpha ÷ r, and so the effective step size, changed too.
- Expecting a higher rank to rescue a small or inconsistent dataset. Capacity doesn't help when the examples show no clear pattern.
- Loading an adapter on a different base model, or a different version of it, than the one it was trained on.
References and further reading
External sources open in a new tab.
- 01LoRA: Low-Rank Adaptation of Large Language ModelsHu et al., 2021 · arXiv · arxiv.orgThe original paper: the low-rank idea, the alpha ÷ r scaling and the GPT-3 results.
- 02QLoRA: Efficient Finetuning of Quantized LLMsDettmers et al., 2023 · arXiv · arxiv.org4-bit NF4 base weights, double quantisation and paged optimizers.
- 03LoRA Without RegretThinking Machines Lab, 2025 · thinkingmachines.aiWhen LoRA matches full fine-tuning, why all layers matter, and the 10× learning-rate rule.
- 04LoRAHugging Face PEFT docs · huggingface.coEvery LoRA setting as implemented: rank, alpha, dropout, target modules and rsLoRA.
- 05A Rank Stabilization Scaling Factor for Fine-Tuning with LoRAKalajdzievski, 2023 · arXiv · arxiv.org