Concepts / Adapter Methods for Parameter-Efficient Finetuning

Adapter Methods for Parameter-Efficient Finetuning

Two facts about W define the whole method. W is the frozen original, and its size, n by m, is the size that any learned change must match.

  • Programming

Why Not Retrain Every Weight

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 it not slow the model down when it runs? The only reliable way to answer this is to follow one weight matrix from start to finish, so that is where we begin.

Picking the 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 will never change W itself during training.

Key point

Two facts about W define the whole method. W is the frozen original, and its size, n by m, is the size that any learned change must match.

During finetuning only the new matrices are trained, and the original W is kept intact. This is the reason the method saves memory and computation: the large matrix is never updated, and the optimizer only has to track the small matrices that LoRA creates.

Shapes of A and B

Once W is chosen, LoRA picks a number r. This number sets the size of the two smaller matrices. Matrix A has dimension n by r, and matrix B has dimension r by m. In shape notation, $A \in \mathbb{R}^{n \times r}$ and $B \in \mathbb{R}^{r \times m}$.

Notice how 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. That match is exactly what makes it possible to combine them later. The product $AB$ has shape $(n \times r)(r \times m) = n \times m$.

Wn rows by m columns, frozenAn rows by r columnsABn rows by m columns, sameas WBr rows by m columnsmultiplyshared inner rsame shape
If W is n by m and the rank is r, what are the row and column counts of A and B, and why does their product match W's shape?
Worked example

Shapes and Size for a 1000 by 1000 Matrix

W is a 1000 by 1000 matrix (n = 1000, m = 1000), and LoRA is configured with rank r = 8. Find the shapes of A and B and check that their product matches W.

  1. 1
    Read the dimensions of W

    Here n = 1000 and m = 1000, so W has 1000 rows and 1000 columns.

  2. 2
    Set the shape of A

    A has dimension n by r, which is 1000 by 8. It has 1000 rows and 8 columns.

  3. 3
    Set the shape of B

    B has dimension r by m, which is 8 by 1000. It has 8 rows and 1000 columns.

  4. 4
    Check the inner dimension

    A has 8 columns and B has 8 rows, so they can be multiplied.

  5. 5
    Check the product

    The product AB has 1000 rows (from A) and 1000 columns (from B), so it is 1000 by 1000, exactly the shape of W.

Result

A is 1000 by 8, B is 8 by 1000, and AB is 1000 by 1000. The product matches W, so it can be added to W.

Scaling and Merging the Update

After 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.

Formula

Read the formula as a shape contract. A and B are the only pieces LoRA creates. Their product reconstructs something with the footprint of W, but it is built from far fewer numbers whenever r is small compared with n and m. The scale factor divides by r, so alpha and r work together. Alpha is a setting you choose to decide how much the update should contribute. Because the rank appears in the scale, changing r also changes how large the contribution is, not just how many parameters are stored.

The forward pass can be read in two equivalent ways. One reading is that the input passes through the frozen W and also through the scaled B then A path, and the two outputs are summed. The other reading is that the input passes through the single merged matrix W'. Because matrix multiplication distributes over addition, these give the same result. This is why the adapted model can be treated as one matrix.

Input xm entriesFrozen Wn by m, never trainedSumWx plus scaled updateOutputn entriesBr by m, trainedAn by r, trainedScale by alpha over rscaled learned contributionmultiply by Wmultiply by Bmultiply by AscaleWxscaled updateadd
During a forward pass, the input reaches the frozen W and the B then A path. The two results are scaled and added to form the output.

Why Factorization Saves Parameters

LoRA is built 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.

What do you think happens?

A 9 by 9 matrix has 81 entries. If you write it as a 9 by 1 matrix times a 1 by 9 matrix, how many numbers do you need to store in total?

Reveal answer
Answer:

18 numbers: the 9 by 1 matrix has 9 values and the 1 by 9 matrix has 9 values.

The source example uses this exact case. The factored pair needs 18 parameters where the full matrix needs 81, but the pair only approximates the original, so the saving comes with a loss of information.

The savings are dramatic, but the trade is that factorization is lossy. The pair only approximates the original matrix. A higher rank preserves more of the original information, while a lower rank compresses harder and discards more. In LoRA, this means that choosing r is a decision about how much change the update can express, not only how many numbers are stored.

Full updaten times m valuesA and B pairr(n + m) values9 by 9 example81 values9 by 1 and 1 by 9pair18 values, r = 1replaced byfactorized
A full n by m update needs n times m values, while the pair A and B needs r(n + m) values. The gap grows as r gets smaller relative to n and m.
Best practice

When you compare LoRA settings, compute r(n + m) for each candidate rank and compare it with n times m. Small r gives a large reduction in trainable values, but a small r also gives the update less room to express a change, so the choice of r always balances savings against approximation quality.

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. This 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.

Mistakes Learners Make with LoRA Shapes

  • Common mistake

    Thinking LoRA changes W during training

    Why it fails

    The source is explicit that only A and B are trained and the original W is kept intact. The learned change lives in A and B, not in W.

    Do this instead

    Treat W as fixed and track the trainable values only in A and B.

  • Common mistake

    Giving A the shape r by n, or B the shape m by r

    What it looks like

    For W of size 1000 by 1000 with r = 8, writing A as 8 by 1000 breaks the product because AB would then not have W's n rows.

    Why it fails

    A must be n by r so that its rows match W's rows, and B must be r by m so that its columns match W's columns.

    Do this instead

    Write A as n by r and B as r by m, then check that the inner r values match before you multiply.

  • Common mistake

    Assuming a smaller r never hurts

    Why it fails

    The source notes that factorization is lossy and that a lower rank compresses harder and discards more of the original information.

    Do this instead

    Choose r by balancing the parameter savings against how much change the update must express.

  • Common mistake

    Believing alpha alone sets the update size, without considering r

  • Common mistake

    Assuming LoRA adds inference latency

    Why it fails

    The added calculation is folded into the weights, so the model keeps its original structure and does not gain extra layers.

    Do this instead

    Remember that the adapted matrix W' replaces W, so the runtime structure is unchanged.

Tracing a Single Matrix Through LoRA

MEDIUM

A weight matrix W has n = 512 rows and m = 256 columns. LoRA is configured with rank r = 4. Give the shapes of A and B, check that their product matches W, and then count how many trainable values the pair contains compared with a full 512 by 256 update.

Hints
  • A has dimension n by r, so start by writing its rows and columns from n = 512 and r = 4.
  • B has dimension r by m. Its inner dimension must match A's columns.
  • The number of values in a matrix is rows times columns. Compare n times m with r times (n + m).
EASY

Explain in one sentence why the adapted matrix W' can be used in place of W without adding a new layer to the network.

Hints
  • Think about what happens to the product AB after training.
  • The source says the adapted matrix is used in place of W.

Pulling the Mechanism Together

Following one matrix from start to finish shows the whole mechanism. LoRA chooses a weight matrix W of size n by m and freezes it. It chooses a rank r and creates A of size n by r and B of size r by m. Their product AB has the same shape as W. The product is scaled by alpha over r and added to W, producing W', which replaces W in the model. Because the change is merged into one matrix, the structure and speed of the model stay the same. The reduction in trainable values comes from factorization, and it works for finetuning because pre-training lowers the intrinsic dimension of the model.

Key Takeaways

  • LoRA chooses a weight matrix W of size n by m, keeps it frozen, and trains only two smaller matrices A (n by r) and B (r by m).
  • The product AB has the same n by m shape as W, so the scaled update alpha over r times AB can be added to W to form the adapted matrix W'.
  • Low-rank factorization reduces trainable values from n times m to r(n + m), at the cost of an approximation that is lossy when r is small.
  • Because the update is merged into a single matrix, LoRA adds no extra layers and no inference latency, and pre-training lowers intrinsic dimension so that small updates are enough.

Related concepts

More concepts starting with A