{"course":{"slug":"maths-you-need","title":"The Maths You Actually Need","url":"https://addaly.com/learn/maths-you-need","level":"intermediate","track":"deep"},"lesson":{"slug":"rank-and-low-rank","title":"Rank, and why a huge matrix can be two small ones","url":"https://addaly.com/learn/maths-you-need/rank-and-low-rank","position":16,"of":76,"minutes":9,"answer":"Rank counts the genuinely independent directions in a matrix, and when it is far below the matrix's size the matrix can be factored into two thin ones at a fraction of the parameters.","keyIdea":"Rank counts the genuinely independent directions in a matrix, and when it is far below the matrix's size the matrix can be factored into two thin ones at a fraction of the parameters."},"body":{"format":"markdown","text":"## Counting what is actually there\n\nA matrix has a number of rows and a number of columns. It also has a **rank**: the number of linearly independent rows, which always equals the number of linearly independent columns. Rank counts how many different directions the matrix contains, as opposed to how many it is written with.\n\n```\nA = [ 1  2  3 ]      row 2 = 2 x row 1\n    [ 2  4  6 ]      row 3 = 3 x row 1\n    [ 3  6  9 ]      rank = 1\n```\n\nThree rows, one independent direction. This 3×3 matrix, nine numbers, carries the information of one 3-vector.\n\nBecause rank 1 means every row is a multiple of one row, such a matrix can be written as an outer product:\n\n```\nA = [1, 2, 3]^T  x  [1, 2, 3]      3 + 3 = 6 numbers instead of 9\n```\n\nThat saving is trivial at 3×3. It is not trivial at 4096×4096.\n\n## The arithmetic that makes it matter\n\nA dense 4096 × 4096 weight matrix holds 16,777,216 parameters. Suppose it has rank 8, or is well approximated by a rank-8 matrix. Then it can be written as `A ≈ U V` where U is 4096 × 8 and V is 8 × 4096:\n\n> Figure: One 4096 by 4096 layer, dense and factored. Bars (millions of parameters): Dense 4096 by 4096 16.78; Two thin matrices, rank 64 0.52; Two thin matrices, rank 16 0.13; Two thin matrices, rank 8 0.07. A rank-8 factorisation holds 65,536 numbers against 16,777,216: 256 times fewer, and the reason a fine-tune of a large model fits on one consumer card. It buys that by assuming the change the task needs is low rank, which is a claim about the task and not a theorem.\n\n```\ndense:    4096 * 4096 = 16,777,216 parameters\nrank 8:   4096 * 8 + 8 * 4096 = 65,536 parameters\nratio:    256x fewer\n```\n\nThat is the entire idea behind LoRA, the fine-tuning method used almost everywhere people adapt a large model on modest hardware. You freeze the original weights and learn only a low-rank update `ΔW = BA` with a small inner dimension, typically 8 to 64. The forward pass becomes `W x + B(A x)`, and you train 65,536 numbers instead of 16.7 million.\n\nThe empirical claim behind it is that the *change* a fine-tune needs to make is much lower rank than the weights themselves. The original weights need all their capacity; adapting them to one new task apparently does not. That claim is supported by a lot of practice and it is not a theorem: it fails when the new task is far from anything the base model does, and the standard response is to raise the rank until it stops failing.\n\n## What rank tells you about a layer\n\nThe rank of a weight matrix bounds what the layer can do. A 768 → 768 layer whose weight matrix has rank 100 can only produce outputs lying in a 100-dimensional subspace, whatever the input. It has 590,000 parameters and 100 directions of expressive power.\n\nThis is why the low-rank bottleneck appears deliberately in architectures. An autoencoder squeezes through a narrow middle layer precisely to force a low-rank representation and make the network discard everything but the essentials. Attention projects to 64 dimensions per head for a related reason: comparisons happen in a small subspace, cheaply.\n\nIt is also why exact rank is the wrong thing to measure on real weights. A trained matrix is almost never exactly rank-deficient: floating-point noise sees to that. What you want is the *effective* rank: how many singular values are large enough to matter. `np.linalg.matrix_rank` uses a tolerance for exactly this reason, and looking at the singular values directly tells you more than the count does.\n\n```python\nimport numpy as np\ns = np.linalg.svd(W, compute_uv=False)\nprint((s > s[0] * 0.01).sum(), \"of\", len(s), \"singular values above 1% of the largest\")\n```\n\n## Where low rank shows up besides LoRA\n\n- **Recommendation.** A users × items rating matrix is enormous and mostly empty. Matrix factorisation approximates it as (users × k)(k × items) with k around 50 to 200. Those k dimensions are the \"latent factors\", and the whole approach exists because the true matrix is close to low rank: taste is not arbitrary.\n- **Compressing a trained model.** Replace a big layer with two thin ones fitted to the original's behaviour. It works reasonably for layers whose singular values decay quickly and badly for layers whose do not, which is something you can check before you try.\n- **PCA and embeddings.** Reducing 768 dimensions to 128 is a low-rank approximation of your data matrix, and the question of how much you lose is the question of how fast the singular values decay.\n\n## The limitation nobody mentions\n\nLow-rank methods assume the important structure is *linear*. A matrix can be full rank and still be highly compressible in some non-linear sense, and conversely, data lying on a curved surface may need full rank to describe linearly while having very few real degrees of freedom. Rank measures linear redundancy only.\n\nThe practical version of this warning: when a low-rank fine-tune underperforms, the honest first hypothesis is that the required change was not low rank, not that you chose the learning rate badly. Raising the rank from 8 to 64 costs little and answers the question directly.\n\n## The rule to keep\n\nRank is the number of directions, not the number of numbers. When the second is far larger than the first, you are storing and computing redundancy, and a factorisation will get most of the behaviour for a fraction of the cost."},"check":{"question":"A team applies LoRA with rank 4 to fine-tune a model for a task quite unlike anything in its pre-training, and quality is poor. Which diagnosis follows most directly from what rank means?","options":[{"text":"The base model's weights are too high-rank for a low-rank update to attach to, so full fine-tuning is the only option.","correct":false,"tempting":"The base model's rank does not limit the update's rank; LoRA adds to the weights rather than living inside them."},{"text":"Rank 4 is a very small subspace for the weight change, and a distant task plausibly requires a change that does not fit in it, so raising the rank is the first thing to test.","correct":true},{"text":"The frozen base weights prevent the adapter from learning anything the base model cannot already do.","correct":false,"tempting":"The adapter changes the effective weights and so changes the function; freezing the base does not cap what the sum can express."},{"text":"Rank 4 causes numerical instability because the factor matrices are ill-conditioned.","correct":false,"tempting":"Conditioning of the factors is not the mechanism here, and LoRA at rank 4 trains stably in practice."}]},"prev":{"slug":"least-squares-and-the-normal-equations","title":"The best fit, and what \"best\" was defined to mean","url":"https://addaly.com/learn/maths-you-need/least-squares-and-the-normal-equations"},"next":{"slug":"eigenvectors-plainly","title":"The directions a matrix does not turn","url":"https://addaly.com/learn/maths-you-need/eigenvectors-plainly"},"authorship":"Founder and series editor: Dr Mustafa Mun. Written by AI models to a written standard. Source and assessment review continues. Academic review invited.","review":{"status":"Draft, open for academic review"},"cite":"Addaly (2026) 'Rank, and why a huge matrix can be two small ones', in The Maths You Actually Need. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/maths-you-need/rank-and-low-rank (Accessed: 29 November 2026).","licence":{"name":"CC BY-NC-SA 4.0","url":"https://creativecommons.org/licenses/by-nc-sa/4.0/"},"reader":{"schema":1,"title":"Rank, and why a huge matrix can be two small ones","courseTitle":"The Maths You Actually Need","module":{"index":2,"slug":"matrices-and-layers","title":"Matrices, and what a layer really does"},"answer":null,"keyIdea":"Rank counts the genuinely independent directions in a matrix, and when it is far below the matrix’s size the matrix can be factored into two thin ones at a fraction of the parameters.","hero":{"kind":"figure","figure":{"t":"figure","label":"Figure","figure":{"caption":"A rank-8 factorisation holds 65,536 numbers against 16,777,216: 256 times fewer, and the reason a fine-tune of a large model fits on one consumer card. It buys that by assuming the change the task needs is low rank, which is a claim about the task and not a theorem.","series":[{"highlight":true,"label":"Dense 4096 by 4096","value":16.78},{"label":"Two thin matrices, rank 64","value":0.52},{"label":"Two thin matrices, rank 16","value":0.13},{"label":"Two thin matrices, rank 8","value":0.07}],"title":"One 4096 by 4096 layer, dense and factored","type":"bars","unit":"millions of parameters"},"alt":"Figure: One 4096 by 4096 layer, dense and factored. Bars (millions of parameters): Dense 4096 by 4096 16.78; Two thin matrices, rank 64 0.52; Two thin matrices, rank 16 0.13; Two thin matrices, rank 8 0.07. A rank-8 factorisation holds 65,536 numbers against 16,777,216: 256 times fewer, and the reason a fine-tune of a large model fits on one consumer card. It buys that by assuming the change the task needs is low rank, which is a claim about the task and not a theorem."}},"blocks":[{"t":"h2","id":"counting-what-is-actually-there","runs":[{"text":"Counting what is actually there"}]},{"t":"p","runs":[{"text":"A matrix has a number of rows and a number of columns. It also has a "},{"text":"rank","b":true},{"text":": the number of linearly independent rows, which always equals the number of linearly independent columns. Rank counts how many different directions the matrix contains, as opposed to how many it is written with."}]},{"t":"code","lang":"","label":"Text","text":"A = [ 1  2  3 ]      row 2 = 2 x row 1\n    [ 2  4  6 ]      row 3 = 3 x row 1\n    [ 3  6  9 ]      rank = 1"},{"t":"p","runs":[{"text":"Three rows, one independent direction. This 3×3 matrix, nine numbers, carries the information of one 3-vector."}]},{"t":"p","runs":[{"text":"Because rank 1 means every row is a multiple of one row, such a matrix can be written as an outer product:"}]},{"t":"code","lang":"","label":"Text","text":"A = [1, 2, 3]^T  x  [1, 2, 3]      3 + 3 = 6 numbers instead of 9"},{"t":"p","runs":[{"text":"That saving is trivial at 3×3. It is not trivial at 4096×4096."}]},{"t":"h2","id":"the-arithmetic-that-makes-it-matter","runs":[{"text":"The arithmetic that makes it matter"}]},{"t":"p","runs":[{"text":"A dense 4096 × 4096 weight matrix holds 16,777,216 parameters. Suppose it has rank 8, or is well approximated by a rank-8 matrix. Then it can be written as "},{"text":"A ≈ U V","code":true},{"text":" where U is 4096 × 8 and V is 8 × 4096:"}]},{"t":"code","lang":"","label":"Text","text":"dense:    4096 * 4096 = 16,777,216 parameters\nrank 8:   4096 * 8 + 8 * 4096 = 65,536 parameters\nratio:    256x fewer"},{"t":"p","runs":[{"text":"That is the entire idea behind LoRA, the fine-tuning method used almost everywhere people adapt a large model on modest hardware. You freeze the original weights and learn only a low-rank update "},{"text":"ΔW = BA","code":true},{"text":" with a small inner dimension, typically 8 to 64. The forward pass becomes "},{"text":"W x + B(A x)","code":true},{"text":", and you train 65,536 numbers instead of 16.7 million."}]},{"t":"p","runs":[{"text":"The empirical claim behind it is that the "},{"text":"change","i":true},{"text":" a fine-tune needs to make is much lower rank than the weights themselves. The original weights need all their capacity; adapting them to one new task apparently does not. That claim is supported by a lot of practice and it is not a theorem: it fails when the new task is far from anything the base model does, and the standard response is to raise the rank until it stops failing."}]},{"t":"h2","id":"what-rank-tells-you-about-a-layer","runs":[{"text":"What rank tells you about a layer"}]},{"t":"p","runs":[{"text":"The rank of a weight matrix bounds what the layer can do. A 768 → 768 layer whose weight matrix has rank 100 can only produce outputs lying in a 100-dimensional subspace, whatever the input. It has 590,000 parameters and 100 directions of expressive power."}]},{"t":"p","runs":[{"text":"This is why the low-rank bottleneck appears deliberately in architectures. An autoencoder squeezes through a narrow middle layer precisely to force a low-rank representation and make the network discard everything but the essentials. Attention projects to 64 dimensions per head for a related reason: comparisons happen in a small subspace, cheaply."}]},{"t":"p","runs":[{"text":"It is also why exact rank is the wrong thing to measure on real weights. A trained matrix is almost never exactly rank-deficient: floating-point noise sees to that. What you want is the "},{"text":"effective","i":true},{"text":" rank: how many singular values are large enough to matter. "},{"text":"np.linalg.matrix_rank","code":true},{"text":" uses a tolerance for exactly this reason, and looking at the singular values directly tells you more than the count does."}]},{"t":"code","lang":"python","label":"Python","text":"import numpy as np\ns = np.linalg.svd(W, compute_uv=False)\nprint((s > s[0] * 0.01).sum(), \"of\", len(s), \"singular values above 1% of the largest\")"},{"t":"h2","id":"where-low-rank-shows-up-besides-lora","runs":[{"text":"Where low rank shows up besides LoRA"}]},{"t":"ul","items":[[{"text":"Recommendation.","b":true},{"text":" A users × items rating matrix is enormous and mostly empty. Matrix factorisation approximates it as (users × k)(k × items) with k around 50 to 200. Those k dimensions are the “latent factors”, and the whole approach exists because the true matrix is close to low rank: taste is not arbitrary."}],[{"text":"Compressing a trained model.","b":true},{"text":" Replace a big layer with two thin ones fitted to the original’s behaviour. It works reasonably for layers whose singular values decay quickly and badly for layers whose do not, which is something you can check before you try."}],[{"text":"PCA and embeddings.","b":true},{"text":" Reducing 768 dimensions to 128 is a low-rank approximation of your data matrix, and the question of how much you lose is the question of how fast the singular values decay."}]]},{"t":"h2","id":"the-limitation-nobody-mentions","runs":[{"text":"The limitation nobody mentions"}],"role":"limit"},{"t":"p","runs":[{"text":"Low-rank methods assume the important structure is "},{"text":"linear","i":true},{"text":". A matrix can be full rank and still be highly compressible in some non-linear sense, and conversely, data lying on a curved surface may need full rank to describe linearly while having very few real degrees of freedom. Rank measures linear redundancy only."}]},{"t":"p","runs":[{"text":"The practical version of this warning: when a low-rank fine-tune underperforms, the honest first hypothesis is that the required change was not low rank, not that you chose the learning rate badly. Raising the rank from 8 to 64 costs little and answers the question directly."}]},{"t":"h2","id":"the-rule-to-keep","runs":[{"text":"The rule to keep"}]},{"t":"p","runs":[{"text":"Rank is the number of directions, not the number of numbers. When the second is far larger than the first, you are storing and computing redundancy, and a factorisation will get most of the behaviour for a fraction of the cost."}]}],"check":{"question":[{"text":"A team applies LoRA with rank 4 to fine-tune a model for a task quite unlike anything in its pre-training, and quality is poor. Which diagnosis follows most directly from what rank means?"}],"options":[{"text":[{"text":"The base model’s weights are too high-rank for a low-rank update to attach to, so full fine-tuning is the only option."}],"correct":false,"tempting":[{"text":"The base model’s rank does not limit the update’s rank; LoRA adds to the weights rather than living inside them."}]},{"text":[{"text":"Rank 4 is a very small subspace for the weight change, and a distant task plausibly requires a change that does not fit in it, so raising the rank is the first thing to test."}],"correct":true,"tempting":null},{"text":[{"text":"The frozen base weights prevent the adapter from learning anything the base model cannot already do."}],"correct":false,"tempting":[{"text":"The adapter changes the effective weights and so changes the function; freezing the base does not cap what the sum can express."}]},{"text":[{"text":"Rank 4 causes numerical instability because the factor matrices are ill-conditioned."}],"correct":false,"tempting":[{"text":"Conditioning of the factors is not the mechanism here, and LoRA at rank 4 trains stably in practice."}]}],"order":[3,0,1,2],"why":null},"prev":{"slug":"least-squares-and-the-normal-equations","title":"The best fit, and what “best” was defined to mean","minutes":9},"next":{"slug":"eigenvectors-plainly","title":"The directions a matrix does not turn","minutes":9}}}