Skip to content
AriadneTechnology

The Middle Ring · Chamber 6 of 9

Rank and the Four Subspaces

Column space, null space and rank–nullity: what a matrix keeps, what it destroys, and why LoRA works.

40 min 60 XP + 11 questions + 1 challengeMathVideoPapersProofsCodeLab

In this chamber you will

  • Find the column space and null space of a matrix
  • State and use the rank–nullity theorem
  • Build low-rank matrices from outer products
  • Explain LoRA's parameter savings with rank
DiscoverLearnRead beyondPapers & lecturesYour turn

Discover: fine-tuning a giant with a sliver of its parameters

GPT-3 has 175 billion parameters. Fine-tuning all of them for a new task produces a new 175-billion-parameter model, and a company with a hundred tasks would have to store a hundred of them. In 2021 a team at Microsoft proposed a way out called LoRA, low-rank adaptation. Freeze every pretrained weight matrix W0W_0, and learn only a correction ΔW\Delta W (read “delta W”), written as a product of two thin matrices:

Spotted in the wild

h=W0x+ΔWx=W0x+BAxh = W_0 x + \Delta W x = W_0 x + BA x
Hu et al. (2022), “LoRA: Low-Rank Adaptation of Large Language Models”, Eq. 3

Here W0W_0 is d×kd \times k, BB is d×rd \times r and AA is r×kr \times k, where rr is tiny. The paper uses values like r=4r = 4 for matrices with d=k=12,288d = k = 12{,}288, and reports that even r=1r = 1 or 22 can be enough. On GPT-3 that cuts the number of trainable parameters by a factor of about 10,000, while performing on par with full fine-tuning on the benchmarks they tested.

That sounds too good to be true, so check the arithmetic yourself.

Quick check +20 XP

A weight matrix is 4096×40964096 \times 4096. LoRA writes its update as ΔW=BA\Delta W = BA with B∈R4096×8B \in \mathbb{R}^{4096 \times 8} and A∈R8×4096A \in \mathbb{R}^{8 \times 4096}. How many numbers do BB and AA hold together?

BABA is a full-size matrix, but it can't be any matrix. Its columns are all combinations of just rr columns of BB, so it only ever reaches an rr-dimensional slice of the space. That number, the true dimension of what a matrix can produce, is its rank. To see why LoRA works, you need to know what a matrix keeps, what it throws away, and how the two are related.

DiscoverLearnRead beyondPapers & lecturesYour turn

Learn: the column space, everything A can reach

Let AA be an m×nm \times n matrix, so it takes inputs x∈Rn\mathbf{x} \in \mathbb{R}^n to outputs Ax∈RmA\mathbf{x} \in \mathbb{R}^m. Its column space is the set of every output it can produce:

C(A)={Ax:x∈Rn}.C(A) = \{A\mathbf{x} : \mathbf{x} \in \mathbb{R}^n\}.

Read it as “C of A is the set of all A x, for x in R n”. Since AxA\mathbf{x} is a combination of the columns of AA weighted by the entries of x\mathbf{x} (Chamber 4), the column space is exactly the span of the columns (Chamber 3). It's a subspace of Rm\mathbb{R}^m: it contains 0\mathbf{0}, and sums and multiples of outputs are outputs again.

This answers the question Chamber 5 kept circling. Ax=bA\mathbf{x} = \mathbf{b} has a solution exactly when b\mathbf{b} is in C(A)C(A). Take

A=[100111],Ax=x1[101]+x2[011]=[x1x2x1+x2].A = \begin{bmatrix} 1 & 0 \\ 0 & 1 \\ 1 & 1 \end{bmatrix}, \qquad A\mathbf{x} = x_1\begin{bmatrix} 1 \\ 0 \\ 1 \end{bmatrix} + x_2\begin{bmatrix} 0 \\ 1 \\ 1 \end{bmatrix} = \begin{bmatrix} x_1 \\ x_2 \\ x_1 + x_2 \end{bmatrix}.

Two independent columns span a plane in R3\mathbb{R}^3: the plane where the third entry is the sum of the first two. A right-hand side on that plane has a solution, and one off it has none.

Quick check +20 XP

Let A=[100111]A = \begin{bmatrix} 1 & 0 \\ 0 & 1 \\ 1 & 1 \end{bmatrix}. Which vector lies in the column space C(A)C(A)?

To find a basis for C(A)C(A) in general, row reduce and look at where the pivots land: the pivot columns of the original AA form a basis. Careful: of AA, not of its echelon form. Row operations change the columns themselves (and so the column space), but they never change which combinations of columns add up to zero, since those combinations are the solutions of Ax=0A\mathbf{x} = \mathbf{0}, and row operations never change solutions. So a column that depends on earlier ones in the echelon form depended on the same ones, with the same weights, in AA.

Learn: the null space, everything A destroys

The null space is the set of inputs that AA sends to zero:

N(A)={x∈Rn:Ax=0}.N(A) = \{\mathbf{x} \in \mathbb{R}^n : A\mathbf{x} = \mathbf{0}\}.

Read it as “N of A, the set of x such that A x equals zero”. It's a subspace of Rn\mathbb{R}^n, the input side: if Ax=0A\mathbf{x} = \mathbf{0} and Ay=0A\mathbf{y} = \mathbf{0}, then A(x+y)=0A(\mathbf{x} + \mathbf{y}) = \mathbf{0} and A(cx)=0A(c\mathbf{x}) = \mathbf{0}. It's also called the kernel, written ker⁡A\ker A. The null space is what the transformation destroys. Two inputs that differ by a null-space vector v\mathbf{v}, say x\mathbf{x} and x+v\mathbf{x} + \mathbf{v}, give exactly the same output, because A(x+v)=Ax+Av=AxA(\mathbf{x} + \mathbf{v}) = A\mathbf{x} + A\mathbf{v} = A\mathbf{x}. A layer h=Wx\mathbf{h} = W\mathbf{x} in a neural network literally cannot tell them apart.

Finding the null space is Chamber 5's elimination with b=0\mathbf{b} = \mathbf{0}. Here it is in full for

A=[12032418].A = \begin{bmatrix} 1 & 2 & 0 & 3 \\ 2 & 4 & 1 & 8 \end{bmatrix}.
  1. 1

    Reduce to reduced row echelon form

    One operation does it: R2←R2−2R1R_2 \leftarrow R_2 - 2R_1 gives

    R=[12030012].R = \begin{bmatrix} 1 & 2 & 0 & 3 \\ 0 & 0 & 1 & 2 \end{bmatrix}.

    The pivots are in columns 1 and 3, so x1x_1 and x3x_3 are pivot variables and x2x_2 and x4x_4 are free variables.

  2. 2

    Write the pivot variables in terms of the free ones

    Rx=0R\mathbf{x} = \mathbf{0} says x1+2x2+3x4=0x_1 + 2x_2 + 3x_4 = 0 and x3+2x4=0x_3 + 2x_4 = 0, so

    x1=−2x2−3x4,x3=−2x4.x_1 = -2x_2 - 3x_4, \qquad x_3 = -2x_4.
  3. 3

    One special solution per free variable

    Set one free variable to 11 and the others to 00. With x2=1,x4=0x_2 = 1, x_4 = 0 you get s1=(−2,1,0,0)\mathbf{s}_1 = (-2, 1, 0, 0). With x2=0,x4=1x_2 = 0, x_4 = 1 you get s2=(−3,0,−2,1)\mathbf{s}_2 = (-3, 0, -2, 1). Check the second in the original AA: −3+0+0+3=0-3 + 0 + 0 + 3 = 0 and −6+0−2+8=0-6 + 0 - 2 + 8 = 0.

  4. 4

    Every solution is a combination of them

    Any solution has some values x2=t1x_2 = t_1 and x4=t2x_4 = t_2, and the pivot variables follow, so x=t1s1+t2s2\mathbf{x} = t_1 \mathbf{s}_1 + t_2 \mathbf{s}_2. The null space is the plane N(A)=span⁡{s1,s2}N(A) = \operatorname{span}\{\mathbf{s}_1, \mathbf{s}_2\} inside R4\mathbb{R}^4.

This also completes the story of Chamber 5's “infinitely many solutions”. If xp\mathbf{x}_p is any one solution of Ax=bA\mathbf{x} = \mathbf{b} (a particular solution), then every solution is xp+xn\mathbf{x}_p + \mathbf{x}_n with xn∈N(A)\mathbf{x}_n \in N(A), because A(xp+xn)=b+0=bA(\mathbf{x}_p + \mathbf{x}_n) = \mathbf{b} + \mathbf{0} = \mathbf{b}, and the difference of two solutions always lands in the null space. The line of solutions in Chamber 5's workbench was a copy of the null space, shifted away from the origin.

Learn: rank

The rank of AA is the number of pivots elimination finds:

r=rank⁡(A)=number of pivots=dim⁡C(A).r = \operatorname{rank}(A) = \text{number of pivots} = \dim C(A).

Each pivot column contributes one independent direction to the column space, so the rank is the dimension of everything AA can reach. Two facts make rank the single most useful number about a matrix.

Row rank equals column rank. The rows of AA span a subspace of Rn\mathbb{R}^n, the row space C(A⊤)C(A^\top). Row operations only replace rows by combinations of rows, reversibly, so they never change the row space. In the echelon form, the non-zero rows hold one pivot each and are independent, so the row space has dimension rr too: the rank also counts the independent rows. That holds even for a 3×10003 \times 1000 matrix. So among those 10001000 columns, at most 33 can be independent.

The rank is at most min⁡(m,n)\min(m, n), since there is at most one pivot per row and at most one per column. A matrix that reaches this limit has full rank:

  • Full column rank (r=nr = n): every column has a pivot, there are no free variables, and N(A)={0}N(A) = \{\mathbf{0}\}. Then Ax=bA\mathbf{x} = \mathbf{b} has at most one solution.
  • Full row rank (r=mr = m): every row has a pivot, so no row can turn into 0=10 = 1. Then Ax=bA\mathbf{x} = \mathbf{b} has at least one solution, for every b\mathbf{b}.
  • Square and full rank (r=m=nr = m = n): both at once. That's exactly an invertible matrix from Chamber 5.
Subspace and rank notation
  • C(A)C(A)“the column space of A”
    Every output AxA\mathbf{x}, that is, every combination of the columns of AA. A subspace of Rm\mathbb{R}^m. Also written col⁡(A)\operatorname{col}(A), range⁡(A)\operatorname{range}(A) or im⁡(A)\operatorname{im}(A).
    b∈C(A)\mathbf{b} \in C(A)
  • N(A)N(A)“the null space of A”
    Every input x\mathbf{x} with Ax=0A\mathbf{x} = \mathbf{0}: what AA destroys. A subspace of Rn\mathbb{R}^n. Also called the kernel, ker⁡A\ker A.
    N(A)={x∈Rn:Ax=0}N(A) = \{\mathbf{x} \in \mathbb{R}^n : A\mathbf{x} = \mathbf{0}\}
  • C(A⊤)C(A^\top)“the row space of A”
    Every combination of the rows of AA (the column space of A⊤A^\top). A subspace of Rn\mathbb{R}^n.
    C(A⊤)⊆RnC(A^\top) \subseteq \mathbb{R}^n
  • N(A⊤)N(A^\top)“the left null space of A”
    Every y\mathbf{y} with A⊤y=0A^\top \mathbf{y} = \mathbf{0}, equivalently y⊤A=0⊤\mathbf{y}^\top A = \mathbf{0}^\top. A subspace of Rm\mathbb{R}^m.
    y⊤A=0⊤\mathbf{y}^\top A = \mathbf{0}^\top
  • rank⁡(A)\operatorname{rank}(A)“the rank of A”
    The number of pivots, which is also the number of independent columns and the number of independent rows. Some books write rk⁡(A)\operatorname{rk}(A).
    rank⁡(A)≤min⁡(m,n)\operatorname{rank}(A) \le \min(m, n)
  • dim⁡V\dim V“the dimension of V”
    The number of vectors in any basis of the subspace VV (Chamber 3). The dimension of the null space is sometimes called the nullity.
    dim⁡N(A)=n−r\dim N(A) = n - r
  • uv⊤\mathbf{u}\mathbf{v}^\top“u v transpose”
    The outer product of u∈Rm\mathbf{u} \in \mathbb{R}^m and v∈Rn\mathbf{v} \in \mathbb{R}^n: the m×nm \times n matrix with entries uivju_i v_j. It has rank 1 when u\mathbf{u} and v\mathbf{v} are non-zero.
    (uv⊤)ij=uivj(\mathbf{u}\mathbf{v}^\top)_{ij} = u_i v_j
  • r≪min⁡(d,k)r \ll \min(d, k)“r is much less than the smaller of d and k”
    LoRA's condition on the rank of its update: far smaller than either side of the d×kd \times k weight matrix.
    r=4≪12288r = 4 \ll 12288

Now put the definitions to work. The matrices in the lab range from 2×22 \times 2 to 3×43 \times 4. Some are honest, and some hide a dependency between their rows. Find each rank by eliminating in your head or by spotting the dependency.

Interactive lab

Rank detective

The rank is the number of pivots elimination leaves behind: the number of truly independent rows, which is also the number of independent columns. Work out the rank of each matrix, by elimination or by spotting a dependency. A wrong guess costs nothing; a right one reveals why.
Solved 0 / 8

Matrix 1 · 2 × 2

1234

What is its rank?

Clues to look for

  • Is one row a multiple of another? Then elimination turns it into a zero row.
  • Is one row the sum (or another combination) of the others? Same story, better hidden.
  • The rank can never exceed the number of rows, nor the number of columns.
  • A square matrix with a non-zero determinant has full rank.
Challenge: Rank detectiveIdentify the rank of eight matrices.+40 XP

Learn: rank–nullity and the four subspaces

In the null space example, AA had 44 columns: 22 were pivot columns and 22 were free, and the null space came out 2-dimensional. That's no coincidence.

Theorem (rank–nullity). For any m×nm \times n matrix AA, rank⁡(A)+dim⁡N(A)=n.\operatorname{rank}(A) + \dim N(A) = n.

Proof. Let RR be the reduced row echelon form of AA. Row operations don't change the solutions of Ax=0A\mathbf{x} = \mathbf{0} (Chamber 5), so N(A)=N(R)N(A) = N(R), and the rank rr is the number of pivots in RR. Each of the nn columns of RR is either a pivot column or a free column, never both, so there are exactly n−rn - r free columns. It remains to show that dim⁡N(A)=n−r\dim N(A) = n - r, and we do it by exhibiting a basis with n−rn - r vectors.

For each free column jj, let sj\mathbf{s}_j be the special solution: set xj=1x_j = 1, every other free variable to 00, and solve for the pivot variables. (Each row of RR has a single pivot, so it expresses one pivot variable in terms of the free ones, and the solution exists and is unique.) We check the two properties a basis needs.

  • They span N(A)N(A). Take any x∈N(A)\mathbf{x} \in N(A) and form y=∑free jxjsj\mathbf{y} = \sum_{\text{free } j} x_j \mathbf{s}_j. The vector y\mathbf{y} is in the null space (a combination of null-space vectors), and it has the same free entries as x\mathbf{x}. The pivot entries of a null-space vector are determined by its free entries, so y=x\mathbf{y} = \mathbf{x}.
  • They're independent. In ∑jcjsj\sum_j c_j \mathbf{s}_j, look at the entry in free position jj. Only sj\mathbf{s}_j has a 11 there, and every other special solution has a 00, so that entry is cjc_j. If the combination is the zero vector, every cjc_j is 00.

So the n−rn - r special solutions form a basis of N(A)N(A), and dim⁡N(A)=n−r\dim N(A) = n - r. ■\blacksquare

The theorem is an accounting identity for input directions. Each of the nn dimensions of the input is either kept, contributing to the output (a pivot), or destroyed, lost to the null space (a free variable). Nothing is lost without a trace and nothing is double-counted.

Quick check +20 XP

AA is a 5×85 \times 8 matrix of rank 33. What is dim⁡N(A)\dim N(A)?

Apply the theorem to A⊤A^\top as well and you have all four fundamental subspaces, as Gilbert Strang calls them:

SubspaceNameLives inDimension
C(A)C(A)column spaceRm\mathbb{R}^mrr
N(A⊤)N(A^\top)left null spaceRm\mathbb{R}^mm−rm - r
C(A⊤)C(A^\top)row spaceRn\mathbb{R}^nrr
N(A)N(A)null spaceRn\mathbb{R}^nn−rn - r

There's a hidden geometry here. Ax=0A\mathbf{x} = \mathbf{0} says every row of AA has dot product 00 with x\mathbf{x} (Chamber 2), so every null-space vector is perpendicular to the whole row space. The input space Rn\mathbb{R}^n splits into two perpendicular pieces, of dimensions rr and n−rn - r, and the output space Rm\mathbb{R}^m does the same. Chamber 7 builds least squares on exactly this picture.

Learn: rank one, and low-rank factorisation

The simplest non-zero matrices are outer products. For u∈Rm\mathbf{u} \in \mathbb{R}^m and v∈Rn\mathbf{v} \in \mathbb{R}^n, the m×nm \times n matrix uv⊤\mathbf{u}\mathbf{v}^\top (read “u v transpose”) has entries (uv⊤)ij=uivj(\mathbf{u}\mathbf{v}^\top)_{ij} = u_i v_j:

[123][2−11]=[2−114−226−33].\begin{bmatrix} 1 \\ 2 \\ 3 \end{bmatrix}\begin{bmatrix} 2 & -1 & 1 \end{bmatrix} = \begin{bmatrix} 2 & -1 & 1 \\ 4 & -2 & 2 \\ 6 & -3 & 3 \end{bmatrix}.

Column jj is vjuv_j \mathbf{u}, so every column is a multiple of u\mathbf{u}, and every row is a multiple of v⊤\mathbf{v}^\top. When u\mathbf{u} and v\mathbf{v} are non-zero the rank is exactly 11 (you'll prove it below). Nine entries, but six numbers describe them completely: an m×nm \times n rank-one matrix needs only m+nm + n numbers instead of mnmn.

Quick check +20 XP

What is the rank of [26−4−1−32515−10]\begin{bmatrix} 2 & 6 & -4 \\ -1 & -3 & 2 \\ 5 & 15 & -10 \end{bmatrix}?

Chamber 4's outer product view of multiplication says that a product is a sum of outer products. If BB has columns b1,…,br\mathbf{b}_1, \ldots, \mathbf{b}_r and AA has rows a1⊤,…,ar⊤\mathbf{a}_1^\top, \ldots, \mathbf{a}_r^\top, then

BA=b1a1⊤+b2a2⊤+⋯+brar⊤.BA = \mathbf{b}_1 \mathbf{a}_1^\top + \mathbf{b}_2 \mathbf{a}_2^\top + \cdots + \mathbf{b}_r \mathbf{a}_r^\top.

Each term has rank at most 11, and the rank of a sum is at most the sum of the ranks (the columns of P+QP + Q are combinations of the columns of PP and QQ). So rank⁡(BA)≤r\operatorname{rank}(BA) \le r. More generally, a product can never have more rank than either of its factors:

rank⁡(AB)≤min⁡(rank⁡(A), rank⁡(B)).\operatorname{rank}(AB) \le \min\big(\operatorname{rank}(A),\ \operatorname{rank}(B)\big).

You'll assemble the proof in the last part of this chamber. The converse holds too: any matrix of rank rr can be written as BABA with rr columns in BB, for instance with its rr pivot columns as BB and the non-zero rows of its reduced echelon form as AA. Low rank and a thin factorisation are the same thing.

Now derive LoRA's savings. The full update ΔW∈Rd×k\Delta W \in \mathbb{R}^{d \times k} has dkdk entries. The factored update BABA has drdr entries in BB and rkrk in AA:

trainable parametersentries of ΔW=dr+rkdk=r(d+k)dk  =d=k  2rd.\frac{\text{trainable parameters}}{\text{entries of } \Delta W} = \frac{dr + rk}{dk} = \frac{r(d + k)}{dk} \;\overset{d = k}{=}\; \frac{2r}{d}.

For GPT-3's d=k=12,288d = k = 12{,}288 with r=4r = 4, that's 8/12,288=1/15368/12{,}288 = 1/1536 per adapted matrix. The price is the constraint rank⁡(ΔW)≤r\operatorname{rank}(\Delta W) \le r. LoRA's authors bet that it's a price worth paying: that the change a pretrained model needs for a new task has a low “intrinsic rank”. They took the idea from work on intrinsic dimension, including Li et al. (2018), the paper from Chamber 3. The experiments say the bet pays off, at least for the tasks they tried.

DiscoverLearnRead beyondPapers & lecturesYour turn

Read beyond the course

Pick at least one. The first two deepen the linear algebra; the last two take you into LoRA itself.

Book · free online · ~30 min

Mathematics for Machine Learning

Marc Peter Deisenroth, A. Aldo Faisal & Cheng Soon Ong · Section 2.6.2, Rank; Section 2.7.3, Image and Kernel

The same ideas in the language of linear mappings: the column space becomes the image and the null space the kernel, and Theorem 2.24 is rank–nullity. Worth reading now to get used to the notation rk⁡(A)\operatorname{rk}(A), Im⁡(Φ)\operatorname{Im}(\Phi) and ker⁡(Φ)\ker(\Phi), which you'll meet in papers.

Interactive · free online · ~35 min

Immersive Linear Algebra

Jacob Ström, Kalle Åström & Tomas Akenine-Möller · Chapter 8, Rank

Interactive figures of null spaces and column spaces in 3D, which you can rotate. The chapter also proves that rank equals the number of pivots and that row rank equals column rank, and it states rank–nullity as the “dimension theorem”.

Tool · free online · ~15 min

microsoft/LoRA: loralib/layers.py

Edward J. Hu and colleagues (official implementation) · class Linear

The paper's equation as about sixty lines of PyTorch. Find the shapes of lora_A (r×kr \times k) and lora_B (d×rd \times r), the scaling of α/r\alpha / r, the zero initialisation of lora_B, and the train method, which merges BABA into the frozen weight for inference. One small surprise: the code initialises lora_A with a uniform Kaiming initialisation rather than the Gaussian the paper describes, and a comment admits the difference. Reading code alongside a paper often turns up details like this.

Paper · free online · ~40 min

Intrinsic Dimensionality Explains the Effectiveness of Language Model Fine-Tuning

Armen Aghajanyan, Sonal Gupta & Luke Zettlemoyer (ACL 2021)

One of the two papers that inspired LoRA's low-rank hypothesis. It shows that fine-tuning a large language model in a random low-dimensional subspace of its parameters can get close to full fine-tuning. Read the abstract, the introduction and the first figure to see the evidence LoRA built on.

DiscoverLearnRead beyondPapers & lecturesYour turn

Papers and lectures

LoRA is one of the most widely used ideas in modern machine learning, and its core is this chamber's linear algebra. Read the abstract and look at Figure 1, which draws WW, AA and BB side by side. Then read Section 4.1 in full: it's one page, containing the equation you'll decode below, the initialisation, and the argument that merging W0+BAW_0 + BA adds no inference cost. Skim Section 4.2, which says which weight matrices to adapt. Then jump to Section 7.2, What is the optimal rank r for LoRA?, where Table 6 shows that r=1r = 1 is already competitive on some tasks. Skip Section 3 (on other adaptation methods), the experiment tables in Section 5 and the appendices for now.

LoRA: Low-Rank Adaptation of Large Language ModelsEdward J. Hu, Yelong Shen, Phillip Wallis, Zeyuan Allen-Zhu, Yuanzhi Li, Shean Wang, Lu Wang, Weizhu Chen · ICLR, 2022

Freeze the pretrained weights and train a rank-rr update BABA beside each chosen matrix. It became the standard way to fine-tune large models on modest hardware.

Decode the paper · Eq. (3), Section 4.1

LoRA: Low-Rank Adaptation of Large Language Models

Edward J. Hu, Yelong Shen, Phillip Wallis, Zeyuan Allen-Zhu, Yuanzhi Li, Shean Wang, Lu Wang, Weizhu Chen · ICLR, 2022

+30 XP
h=W0x+ΔWx=W0x+BAxh = W_0 x + \Delta W x = W_0 x + BA x

LoRA fine-tunes a pretrained network without changing its weights. For each chosen weight matrix W0∈Rd×kW_0 \in \mathbb{R}^{d \times k} it learns a low-rank correction, and this equation is the layer's new forward pass. Match each symbol to its meaning.

hh
W0W_0
xx
ΔW\Delta W
BB
AA

Options

Watch

Inverse matrices, column space and null space | Chapter 7, Essence of linear algebra3Blue1Brown · 12 min

The geometric view of this chamber and the last. Watch for the moment a transformation squashes space onto a line: the line is the column space, the rank is its dimension, and the vectors that land on the origin form the null space.

10. The Four Fundamental SubspacesMIT OpenCourseWare · 49 min

Gilbert Strang's lecture on the four subspaces from MIT's 18.06. He works out the dimension of each subspace and how to find a basis for it, which is exactly the reasoning of this chamber, done at the blackboard.

DiscoverLearnRead beyondPapers & lecturesYour turn

Your turn

Start by matching the four subspaces, then translate the notation into NumPy.

Match · Object ↔ What it is

The four fundamental subspaces

+25 XP

AA is an m×nm \times n matrix of rank rr. Match each object to its description.

C(A)C(A)
N(A)N(A)
C(A⊤)C(A^\top)
N(A⊤)N(A^\top)
rank⁡(A)\operatorname{rank}(A)
n−rank⁡(A)n - \operatorname{rank}(A)

Options

Match · Maths ↔ NumPy

From notation to NumPy

+25 XP

Match each piece of notation to the NumPy that computes it. u, v and x are 1-D arrays; A, B and W0 are 2-D arrays of compatible shapes.

rank⁡(A)\operatorname{rank}(A)
uv⊤\mathbf{u}\mathbf{v}^\top
dim⁡N(A)\dim N(A)
W0x+BAxW_0 \mathbf{x} + BA\mathbf{x}
W=W0+BAW = W_0 + BA
the number of trainable LoRA parameters, r(d+k)r(d + k)
A⊤A^\top

Options

Proofs

Put the first proof in order, leaving out the lines that don't belong. It's the rank bound that makes LoRA's updates low-rank. Then write the second yourself.

Proof puzzle

A product can't have more rank than its factors

+25 XP

Claim

For any A∈Rm×nA \in \mathbb{R}^{m \times n} and B∈Rn×pB \in \mathbb{R}^{n \times p}, rank⁡(AB)≤min⁡(rank⁡(A), rank⁡(B)).\operatorname{rank}(AB) \le \min\big(\operatorname{rank}(A),\ \operatorname{rank}(B)\big).

Tap lines in the order they should appear. Not every line belongs. Tap a line in your proof to send it back.

Your proof

  1. Pick the first line below.

Available lines

Prove it yourself

Outer products have rank one

+40 XP

Claim

Let u∈Rm\mathbf{u} \in \mathbb{R}^m and v∈Rn\mathbf{v} \in \mathbb{R}^n be non-zero vectors. Then the outer product uv⊤\mathbf{u}\mathbf{v}^\top has rank exactly 11.

Preview

Your typeset proof appears here.

Code it up

Count LoRA's parameters on GPT-3, classify every small 0/1 matrix by rank, and uncover the low rank hiding in a distance matrix.

Problem 16·Warm-up

Apply the paper: LoRA's parameter budget

+20 XP

Most of LoRA's GPT-3 experiments adapt only the attention's query and value projections, WqW_q and WvW_v, in every layer. GPT-3 175B has 9696 layers and model width dmodel=12288d_{\text{model}} = 12288, and each of WqW_q and WvW_v is a dmodel×dmodeld_{\text{model}} \times d_{\text{model}} matrix.

Each adapted matrix W0∈Rd×kW_0 \in \mathbb{R}^{d \times k} gets its own trainable pair B∈Rd×rB \in \mathbb{R}^{d \times r} and A∈Rr×kA \in \mathbb{R}^{r \times k}. With rank r=4r = 4, how many trainable parameters does LoRA add in total?

An exact integer (or a fraction like 7/12)

Problem 17·Standard

The ranks of all 0/1 matrices

+35 XP

Consider every 3×33 \times 3 matrix whose nine entries are each 00 or 11. There are 29=5122^9 = 512 of them.

How many of them have rank exactly 2? Rank means the usual rank over the real numbers, as in this chamber: the number of pivots that ordinary Gaussian elimination produces.

An exact integer (or a fraction like 7/12)

Problem 18·Challenge

Distance matrices hide low rank

+50 XP

Given points p1,…,pn∈Rd\mathbf{p}_1, \ldots, \mathbf{p}_n \in \mathbb{R}^d, the squared distance matrix D∈Rn×nD \in \mathbb{R}^{n \times n} has entries

Dij=∥pi−pj∥2.D_{ij} = \lVert \mathbf{p}_i - \mathbf{p}_j \rVert^2.

For each dimension d=1,2,…,8d = 1, 2, \ldots, 8, take the n=30n = 30 points p1,…,p30∈Rd\mathbf{p}_1, \ldots, \mathbf{p}_{30} \in \mathbb{R}^d with coordinates

(pi)k=(ik2+k) mod 7,i=1,…,30,k=1,…,d,(\mathbf{p}_i)_k = (i k^2 + k) \bmod 7, \qquad i = 1, \ldots, 30, \quad k = 1, \ldots, d,

and let rdr_d be the rank of the resulting 30×3030 \times 30 matrix DD. Find r1+r2+⋯+r8r_1 + r_2 + \cdots + r_8.

An exact integer (or a fraction like 7/12)

Key takeaways

  • The column space C(A)C(A) is everything AA can reach, the span of its columns; Ax=bA\mathbf{x} = \mathbf{b} is solvable exactly when b∈C(A)\mathbf{b} \in C(A).
  • The null space N(A)N(A) is everything AA destroys; it's spanned by one special solution per free variable, and all solutions of Ax=bA\mathbf{x} = \mathbf{b} are one particular solution plus the null space.
  • Rank is the number of pivots: the dimension of the column space and of the row space, at most min⁡(m,n)\min(m, n).
  • Rank–nullity: rank⁡(A)+dim⁡N(A)=n\operatorname{rank}(A) + \dim N(A) = n. Every input direction is either kept or destroyed.
  • Low rank means a thin factorisation: a rank-rr matrix is a sum of rr outer products, BABA, stored with r(m+n)r(m + n) numbers, and rank⁡(AB)≤min⁡(rank⁡A,rank⁡B)\operatorname{rank}(AB) \le \min(\operatorname{rank} A, \operatorname{rank} B).
  • LoRA trains ΔW=BA\Delta W = BA with r≪min⁡(d,k)r \ll \min(d, k), betting that fine-tuning needs only a low-rank change, and cuts trainable parameters by orders of magnitude.

Checkpoint

Prove it to the labyrinth

Answer every question to clear this chamber. First-try answers earn the most XP.

0/7
Question 1 of 7 +20 XP

A linear layer W∈R256×512W \in \mathbb{R}^{256 \times 512} maps 512-dimensional inputs to 256-dimensional outputs. What is the smallest possible dimension of its null space N(W)N(W)?

Question 2 of 7 +20 XP

Which vector is in the null space of A=[123246]A = \begin{bmatrix} 1 & 2 & 3 \\ 2 & 4 & 6 \end{bmatrix}?

Question 3 of 7 +20 XP

In LoRA, ΔW=BA\Delta W = BA with B∈Rd×rB \in \mathbb{R}^{d \times r} and A∈Rr×kA \in \mathbb{R}^{r \times k}. What can you say for certain about rank⁡(ΔW)\operatorname{rank}(\Delta W)?

Question 4 of 7 +20 XP

AA is a 4×64 \times 6 matrix of rank 22. What is the dimension of its left null space N(A⊤)N(A^\top)?

Question 5 of 7 +20 XP

The columns of A∈Rm×nA \in \mathbb{R}^{m \times n} are linearly independent, so rank⁡(A)=n\operatorname{rank}(A) = n. What does that tell you about Ax=bA\mathbf{x} = \mathbf{b}?

Question 6 of 7 +20 XP

AA is 10×310 \times 3 and BB is 3×103 \times 10. What is the largest possible rank of the 10×1010 \times 10 matrix ABAB?

Question 7 of 7 +20 XP

For a square d×dd \times d weight matrix, what fraction of the full update's d2d^2 entries does a rank-rr LoRA update BABA need to train?

End of the chamber

Clear this chamber

+60 XPColumn SpaceNull SpaceRankRank–Nullity Theorem