LoRA: Low-Rank Adaptation
Volume III, Chapter 14 — Part I. Low-rank decomposition of weight updates: theoretical motivation from intrinsic dimension, LoRA formulation, merge at inference, and connection to the SVD.
Table of Contents
- Learning Objectives
- Prerequisites
- Notation
- Core Intuition
- The Full Fine-Tuning Problem
- Low-Rank Hypothesis
- LoRA Formulation
- Parameter Count and Efficiency
- Where to Apply LoRA
- Training and Merging
- Connection to SVD
- Worked Examples
- Connection to the Broader Curriculum
- Common Pitfalls and Misconceptions
- Research Perspective
- Summary of Takeaways
- Exercises
Learning Objectives
After reading this chapter, you should be able to:
- State the LoRA weight update with rank- decomposition.
- Compute LoRA parameter count vs. full fine-tuning.
- Explain the low-rank hypothesis for adaptation tasks.
- Identify which layers (Q/K/V/O projections) LoRA typically targets.
- Describe weight merging at inference: .
Prerequisites
- SVD — low-rank approximation
- Backpropagation — gradient flow
- Self-Attention — projection matrices
Notation
- — Frozen pretrained weight
- — Low-rank adapter factors
- — LoRA rank ()
- — LoRA scaling hyperparameter
- — Low-rank weight update
Core Intuition
Fine-tuning a 70B-parameter LLM requires updating all weights — prohibitive in memory and storage. LoRA (Hu et al., 2021) freezes pretrained weights and learns a low-rank update where , , .
The hypothesis: task-specific adaptation lives in a low-dimensional subspace of weight space — supported by intrinsic dimension studies and SVD theory.
Series context. Volume III, Chapter 14 (Fine-Tuning).
Low-Rank Adaptation (LoRA)
The Full Fine-Tuning Problem
Definition 1 (Full Fine-Tuning). Update all parameters of pretrained model:
Proposition 1. For , fine-tuning requires storing optimizer states + gradients — typically additional memory.
For , FP16: GB — infeasible on consumer hardware.
Low-Rank Hypothesis
Definition 2 (Intrinsic Rank). The effective dimension of task-specific weight updates is much smaller than ambient dimension.
Proposition 2 (Eckart–Young). Best rank- approximation to in Frobenius norm comes from top- SVD components.
LoRA parameterizes directly as low-rank product rather than computing SVD post-hoc.
LoRA Formulation
Definition 3 (LoRA Layer). For linear layer :
where , , rank .
Initialization: random Gaussian, — so at start (pretrained behavior preserved).
Scaling: Often with hyperparameter .
Parameter Count and Efficiency
Proposition 3. LoRA parameters for one layer: vs. full: .
Example. , : LoRA K vs. full M — 128× reduction per layer.
For entire Transformer: apply to Q/K/V/O projections across layers.
Where to Apply LoRA
Standard targets: in Self-Attention.
Optional: MLP layers (), embedding layer.
Proposition 4. Applying LoRA to all attention projections captures most adaptation benefit at modest parameter cost.
Training and Merging
Training: Only receive gradients; frozen.
Inference merge:
Merged model has zero inference overhead — same architecture as base model.
Multi-adapter: Keep separate per task; swap at runtime without merging.
Connection to SVD
Proposition 5. If optimal has rank , LoRA with can represent exactly.
Proposition 6. LoRA is a reparameterization of rank- matrices via product manifold — not unique factorization (unlike SVD).
See SVD for optimal low-rank approximation theory.
Worked Examples
Example 1: Parameter Savings
Llama 7B: 32 layers, 4 projections, , . LoRA params M vs. 7B full.
Example 2: Merge
After training, — single matrix multiply at inference.
Connection to the Broader Curriculum
- SVD — theoretical basis
- DPO — LoRA for alignment
- Self-Attention — target layers
- Quantization — composable with QLoRA
Common Pitfalls and Misconceptions
Pitfall 1: too small → underfitting; too large → no savings.
Pitfall 2: Forgetting scaling factor .
Pitfall 3: LoRA on all layers may not beat selective application.
Pitfall 4: Merged weights lose adapter modularity.
Research Perspective
LoRA (Hu et al., 2021). QLoRA (Dettmers et al., 2023). DoRA, AdaLoRA, VeRA. Standard for DPO and instruction tuning.
Summary of Takeaways
- LoRA —
- Params — per layer
- Merge — Zero inference overhead
- Basis — Low-rank / SVD
Next: KV Cache
Exercises
Exercise 1. Compute LoRA params for given .
Exercise 2. Prove .
Exercise 3. Why initialize ?
Exercise 4. Compare LoRA to top- SVD of full .
Exercise 5. Gradient flow: which params update in LoRA?
Exercise 6. LoRA + Quantization (QLoRA concept).
Exercise 7. Apply LoRA to Self-Attention Q projection only.
Exercise 8. Storage for 10 task-specific LoRA adapters vs. 10 full models.