LoRA Mathematics › The LoRA Formulation
Language AI HandbookAll chapters LoRA Mathematics › The LoRA FormulationOne section · Sections in this chapter2 / 12 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
LoRA reparameterizes weight updates using a factorized form that captures the essence of efficient adaptation. Rather than learning an arbitrary update to each weight matrix, LoRA constrains the update to live in a low-dimensional subspace. This constraint reflects the empirical observation that useful fine-tuning updates often have simple structure, revealing important patterns in how models adapt to new tasks.
To appreciate why this matters, consider the scale of the problem. A modern language model like LLaMA-7B has roughly 7 billion parameters. Even if you only wanted to fine-tune a fraction of the model, say the attention projection matrices, you would be looking at hundreds of millions of trainable parameters. Storing the gradients and optimizer states for these parameters requires multiple times their storage in GPU memory, quickly exhausting even high-end hardware. LoRA's factorized form side-steps this entirely: instead of treating each weight as an independent variable, it represents weight changes as the product of two small matrices, dramatically reducing the number of independent quantities to learn.
The key insight is that not all directions in weight space are equally useful for a given task. Most of the adaptation signal concentrates in a small subspace, and optimizing only within that subspace costs a fraction of the resources while sacrificing almost nothing in task performance. The mathematical structure of the factorized decomposition enforces this constraint naturally: you cannot express an arbitrary weight change as the product of small matrices, so LoRA forces the optimization to discover the most useful low-dimensional subspace.
For a pre-trained weight matrix , LoRA expresses the adapted weight as:
where:
- : the adapted weight matrix (final parameters)
- : the pre-trained weight matrix (frozen during training)
- : the weight update matrix (learned through gradient descent)
- : the up-projection matrix (trainable)
- : the down-projection matrix (trainable)
- : the rank of the adaptation, the central hyperparameter
The key insight is that has rank at most . To understand why, recall that the rank of a matrix product cannot exceed the rank of either factor. Since has rows and has columns, the product can have rank at most . Even though has the same dimensions as , potentially millions of entries, it lives in a much lower-dimensional subspace determined by the choice of . This constraint is what enables LoRA's parameter efficiency: instead of learning independent parameters, we learn only parameters while still creating updates that span the full weight matrix dimensions.
Think of and as two collaborating translators working through a tiny shared vocabulary. Matrix compresses any input into a vocabulary of basic concepts, while matrix expands those concepts into the output space. Any adaptation we can express is forced to pass through this bottleneck of concepts, which dramatically limits the number of possible updates while still letting enormous flexibility about which -dimensional subspace to occupy.
Forward Pass Computation
During the forward pass, the network must compute the output of each adapted layer. This computation reveals opportunities for efficient implementation and clarifies each matrix's role in the decomposition. The structure of the computation is not just mathematically correct; it is also computationally efficient in a way that becomes clear once we trace through the operations.
For an input , the output is computed as:
where:
- : the output vector of the layer
- : the full adapted weight matrix
- : the input vector to the layer
- : the frozen pre-trained weight matrix
- : the trainable up-projection matrix
- : the trainable down-projection matrix
The final line reveals LoRA's computational structure. The parenthesization in is necessary for computational efficiency. The naive approach would form the full matrix explicitly and then multiply by . This defeats the purpose of the low-rank decomposition because we would need to compute and store a matrix with entries, which is exactly what we were trying to avoid.
Instead, we exploit the associativity of matrix multiplication to compute the result sequentially through a bottleneck of dimension . The computation proceeds in three stages:
- First, we compute , yielding . This operation involves an matrix multiplying a -dimensional vector, requiring operations.
- Next, we compute , yielding . This involves a matrix multiplying an -dimensional vector, requiring operations.
- Finally, we add the base model's output: .
This sequential computation requires operations for the LoRA path, compared to if we materialized the full update matrix. When , which is the regime where LoRA operates, this provides significant savings during both training and inference. For a typical transformer layer where and , the LoRA path requires roughly 0.8% of the operations needed to compute with a full update matrix.

Scaling Factor
The original LoRA paper introduces a scaling factor to control the magnitude of the low-rank update relative to the pre-trained weights. This scaling factor plays a useful role in making LoRA practical across different rank choices and learning rate settings, and understanding it carefully will save you from common tuning mistakes.
The need for a scaling factor arises from a subtle interaction between the rank and the magnitude of the LoRA contribution. If you increase while keeping everything else fixed, the product tends to produce larger values because there are more terms adding to each output. This means that switching from to would change the effective scale of the LoRA update even if the underlying "adaptation direction" remained the same. Such rank-dependent scaling behavior would make it impossible to transfer hyperparameter settings between different rank experiments, forcing expensive re-tuning every time you adjust .
The scaled formulation addresses this by introducing an explicit normalization:
where:
- : the output vector
- : the pre-trained weight matrix
- : the input vector
- : a constant scaling factor (a hyperparameter you choose)
- : the rank of the LoRA matrices
- : the up-projection matrix
- : the down-projection matrix
- : the low-rank update matrix product
The ratio serves several important purposes that become apparent once you understand how it interacts with rank changes.
- Learning rate stability: Without the scaling factor, changing the rank would fundamentally alter the magnitude of updates produced by the LoRA path. A higher rank means more terms adding to the product , which, all else being equal, would produce larger outputs. By dividing by , we normalize this effect, letting the same learning rate to produce updates of similar magnitude regardless of rank choice.
- Initialization compatibility: As we will see in the initialization section below, the scaling interacts with how we initialize and to ensure consistent behavior at the start of training. The combination of proper initialization and scaling means that the model's behavior at the beginning of training does not depend sensitively on the rank choice.
- Hyperparameter transfer: Because the scaling normalizes the effect of rank, a good value of often transfers across different rank choices. This simplifies hyperparameter search considerably: you can tune at a lower rank where experiments are cheaper, then scale up the rank while keeping fixed and expect similar behavior.
Think of as the "volume knob" for the LoRA path. It controls how loudly the adaptation speaks relative to the frozen pre-trained output. Too large, and the LoRA update overwhelms the pretrained knowledge. Too small, and the model learns too slowly to adapt. Setting makes the ratio equal to 1, effectively removing the normalization, while treating as a separate hyperparameter decouples the volume knob from the rank choice.
In practice, many implementations set , making the scaling factor equal to 1 and effectively removing the normalization. Others treat as a tunable hyperparameter, typically in the range . The choice depends on whether you want rank-independent behavior (use scaling) or prefer to absorb any magnitude adjustments into the learning rate (set ).