LoRA (Low-Rank Adaptation) is the parameter-efficient fine-tuning method that injects small trainable low-rank matrices into frozen pretrained model layers — enabling fine-tuning of billion-parameter models on consumer GPUs by training only 0.1-1% of total parameters while achieving 90-100% of full fine-tuning quality, democratizing LLM customization.
Core Idea
- Original weight matrix: $W_0 \in R^{d\times d}$ (frozen, not updated).
- LoRA adds: $\Delta W = B \times $ A where A $\in R^{r\times d}, B \in R^{d\times r}, \operatorname{rank} r \ll d$.
- Forward pass: $h = (W_0 + \dfrac{\alpha}{r} \mathrm{BA})x$.
- Only A and $B$ are trained — $W_0$ stays frozen.
Why It Works
- Aghajanyan et al. (2021): Pretrained models have low intrinsic dimensionality.
- Fine-tuning changes are concentrated in a low-rank subspace.
$- Rank r =$ 8-64 captures most of the adaptation signal (d = 4096 for a 7B model).
Parameter Efficiency
| Model | Full FT Params | LoRA $(r=16)$ | Reduction |
|---|---|---|---|
| $LLaMA-7B$ | 6.7B | $\sim 4M$ | $1675x$ |
| $LLaMA-13B$ | $13B$ | $\sim 6.5M$ | $2000x$ |
| $LLaMA-70B$ | $70B$ | $\sim 33M$ | $2121x$ |
Memory Savings
- Full fine-tuning 7B model: $\sim 120GB$ (weights + gradients + optimizer states in fp32).
- LoRA fine-tuning 7B model: $\sim 16-24GB$ (frozen weights in bf16 + small trainable params).
- Fits on a single $24GB \mathrm{GPU}$ (RTX 4090) — vs. 4+ A100s for full fine-tuning.
QLoRA (Quantized LoRA)
- Quantize frozen base model to $4-bit$ (NF4 quantization).
- LoRA adapters remain in $bf16/fp16$.
- Backprop through quantized weights using double quantization.
- Result: Fine-tune 65B model on a single $48GB \mathrm{GPU}$ (A6000).
- Quality: Within 1% of full 16-bit fine-tuning on most benchmarks.
Practical Configuration
| Parameter | Typical Value | Notes |
|---|---|---|
| Rank $(r)$ | 8-64 | Higher = more capacity, more params |
| Alpha $(\alpha )$ | 16-32 | Scaling factor, often set to $2\times \operatorname{rank}$ |
| Target modules | $q_{\operatorname{\operatorname{proj}}}, v_{\operatorname{\operatorname{proj}}}$ (attention) | Can also target $k_{\operatorname{\operatorname{proj}}}, o_{\operatorname{\operatorname{proj}}}, \mathrm{FFN}$ |
| Dropout | 0.05-0.1 | On LoRA layers |
| Learning rate | $10^{-4}$ to $3\times 10^{-4}$ | Higher than full fine-tuning |
LoRA Variants
- DoRA: Decompose weight into magnitude and direction, LoRA adapts direction.
- AdaLoRA: Adaptive rank allocation — more rank for important layers.
- LoRA+: Different learning rates for A and $B$ matrices.
- Tied LoRA: Share LoRA weights across layers.
Merging and Serving
- After training: Merge LoRA weights into base model: $W_{\text{merged}} = W_0 + \dfrac{\alpha}{r}\mathrm{BA}$.
- Merged model has zero inference overhead — identical architecture to base.
- Multiple LoRA adapters can be swapped at inference time for different tasks.
LoRA is the technique that made $\mathrm{LLM} \text{fine-tuning}$ accessible to everyone — by reducing the hardware requirements from a cluster of A100s to a single consumer GPU, it enabled the explosion of open-source fine-tuned models and custom AI applications.