Low-Rank Adaptation (LoRA) Technique
A higher LoRA rank does not automatically improve performance. Beyond a certain value, extra rank may give no discernible gain and can overfit, so the rank should be tuned by experiment.
Testing the Bigger-Is-Better Belief
When people first configure LoRA, a tempting rule of thumb appears: if a little adaptation helps, a larger adapter should help more. Under that belief, the safest move is to set the rank as high as the hardware allows. This article tests that belief against what the research reports. Configuring LoRA means making three kinds of decisions: which weight matrices receive an adapter, what rank each factorization uses, and how the scaling hyperparameters are set. After that, you still have to decide how the adapted model will be served.
What do you think happens?
Suppose every other setting stays fixed and you keep raising the rank r of your LoRA adapters. Which outcome do you expect?
Reveal answer
Performance does not automatically improve. Past a certain value, extra rank may give no discernible gain and can overfit.
The rank sets how many parameters each adapter contains. More parameters give more capacity to change the base model, but extra capacity is not the same as extra quality. The LoRA authors found that increasing r did not increase finetuning performance.
Keep the wrong belief in mind as you read. The rest of this article replaces it with a more accurate picture of how rank, matrix choice, and serving strategy interact, and it traces what actually happens to the numbers at each step.
Where the Adapter Attaches
LoRA can be applied to each individual weight matrix in a model. Its efficiency therefore depends on two things: which matrices receive an adapter, and the model's architecture, because different architectures have different weight matrices. LoRA has been used in other architectures such as convolutional neural networks, but it has been used primarily with transformer models.
In transformers, LoRA is most commonly applied to the four weight matrices inside the attention modules: the query matrix $W_q$, the key matrix $W_k$, the value matrix $W_v$, and the output projection matrix $W_o$. The choice is usually applied uniformly, so applying LoRA to the query matrix means applying it to every query matrix in the model.
Adapting more matrices, including the feedforward matrices, can yield better results. Databricks found that the biggest performance boost they obtained came from applying LoRA to all feedforward layers. Fomenko et al. reported that feedforward-based LoRA can complement attention-based LoRA, but attention-based LoRA typically offers greater efficacy within memory constraints.
Tracing the Forward Pass
The core idea of LoRA is that the frozen base weight W stays unchanged, while two small trainable matrices A and B learn a low-rank update. During a forward pass, the layer output is the base output plus the adapter's contribution. The adapter's product BA has the same shape as W, so it can be added directly to it.
Here $h$ is the layer output, $x$ is the input, $W$ is the frozen base matrix, $B$ and $A$ are the trainable low-rank matrices, and $\frac{\alpha}{r}$ is the scaling factor. The scaling factor is what ties alpha and r together, and it is discussed further below.
Counting trainable parameters for one adapted matrix
A single weight matrix W has shape 1024 by 1024. Compare the number of trainable parameters when you fully finetune it against a LoRA adapter at rank r = 8, where A has shape r by k and B has shape d by r.
- 1Count the full matrix
Full finetuning trains every entry of W, so it has 1024 times 1024 = 1,048,576 trainable parameters.
- 2Count matrix A
A has shape r by k = 8 by 1024, which is 8,192 parameters.
- 3Count matrix B
B has shape d by r = 1024 by 8, which is 8,192 parameters.
- 4Add the two adapter matrices
Together the adapter has 8,192 plus 8,192 = 16,384 trainable parameters, which is r times (d + k).
- 5Compare the two
16,384 is about 1.56 percent of 1,048,576, so this one matrix is trained with a small fraction of the full parameter count.
A rank-8 adapter on this matrix trains 16,384 parameters instead of 1,048,576. The product BA has shape d by k, matching W, so the update fits directly into the layer.
Rank, Alpha, and the Parameter Budget
Rank is not the only hyperparameter. The value alpha controls how much the adapter's product contributes when it is merged into the base weights. Because the scaling factor is alpha over r, the two hyperparameters should be configured together. In practice, the ratio of alpha to r is typically set somewhere between 1:8 and 8:1, but the best ratio varies by task.
A useful intuition from the source is that if r is small, you might want alpha to be larger, and if r is large, you might want alpha to be smaller. Because the optimal pair depends on the task, experimentation is needed to find the best (r, alpha) combination for your use case.
The same budget can be spent in several ways. In the GPT-3 175B finetuning setup described in the source, Hu et al. set a trainable parameter budget of 18M, which is 0.01 percent of the model's total parameters. Within that budget, the parameters could go to one matrix at rank 8, two matrices at rank 4, or all four attention matrices at rank 2. The table below shows the idea for a single generated matrix size, where each option costs the same.
| Configuration | Matrices adapted | Rank | Trainable parameters (d = k = 1024) |
|---|---|---|---|
| One matrix at rank 8 | 1 | 8 | 16,384 |
| Two matrices at rank 4 | 2 | 4 | 16,384 |
| Four matrices at rank 2 | 4 | 2 | 16,384 |
Three ways to spend the same parameter budget on one 1024 by 1024 matrix size (generated example)
The source reports that on its benchmarks the value and output matrices scored higher than the query and key matrices in the single-matrix case. It also reports that applying LoRA to all four matrices at rank 2 gave the best performance on WikiSQL and MultiNLI. If you can choose only two attention matrices, the query and value matrices generally yield the best results.
Why Higher Rank Stops Helping
The source gives two reasons a large rank can disappoint. First, a higher r can lead to overfitting, which means the adapter learns the training data too closely and generalizes worse. Second, a larger adapter costs more memory and training effort without a matching gain. Studies have shown that a small r between 4 and 64 is usually sufficient for many use cases, and a smaller r means fewer LoRA parameters and a lower memory footprint.
The opposite case also appears in the source: a researcher found that r = 256 achieved the best performance on his tasks. The lesson is not that large ranks are bad. The best rank depends on the task and must be tested. Turning r down risks underfitting if the task needs more capacity, so the right setting is found by experiment.
Merged or Separate: Tracing the Serving Path
Once a LoRA model is trained, there are two general ways to serve it. The first merges the LoRA matrices A and B into the original model to create a new matrix W' before serving. Because no extra computation happens during inference, no extra latency is added. The second keeps W, A, and B separate during serving. The combination of the adapter with W then happens during inference, which adds latency.
The first option is generally better if you have only one LoRA model to serve. The second is generally better for multi-LoRA serving, which means serving multiple LoRA models that share the same base model. Keeping adapters separate adds some latency, but optimization techniques can reduce the added latency.
Imagine you finetune a model for each of 100 customers using LoRA. You end up with 100 finetuned models that all share the same base model. If you merged each one, you would store 100 full matrices for every adapted layer. If you keep the adapters separate, one base matrix W is reused across all of them, and each customer contributes only a small adapter. The trade-off is a little extra latency per request in exchange for far less storage.
Mistakes Beginners Make with LoRA Settings
Common mistake Assuming the highest possible rank is the safest choice
Why it failsBeyond a certain value, extra rank may give no discernible gain and can overfit, while costing more memory and training effort.
Do this insteadStart from a small rank, often in the 4 to 64 range, and raise it only when evaluation shows a gap.
Common mistake Setting alpha without considering r
Why it failsThe scaling factor is alpha over r, so the same alpha produces a different update size at different ranks.
Do this insteadConfigure alpha and r together, keeping the ratio between 1:8 and 8:1 as a starting range, then tune by experiment.
Common mistake Choosing matrices without considering the budget
Why it failsA fixed budget means adapting more matrices forces a lower rank on each, so the two choices trade off against each other.
Do this insteadDecide the budget first, then compare configurations such as one matrix at rank 8 against four matrices at rank 2.
Common mistake Merging adapters when many models share one base, which multiplies storage needs
Common mistake Keeping adapters separate for a single model in production when latency matters most
Choosing a Configuration for Your Task
You have a fixed parameter budget for LoRA on a transformer. You are choosing between adapting the query and value matrices at rank 4 each, or adapting only the value matrix at rank 8. Using the parameter-count logic from the worked example, which option uses the same number of trainable parameters, and what would you test next to decide which one performs better on your task?
Hints
- Count trainable parameters as r times (d + k) for each adapted matrix, and compare the totals.
- Both options use the same matrix size, so compare the number of matrices times the rank.
- Performance is decided by experiment, so plan an evaluation rather than assuming the answer from the parameter count alone.
Key Takeaways
- A higher LoRA rank does not automatically improve performance. Beyond a certain value it may give no discernible gain and can overfit, so rank should be tuned by experiment.
- LoRA is most commonly applied to the query, key, value, and output matrices in attention modules, and adapting feedforward matrices can yield better results. Under a fixed budget, you trade the number of matrices against the rank on each.
- The scaling factor alpha over r should be configured together with r, with the ratio typically between 1:8 and 8:1, and the best pair depends on the task.
- Merging LoRA weights adds no inference latency but stores a full matrix per model, while keeping adapters separate adds latency but greatly reduces storage when many models share one base.