I was searching for a solution for the same problem and found out that Autograd now has a functional module 23 that solves this exact problem. Specifically, torch.autograd.functional.jacobian 249, given a function and input variables, returns the Jacobian. There are also functions to compute the Hessian, Jacobian-vector-product, etc.