LoRA: a Low-Rank Update
An interactive live film: an 8 x 8 weight update as dots, the best rank-r update (truncated SVD) as bars and the residual in red; LoRA's Delta W = (alpha/r) B A trains r(m + n) numbers. Find the smallest rank with 95% of the energy.
Narration
Fine tuning changes a frozen weight matrix W zero by an update, delta W. Here the update is eight by eight: each dot above the floor is one of its entries.
Low rank adaptation writes the update as alpha over r, times B times A. B is tall and thin, with r columns, A is short and wide, with r rows, so the update has rank at most r.
Only B and A are trained: r times m plus n numbers, instead of m times n. For a projection of size four thousand ninety six with r equal to eight, that is two hundred fifty six times fewer.
Which rank r update comes closest to the one we want? By the Eckart Young theorem, the truncated SVD. The bars are the best rank r update, and the red gaps are what it misses. LoRA learns B and A by gradient descent instead of computing that SVD.
Your turn. Change the rank r. Find the smallest rank that captures ninety five percent of the update's energy.
When the update has low intrinsic rank, a thin B and a short A carry almost all of it, at a fraction of the cost.
More from Chapter 9
Preview1:48LDL Is Completing the SquareChapter 9
Preview1:25Superposition and Sparse CodingChapter 9
Preview1:47Rank-Revealing QR: Pick the Columns in a Good OrderChapter 9
Preview1:56The QR Algorithm: Sweeping a Matrix into Schur FormChapter 9
Preview1:36Non-Negative Matrix Factorization: a Cone of PartsChapter 9
Preview1:33CUR: Rebuilding a Matrix from Its Own Rows and ColumnsChapter 9