The Problem: Fine-Tuning a Giant Is Way Too Expensive
Imagine: it's 2020, and you want to adapt GPT-3 (Generative Pre-trained Transformer 3) to your use case. The model has 175 billion parameters. To fine-tune it the traditional way, you need to update every single one of those 175 billion weights.
Concretely, here is what that means for a "small" 7-billion-parameter model. Everything reduces to one multiplication: bytes per parameter x 7 billion.
- Model weights in 16 bits, i.e. 2 bytes per parameter: GB.
- Gradients (the direction in which to nudge each weight) also in 16 bits: another 14 GB.
- Optimizer states: AdamW keeps two running averages per parameter (one of past gradients, one of their squares), each held in 32 bits so it does not drift, i.e. bytes per parameter: 56 GB. This is the heaviest item of all, four times bigger than the weights themselves.
- Total: about 84 GB, before counting intermediate activations. This memory lives on the graphics card (VRAM, for Video Random Access Memory) and caps at 80 GB on the most common datacentre cards. A 7-billion-parameter model already does not fit on a single card.
The item-by-item breakdown is worked out in Full fine-tuning vs parameter-efficient; we will not repeat it here.
And for GPT-3 with its 175 billion parameters? Multiply by 25: you need a cluster of several dozen cards.
But the worst part is that if you have 10 different tasks (translation, summarization, classification), you need 10 complete copies of the model. For a 7-billion-parameter model, that is 10 x 14 GB = 140 GB just to store your models.
Fine-tuning means taking a model already trained on a general task (understanding language) and specializing it for a narrow one. For example, steering a generalist LLM (large language model) towards medical diagnosis or legal drafting. It is sending a general practitioner off for specialist training.
The Brilliant Intuition: The Brain Doesn't Use All Its Capacity
In 2021, researchers at Microsoft had a brilliant intuition. When you fine-tune a model on a new task, you modify its weights. But by how much do you actually modify them?
They measured it, and the answer is staggering: the necessary modification is tiny compared to the model's size. Mathematically, the changes live in a low-dimensional subspace. In plain terms: to learn a new task, the model doesn't need to mobilize all its power. A tiny adjustment is enough.
It's a bit like a concert pianist learning a new piece. They don't relearn how to play piano from scratch. They adjust a few reflexes, memorize a few passages. The foundation is already there.
This observation gave birth to LoRA (Low-Rank Adaptation).
LoRA: Low-Rank Adaptation of Large Language Models (Hu et al., 2021)The Analogy: The Encyclopedia and the Sticky Note Pad
To understand LoRA, imagine this situation.
You own a monumental encyclopedia of 1,000 pages. That's your base model: it knows a tremendous amount of things, but in a general way.
The old method (full fine-tuning): you photocopy the entire encyclopedia, then modify pages one by one with correction fluid and a pen. Result: you have a second complete 1,000-page encyclopedia, adapted to your needs. It's heavy, it's expensive, and if you want one version for medicine and another for law, you need two modified copies.
The LoRA method: you keep the original encyclopedia intact, and you stick a small pad of sticky notes on it. This pad is only 5-10 pages and contains just the adjustments: "page 42, replace this concept with that one", "page 317, add this nuance". When you read the encyclopedia, you combine both: the original text + the notes from the pad.
The advantages are huge:
- The pad weighs 1,000 times less than the encyclopedia
- You can have dozens of pads for different domains, all based on the same encyclopedia
- The original encyclopedia is never damaged
- You can swap pads with other people easily

How It Actually Works
Now, let's dive a bit into the mechanics. Don't worry, we'll go step by step.
Weight Matrices: The Heart of the Model
A model like LLaMA or GPT is made up of layers, and each layer contains weight matrices. A matrix is simply a large table of numbers. A 4096 x 4096 matrix contains numbers, about 16.8 million.
Those numbers are learned parameters: they were fixed during pre-training and do not change while the model works. Keep them apart from activations, which are the results recomputed on every pass over a new piece of text. LoRA acts on the former, never on the latter.
When you do traditional fine-tuning, you compute an adjustment (called ΔW, "delta W") for each matrix. That ΔW is exactly the same size as the original matrix: 16.8 million parameters to store and update. That is what makes it expensive.
The LoRA Trick: Decompose Into Two Small Matrices
The key idea of LoRA: instead of storing this large ΔW directly, we decompose it into two much smaller matrices. ΔW is replaced by the product B multiplied by A, where A is of size r by 4096 and B of size 4096 by r.
The r is the rank, a number you choose, typically between 4 and 64. It is the knob that sets the "size of the sticky note pad."
Three categories, never to be mixed up, this is exactly where readers get lost.
- Frozen: the original matrix W. The input passes through it, it contributes to the output, but not one of its values moves during LoRA fine-tuning.
- Learned: the two small matrices A and B, and nothing else. These are the trainable parameters, and these are what the adapter file contains.
- Recomputed on every pass: the activations, the vectors flowing through the network for the text currently being processed. None of them are saved.
And at the end, merged: since B x A has exactly the shape of W, the two can be added together once and for all before deployment. The model you then serve is indistinguishable from an ordinary one.

To concretely illustrate the savings, let's take r = 16:
- A: 16 x 4096 = 65,536 parameters
- B: 4096 x 16 = 65,536 parameters
- Total: 131,072 parameters
The general rule, and the one worth remembering: you go from parameters to . Here : you train under one percent of this matrix, i.e. 128 times fewer parameters.
Imagine you need to describe the positions of 1,000 stars in the sky. If they're scattered throughout all of 3D space, you need 3,000 coordinates. But if they're almost all lined up along a single line, you can describe that line (a few parameters) and then just the distance of each star along that line. That's the idea of low rank: the modifications during fine-tuning aren't scattered in every possible direction, they concentrate along a few key directions.
An Important Detail: Initialization
LoRA uses a simple but crucial trick:
- Matrix A is initialized with small random values
- Matrix B is initialized to zero
Why? Because B x A = 0 at the start. The model therefore begins identical to the original model, then progressively learns its adjustments. No surprises at startup.
During Inference: It's Free!
One of the most elegant advantages of LoRA is that it doesn't slow down the model at all in production. Once training is done, you can merge the adapters with the original weights:
Read the formula back in words: the weights you serve are the original weights, plus the product of the two learned matrices, scaled by the ratio . is the frozen matrix, and the two learned ones, the chosen rank, a setting explained next.
The result is a matrix the same size as the original. The model runs at the same speed as before, as if nothing had happened. The sticky note pad has been copied into the encyclopedia.
α (alpha) sets how much weight the LoRA correction carries relative to the original weights. Larger α, heavier correction. In practice α = r (so α/r = 1) or α = 2r. It is a volume knob: too low and the adaptation is inaudible, too high and it drowns out the base knowledge.
Why divide by r? Because otherwise doubling the rank would mechanically double the size of the correction, and you would have to retune the learning rate every time you changed the rank. The division makes settings portable across ranks.
The Numbers Speak: Before and After LoRA
Take LLaMA-2 7B, whose exact count is 6,738,415,616 parameters, and apply LoRA with r = 16 to the four attention matrices in each of its 32 layers. All of those matrices are square, 4096 x 4096.
That is 16.8 million trainable parameters, i.e. of the total, one parameter in four hundred.
| Full fine-tuning | LoRA (r = 16, attention only) | |
|---|---|---|
| Trained parameters | 6.74 billion (100%) | 16.8 million (0.25%) |
| Graphics card memory | about 84 GB, activations excluded | about 16 GB |
| Saved file size | 14 GB | bytes MB |
| Training throughput | baseline | higher, the LoRA paper says so without putting a number on it in its abstract |
Read the file-size line again: 34 MB instead of 14 GB, roughly 400 times lighter. A LoRA adapter fits in an email.
We put no number on a "quality" row. The paper claims quality "on par or better than" full fine-tuning on the models it tested, and that is all that has been published: the "95 to 99% of performance" figures that circulate trace back to no identifiable measurement.
And with a 70-billion-parameter model: full fine-tuning wants a cluster, LoRA fits on one well-equipped machine.
LoRA democratized fine-tuning. Students, startups and independent researchers could suddenly customize models previously reserved for large corporations.
Which Layers to Adapt?
In a Transformer, there are several types of weight matrices. LoRA can be applied to any of them, but some are more cost-effective than others.
Attention Matrices (The Classic Choice)
The attention mechanism rests on four weight matrices, one per role:
- (query): "what is this word looking for?"
- (key): "what does this word contain?"
- (value): "what information does this word carry?"
- (output): "how do we recombine the results?"
Mind the distinction, it comes up constantly: what gets adapted are these weight matrices, not the Q, K and V vectors they produce. The former are learned once; the latter are recomputed for every piece of text.
The original paper shows that targeting and with rank r = 4 is already enough to rival full fine-tuning on GPT-3. Today the common practice is to adapt all four.
Multi-Layer Perceptron Layers
Each Transformer layer also contains a small network called a multi-layer perceptron, abbreviated MLP, three matrices named gate_proj, up_proj and down_proj in most implementations. Adapting them on top of the attention matrices sometimes buys a little quality, at the cost of more trainable parameters.
Two claims you can check in the LoRA abstract: the method cuts trainable parameters by a factor of 10,000 and graphics card memory by a factor of 3 on GPT-3 175B, for quality "on par or better than" full fine-tuning on the models tested (RoBERTa, DeBERTa, GPT-2, GPT-3).
The factor of 10,000 checks out: 175 billion divided by 10,000 is 17.5 million trainable parameters, the right order of magnitude for a low-rank LoRA on the attention matrices alone.
Which matrices to target is studied in the paper at a fixed parameter budget: a small rank spread over and beats a rank twice as large on only one of them.
Practical Guide: How to Choose Your Hyperparameters
Rank r: The Size of Your Sticky Note Pad
This is the most important parameter. The larger r is, the more expressive your adapter is (but also larger).
- r = 4 to 8: for simple tasks (labelling a review positive or negative, pulling out proper nouns). A pad of a few pages.
- r = 16 to 32: the balance point for most cases. This is the usual recommended default.
- r = 64 to 128: for heavy adaptations, changing the model's writing style, pushing it into a domain far from its training data. A thick notebook.
- r beyond 256: rarely useful. The risk becomes overfitting: the model memorizes the training examples instead of extracting a general rule. And you drift back towards the cost of full fine-tuning.
Learning Rate
The learning rate is the size of each correction applied to the parameters. With LoRA you set it higher than in classic fine-tuning, typically 0.0001 to 0.0003 against 0.00001 to 0.00005. The reason is intuitive: you are touching almost nothing, and that almost-nothing starts from zero, so each correction can be bolder without damaging the model.
Which Layers to Target?
- The minimum:
q_proj,v_proj, i.e. and (those are the names these matrices carry in code). - The standard:
q_proj,k_proj,v_proj,o_proj, i.e. all of attention. - The maximum: every linear layer, attention and multi-layer perceptron alike.
Do not confuse trainable parameter count with result quality. At equal budget, a low rank spread over many matrices often beats a high rank concentrated on two of them, which is precisely what the original paper measures. Sprinkle rather than concentrate.
In Practice: A LoRA Fine-Tuning in a Few Lines
Thanks to Hugging Face's PEFT (Parameter-Efficient Fine-Tuning) library, applying LoRA takes a few lines:
from peft import LoraConfig, get_peft_model
config = LoraConfig(
r=16, # The rank: size of the sticky note pad
lora_alpha=32, # The scaling factor alpha, here 2r
target_modules=[ # The weight matrices to adapt
"q_proj", "k_proj", "v_proj", "o_proj"
],
lora_dropout=0.05, # A bit of regularization
bias="none",
task_type="CAUSAL_LM"
)
model = get_peft_model(base_model, config)
model.print_trainable_parameters()
# On LLaMA-2 7B: 16,777,216 trainable parameters
# out of 6,755,192,832 total, i.e. 0.25%
A quarter of a percent: one parameter in four hundred. And the results stand comparison with full fine-tuning.
Modularity: LoRA's Most Underrated Asset
Since the original weights are never modified, you can:
-
Store dozens of adapters for a single base model. A medical adapter, a legal one, a code one, a few dozen megabytes each, instead of three complete 14 GB copies.
-
Swap adapters on the fly. The server loads the base model once, then plugs in whichever adapter the request calls for. Medicine? Plug in the medical adapter. Code? Swap it out. One caveat, though: this only works if you do not merge the adapter into the weights. Merging removes the compute cost of the LoRA branch but locks the model into a single specialty. You have to pick one.
-
Share easily. The community has published thousands of LoRA adapters on the Hugging Face Hub. A file of a few dozen megabytes is enough to specialize a model.
-
Combine adapters. Techniques exist for merging several adapters to stack their specialties, covered in Model merging: TIES.
The Limits: What LoRA Can't Do
LoRA is powerful, but it's not magic. Here are its limits:
-
No deep restructuring. LoRA adjusts the model, it doesn't fundamentally transform it. If the base model has zero knowledge of a domain, LoRA will struggle to fill the gap from nothing. It's an adjustment, not a reconstruction.
-
A rank that is too small degrades the result. If the task is complex and r too low, the adapter has no room to carry the adjustments it needs. It is summarizing a novel on one sticky note.
-
Catastrophic forgetting is mitigated, not eliminated. The original weights are frozen, which protects the base knowledge. But the adapter can still over-specialize the model: excellent on the target task, weaker everywhere else. The mechanism is described in Full fine-tuning vs parameter-efficient.
The Impact: A Quiet Revolution
Before LoRA: fine-tuning belonged to organizations with clusters of graphics cards. Adapting GPT-3 was a luxury.
After LoRA: one consumer card is enough to fine-tune a 7-billion-parameter model on your own dataset. Adapters circulate freely.
LoRA became the reference method for efficient fine-tuning, and spawned a family of variants. Each one fixes a specific flaw in the last:
- QLoRA (Quantized LoRA): LoRA leaves the frozen model in 16 bits, i.e. 14 GB for a 7-billion-parameter model, which stays the dominant memory item. QLoRA compresses that frozen model to 4 bits to free it up.
- DoRA (Weight-Decomposed Low-Rank Adaptation): LoRA's correction changes the length and the orientation of the weights in one lump. DoRA splits the two and applies the low-rank trick to orientation only.
- AdaLoRA (Adaptive LoRA): LoRA forces the same rank on every layer, though layers do not all need the same. AdaLoRA redistributes the rank budget to where it pays.
LoRA rests on one simple idea: when a model learns a new task, the change needed in its weights is low-rank, two small matrices can carry it instead of one large one. The cost of fine-tuning dropped by several orders of magnitude.
Technical Corner: The Exact Formulation
Consider a pre-trained linear layer whose weight matrix has rows and columns. The ordinary forward pass computes:
where is the layer's input vector, the frozen weight matrix, and the output vector. In words: push the input through the matrix.
With LoRA, that computation becomes:
The same input additionally travels the narrow route then , and the two results are added. Symbol by symbol:
- , of size by , initialized with small random values. Learned parameter.
- , of size by , initialized to zero. Learned parameter.
- , the rank, very small next to and , the bottleneck the correction is forced through.
- , the scaling factor, with acting as the volume of the correction.
- : frozen, never updated.
Trainable parameters per layer therefore go from to . With and : from 16,777,216 down to 131,072, i.e. 128 times fewer.

The mathematical beauty: since B multiplied by A always produces a matrix of rank at most r, the space of possible adaptations is constrained to a subspace of dimension r. LoRA's hypothesis, validated empirically, is that this subspace is sufficient to capture the necessary adaptations for most fine-tuning tasks.
1. A rank-16 LoRA on LLaMA-2 7B reports 16.8 million trainable parameters. Where does that number come from?
2. During LoRA fine-tuning, what exactly happens to the original matrix W?
3. After training you can merge the adapter into the weights (W + BA). What do you gain, and what do you lose?
4. With a fixed budget of trainable parameters, what does the LoRA paper recommend?
5. Before LoRA, why does fully fine-tuning a 7-billion-parameter model overflow the 80 GB of a data-center GPU?