JA EN
LearnLinear Algebra
·★ MEMBER·PAPER·10 min read

Singular Value Decomposition and Low-Rank Approximation — the Math Behind LoRA

Starting from the 'rotate, stretch, rotate' picture, this article builds Singular Value Decomposition (SVD) from zero: matrices as stacks of rank-1 layers, why real-world data needs only a few of them, and how that single fact lets LoRA fine-tune a giant model with 0.4% of the parameters.

ModalitytextTaskmath

LoRA: Low-Rank Adaptation of Large Language Models

Primary source — what this article is built on

undefined2021-06-17undefined2026-08-135y 2mo later

LoRA: Low-Rank Adaptation of Large Language ModelsEdward J. Hu, Yelong Shen, Phillip Wallis et al. · 2021-06-17 · v2arXiv:2106.09685Paper page·PDF
undefined

An important paradigm of natural language processing consists of large-scale pre-training on general domain data and adaptation to particular tasks or domains. As we pre-train larger models, full fine-tuning, which retrains all model parameters, becomes less feasible. Using GPT-3 175B as an example -- deploying independent instances of fine-tuned models, each with 175B parameters, is prohibitively expensive. We propose Low-Rank Adaptation, or LoRA, which freezes the pre-trained model weights and injects trainable rank decomposition matrices into each layer of the Transformer architecture, greatly reducing the number of trainable parameters for downstream tasks. Compared to GPT-3 175B fine-tuned with Adam, LoRA can reduce the number of trainable parameters by 10,000 times and the GPU memory requirement by 3 times. LoRA performs on-par or better than fine-tuning in model quality on RoBERTa, DeBERTa, GPT-2, and GPT-3, despite having fewer trainable parameters, a higher training throughput, and, unlike adapters, no additional inference latency. We also provide an empirical investigation into rank-deficiency in language model adaptation, which sheds light on the efficacy of LoRA. We release a package that facilitates the integration of LoRA with PyTorch models and provide our implementations and model checkpoints for RoBERTa, DeBERTa, and GPT-2 at https://github.com/microsoft/LoRA.


Giant matrices are smaller than they look

LoRA, now the default recipe for fine-tuning LLMs, adjusts models with billions of parameters using less than 1% as many trainable weights. On its face that sounds absurd — like claiming you can retune a machine with four billion dials by turning only a few million small ones.

Why does it work? The root of the answer is the star of this article: Singular Value Decomposition (SVD).

A matrix looks like a plain table of numbers, but matrices born from real data almost never carry as much information as their size suggests. A 1000×1000 matrix holds a million entries, yet in practice it often contains only "ten directions' worth" of information. SVD is the tool that measures this effective information content precisely and reorders the matrix's contents from most to least important. Once things are sorted, you can throw away the tail. What's left after the cut is a low-rank approximation — and applying that idea to fine-tuning gives you LoRA.

The metaphor: every transformation is "rotate, stretch, rotate"

Multiplying a vector by a matrix can be drawn as a deformation of space. Picture a thin rubber sheet with a circle drawn on it; apply a matrix, and the sheet warps, turning the circle into some other shape. The warps look endlessly varied — some shear diagonally, some flatten the sheet, some flip it over. Yet SVD makes a startlingly simple claim:

Any matrix's deformation can be reproduced exactly by three steps: ① rotate the sheet, ② stretch or shrink it along the axes, each by its own factor, ③ rotate again.

There are no exceptions. The matrix doesn't have to be square or symmetric — any matrix at all. Each step has a name: the first rotation is VV^\top, the per-axis stretch factors are the singular values σ1σ20\sigma_1 \ge \sigma_2 \ge \cdots \ge 0, and the final rotation is UU.

Since rotations don't change shape, a matrix's entire "personality" is concentrated in the middle step. The circle becomes an ellipse, whose long axis corresponds to σ1\sigma_1 (the most-stretched direction) and short axis to σ2\sigma_2. An axis whose factor is nearly zero gets squashed flat — a direction along which the matrix transmits almost no information. The story of low-rank approximation has already begun right here.

The intuition: a matrix is a stack of layers, not a monolith

SVD supports a second reading, closer to this article's destination: it decomposes a matrix AA into a sum of rank-1 layers — the simplest possible matrices, each carrying information about just one direction.

A=σ1u1v1+σ2u2v2+σ3u3v3+A = \sigma_1 u_1 v_1^\top + \sigma_2 u_2 v_2^\top + \sigma_3 u_3 v_3^\top + \cdots

Read that as a shopping list rather than a formula: it is one line which says AA equals layer one plus layer two plus layer three and onward, each layer scaled by its own number σi\sigma_i — and those numbers shrink as you move right.

In words: each layer uiviu_i v_i^\top is a single-purpose component that "measures how much of the input points along viv_i, and outputs that amount in the direction uiu_i." The singular value σi\sigma_i is that layer's volume knob — the bigger it is, the more the layer contributes to the matrix's overall behavior. Stack the loudest layers first, and you approach the original matrix quickly with very few of them.

"Measuring the component along viv_i" is exactly the dot product — one number that says how much of one vector you can lay along another. Rotate the two vectors in the figure below to get that feeling into your hands.

FIG 1The dot product measures how much of one vector lies along another. Every SVD layer does exactly one thing — take the dot product of the input with v_i and emit the result along u_i. All matrices are stacks of such parts

So SVD is two things at once: a geometric decomposition into rotate–stretch–rotate, and an inventory audit that splits a matrix into single-purpose parts sorted by importance. From here on, we'll see just how powerful that inventory is, with a theorem and hard numbers.

The machinery: SVD as an equation

Everything so far compresses into one line.

A=UΣVA = U \Sigma V^\top
(1)

Put in words, that line says: applying AA to a vector is the same as turning it (VV^\top), stretching each axis by its own factor (Σ\Sigma), and then turning it once more (UU) — the rubber sheet from the last section, written down in symbols.

Here's what each symbol means. AA is any m×nm \times n matrix — the thing being decomposed. UU is an m×mm \times m orthogonal matrix whose columns u1,u2,u_1, u_2, \ldots (the left singular vectors) are mutually perpendicular unit vectors, i.e. a rotation (or reflection). VV is likewise an n×nn \times n orthogonal matrix whose columns are the right singular vectors v1,v2,v_1, v_2, \ldots. And Σ\Sigma is an m×nm \times n matrix with the singular values σ1σ20\sigma_1 \ge \sigma_2 \ge \cdots \ge 0 lined up on its diagonal, largest first, and zeros everywhere else.

Unlike the eigendecomposition, an SVD exists for every matrix — no squareness, no symmetry required. That "works unconditionally" property is why SVD is the first tool practitioners reach for.

What's behind this

§

Members-only from here

371 walkthroughs, 26 textbook chapters, 48 student units and 6 close readings — all included for $4.99/mo, with three new explainers every day. Cancel any time; access runs to the end of the period.

Already a member? Sign in to keep reading

References

  1. Edward J. Hu, Yelong Shen, Phillip Wallis, Zeyuan Allen-Zhu et al.. (2021-06-17) LoRA: Low-Rank Adaptation of Large Language Models. arXiv:2106.09685Paper page·PDF

This article is written from the source paper above. Where they differ, the original is authoritative.

Comments

Sign in to comment