LoRA: Freeze the Pretrained Weights, Train Only a Low-Rank Update
LoRA (Hu et al., 2021) freezes the pretrained weights and trains only a low-rank update ΔW=BA: about 10,000 times fewer trainable parameters on GPT-3 175B, a 350GB checkpoint shrinking to 35MB, no extra latency after merging, and quality on par with full fine-tuning. Method, experiments, caveats.
On this page
- Why This Paper Matters
- The Problem the Paper Tackles
- The Method: A Low-Rank Update in Parallel with Frozen Weights
- The low-rank update
- Trainable parameters and the resource bill
- Relation to full fine-tuning
- Experiments: Where the Paper Validates It
- GPT-3 175B: the most important group
- GLUE and E2E: results on smaller models
- Few-shot
- The Paper’s Own Analysis: Where Is the Low Rank?
- Which matrices should get LoRA
- What rank to use
- How the update relates to the original weights
- Qualifications Later Research Added
- Reproducing the Paper’s Claims on a Small Model
- Limitations and Things to Watch When Reading
- What to Take Away from This Paper
- Further Reading
- FAQ
Why This Paper Matters
GPT-3 pushed “pretrain, then fine-tune” into an awkward position: the model has 175 billion parameters, so every fine-tuned copy for a downstream task is as large as the original (about 350GB in 16-bit floating point), and deploying 100 tasks means about 35TB; training also has to keep gradients and optimizer state for all parameters. LoRA (Low-Rank Adaptation), proposed by Hu et al. at Microsoft in 2021, is the fix: freeze the pretrained weights, train only a low-rank update, and add the update back into the weights after training, so the inference structure is exactly that of the original model. It became one of the most widely used methods in open-source fine-tuning toolchains, and later work such as QLoRA builds on it.
Before reading the paper, remember its core numbers (all from the paper, with the source in parentheses):
| Item | Number given in the paper |
|---|---|
| Trainable parameters | About 10,000 times fewer on GPT-3 175B (abstract) |
| Training memory | From 1.2TB down to 350GB (section 4.2) |
| Checkpoint size | With r=4 and only and adapted, from 350GB to about 35MB (section 4.2) |
| Training throughput | From 32.5 tokens per second per V100 (full fine-tuning) to 43.1 (footnote 5) |
| Inference latency | Same as full fine-tuning after merging; Adapters add 20.7% to 30.3% at batch size 1 and sequence length 128 (table 1) |
| Task quality | Matches or beats full fine-tuning on WikiSQL, MNLI and SAMSum with GPT-3 175B (table 4) |
The Problem the Paper Tackles
The paper lists the cost of each of the three main routes at the time (section 3), and LoRA is designed to avoid those costs:
| Route | Problem the paper points out |
|---|---|
| Full fine-tuning | One full copy per task; training memory comparable to pretraining |
| Adapter (small modules inserted between layers) | The small modules must run in series and cannot use hardware parallelism; latency rises clearly for online inference at batch size 1; sharded models need extra synchronization |
| Prefix / Prompt Tuning (optimize the input or per-layer prefixes) | Uses part of the sequence length; hard to optimize, and performance is not monotonic in the number of trainable parameters |
The latency cost of Adapters can be quantified directly. Table 1 times one forward pass on GPT-2 medium, comparing full fine-tuning (the same as merged LoRA) with two kinds of Adapter:
| Setting | batch 32, sequence 512 | batch 16, sequence 256 | batch 1, sequence 128 |
|---|---|---|---|
| Full fine-tuning / LoRA | 1449.4 ms | 338.0 ms | 19.8 ms |
| AdapterL | 1482.0 ms (+2.2%) | 354.8 ms (+5.0%) | 23.9 ms (+20.7%) |
| AdapterH | 1492.2 ms (+3.0%) | 366.3 ms (+8.4%) | 25.8 ms (+30.3%) |
With a large batch and long sequences the extra serial layers are spread over a big block of compute and cost only 2% to 3%; in the online setting at batch size 1 the same small layers cost 20% to 30% more. That is why the paper stresses “zero inference overhead” again and again.
The Method: A Low-Rank Update in Parallel with Frozen Weights
The low-rank update
For a pretrained weight , LoRA constrains its update to a low-rank factorization:
During training is frozen and only and receive gradients. The forward pass becomes:
Both branches take the same input and their outputs are added element-wise. The paper also fixes three details:
- Initialization. is initialized from a Gaussian and to 0, so at the start of training and the model is identical to the pretrained one.
- Scaling. The update is multiplied by , where is a constant that does not change with . The paper says that with Adam, tuning is roughly the same as tuning the learning rate if the initialization is scaled properly, so the authors simply set to the first they tried and never tuned it; the scaling is there to reduce retuning when changes.
- Merging for inference. At deployment you can compute explicitly and run inference as usual; to switch tasks, subtract and add another pair .
Trainable parameters and the resource bill
Each adapted matrix adds parameters. On GPT-3 175B the paper adapts only the square matrices in attention (), so the total is , where is the number of adapted matrices (the number of layers times the number of matrix types per layer). GPT-3 175B has 96 layers and . The code below checks the parameter counts in tables 4 and 15 of the paper, and the storage numbers in the text:
D_MODEL, LAYERS = 12288, 96 # GPT-3 175B (Brown et al., 2020)
def lora_params(r, n_matrices):
# each adapted matrix is d_model x d_model: A is r x d, B is d x r
return LAYERS * n_matrices * r * 2 * D_MODEL
settings = [("Wq,Wv", 2, 1), ("Wq,Wv", 2, 4), ("Wq,Wv", 2, 8),
("Wq,Wv", 2, 64), ("Wq,Wk,Wv,Wo", 4, 2),
("Wq,Wk,Wv,Wo", 4, 64)]
for name, m, r in settings:
n = lora_params(r, m)
print(f"{name:12s} r={r:<3d} {n:>12,d} params = {n / 1e6:6.1f}M"
f" fp16 {n * 2 / 2**20:6.1f} MiB")
full = 175e9
ckpt = lora_params(4, 2) * 2
print(f"Whole model in fp16: {full * 2 / 1e9:.0f} GB")
print(f"Checkpoint shrinks by (r=4, Wq,Wv): {full * 2 / ckpt:,.0f}x")
print(f"100 tasks: full copies {100 * full * 2 / 1e12:.0f} TB, "
f"base plus adapters {(full * 2 + 100 * ckpt) / 1e9:.0f} GB")
print(f"Throughput 43.1 vs 32.5: {1 - 32.5 / 43.1:.1%} less time "
f"({43.1 / 32.5:.2f}x the throughput)")
Output:
Wq,Wv r=1 4,718,592 params = 4.7M fp16 9.0 MiB
Wq,Wv r=4 18,874,368 params = 18.9M fp16 36.0 MiB
Wq,Wv r=8 37,748,736 params = 37.7M fp16 72.0 MiB
Wq,Wv r=64 301,989,888 params = 302.0M fp16 576.0 MiB
Wq,Wk,Wv,Wo r=2 18,874,368 params = 18.9M fp16 36.0 MiB
Wq,Wk,Wv,Wo r=64 603,979,776 params = 604.0M fp16 1152.0 MiB
Whole model in fp16: 350 GB
Checkpoint shrinks by (r=4, Wq,Wv): 9,272x
100 tasks: full copies 35 TB, base plus adapters 354 GB
Throughput 43.1 vs 32.5: 24.6% less time (1.33x the throughput)
Points to compare against the paper:
- The 4.7M and 37.7M in table 4 correspond to and (only and adapted) and match the code; the 18.8M, 301.9M and 603.8M in table 15 are 0.1M to 0.2M below the 18.9M, 302.0M and 604.0M above. The paper does not say how it rounds, and neither the order of magnitude nor the conclusions change.
- The paper says the checkpoint is “about 35MB”; 18,874,368 parameters times 2 bytes is 36 MiB (about 37.7 MB), a reduction of about 9,300 times, the same order of magnitude as the “about 10,000 times” in the abstract.
- The “25% speedup” in the paper corresponds to time saved: throughput rises from 32.5 to 43.1 tokens per second, so the same data needs about 24.6% less time. Footnote 5 says both runs use the same number of model-parallel shards.
- The paper says training memory falls by up to 2/3: as long as , the frozen parameters need no gradients or optimizer state. For GPT-3 175B this is 1.2TB down to 350GB (about 3.4 times), and 350GB happens to be the size of 175B parameters stored in fp16: the frozen weights still sit in memory and take part in the forward pass, and what is saved is the gradients and the optimizer state. The full breakdown of this bill is in Compute and Memory.
Relation to full fine-tuning
The paper points out that LoRA does not require the accumulated weight update to be full-rank: if you apply it to all weight matrices, train all biases, and raise to the rank of the pretrained weights, you roughly recover the expressiveness of full fine-tuning. In other words, as the number of trainable parameters grows LoRA roughly converges to training the original model, whereas Adapters converge to an MLP and prefix methods converge to a model that cannot handle long inputs. So is both a capacity knob and a cost knob.
Experiments: Where the Paper Validates It
The paper covers four groups of models: RoBERTa (GLUE), DeBERTa XXL (GLUE), GPT-2 medium and large (E2E NLG) and GPT-3 175B (WikiSQL, MNLI, SAMSum). In most experiments LoRA is applied only to and .
GPT-3 175B: the most important group
Table 4 is the most persuasive table in the paper, with trainable parameters from 3.2M to 175,255.8M:
| Method | Trainable parameters | WikiSQL accuracy | MNLI-m accuracy | SAMSum (R1/R2/RL) |
|---|---|---|---|---|
| Full fine-tuning | 175,255.8M | 73.8 | 89.5 | 52.0/28.0/44.5 |
| BitFit | 14.2M | 71.3 | 91.0 | 51.3/27.4/43.5 |
| PreEmbed | 3.2M | 63.1 | 88.6 | 48.3/24.2/40.5 |
| PreLayer | 20.2M | 70.1 | 89.5 | 50.8/27.3/43.5 |
| AdapterH | 7.1M | 71.9 | 89.8 | 53.0/28.9/44.8 |
| AdapterH | 40.1M | 73.2 | 91.5 | 53.2/29.0/45.1 |
| LoRA | 4.7M | 73.4 | 91.7 | 53.8/29.8/45.9 |
| LoRA | 37.7M | 74.0 | 91.6 | 53.4/29.2/45.1 |
The paper gives the fluctuation as about ±0.5 on WikiSQL, ±0.1 on MNLI-m and ±0.2/±0.2/±0.1 on SAMSum. So LoRA’s 73.4 and 74.0 on WikiSQL cannot be told apart from full fine-tuning’s 73.8; the lead of about 2 points on MNLI-m and of 0.6 to 1.8 points on SAMSum is beyond the fluctuation. The paper also stresses that not every method improves with more parameters: PreEmbed degrades clearly beyond 256 special tokens and PreLayer beyond 32, while LoRA’s performance levels off as parameters are added (appendix table 15).
GLUE and E2E: results on smaller models
| Model and task | Full fine-tuning | LoRA | LoRA trainable parameters |
|---|---|---|---|
| RoBERTa base, GLUE average | 86.4 | 87.2 | 0.3M (full 125.0M) |
| RoBERTa large, GLUE average | 88.9 | 89.0 | 0.8M (full 355.0M) |
| DeBERTa XXL, GLUE average | 91.1 | 91.3 | 4.7M (full 1500.0M) |
| GPT-2 medium, E2E BLEU | 68.2 | 70.4±.1 | 0.35M (full 354.92M) |
| GPT-2 large, E2E BLEU | 68.5 | 70.4±.1 | 0.77M (full 774.03M) |
Read this table with some skepticism. The full fine-tuning column is quoted from earlier work (the starred rows in tables 2 and 3), not rerun under the same hyperparameter search. RoBERTa base’s 0.8-point average advantage comes mainly from one task: in the per-task scores of table 2, LoRA gets 86.6 on RTE against 78.7 for full fine-tuning, a gap of 7.9 points; without RTE, the other 7 tasks average 87.44 (full fine-tuning) against 87.33 (LoRA), so LoRA is actually 0.1 lower. The safer reading is “on a par with full fine-tuning on these tasks”, not “better across the board”.
Few-shot
Appendix table 16 takes subsets of MNLI of different sizes on GPT-3 175B and compares the sample efficiency of the methods:
| Training examples | 100 | 1,000 | 10,000 | 392K (all) |
|---|---|---|---|---|
| Full fine-tuning | 60.2 | 85.8 | 88.9 | 89.5 |
| PrefixEmbed | 37.6 | 75.2 | 79.5 | 88.6 |
| PrefixLayer | 48.3 | 82.5 | 85.9 | 89.6 |
| LoRA | 63.8 | 85.6 | 89.2 | 91.7 |
LoRA is 3.6 points above full fine-tuning at 100 examples and 0.2 points below at 1,000. The paper calls this favorable sample efficiency; it gives no fluctuation range for this table, so the more conservative reading is “no disadvantage was observed with little data”.
The Paper’s Own Analysis: Where Is the Low Rank?
Section 7 is the most thoughtful part of the paper; on GPT-3 175B it answers three questions.
Which matrices should get LoRA
With a fixed budget of 18M parameters (all 96 layers), distributed among (table 5):
| Adapted matrices | all four | ||||||
|---|---|---|---|---|---|---|---|
| Rank r | 8 | 8 | 8 | 8 | 4 | 4 | 2 |
| WikiSQL (±0.5) | 70.4 | 70.0 | 73.0 | 73.2 | 71.4 | 73.7 | 73.7 |
| MNLI (±0.1) | 91.0 | 90.8 | 91.0 | 91.3 | 91.3 | 91.3 | 91.7 |
Putting the whole budget on or is clearly worse (WikiSQL 70.4 and 70.0); adapting and together, or all four, is best (73.7), and or alone come close (73.0 and 73.2). The paper’s reading is that even a rank of 4 already holds enough of the information in , so “adapt more kinds of matrices with a small rank each” beats “adapt one kind with a large rank”.
What rank to use
Table 6 scans for three combinations of matrices:
| Adapted matrices | Task | r=1 | r=2 | r=4 | r=8 | r=64 |
|---|---|---|---|---|---|---|
| WikiSQL | 68.8 | 69.6 | 70.5 | 70.4 | 70.0 | |
| WikiSQL | 73.4 | 73.3 | 73.7 | 73.8 | 73.5 | |
| all four | WikiSQL | 74.1 | 73.7 | 74.0 | 74.0 | 73.9 |
| MNLI | 90.7 | 90.9 | 91.1 | 90.7 | 90.7 | |
| MNLI | 91.3 | 91.4 | 91.3 | 91.6 | 91.4 | |
| all four | MNLI | 91.2 | 91.7 | 91.7 | 91.5 | 91.4 |
From rank 1 to 64 the scores hardly change, and is enough on and (only alone needs a somewhat larger rank). The paper supports this with subspace similarity: comparing the singular-vector subspaces of learned with and , the top direction overlaps strongly between the two (normalized similarity above 0.5) while the other directions show no clear overlap, which the paper conjectures are mostly random noise accumulated during training. Two runs with different random seeds, both at , share some singular directions ( shares more than , consistent with needing a larger rank in table 6), while two random Gaussian matrices share none.
How the update relates to the original weights
The paper projects onto the top singular directions of and compares the norms after projection (table 7, GPT-3 layer 48):
| Directions used for the projection | ||
|---|---|---|
| Singular vectors of itself | 0.32 | 1.90 |
| Top singular vectors of itself | 21.67 | 37.71 |
| Random directions | 0.02 | 0.33 |
For reference, , while is 6.91 at and 3.57 at . The paper draws three points: is more correlated with than a random matrix is, so it amplifies features already present in ; but it does not amplify the most prominent directions of ; and the amplification is large, about 21.5 () at . The paper’s interpretation is that the low-rank update amplifies features that were learned in pretraining but not emphasized, and that matter for the downstream task. This is a hypothesis; the paper gives no causal evidence.
Qualifications Later Research Added
Several important follow-ups on “how good is LoRA really” appeared after the paper, and they should be remembered together with it:
- A gap in quality. Biderman et al. (LoRA Learns Less and Forgets Less, 2024) compared LoRA with full fine-tuning in two domains, code and math, with instruction fine-tuning on about 100K examples and continued pretraining on about 20B tokens: with standard low-rank settings LoRA is clearly below full fine-tuning, but it keeps the base model’s abilities outside the target domain better (it forgets less), and it regularizes more effectively than common techniques such as weight decay and dropout. They also found that the perturbations learned by full fine-tuning have a rank 10 to 100 times higher than typical LoRA configurations, which may explain part of the gap. This does not necessarily contradict the paper’s section 7.2 (“a very small rank is enough”): the tasks, data sizes and evaluation methods differ, and the paper itself warns in a footnote that a small rank will not be effective if the downstream task is in a language different from the pretraining one.
- The scaling factor. The paper scales by ; Kalajdzievski (rsLoRA, 2023) shows that one should divide by rather than , because otherwise the gradient shrinks as the rank grows, the large-rank adapter learns slowly and performs no better than a small one; his correction lets larger ranks pay off.
- Where to adapt. The paper adapts only the attention matrices and leaves the MLP, LayerNorm and biases to future work. Today’s practice often applies LoRA to all linear layers; for a comparison on a small model on this site, see LoRA Fine-Tuning in Practice.
Reproducing the Paper’s Claims on a Small Model
Several of the paper’s claims can be tested by hand on a small model. LoRA Fine-Tuning in Practice fine-tunes Qwen2.5-0.5B on banking77 (77 customer-service intents, 20 training examples per class), changes one setting at a time over dozens of training runs, and measures target-task accuracy together with two forgetting probes (WikiText-2 perplexity and ARC-Easy multiple choice). Compared with the paper:
| The paper’s claim | What the small experiment shows |
|---|---|
| A very small rank is enough (section 7.2) | With fixed at 32 the accuracy stays between 85.2% and 86.4% for ranks 1 to 128, so this task is not short of capacity. With a larger rank amounts to a larger learning rate: accuracy rises to 88.0% while perplexity goes from 17.40 to 27.81 |
| For the same parameter budget, adapting several kinds of matrices with a small rank beats adapting one kind with a large rank (section 7.1, table 5) | With comparable trainable parameters, q and v only at rank 128 reaches 77.9%, q, k, v, o at rank 64 reaches 83.0%, and all 7 linear layers at rank 16 reach 85.8% |
| The paper adapts only the attention matrices and leaves the MLP for future work | Adapting just the three MLP matrices gives 85.5%, almost matching all linear layers; q and v only give 52.0% |
| After merging there is no extra inference latency | Merged in fp32, not one of the 3,080 predictions changed; in bf16, 0.6% of them changed, mostly because of bf16 rounding itself |
These are observations on one model and one task and cannot replace the paper’s conclusions on GPT-3 175B, but they show that several of the paper’s claims can also be seen on a small model. For the claim that placement matters more than rank, today’s default of adapting all linear layers goes further than the paper did. The same page also compares LoRA with full fine-tuning and QLoRA under one setup and gives all the code and numbers.
Limitations and Things to Watch When Reading
- Limitations the paper states. If you fold and into to remove the inference latency, you cannot handle tasks that need different and in one batch; without merging you can pick the adapter per example, but you pay in latency. Choosing which matrices to adapt relies mainly on heuristics, with no principled method.
- Only attention weights were studied. The paper leaves the MLP, LayerNorm and biases for later, so it does not answer whether “all linear layers” is better.
- Many baseline numbers are quoted. The starred baselines come from earlier papers, and their hyperparameters and evaluation setup may not match LoRA’s. The paper also makes a stricter comparison (the rows marked † in table 2: MRPC, RTE and STS-B do not start from a model already adapted to MNLI): on RoBERTa large, LoRA averages 88.6, below the quoted full fine-tuning’s 88.9 and above Adapters under the same setting (86.4 to 88.4).
- The GPT-3 175B results cannot be reproduced. Readers do not have the same base model or fine-tuning conditions, so conclusions at that scale rest on the paper’s report; the fluctuation is given only as a typical value, not item by item.
- “A low rank is enough” is not a universal law. The footnote in section 7.2 says plainly that a small is not expected to work for every task, and that the farther the task is from the pretraining distribution (for example, a different language), the higher the rank needed.
- Dates. The memory and speed numbers in the paper are measurements of GPT-3 175B on V100s; today’s hardware, mixed precision and optimizer implementations change the exact values, but the logic “frozen parameters need no gradients or optimizer state” does not.
What to Take Away from This Paper
- The core of LoRA is a parallel branch. with initialized to zero, so the starting point is the pretrained model; the update can be merged back into , with zero inference overhead.
- What it saves is gradients, optimizer state and storage, not forward computation. The frozen still sits in memory and takes part in the forward pass, so LoRA reduces training memory and per-task storage, and the choice of is a trade between capacity and cost.
- Which kinds of matrices to adapt matters more than the rank. In the paper’s budget comparison, several kinds of matrices with a small rank beat one kind with a large rank.
- “A tiny rank is enough” has to be read against the task distribution. On the paper’s tasks is enough; on tasks far from the pretraining distribution such as code, math and new languages, later work saw clear gaps.
- Quality and forgetting are two dimensions. LoRA often learns less and forgets less; whether to choose LoRA or full fine-tuning depends on which risk you fear more.
Further Reading
- The paper: LoRA: Low-Rank Adaptation of Large Language Models (this page was checked against version 2, October 2021)
- Related wiki pages on this site: LoRA Fine-Tuning in Practice (from-scratch implementation, hyperparameter experiments, merging and deployment), Compute and Memory, SFT Data Construction and Quality Control
- Another paper breakdown in this series: InstructGPT; LLaMA (the open base model LoRA is often paired with)
- Earlier work: Aghajanyan et al., Intrinsic Dimensionality Explains the Effectiveness of Language Model Fine-Tuning (one of LoRA’s motivations); Houlsby et al., Parameter-Efficient Transfer Learning for NLP (Adapters); Li and Liang, Prefix-Tuning; Lester et al., The Power of Scale for Parameter-Efficient Prompt Tuning
- Later work: Dettmers et al., QLoRA (quantize the frozen base to 4 bits, then train LoRA); Kalajdzievski, rsLoRA; Biderman et al., LoRA Learns Less and Forgets Less
FAQ
- What is the core idea of LoRA?
- Freeze the pretrained weight W and do not update it directly. Instead learn a low-rank update ΔW=BA, where B is d×r and A is r×k, and the rank r is far smaller than d and k. The forward pass is h=W₀x+BAx. A is initialized randomly from a Gaussian and B is initialized to 0, so at the start of training the model is identical to the pretrained one. The paper's hypothesis is that the weight change needed to adapt to a downstream task has a very low intrinsic rank.
- How much does LoRA save?
- For GPT-3 175B the paper reports training memory falling from 1.2TB to 350GB, and with r=4 on Wq and Wv only, the checkpoint falling from 350GB to about 35MB, which is about 10,000 times fewer trainable parameters. Training throughput rises from 32.5 to 43.1 tokens per second per V100, about 25% less time. After the update is merged back into the weights the inference structure equals the original model, with no extra latency, so storing 100 tasks takes about 354GB instead of 35TB.
- Which matrices should get LoRA, and what rank should I use?
- On GPT-3 175B with a fixed budget of 18M parameters, the paper finds that adapting both Wq and Wv works best (WikiSQL 73.7, MNLI 91.3), and putting the whole budget on Wq alone is clearly worse (70.4); with Wq and Wv, r=1 already reaches 73.4 and 91.3. The paper itself warns that a small rank will not be enough for every task, and today's practice usually adapts all linear layers; scan r on your own task.
- Is LoRA really as good as full fine-tuning?
- On the paper's tasks it is: on GPT-3 175B, WikiSQL, MNLI and SAMSum match or slightly beat full fine-tuning. But that is a result for specific tasks and budgets, and WikiSQL fluctuates by about ±0.5. Later work by Biderman et al. on code and math found that with standard low-rank settings LoRA is clearly below full fine-tuning, though it forgets less. Whether it is enough depends on how far the task is from the pretraining distribution, so verify on your own evaluation set.
- How is LoRA different from Adapters and Prefix Tuning?
- Adapters insert small modules between layers, in series, so they cannot run in parallel; the paper measures a 20.7% to 30.3% latency increase at batch size 1. Prefix and prompt tuning use up part of the sequence length, and performance can fall once the number of parameters grows past a point. LoRA's update runs in parallel next to the weight and can be added back to W after training, so inference has no extra computation and no sequence length is used.