Zenaique

Rank r in LoRA: what does the number actually count?

Flashcard·Easy·4.0 · 0·~30s·Asked atSambanovaSapWeaviate·Relevant atDatabricks
Attempt it
TL;DR

Rank r is the shared inner dimension of the LoRA factorisation. It linearly controls trainable parameter count and caps how many directions in weight space the adapter can move.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

Picture trying to summarise a thick novel using a fixed number of index cards. With four cards you can capture the broadest strokes; with sixty-four you can keep most of the nuance; with two hundred you are essentially copying the book. The number of cards is the rank. In LoRA, rank r decides how many independent directions of change the adapter has to work with. Too few cards and you cannot capture the new behaviour. Too many and you have lost the whole point of a compact summary. The sweet spot sits in the middle, big enough to express what you need, small enough to stay cheap. The smaller the number, the more compressed the change has to be.

Concept explanation~2 min read

Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.

Rank r is the most important hyperparameter in LoRA and one of the most commonly misunderstood. People know it controls some kind of capacity, but few can explain precisely where it appears in the math, what it costs in parameters and memory, or how it interacts with the companion hyperparameter alpha. Getting this wrong leads to fine-tunes that quietly underfit, fine-tunes that overfit small datasets, or fine-tunes that throw away LoRA's storage benefits by picking r so high you are nearly back to full-rank cost.

This deep dive walks through the geometry of LoRA, locates where r appears in the factorisation, derives the parameter count and the expressive ceiling from the shapes, explains the alpha/r scaling that turns r into a magnitude knob as well as a capacity knob, and surveys the typical r ranges that have emerged across the open-weight ecosystem.

The headline is that r controls two things at once. Trainable parameter count grows linearly with r because the adapter matrices have shape d x r and r x k. The expressive ceiling is also r, because the rank of the update matrix BA cannot exceed the shared inner dimension. These two consequences are tightly coupled, and tuning r means navigating the trade-off between expressive capacity and the cost (in parameters, optimizer state, and serving memory) of providing that capacity.

For most production work, r lives between 8 and 64. Outside that range you should have a specific reason: either the task is narrow enough that r=4 is sufficient, or you have measured a quality gap that genuinely requires r above 64. Default to r=8 or r=16 for new fine-tunes and tune from there based on measured behaviour, not based on the intuition that bigger is better.

Where r appears in the LoRA factorisation

The factorisation

LoRA replaces a full-rank weight update with a low-rank one. If the original weight matrix is W of shape d x k, the update is written as:

ΔW=BA\Delta W = B A

where B has shape d x r and A has shape r x k. The full updated weight at inference time is W + (alpha / r) * B A. During training, only B and A are updated; W stays frozen.

The two roles of r

The integer r plays two roles simultaneously. First, it is the second dimension of B and the first dimension of A, so it controls how many trainable parameters live in the adapter. The total parameter count per adapted layer is:

r(d+k)r \cdot (d + k)

Second, it is the rank of the product matrix BA. By the rank-of-product inequality, the rank of BA is at most min(d, r, k), which for typical large layers (r much smaller than d and k) equals r. So r is also the maximum number of linearly independent directions in weight space that the adapter can move.

Initialisation matters

B is initialised to zero. A is initialised with small random Gaussian values. This is deliberate: at step zero the product BA is the zero matrix, so the adapted model behaves identically to the base. Once gradients start flowing, B lifts off zero and the adapter begins to deviate. Symmetric zero initialisation on both matrices would freeze the adapter at zero forever because the gradient through a zero product is zero in both directions.

Parameter count, memory, and the linear scaling
The expressive ceiling and the intrinsic-rank hypothesis
Alpha, the alpha/r scaling, and picking r in practice
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.
Rank rTrainable params (per 4096x4096 layer)Typical use case
4~32kNarrow style adaptation
8~65kDefault starting point
16~131kCommon instruction tuning
64~524kBroad behaviour shaping
128~1MDiminishing returns territory

Real products, models, and research that use this idea.

  • Hugging Face PEFT defaults LoRA r to 8 in its example configs, a starting point most teams keep for initial experiments.
  • QLoRA fine-tunes of Llama 4 Maverick commonly use r=64 with alpha=16 on all linear layers, balancing capacity against single-GPU memory.
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QWhy does LoRA initialise B to zero and A randomly?
A

Zero-init on B ensures the adapter starts as the identity (the product BA is zero), so the model behaves exactly like the base at step zero. Random A ensures gradients can flow through both matrices once training starts. Symmetric zero-init would freeze the adapter at zero forever.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Confusing rank r with the number of LoRA layers. r is the inner dimension of each adapter matrix; the number of layers and which modules get adapted are separate config choices.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • Where r appears in the LoRA factorisation

  • The formula for adapter parameters per layer

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
What is RLHF, and why is it used after pretraining?
MCQ·Easy