LoRA as a small correction
Specialization need not update every weight. LoRA adds a small factored correction. Explain its capacity, scale, initialization, and gradient path before assuming it removes the cost of training.
#Section 27Full fine-tuning
A weight needs more company in training than in inference: its gradient and the optimizer’s running statistics. A model that fits for generation can fail to fit for training.
Updating all parameters and compute cost
Full fine-tuning makes all selected parameters trainable, normally all of them. The forward pass predicts, backpropagation computes gradients, and the optimizer updates weights. The forward pass is a full decoder computation however small the dataset.
Memory cost and optimizer-state cost
An optimizer state is information retained between updates. Adam stores running gradient statistics alongside trainable parameters; those tensors add memory beyond the weights.
Activations and temporary buffers add further memory. Mixed precision can also retain a high-precision copy of weights.
#Section 28Parameter-efficient fine-tuning
The stockroom task needs a small tool vocabulary and a consistent protocol. Updating every feature may be unnecessary, and storing a full model copy per specialization is expensive.
PEFT, adapters, and why LoRA exists
Parameter-efficient fine-tuning, or PEFT, trains a subset of parameters or a small added set. An adapter is a trainable component attached to a fixed model. PEFT methods differ in what they change; the term is not a synonym for LoRA.
Low-rank adaptation, or LoRA, adds a factored correction to a weight matrix and keeps the original fixed. Hu and colleagues introduced it in 2021 as a useful restriction on adaptation, not a proof that all updates are low rank. LoRA paper.
Training still runs the base forward pass, and gradients still flow through frozen layers to reach earlier adapters. LoRA removes base gradients and base optimizer state, but activations and most decoder compute remain. Its memory saving is easier to predict than its speedup.
#Section 29LoRA intuition
A projection already encodes useful language patterns, and we want it to adapt to tool calls without replacing it. Write the effective matrix as the old one plus a learned correction.
Frozen base weights and low-rank updates
Frozen weights take part in the forward pass but get no optimizer updates. A low-rank update expresses change through fewer independent directions than a general dense matrix. For a projection from width to , LoRA learns factors and instead of every entry.
Read this as the effective weight is the frozen weight plus correction . With column vectors, is d_out × d_in; libraries may store the transpose for the same map.
Why low rank can be enough
Adapting a trained representation may need far fewer directions than learning it from scratch. A small rank can still touch every output coordinate; it does not mean only a few rows change, nor that the capacity suffices for every task.
#Section 30Low-rank factorization
A matrix with many entries can describe a change built from one shared feature. What matters is how many independent directions the update can express, not how many entries are nonzero.
Matrices A and B, rank r, and shape intuition
The rank is the width of the adapter's intermediate representation. is r × d_in, mapping the input to features; is d_out × r, expanding them back. Their product is d_out × d_in with rank at most .
4 × 4 rank-one correction uses a 4 × 1 and a 1 × 4 factor. The computed count falls from 16 dense entries to 8 factor entries.Read actual projection shapes: grouped-query keys and values are narrower than queries, so their adapter costs differ.
#Section 31LoRA forward pass
Follow the two paths in the figure: the original projection and a small learned correction.
Base projection, adapter branch, and combining outputs
Read this as the output is the base projection plus the scaled adapter projection. Computing first avoids building a dense during unmerged inference.
Training only adapter parameters
Base output and correction must match in shape, device, and dtype. Check rectangular projections, which reveal transpose bugs that square matrices can hide.
The optimizer gets only the factors and any explicitly chosen extras. Freezing stops updates to , not gradient flow through it; gradients still pass to the input and upstream adapters.
#Section 32LoRA scaling
Doubling rank changes both the number of features and how their output is scaled. A comparison that silently changes the effective scale confuses capacity with update size.
Rank, alpha, and alpha/r
The alpha setting scales the correction. In the original convention, scale is alpha divided by rank.
Read this as the correction multiplier is alpha over rank. Alpha is a scale setting, not rank or learning rate, and it changes both the forward correction and the gradients through it.
Controlling update magnitude
Training moves both factors, so scale alone does not predict correction size. Judge rank and scale together using validation.
Some methods divide by instead. Load the convention used in training: applying the wrong one changes the function even when the tensors load cleanly. PEFT records these options in its LoRA configuration reference.
#Section 33LoRA initialization
Attaching an adapter to a trained model should leave its outputs unchanged at first. A random correction would shift behavior before the first step and muddy the baseline comparison.
Initializing A, initializing B, and base equivalence
Initialization sets parameters before training. The common LoRA choice is random nonzero and zero , so BA = 0 and W + sBA = W at attachment. Other schemes exist; this chapter uses this one.
It also shapes the first backward pass. With , the gradient for contains and is zero, while the gradient for is nonzero because is. If both start at zero, both gradients are zero and the adapter never starts learning.
Check attachment by comparing base and adapted logits in evaluation mode with the same numerics. Dropout, changed precision, or a modified template can cause differences unrelated to the correction, so disable stochastic layers and record the tolerance.
makes the functions equal mathematically, but measure anyway: replacement-module bugs can transpose weights, double the scale, or alter a bias. Section 69 applies the same check to merging, where floating-point arithmetic adds more differences.