Linear algebra for LLMsPart 7: Decompositions and low rank
Matrix norms and conditioning
5 min
Frobenius norm: all the entries
Treat the matrix as one long vector and take its length. It also equals the length of the singular-value list: . Weight decay penalizes this (squared).
Write
Spectral norm: the largest stretch
How much can the matrix lengthen a vector at most? Exactly , reached along . It bounds the output: for every .
Write
Condition number
The ratio of the largest to the smallest stretch. When is large, the matrix nearly collapses some direction, and solving can turn a tiny error in into a large error in . Orthogonal matrices have , the best possible.
Write
✏️ Your turn
Compute the norms
Its singular values are 3 and 2 (last deck but one). Write the Frobenius norm, the spectral norm and the condition number.
Work it out on paper, then go to the next card to check.
Answer
Why it matters in training
In a transformer
A layer’s spectral norm limits how much it can amplify its input, so stacks of layers with large blow activations up. Some methods control it directly: spectral normalization divides a weight by , and some recent optimizers (Muon, for example) replace an update matrix by its orthogonal factor , whose singular values are all 1. Mixed-precision training also watches conditioning, since BF16 has few digits to spare (Part 9).
torch.linalg.matrix_norm(A) # Frobenius
torch.linalg.matrix_norm(A, ord=2) # spectral: the largest singular value
torch.linalg.cond(A) # condition number📌 Recap
Matrix norms in one card
- Frobenius: .
- Spectral: , the largest stretch; .
- Condition number ; orthogonal matrices have .
Write