You can feed a tensor backward as in x.backward(weight)’ this is mathematically equivalent to (x * weight).sum().backward(). There isn’t anything that let’s you get arbitrary derivatives of vectors (i.e. Jacobians).
Best regards
Thomas