6/31
Part 1 of 6 · Derive the two gradientsLearn and do

Every entry follows the same rule, so each gradient is one matmul

The two loops are the same rule written once for every entry.

dA=dY B⊤,dB=A⊤dYdA = dY\, B^\top, \qquad dB = A^\top dY

In code, next to the forward:

Code
forwardy = a @ b
backwardgrad_a = grad_out @ bᵀ
backwardgrad_b = aᵀ @ grad_out

Each gradient uses the other input, turned over, on the side where that input sat in the forward. In PyTorch, bᵀ is b.transpose(-1, -2).

In the editor, write grads(A, B, dY): both gradients, one matmul each.

The video builds the Jacobian, the grid of slopes of every output entry with respect to every input entry, one entry at a time.