# LoRA: Low-Rank Adaptation of Large Language Models

> Freezes the pretrained model and learns a low-rank update for each attention matrix. On GPT-3 175B it matches or beats full fine-tuning with 10,000× fewer trainable parameters, 3× less GPU memory and no added inference latency.

- arXiv: https://arxiv.org/abs/2106.09685
- Authors: Edward J. Hu, Yelong Shen, Phillip Wallis, Zeyuan Allen-Zhu, Yuanzhi Li, Shean Wang, Lu Wang, Weizhu Chen
- Published: 2021-06-17
- Topic: Training & fine-tuning
- Visual carousel: https://instaxiv.com/p/2106.09685
- Explanation by InstaXiv, a secondary educational summary. Cite the original paper for exact results. InstaXiv is not affiliated with or endorsed by arXiv or Cornell University.

## Fine-tune GPT-3 while training 10,000× fewer parameters

**4.7M** trainable parameters instead of 175B

## Full fine-tuning copies the whole model per task

**Full fine-tuning:** Every task gets its own 175B-parameter copy, about 350 GB each. Adapters avoid that but add sequential layers, and latency, at inference.

**LoRA:** Freeze the pretrained weights. Learn a tiny low-rank update beside each projection, then merge it in after training. A task checkpoint shrinks to 35 MB.

The weight change needed for adaptation has very low intrinsic rank.

## Keep W frozen and learn a low-rank detour

$$
h = W_0\,x + \frac{\alpha}{r}\,B\,A\,x
$$

$B$ starts at zero, so training begins exactly at the pretrained model. With rank $r$ as small as 1 to 8, the update adds almost no parameters.

- $W_0$: Frozen pretrained weight, $d \times k$
- $B$: Trainable $d \times r$ matrix, initialized to zero
- $A$: Trainable $r \times k$ matrix, random Gaussian init
- $\alpha / r$: Scale, so changing the rank needs little retuning

## Three steps from frozen model to task expert

1. **Pick the projections**: Apply LoRA to attention weights; adapting both $W_q$ and $W_v$ worked best under a fixed parameter budget.
2. **Train only A and B**: Optimizer state shrinks with them. On GPT-3 175B, training memory drops from 1.2 TB to 350 GB.
3. **Merge for deployment**: Compute $W = W_0 + BA$ once. Inference runs at full speed with zero added latency.

## More trainable parameters do not mean better accuracy

![Figure 2](https://cdn.instaxiv.com/figures/2106.09685/figure1.webp)

GPT-3 175B on WikiSQL and MultiNLI. LoRA, the pink triangles, stays near the top at small budgets, while prefix-based methods degrade as their parameter count grows. (Figure 2)

## Matches or beats full fine-tuning on GPT-3

| Method | WikiSQL | MNLI-m | Trainable |
| --- | --- | --- | --- |
| Full fine-tune | 73.8 | 89.5 | 175,255.8M |
| BitFit | 71.3 | 91.0 | 14.2M |
| Adapter (H) | 73.2 | 91.5 | 40.1M |
| **LoRA (+2.2 MNLI)** | **73.4** | **91.7** | **4.7M** |

_GPT-3 175B validation accuracy (%), from Table 4._

## Where low rank stops being free

- **Batching mixed tasks is awkward**: Merged weights serve one task. Mixing tasks in one batch means keeping A and B separate, which brings back some overhead.
- **Which matrices to adapt is heuristic**: The paper studied attention weights only and left MLP, LayerNorm and bias adaptation to future work.
- **Rank is a guess**: Tiny ranks suffice on these benchmarks, but tasks far from pretraining, like a new language, may need more.

Best used when: You serve many tasks from one base model and storage or GPU memory is the bottleneck.

## Key takeaways

- Adaptation updates live in a tiny subspace; ranks of 1 to 8 often suffice.
- Zero inference latency: merge $BA$ into the base weights before deployment.
- LoRA became the default parameter-efficient fine-tuning method across open models and toolkits.

## Links

- arXiv: https://arxiv.org/abs/2106.09685
- PDF: https://arxiv.org/pdf/2106.09685
- Code: https://github.com/microsoft/LoRA

## Citation

```bibtex
@article{hu2021lora,
  title   = {LoRA: Low-Rank Adaptation of Large Language Models},
  author  = {Hu, Edward J. and Shen, Yelong and Wallis, Phillip and Allen-Zhu, Zeyuan and Li, Yuanzhi and Wang, Shean and Wang, Lu and Chen, Weizhu},
  journal = {arXiv preprint arXiv:2106.09685},
  year    = {2021},
  url     = {https://arxiv.org/abs/2106.09685}
}
```
