Low-Rank Adaptation (LoRA)
Low-Rank Adaptation (LoRA) is an innovative parameter-efficient fine-tuning (PEFT) technique introduced by Edward Hu et al. in 2021. It addresses the computational and storage bottlenecks of adapting massive pre-trained models to specific downstream tasks.
Core Concept & Mathematical Formulation
Traditional Fine-Tuning updates the entire weight matrix of a neural network layer by calculating a gradient step . In contrast, LoRA assumes that the weight updates during adaptation have a low “intrinsic dimension” or rank.
LoRA parameterizes the update using two low-rank decomposition matrices and , where the rank : During training, the pre-trained weight matrix is frozen (receives no gradient updates), while only and are trainable. is typically initialized using a random Gaussian distribution, and is initialized to zero, ensuring at the start of training. is a constant scaling factor.
Key Features
- Reduced Trainable Parameters: By adapting only the low-rank matrices, LoRA can reduce the number of trainable parameters by up to 10,000x for large models like GPT-3 175B.
- Zero Inference Latency: Since the learned updates are of the same dimensions as the original weight matrix, they can be merged directly back into the base model () before deployment. This incurs zero latency overhead at inference time.
- VRAM and Storage Savings: Freezing the base model drastically reduces optimizer states (such as those in Adam), dropping GPU memory usage by up to 3x. Task-specific adapters are only a few megabytes in size, facilitating cheap storage.
- Modular Adaptation: The same frozen base model can be deployed alongside multiple task-specific LoRA adapters. Adapters can be dynamically swapped in and out of GPU memory depending on the input request.
Prominent Extensions
- QLoRA (Quantized LoRA): Quantizes the base model to 4-bit precision (NormalFloat4) and performs backpropagation through it into 16-bit LoRA adapters. This enables fine-tuning 65B+ parameter Large Language Models on single consumer GPUs.
- DoRA (Weight-Decomposed Low-Rank Adaptation): Decomposes weights into magnitude and directional components and applies LoRA updates specifically to the directional component, aligning learning dynamics closely with full fine-tuning.
- AdaLoRA (Adaptive LoRA): Dynamically allocates parameter budgets (ranks) across different layers based on importance, pruning low-rank matrices with negligible singular values.