28/31
Part 6 of 6 · What interviewers ask nextLearn and do

Why it's two matmuls and never the full Jacobian

An interviewer may ask why the backward isn't the textbook recipe, the gradient times the Jacobian.

Numbers at n = k = m = 4,096
The full Jacobian ∂Y/∂A, (n·m) × (n·k)2482^{48}, about 2.8×10142.8 \times 10^{14}: 1 PiB in fp32, nearly all of it zero
B itself, k × m16.8 million

YY changes in a straight line with AA, so its backward is one more matmul: multiply by B⊤B^\top where the forward multiplied by BB. The same holds for BB, with A⊤A^\top.

So both gradients are matmuls with the forward's own three sizes: the same cost, the same fast kernels, and transposes that are free views.

The general recipe, the incoming gradient times the Jacobian, would never fit in memory. All but a 1/n1/n share of its numbers are zero, because YijY_{ij} depends only on row ii of AA. dY B⊤dY\,B^\top gets the same answer without building any of it.

In the editor, write jacobian_entries(n, k, m) and nonzero_share(n).