Linear algebra for LLMsPart 7: Decompositions and low rank

Matrix norms and conditioning

5 min

Frobenius norm: all the entries

∥A∥F=∑ijaij2=∑iσi2\displaystyle \|A\|_F = \sqrt{\textstyle\sum_{ij} a_{ij}^2} = \sqrt{\textstyle\sum_i \sigma_i^2}
∥[3045]∥F=9+0+16+25=50≈7.07\displaystyle \left\| \begin{bmatrix} 3 & 0 \\ 4 & 5 \end{bmatrix} \right\|_F = \sqrt{9 + 0 + 16 + 25} = \sqrt{50} \approx 7.07

Treat the matrix as one long vector and take its length. It also equals the length of the singular-value list: 45+5\sqrt{45 + 5}. Weight decay penalizes this (squared).

Write

∥A∥F=∑aij2=∑σi2\|A\|_F = \sqrt{\sum a_{ij}^2} = \sqrt{\sum \sigma_i^2}.

Spectral norm: the largest stretch

∥A∥2=max⁡∣x∣=1∣Ax∣=σ1\displaystyle \|A\|_2 = \max_{|x| = 1} |Ax| = \sigma_1
∥A∥2=45≈6.71\displaystyle \|A\|_2 = \sqrt{45} \approx 6.71

How much can the matrix lengthen a vector at most? Exactly σ1\sigma_1, reached along v1v_1. It bounds the output: ∣Ax∣≤σ1∣x∣|Ax| \le \sigma_1 |x| for every xx.

Write

∥A∥2=σ1\|A\|_2 = \sigma_1, so ∣Ax∣≤σ1∣x∣|Ax| \le \sigma_1|x|.

Condition number

κ(A)=σmax⁡σmin⁡=455=3\displaystyle \kappa(A) = \frac{\sigma_{\max}}{\sigma_{\min}} = \frac{\sqrt{45}}{\sqrt5} = 3

The ratio of the largest to the smallest stretch. When κ\kappa is large, the matrix nearly collapses some direction, and solving Ax=bAx = b can turn a tiny error in bb into a large error in xx. Orthogonal matrices have κ=1\kappa = 1, the best possible.

Write

κ=σmax⁡/σmin⁡\kappa = \sigma_{\max}/\sigma_{\min}. Large κ\kappa: errors amplified.

✏️ 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

∥A∥F=4+9=13≈3.61\displaystyle \|A\|_F = \sqrt{4 + 9} = \sqrt{13} \approx 3.61
∥A∥2=3,κ=3/2=1.5\displaystyle \|A\|_2 = 3, \qquad \kappa = 3/2 = 1.5

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 σ1\sigma_1 blow activations up. Some methods control it directly: spectral normalization divides a weight by σ1\sigma_1, and some recent optimizers (Muon, for example) replace an update matrix by its orthogonal factor UV⊤UV^\top, 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: ∑aij2=∑σi2\sqrt{\sum a_{ij}^2} = \sqrt{\sum\sigma_i^2}.
  • Spectral: σ1\sigma_1, the largest stretch; ∣Ax∣≤σ1∣x∣|Ax| \le \sigma_1|x|.
  • Condition number κ=σmax⁡/σmin⁡\kappa = \sigma_{\max}/\sigma_{\min}; orthogonal matrices have κ=1\kappa = 1.

Write

The three lines above.