# QLoRA: Efficient Finetuning of Quantized LLMs

> Fine-tunes LoRA adapters on top of a frozen 4-bit model using NormalFloat4, double quantization and paged optimizers. A 65B model trains on one 48 GB GPU, and Guanaco reaches 99.3% of ChatGPT on the Vicuna benchmark.

- arXiv: https://arxiv.org/abs/2305.14314
- Authors: Tim Dettmers, Artidoro Pagnoni, Ari Holtzman, Luke Zettlemoyer
- Published: 2023-05-23
- Topic: Training & fine-tuning
- Visual carousel: https://instaxiv.com/p/2305.14314
- 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 a 65B model on one 48 GB GPU without losing quality

**99.3%** of ChatGPT on Vicuna, in 24 hours

## LoRA on a 4-bit base, with paging for spikes

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

Full fine-tuning keeps 32-bit optimizer state for every weight. LoRA trains small 16-bit adapters. QLoRA also stores the frozen base in 4 bits and pages optimizer state to CPU memory. (Figure 1)

## Three tricks shrink memory without hurting accuracy

1. **4-bit NormalFloat**: A data type whose levels are quantiles of a normal distribution, information-theoretically optimal for normally distributed weights.
2. **Double quantization**: Quantize the quantization constants too, saving about 0.37 bits per parameter, roughly 3 GB on a 65B model.
3. **Paged optimizers**: Unified memory moves optimizer state to CPU RAM during memory spikes, avoiding out-of-memory crashes.

## Memory was the wall, not compute

**16-bit fine-tuning:** Fine-tuning LLaMA 65B in 16-bit needs more than 780 GB of GPU memory, a multi-node job.

**QLoRA:** The same model fine-tunes in under 48 GB on a single GPU, with gradients flowing through the frozen 4-bit weights into the adapters.

Store in 4 bits, compute in 16: dequantize on the fly, layer by layer.

## Guanaco nearly matches ChatGPT on Vicuna

| Method | Score vs ChatGPT |
| --- | --- |
| GPT-4 | 114.5% |
| **Guanaco 65B (4-bit, 41 GB)** | **99.3%** |
| Guanaco 33B | 97.8% |
| Bard | 94.8% |

_GPT-4-judged score relative to ChatGPT on the Vicuna benchmark. The authors caution these judgments are noisy._

## What the paper could not settle

- **Parity unproven at 33B and 65B**: Matching full 16-bit fine-tuning was not established at the largest scales because of resource costs.
- **Chatbot benchmarks are shaky**: Vicuna and OpenAssistant evaluations are small, and GPT-4 judges show ordering and self-preference biases.
- **Data choice dominates**: A 9k-example OASST1 set beat a 450k-example FLAN v2 subset for chat quality.

Best used when: You want to fine-tune large open models on a single GPU or a tight budget.

## Key takeaways

- Freezing a 4-bit base and training LoRA adapters matches 16-bit fine-tuning quality.
- NF4, double quantization and paged optimizers put 65B fine-tuning on one 48 GB GPU.
- Small, high-quality instruction data mattered more than size for chatbot quality.

## Links

- arXiv: https://arxiv.org/abs/2305.14314
- PDF: https://arxiv.org/pdf/2305.14314
- Code: https://github.com/artidoro/qlora

## Citation

```bibtex
@article{dettmers2023qlora,
  title   = {QLoRA: Efficient Finetuning of Quantized LLMs},
  author  = {Dettmers, Tim and Pagnoni, Artidoro and Holtzman, Ari and Zettlemoyer, Luke},
  journal = {arXiv preprint arXiv:2305.14314},
  year    = {2023},
  url     = {https://arxiv.org/abs/2305.14314}
}
```
