LoRA: Low-Rank Adaptation of Large Language Models

Edward J. Hu, Yelong Shen, Phillip Wallis, Zeyuan Allen-Zhu, Yuanzhi Li, Shean Wang, Weizhu Chen

Abstract

An important paradigm of natural language processing consists of large-scale pre-training on general domain data and adaptation to particular tasks or domains. As we pre-train larger models, full fine-tuning, which retrains all model parameters, becomes less feasible. Using GPT-3 175B as an example -- deploying independent instances of fine-tuned models, each with 175B parameters, is prohibitively expensive. We propose Low-Rank Adaptation, or LoRA, which freezes the pre-trained model weights and injects trainable rank decomposition matrices into each layer of the Transformer architecture, greatly reducing the number of trainable parameters for downstream tasks. Compared to GPT-3 175B fine-tuned with Adam, LoRA can reduce the number of trainable parameters by 10,000 times and the GPU memory requirement by 3 times. LoRA performs on-par or better than fine-tuning in model quality on RoBERTa, DeBERTa, GPT-2, and GPT-3, despite having fewer trainable parameters, a higher training throughput, and, unlike adapters, no additional inference latency. We also provide an empirical investigation into rank-deficiency in language model adaptation, which sheds light on the efficacy of LoRA.

Introduction

As Large Language Models (LLMs) scale to hundreds of billions of parameters, such as GPT-3’s 175B, "full fine-tuning"—the process of updating every single parameter for a specific task—becomes practically impossible for most organizations. It requires massive VRAM and results in a checkpoint as large as the original model for every single downstream task.

Existing alternatives, such as Adapters (adding extra layers) or Prefix-Tuning (optimizing input activations), come with significant trade-offs. Adapters introduce sequential processing overhead that increases inference latency, while Prefix-Tuning reduces the available sequence length for actual data. LoRA (Low-Rank Adaptation) seeks to provide the performance of full fine-tuning with the efficiency of lightweight adaptation.

Methodology

The core idea behind LoRA is inspired by the hypothesis that the change in weights during model adaptation has a low "intrinsic rank." Instead of updating the full weight matrix $W \in \mathbb{R}^{d \times k}$, LoRA freezes the original weights and represents the update $\Delta W$ as a product of two low-rank matrices: $$\Delta W = B A$$ where $A \in \mathbb{R}^{r \times k}$ and $B \in \mathbb{R}^{d \times r}$, with the rank $r \ll \min(d, k)$.

The LoRA architecture: Pre-trained weights are frozen, and trainable low-rank matrices A and B are added in parallel.

Key implementation details: * Initialization: Matrix $A$ uses random Gaussian initialization, while $B$ is initialized to zero. This ensures that at the start of training, the "bypass" is zero, and the model behaves exactly like the original pre-trained version. * Weight Merging: During inference, the learned $BA$ can be explicitly added to the frozen $W$. This means the deployed model has the exact same architecture as the original, resulting in zero additional latency. * Scope: The authors primarily apply LoRA to the attention weights ($W_q, W_v$) of the Transformer architecture.

Evaluation and Results

The authors evaluated LoRA across a wide range of benchmarks, including NLU (GLUE), NLG (E2E NLG Challenge, WebNLG, DART), and large-scale tasks like WikiSQL and MultiNLI using GPT-3 175B.

Comparison of LoRA against other adaptation methods on WikiSQL and MultiNLI. LoRA achieves superior performance with significantly fewer trainable parameters.

Key Performance Metrics: * Efficiency: For GPT-3 175B, LoRA reduces the number of trainable parameters by 10,000x and VRAM consumption by 3x (from 1.2TB to 350GB during training). * Inference Speed: Unlike "Adapter" layers which can increase latency by up to 30% in short-sequence scenarios, LoRA-tuned models show 0% increase in latency because the weights are merged. * Storage: Instead of storing 350GB per task for GPT-3, users only need to store the ~35MB LoRA modules. This allows for rapid task-switching by simply swapping the low-rank matrices in VRAM.

Discussion and Insights

Analysis suggests that the intrinsic rank required for adaptation is extremely low; for a model like GPT-3, a rank $r$ as low as 1 or 2 is often sufficient to match the performance of full fine-tuning. LoRA doesn't just repeat the top singular directions of the pre-trained model; instead, it amplifies specific task-relevant features that were present but under-emphasized during general pre-training.

While LoRA is highly efficient, it is not straightforward to batch inputs for different tasks in a single forward pass if the weights have been merged. Additionally, the success of LoRA suggests that the pre-trained weights $W$ themselves might be rank-deficient, a concept that could lead to more efficient pre-training methods in the future.

Conclusion

LoRA provides a powerful framework for efficient adaptation of large-scale models. By leveraging low-rank updates, it achieves the performance of full fine-tuning with a fraction of the computational and storage costs, all while maintaining the inference speed of the original model.

Summary updated

BibTeX
@inproceedings{hu2022lora,
  author = {Edward J. Hu and Yelong Shen and Phillip Wallis and Zeyuan Allen-Zhu and Yuanzhi Li and Shean Wang and Weizhu Chen},
  title = {{LoRA: Low-Rank Adaptation of Large Language Models}},
  booktitle = {International Conference on Learning Representations},
  year = {2022},
  url = {https://openreview.net/forum?id=nZeVKeeFYf9},
}
Figure