Matrix Product: Right-Input Gradient
Let Z=AB, with fixed A of shape m\times d and variable B of shape d\times k.
On this page 7 sections
01Accumulate across output rows#
Let , with fixed of shape and variable of shape . A scalar loss supplies , of shape . We want one derivative for every entry of .
The entry contributes to every output row in column . Its contribution to output is scaled by . Summing the loss sensitivities gives
Collect those sums as
02Sum contributions from the batch#
Let have rows and let have rows . Entry of is .
The other entries give gradient rows . The three output rows contribute to just two parameter rows. Shared parameters collect contributions from every example that uses them.
A has rows (1,2),(3,0); G is column (2,−1). Find ∇B L for Z=AB.
Show answer and explanation
AᵀG gives 1×2+3×−1=−1 and 2×2=4.
03Keep the incoming scale#
The shape is , matching . The transpose aligns the summation over output rows. Correct dimensions are a useful check, but the entrywise argument explains why this order is right.
If already represents an average loss, its averaging factor is already present in this sum. Dividing by again makes the update too small for the stated objective.
A draft uses AG instead of AᵀG for the right-input gradient. Which operation is missing?
Show answer and explanation
The summation must run down each input feature column.
This rule treats the displayed as fixed for the partial derivative with respect to . If the same underlying parameter appears elsewhere in a computation, its other derivative paths must also be accumulated.
Compute the right-input gradient AᵀG for Z = AB from a supplied incoming scalar-loss gradient G.
- Compute the right-input gradient AᵀG 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