Ah, sorry. Your line

gp = 3 * inputs.grad = 3 * l1 * l2

made me realize my mistake. When taking the gradient of gp wrt l1, I was thinking that the inputs was still attached to the graph so something like
gp = 3 * l1 * l1 * inputs which is wrong
Thank you!