Mini WorldLaplace AI / Plate F72 — AI

LoRA: Low-⁠Rank Adaptation

Freeze a large model’s weights and train two thin matrices beside them. On GPT-⁠3 that meant about 10,⁠000 times fewer numbers to train.

Scroll

01

One Part in Ten Thousand

To teach a trained model one more task, the usual way is fine-⁠tuning: keep training every one of its numbers on new data. GPT-⁠3 175B has 175 billion of them, and every task fine-⁠tuned that way is another 350 GB model to store.

The LoRA paper of 2021 does it differently: the original numbers stay as they are, and only a small part added beside them is trained. On GPT-⁠3 that is about 19 million numbers to train, about one in ten thousand; training memory falls from 1.2 TB to 350 GB, and each task is stored in about 35 MB.

GPT-⁠3 175B · numbers trained: 175 billion → about 19 million · memory 1.2 TB → 350 GB · about 35 MB a task

02

Every Number Moves

In full fine-⁠tuning every number of the model gets a gradient, and the optimiser keeps its own state for each one. Adam in mixed precision, the common choice, takes 16 bytes a parameter: 2 for the weight, 2 for its gradient, 12 for the optimiser’s state. At that rate 175 billion parameters need 2.8 TB for these alone.

The paper reports 1.2 TB of GPU memory for fine-⁠tuning GPT-⁠3 in its setting. The cast-⁠iron master plate on the plinth is one weight matrix; in full fine-⁠tuning every pad on it changes.

Adam in mixed precision: 16 bytes a parameter · 175 billion × 16 bytes = 2.8 TB · the paper reports 1.2 TB

03

Freeze It, Add a Side Path

LoRA freezes W and adds two thin matrices beside it: B with d rows and r columns, A with r rows and k columns. The input x goes both ways, and the output is Wx + BAx. Training changes only B and A; W gets no gradient.

One attention weight matrix in GPT-⁠3 is 12,⁠288 × 12,⁠288, about 151 million numbers. With r = 4, B and A together hold 4 × (12,⁠288 + 12,⁠288) = 98,⁠304 numbers: 1,⁠536 times fewer.

At the start A is random and B is all zeros, so BA = 0 and the model is exactly the original one; training starts from it. BA is also multiplied by a constant α⁠/⁠r, and tuning it is much like tuning the learning rate.

One 12,⁠288 × 12,⁠288 matrix: 150,⁠994,⁠944 numbers · r = 4: 98,⁠304 · B = 0 at the start

04

Two Strips, One Full Sheet

Each row of B lines up with a row of W, and each column of A with a column of W. The cell of ΔW in row i and column j is row i of B times column j of A, entry by entry, added up. So ΔW is the same size as W, and every cell can change.

But it is worked out from r × (d + k) numbers, not set by d × k numbers of its own. With r = 1 every row of ΔW is one row of numbers scaled up or down, and it looks like a tartan; the larger r, the more patterns it can make. In mathematical terms, the rank of ΔW is at most r.

ΔW = BA · the size of W · set by r × (d + k) numbers · rank ≤ r

05

Rank One Will Do

Why is so thin enough? A study of 2020 found that fine-⁠tuning a large model still works when the numbers it trains are held to a small random subspace: on MRPC, RoBERTa reached 90% of full fine-⁠tuning with 200 trained parameters. From this LoRA assumes that the change fine-⁠tuning makes, ΔW, has a low rank too.

The paper tried r = 1, 2, 4, 8 and 64 on GPT-⁠3, adapting only Wq and Wv: accuracy on WikiSQL was 73.4%, 73.3%, 73.7%, 73.8% and 73.5%, and on MultiNLI 91.3% to 91.6%. On these two datasets r = 1 was enough.

That is an experiment, not a proof. The paper itself does not expect a small r to work for every task: if the new task were in a language unlike the one the model was trained on, retraining the whole model could do better.

GPT-⁠3 · Wq and Wv only · r = 1…64 · WikiSQL 73.3%–73.8% · MultiNLI 91.3%–91.6%

06

Merged In, No Delay

BA is the size of W, so after training it can simply be added in: W′ = W + BA. The model is then as large and as fast as before, with no extra step when it answers. That is where it differs from the earlier adapter layers, new layers set into the network that every answer has to pass through.

To get the original model back, subtract BA. On the plinth the sheet comes down onto the master plate and every pad changes with it; the sheet lifts away and the plate is as it was.

W′ = W + BA · merged, no extra time per answer · subtract BA to get W back

07

One Base, Many Adapters

Or leave it unmerged: keep one copy of the base, one B and A for each task, and put on whichever set is needed. The paper did the sum: for 100 tasks, full fine-⁠tuning stores 100 copies, about 35 TB; with LoRA it is 350 GB plus 100 times 35 MB, about 354 GB.

The paper names the cost too: with BA merged into W, one batch of inputs cannot easily use different adapters; left unmerged, the side path is one more thing to compute for every answer.

100 tasks · full fine-⁠tuning about 35 TB · LoRA about 354 GB · the base itself is still 350 GB

08

A Four-⁠Bit Base

QLoRA in 2023 went further: the frozen base is stored not in 16 bits but in a 4-bit format, NF4, while the trained B and A stay in 16 bits, on every linear layer of every block. The master plate on the plinth now has only 16 shades.

That way fine-⁠tuning a 65-billion-⁠parameter model needs under 48 GB of GPU memory instead of over 780 GB: one card is enough. For how numbers are squeezed into 4 bits, see “LLM Quantization”.

Guanaco, trained with it in the paper, scored 99.3% of ChatGPT on an 80-question test marked by GPT-⁠4, after 24 hours on one GPU. The authors also say the test has very wide confidence intervals and favours open models, and that they did not show it matches full 16-bit fine-⁠tuning at 33 and 65 billion parameters.

65 billion parameters · memory > 780 GB → < 48 GB · Guanaco: 99.3% of ChatGPT (80 questions, marked by GPT-⁠4, ±4.4%)

09

What It Saves

LoRA saves on training: the numbers trained, the memory, the file each task needs. It does not make the model smaller: the 350 GB base is still needed for every answer, and the merged W′ is as large as W.

Nor is the quality the same everywhere. In the paper’s tables LoRA matches full fine-⁠tuning on GPT-⁠3, sometimes beating it; but it also comes out lower, as for RoBERTa-⁠base on QQP, 90.8% against 91.9%. Whether low rank fits, which r, which matrices: each is found by trying on the task.

Fine-⁠tuning has other aims too. For answers shaped to people’s preferences, see “Learning from Human Feedback”: that page is about which signal to train on; LoRA is about which numbers to change.

It saves on training · the model is no smaller to run · RoBERTa-⁠base QQP: 90.8% against 91.9%

10

Taken Apart

On the plinth: the cast-⁠iron master plate, bolted down with four clamps onto a ribbed iron bed, a lead seal at one corner; a brass carrier holds the side path above it: strip B on the left, strip A at the back, and the correction sheet ΔW, the plate’s full size, between them. On a stepped rack at the back right stand four side paths for other tasks, and a person beside them gives the scale.

Master plate W · bed and clamps · correction sheet ΔW · strip B · strip A · carrier · adapter rack

11

The Bench

A 32 × 32 target change: pick a rank r and see how much of it B times A gets back. The fit comes from the singular value decomposition: keeping the r strongest directions is the best any rank-⁠r product can do, with the error measured as the sum of squared differences. The strips on the plinth grow taller with r.

The readouts are the error left and the numbers stored: r × (32 + 32) against 32 × 32 = 1,⁠024. At r = 16 the two are equal and nothing is saved. On a real 12,⁠288 × 12,⁠288 matrix the same r saves far more. The target is made up by this page, not a real model’s change.

A made-⁠up target · the SVD gives the best rank-⁠r fit · computed by this page

Try thisIn the lab, raise the rank r from 1 to 4: how far does the error fall, and what share of the 32 × 32 numbers is stored? Then go to 16: what happens?

What the model leaves out

The master plate, the strips, the sheet and the rack are this page’s model of the matrices, not objects from any laboratory. The plate’s 32 × 32 pads stand for a 12,⁠288 × 12,⁠288 matrix and the strips stand upright, 2 cells high for r; the proportions are a diagram, and a real r is far smaller against d than this. A model has many layers and many such matrices; the plinth carries one. The sheet’s pattern is computed by this page from a made-⁠up target; the lit pads in “Every Number Moves” are a sketch.

Easy to get wrong

LoRA does not make a model smaller or faster to run: it saves on training and on what each task must store, and the base is still needed for every answer. “About 10,⁠000 times fewer” is the paper’s round figure for GPT-⁠3 with r = 4 on Wq and Wv; counted exactly it is about 9,⁠300 times. Low rank is an assumption the paper supports with experiments; it does not prove it is enough for every task, and LoRA is not always as good as full fine-⁠tuning. “No extra time” holds once BA is merged into W; unmerged, the side path is computed as well. QLoRA is not a different kind of change: it stores the frozen base in 4 bits and does LoRA on top.

Common questions · 5
How many fewer numbers does LoRA train?

On GPT-⁠3 that is about 19 million numbers to train, about one in ten thousand; training memory falls from 1.2 TB to 350 GB, and each task is stored in about 35 MB.

01One Part in Ten Thousand
How does LoRA work?

LoRA freezes W and adds two thin matrices beside it: B with d rows and r columns, A with r rows and k columns. The input x goes both ways, and the output is Wx + BAx. Training changes only B and A; W gets no gradient.

03Freeze It, Add a Side Path
How large does LoRA’s rank r need to be?

The paper tried r = 1, 2, 4, 8 and 64 on GPT-⁠3, adapting only Wq and Wv: accuracy on WikiSQL was 73.4%, 73.3%, 73.7%, 73.8% and 73.5%, and on MultiNLI 91.3% to 91.6%.

05Rank One Will Do
Does LoRA slow down inference?

BA is the size of W, so after training it can simply be added in: W′ = W + BA. The model is then as large and as fast as before, with no extra step when it answers.

06Merged In, No Delay
How is QLoRA different from LoRA?

QLoRA in 2023 went further: the frozen base is stored not in 16 bits but in a 4-bit format, NF4, while the trained B and A stay in 16 bits, on every linear layer of every block.

08A Four-⁠Bit Base

Sources

  1. E. J. Hu et al. (2021): LoRA: Low-⁠Rank Adaptation of Large Language Models, arXiv:2106.09685, ICLR 2022 (the method; 1.2 TB → 350 GB; 35 MB; Tables 4, 5 and 6; merged weights make batching tasks hard)
  2. T. Dettmers et al. (2023): QLoRA: Efficient Finetuning of Quantized LLMs, arXiv:2305.14314, NeurIPS 2023 (NF4; a 65B model fine-⁠tuned on one 48 GB GPU; Guanaco and the limits of its benchmark)
  3. A. Aghajanyan, L. Zettlemoyer and S. Gupta (2020): Intrinsic Dimensionality Explains the Effectiveness of Language Model Fine-⁠Tuning, arXiv:2012.13255 (200 parameters reach 90% of full fine-⁠tuning on MRPC)
  4. T. Brown et al. (2020): Language Models are Few-⁠Shot Learners, arXiv:2005.14165 (GPT-⁠3 175B: 96 layers, d = 12,⁠288)
  5. S. Rajbhandari et al. (2019): ZeRO, arXiv:1910.02054 (mixed-⁠precision Adam: 16 bytes a parameter)
  6. Hugging Face PEFT documentation: LoRA (merging and unmerging adapters)
  7. A. Blum, J. Hopcroft and R. Kannan: Foundations of Data Science, §3.5, Theorem 3.6 (in the Frobenius norm, the truncated SVD is the best approximation of rank at most k)

Data

LoRA after E. J. Hu, Y. Shen, P. Wallis, Z. Allen-⁠Zhu, Y. Li, S. Wang, L. Wang and W. Chen, “LoRA: Low-⁠Rank Adaptation of Large Language Models” (arXiv:2106.09685, ICLR 2022): the method, the 1.2 TB and 350 GB, the 35 MB checkpoint, Tables 4⁠–⁠6 and the limitation on batching. QLoRA after T. Dettmers, A. Pagnoni, A. Holtzman and L. Zettlemoyer, “QLoRA: Efficient Finetuning of Quantized LLMs” (arXiv:2305.14314, NeurIPS 2023). Intrinsic dimension after A. Aghajanyan, L. Zettlemoyer and S. Gupta (arXiv:2012.13255). GPT-⁠3’s sizes after T. Brown et al. (arXiv:2005.14165, Table 2.1); 16 bytes a parameter for mixed-⁠precision Adam after S. Rajbhandari et al., ZeRO (arXiv:1910.02054). Merging and unmerging as in the Hugging Face PEFT documentation. Parameter counts computed by this page (docs/plates/lora/computed.py). The master plate, the strips, the sheet and the rack are this page’s model of the arithmetic, not objects from any laboratory; the plate’s 32 × 32 pads stand for a matrix of 12,⁠288 × 12,⁠288. The lab’s target is made up; its best low-⁠rank fits are computed by the page with the SVD (best in the Frobenius norm: A. Blum, J. Hopcroft and R. Kannan, Foundations of Data Science, Theorem 3.6). Material presets and the model kit as on the site’s other model plates (public/looks/CREDITS.md).

The text, pictures and models on this page are licensed CC BY-NC 4.0: free to use and adapt for teaching and other non-commercial purposes, with credit to world.lapla.si. Third-party material listed above keeps its own licence.

Cite this plate

Laplace’s Mini World, Plate F72, “LoRA: Low-⁠Rank Adaptation”, https://world.lapla.si/en/lora/, CC BY-NC 4.0, updated 2026-11-06.

Embed & API

AI · all plates