All problems
Autograd Node: Add and Multiply
Problem
Implement one node of a tiny reverse-mode autograd engine.
For z = a * b + c, return [z, dz/da, dz/db, dz/dc]. The multiply node feeds the add node, so gradients flow backwards through both: dz/dc = 1, dz/db = a, and dz/da = b.
Hint
Local gradients multiply along the path and add at branches.
Test cases
case 1
in: [2,3,4]
expected: [10,3,2,1]
case 2
in: [0,-1,5]
expected: [5,-1,0,1]
case 3
in: [1.5,2,0]
expected: [3,2,1.5,1]
case 4
in: [-2,3,1]
expected: [-5,3,-2,1]
Starter codePython
def autograd_addmul(a, b, c):
# Return [z, dz_da, dz_db, dz_dc]
# Your code here
pass4 test cases · run your code against them in the editor