LoRA Rank Selection
LoRA compresses the learning space into a small rank (r). Choosing 'r' is a tradeoff between capturing complex reasoning (high r) and saving VRAM while preventing overfitting (low r).
Why Does This Exist?
When you apply Low-Rank Adaptation (LoRA) to a model, you freeze the original weights and train two small adapter matrices, and , which multiply together to form the weight update .
The core hyperparameter in LoRA is the Rank (). If the original layer has dimensions , full fine-tuning updates 16.7 million parameters. If you set , matrix is and matrix is . You are now training only 65,000 parameters—a 99.6% reduction.
But how do you choose ? Make it too low (e.g., ), and the adapter doesn't have the "bandwidth" to learn complex behavior. Make it too high, and you lose the VRAM and speed advantages of LoRA, while increasing the risk of overfitting.
Think of It Like This
A summary document
Imagine a massive 500-page corporate manual (the base model). You want to issue an update (the fine-tune).
- Full fine-tuning is rewriting the entire 500-page book.
- LoRA is attaching an executive summary to the front.
- The Rank () is the page limit of that summary.
If , you only get a post-it note. It's enough to say "Change our greeting to 'Hello' instead of 'Hi'" (simple formatting). If , you get a 10-page brief, which is enough to explain a completely new refund policy (complex reasoning/knowledge).
How It Actually Works
The Intrinsic Dimension Hypothesis
LoRA is built on a mathematical theory that heavily parameterized neural networks have a low "intrinsic dimension." This means that while a layer might have millions of parameters, the actual useful changes required to adapt it to a new task can be mapped in a much smaller dimensional space. This is why incredibly small ranks (often or ) perform almost as well as full fine-tuning.
Alpha () and Scaling
Alongside rank, LoRA uses a parameter called Alpha (). is a scaling factor that controls how much the LoRA adapter impacts the final output compared to the frozen base weights. The update is scaled by .
A standard rule of thumb is to set . So if , . This keeps the scale of the gradients stable even if you decide to change in later experiments.
Target Modules
You don't have to apply LoRA to every layer. In transformers, LoRA is most commonly applied to the attention projection matrices (Query and Value layers, q_proj and v_proj).
However, modern best practice for highly complex tasks (like coding or deep reasoning) is to apply LoRA to all linear layers (Query, Key, Value, Output, and the Feed-Forward Network). Targeting all modules with a small rank (e.g., ) generally outperforms targeting just the attention modules with a large rank (e.g., ).
Watch Out For
Setting the rank unnecessarily high
Many engineers default to or because they assume "more trainable parameters equals better performance." In practice, high ranks often lead to overfitting. The model memorizes the training data rather than generalizing. Start with or ; only increase it if the training loss plateaus prematurely.
The Quick Version
- Rank () determines the size of the bottleneck in LoRA's matrix factorization.
- or is usually sufficient for formatting, tone changes, and basic instruction tuning.
- to is used for injecting new languages or deep, complex reasoning tasks.
- Target all linear layers in the transformer for the best results, rather than just the Attention matrices.
- Keep scaled relative to (usually ) to maintain gradient stability.
What to Read Next
- LoRA & QLoRA covers the foundational mechanics of how these matrices are merged.
- PEFT Methods explores alternatives to LoRA, like adapters and prefix tuning.