Preprint
Machine Learning

QLoRA

May 1, 2023

0

Citations

0

Influential Citations

Venue

2023

Year

Abstract

Allows efficient training of large models on limited GPU memory, through innovations like 4-bit NormalFloat (NF4), double quantization, and paged optimizers.

Analysis

Why This Paper Matters

Fine-tuning large language models (LLMs) typically requires multiple high-end GPUs with ample memory, creating a barrier for many researchers and practitioners. QLoRA addresses this by drastically reducing memory requirements while preserving model quality. It combines quantization and low-rank adaptation in a novel way, allowing models up to 65 billion parameters to be fine-tuned on a single 48GB GPU. This opens up possibilities for customization and domain adaptation of LLMs without expensive hardware.

How It Works

QLoRA builds on LoRA (Low-Rank Adaptation) by quantizing the pretrained model weights to 4-bit precision. The key innovations are:

  • 4-bit NormalFloat (NF4): A new data type designed for normally distributed weights. It uses quantile quantization to ensure each bin has equal probability, avoiding expensive quantile estimation by leveraging the known normal distribution of pretrained weights. The data type is asymmetric to include zero exactly, improving numerical stability.

Figure 3

  • Double Quantization: The quantization constants (c2) from the first quantization step are themselves quantized to 8-bit floats, reducing memory overhead. This is done with a block size of 256 and mean subtraction for symmetric quantization.

  • Paged Optimizers: Using NVIDIA's unified memory, optimizer states are automatically paged between CPU and GPU. When GPU memory is insufficient, states are evicted to CPU RAM and paged back when needed, preventing out-of-memory errors.

Figure 4

The forward and backward passes use dequantized weights in 16-bit BrainFloat, but gradients are only computed for the LoRA adapters, keeping memory usage low.

Results

Experiments across encoder, encoder-decoder, and decoder-only architectures (up to 13B parameters) show that QLoRA with NF4 matches 16-bit full fine-tuning and LoRA performance on GLUE, Super-NaturalInstructions, and MMLU. NF4 consistently outperforms standard 4-bit floats (FP4). Double quantization provides modest gains but is critical for fitting 33B and 65B models into 24GB and 48GB GPUs respectively.

RougeL for LLaMA 7B models on the Alpaca dataset.

Mean zero-shot accuracy over Winogrande, HellaSwag, PiQA, Arc-Easy, and ArcChallenge using LLaMA models with different 4-bit data types.

Experiments comparing 16-bit BrainFloat (BF16), 8-bit Integer (Int8), 4-bit Float (FP4), and 4- bit NormalFloat (NF4) on GLUE and Super-NaturalInstructions.

Mean 5-shot MMLU test accuracy for LLaMA 7–65B models finetuned with adapters on Alpaca and FLAN v2 for different data types.

Significance

QLoRA makes fine-tuning of state-of-the-art LLMs accessible to a wider audience. By matching full-precision performance, it shows that quantization need not compromise quality. The practical tips from the paper (e.g., applying LoRA to all linear layers) help practitioners achieve optimal results. This work is a step toward more efficient and democratized AI, enabling custom models for specific tasks without massive compute budgets.