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.
In code, next to the forward:
| Code | |
|---|---|
| forward | y = a @ b |
| backward | grad_a = grad_out @ bᵀ |
| backward | grad_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.