(BackBack)
ML//7 min read

LORA: LOW-RANK ADAPTATION OF LARGE LANGUAGE MODELS

Many applications in natural language processing rely on adapting one large-scale, pre-trained language model to multiple downstream applications.

Introduction

LLMs become increasingly essential in natural language processing, adapting these models to specific tasks presents significant challenges due to the vast number of parameters involved.

Inspiration from Li et al. (2018a); Aghajanyan et al. (2020) which show that the learned over-parametrized models in fact reside on a low intrinsic dimension.

→ hypothesize that the change in weights during model adaptation also has a low “intrinsic rank”

Traditional fine-tuning methods require retraining all model parameters, making it infeasible for larger models like GPT-3 with 175 billion parameters. LoRA (Low-Rank Adaptation) addresses this issue by introducing a more efficient parameter adaptation approach that significantly reduces computational costs while maintaining high performance.

Fine-tuning

Fine-tuning involves updating all parameters of a pre-trained model to adapt it to a specific downstream task. This process is computationally expensive and memory-intensive, especially for large models.

  1. Forward Pass: Pass data through the model.

  2. Weight Updates: Calculate updates using backpropagation.

  3. Parameter Combination: Combine updated weights with base weights.

In fine-tuning, models require full-rank weight matrices, resulting in a large number of trainable parameters and high memory usage.

Example

Benefits of LoRA

  1. Reduced Trainable Parameters: By decomposing weight matrices into smaller matrices, LoRA drastically reduces the number of trainable parameters.

  2. Memory and Storage Savings: LoRA reduces GPU memory consumption by up to 3x during training. In GPT-3 175B, the VRAM requirement drops from 1.2TB to 350GB.

  3. Task-Switching Efficiency: LoRA enables quick task-switching by swapping the low-rank matrices (A and B) without altering the frozen pre-trained weights.

Conventions

references to the Transformer architecture.

Structure

LoRA proposes that the changes in weights during model adaptation have a low "intrinsic rank." It decomposes the large weight update matrix (ΔW) into two smaller matrices (A and B):

W0W_0: Frozen, W0Rd×kW_0 \in \R^{d\times k}

ARd×rA \in \R^{d\times r}, BRr×kB \in \R^{r\times k}

h=W0x+ΔWx=W0x+BAxh=W_0x+\Delta Wx=W_0x+BAx W0Rd×k,ARd×r,BRr×kW_0 \in \R^{d\times k}, A \in \R^{d\times r}, B \in \R^{r\times k}

weight matrices have low intrinsic dimensionality, meaning they can be accurately represented by fewer dimensions without losing essential information.

For example, a 100x100 matrix with 10,000 elements can be replaced by two smaller matrices with a total of 1,000 elements.

Implementations to Transformer

In principle, we can apply LoRA to any subset of weight matrices in a neural network to reduce the number of trainable parameters.

ly adapting the attention weights for downstream tasks and freeze the MLP modules (so they are not trained in downstream tasks) both for simplicity and parameter-efficiency.

ComponentLoRA AppliedDescription
Wq, Wk, Wv, WoYesWeight matrices in the self-attention module. Key focus of LoRA.
MLP ModuleNoMulti-Layer Perceptron for non-linear transformations. Frozen in LoRA.
LayerNormNoLayer normalization to stabilize training. Frozen in LoRA.
BiasNoBias terms for adjusting neuron activation thresholds. Frozen in LoRA

Results

LoRA has been evaluated on several benchmarks, including:

  1. GLUE Benchmark: Demonstrates competitive performance on various natural language understanding tasks.
  1. E2E NLG Challenge: Outperforms other adaptation methods in natural language generation.
  1. GPT-3 175B: Matches or exceeds the performance of fine-tuning across multiple datasets.

    1. Used less parameters

Key Findings

Questions?

  1. Which weight matrices should we adapt with LoRA to maximize performance?

    1. tested different combinations of attention weight matrices (Wq, Wk, Wv, Wo) in GPT-3 175B to find the best configuration under a fixed parameter budget.
  1. Is the optimal adaptation matrix ∆W really low-rank?
  1. How does ∆W correlate with the pre-trained weight matrix W?
  1. Subspace Similarity Analysis

Relationship between the adaptation matrix (∆W) and the pre-trained weight matrix (W) in a Transformer model.

  1. Does ∆W correlate with W?
  1. How large is ∆W compared to W?

The amplification factor is significant.

  1. What features in W are amplified by ∆W?

Takeaway

Key works

Column 1Column 2Column 3
TopicKey PapersDescription
Transformer ModelsVaswani et al. (2017), Devlin et al. (2019)Introduced Transformers and large pre-trained language models like BERT.
Prompt EngineeringBrown et al. (2020)Highlighted the importance of prompt design in GPT-3’s performance.
Fine-TuningHoulsby et al. (2019), Lin et al. (2020)Discussed traditional fine-tuning methods and adapter layers.
Parameter-Efficient AdaptationMahabadi et al. (2021), Li & Liang (2021)Explored adapter-based methods and input optimization techniques.
Low-Rank StructuresAllen-Zhu et al. (2019), Oymak et al. (2019)Demonstrated the natural low-rank properties of neural networks after training.