Intrinsic Dimension of Pre-Trained Models
LoRA decomposes a weight matrix update into two smaller matrices A of dimension n by r and B of dimension r by m, whose product has the same shape as W.
Why Retraining Every Weight Is Costly
A large pre-trained language model may contain billions of weights. If you want it to behave differently for a particular job, retraining every one of those weights is expensive in memory, computation, and time. Parameter-efficient methods take a different route. They leave most of the model alone and train a small number of new values that steer its behavior. LoRA, which stands for Low-Rank Adaptation, is one of the most widely used methods of this kind.
The question this article answers is concrete. If LoRA does not train the original weights, where does the learned change live, how is it stored in a shape that fits the model, and why does this not slow the model down when it runs? The best way to answer this is to follow one weight matrix from start to finish, so we will begin there.
Picking One Weight Matrix to Adapt
LoRA is not applied to the whole network as one object. You apply it to individual weight matrices. Take one of them and call it W. Suppose W has n rows and m columns, so its dimension is n by m. Everything LoRA does from here on is a response to this one matrix. It will produce a second matrix of the same n by m size that can be added to W, but it never changes W itself during training.
The frozen matrix W is the original n by m weight matrix of the pre-trained model. During finetuning it is kept intact, and only the small matrices A and B are trained.
Choosing the Rank and Matrix Shapes
LoRA begins by choosing a number r, which sets the size of the two smaller matrices. Matrix A has dimension n by r, and matrix B has dimension r by m. The inner dimension r is shared. The number of columns of A matches the number of rows of B, so the two can be multiplied. The product of A and B has dimension n by m, the same as W, and that match is exactly what makes it possible to combine them later.
Working out the shapes for a 8 by 6 matrix
W is a weight matrix with n equal to 8 rows and m equal to 6 columns. Choose rank r equal to 2. What are the shapes of A and B, and what is the shape of their product?
- 1Read off n and m
W has dimension $n \times m = 8 \times 6$, so $n = 8$ and $m = 6$.
- 2Set the shape of A
A has dimension $n \times r$, which is $8 \times 2$.
- 3Set the shape of B
B has dimension $r \times m$, which is $2 \times 6$.
- 4Check the shared dimension
A has 2 columns and B has 2 rows, so the product $AB$ is defined. Its shape is $8 \times 6$, the same as W.
A is 8 by 2, B is 2 by 6, and AB is 8 by 6, matching W exactly.
Combining the Frozen W with the Scaled Update
Once A and B exist, LoRA forms a new matrix W' by adding the product AB to the original W. The product is scaled by a hyperparameter alpha, which controls how strongly the learned contribution affects the result. The new matrix W' takes the place of W inside the model.
- 1W is the frozen original n by m weight matrix.
- 2AB is the n by m product of the two trained factors.
- 3The fraction alpha over r scales that product. Alpha is a setting you choose to decide how much the update contributes.
- 4W' is the adapted matrix, used in place of W in the model.
The division by r inside the scaling term means that alpha and r work together. The rank enters the scale, so changing r changes how large the contribution is, not only how many parameters are stored. Keep this in mind when you change the rank, because the strength of the update moves with it.
During a forward pass, the input takes two paths and the results are summed. One path goes through the frozen W. The other goes through the small factors A and B, is scaled, and is added to the first result. Because the sum is folded into a single matrix, the model keeps its original layer structure.
Low-Rank Factorization and the Parameter Count
LoRA builds on an older idea called low-rank factorization, a dimensionality reduction technique. The principle is that a large matrix can be written as the product of two smaller matrices. Fewer numbers are stored, so both computation and memory needs drop. The number of columns in the first factor, which equals the number of rows in the second, is the rank of the factorization. A full-rank matrix is the uncompressed original, while the two smaller matrices form a low-rank approximation of it.
Factorizing a 9 by 9 matrix
A 9 by 9 matrix has 81 parameters. Can it be written as a 9 by 1 matrix times a 1 by 9 matrix, and how many parameters does that take?
- 1Count the original parameters
A 9 by 9 matrix holds $9 \times 9 = 81$ numbers.
- 2Count the first factor
A 9 by 1 matrix holds $9 \times 1 = 9$ numbers.
- 3Count the second factor
A 1 by 9 matrix holds $1 \times 9 = 9$ numbers.
- 4Combine the factors
Together the two factors need $9 + 9 = 18$ numbers, far fewer than 81.
The pair needs 18 parameters instead of 81, but it only approximates the original matrix, because factorization is lossy.
In LoRA the same counting applies to the update. A full n by m update has $n \times m$ entries. The two factors A and B together have $r(n + m)$ entries. When r is small compared with n and m, the factored form is much smaller. The gap widens as the matrices grow, but it also widens as r grows, because each extra unit of rank adds $n + m$ new numbers.
- 1n times m is the number of entries in a full update to W.
- 2r times (n plus m) is the number of entries in the two factors A and B together.
- 3For the 8 by 6 example with r equal to 2, the full update has 48 entries, while A and B together have 2 times 14, which is 28 entries.
Why Pre-Training Makes Small Updates Workable
A natural objection is that a model with many parameters should need many parameters to change its behavior. Researchers have argued otherwise. Although large language models have enormous parameter counts, their intrinsic dimension, meaning the true complexity of what they have learned, can be much lower than the number of parameters suggests. Pre-training appears to push this intrinsic dimension down, and larger models tend to end up with lower intrinsic dimensions after pre-training.
If that is true, pre-training works like a compression step that prepares the model for later tasks. A well-trained model needs only a small adjustment to be steered toward a new job, which is why a small set of trainable LoRA parameters and a modest amount of finetuning data can be enough. The source reports that for GPT-3, LoRA reached comparable or better performance than full finetuning on several tasks while training about 4.7 million parameters, roughly 0.0027 percent of the full finetuning count.
The same reasoning raises a question about pre-training itself. If factorization works so well during finetuning, could the model be factorized from the start? Low-rank pre-training could cut parameters and cost substantially, but full-rank pre-training still seems necessary to reduce intrinsic dimension to the point where low-rank methods work well. How much full-rank training is needed before switching is an open question.
Mistakes When Reading LoRA Shapes
Common mistake Thinking that LoRA changes the original W during training
What it looks likeAssuming the optimizer updates every entry of W after each step.
Why it failsOnly A and B are trained, and the original W is kept intact.
Do this insteadTreat W as frozen and the learned change as the separate scaled product AB.
Common mistake Assuming A is r by n and B is m by r
What it looks likeFor an 8 by 6 matrix, writing A as 2 by 8.
Why it failsA must have n rows and r columns so that its r columns match the r rows of B.
Do this insteadUse A equal to n by r and B equal to r by m, which gives 8 by 2 and 2 by 6 here.
Common mistake Ignoring the alpha over r scale
What it looks likeChanging r and expecting only the parameter count to change.
Why it failsThe rank also enters the scaling term, so the size of the contribution changes too.
Do this insteadRemember that alpha and r work together when the update is combined with W.
Common mistake Believing LoRA slows inference because it adds a branch
What it looks likeAssuming the model must run two extra layers at every call.
Why it failsThe adapter is merged into one matrix, so the model structure does not gain layers.
Do this insteadThe added calculation is folded into the weights, so inference latency is not increased compared with the original model.
Checking Your Understanding of LoRA Shapes
What do you think happens?
Before reading the answer, predict the shapes of A and B if W is 9 by 9 and r is 1.
Reveal answer
A is 9 by 1 and B is 1 by 9, and their product AB is 9 by 9, matching W.
A has n rows and r columns, and B has r rows and m columns. With n equal to 9, m equal to 9, and r equal to 1, A is 9 by 1 and B is 1 by 9. Their product is 9 by 9, and the 18 entries of the factors replace the 81 entries of a full update.
W is a weight matrix with n equal to 4 rows and m equal to 10 columns. You choose rank r equal to 3. Work out the shape of A, the shape of B, the number of entries in a full n by m update, and the number of entries in the two LoRA factors together.
Hints
- A has dimension n by r, so start with 4 by 3.
- B has dimension r by m, so it is 3 by 10.
- A full update has n times m entries, and the factors have r times (n plus m) entries.
Key Takeaways
- LoRA selects one weight matrix W of size n by m and freezes it, training only two smaller matrices A of size n by r and B of size r by m.
- The shared dimension r makes the product AB the same n by m shape as W, so the scaled update alpha over r times AB can be added to W.
- Low-rank factorization stores r(n + m) numbers instead of n times m, trading some approximation accuracy for far fewer trainable parameters.
- Pre-training is thought to lower intrinsic dimension, so a small LoRA update can steer a well-trained model, and because the update is merged into W, it adds no extra inference layers.