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) | , about : 1 PiB in fp32, nearly all of it zero |
| B itself, k × m | 16.8 million |
changes in a straight line with , so its backward is one more matmul: multiply by where the forward multiplied by . The same holds for , with .
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 share of its numbers are zero, because depends only on row of . gets the same answer without building any of it.
In the editor, write jacobian_entries(n, k, m) and nonzero_share(n).