Matrix Product: Left-Input Gradient
Let Z=AB, where A is m\times d and fixed B is d\times k.
On this page 7 sections
01Send output sensitivities to the left input#
Let , where is and fixed is . Suppose a scalar loss supplies the incoming gradient , shaped . We want the gradient with respect to .
Output depends on with derivative . That input entry affects every output column in its row. Add their contributions:
This is a row-column product with a transpose:
02Collect all output columns#
Let have rows and let have rows . For gradient entry , compute .
For entry , compute . The second row gives and . The left-input gradient therefore has rows .
B has rows (1,2),(3,0), and G=(2,−1) is one row. For Z=AB, find ∇A L.
Show answer and explanation
GBᵀ pairs G with each row of B: 2−2=0 and 6.
03Match the input#
The product has shape , matching . An entrywise product cannot collect the contributions from several output columns.
A draft uses GB for the left gradient and dimensions happen to be square. What rule should replace it?
Show answer and explanation
The index sum pairs a G row with a B row, requiring Bᵀ.
Use exactly as supplied. If an earlier mean-loss derivative already divided by batch size, do not divide again here. This operation propagates sensitivities; it does not choose a new loss reduction.
Compute the left-input gradient GBᵀ for Z = AB from a supplied incoming scalar-loss gradient G.
- Compute the left-input gradient GBᵀ for Z = AB from a supplied incoming scalar-loss gradient G.
Sources & further reading
- [1]MIT 6.390, Appendix A: Matrix Calculus ↗introml.mit.edu · Article
- [2]Boyd and Vandenberghe, Introduction to Applied Linear Algebra ↗stanford.edu · Article