I  found out that Autograd now has a functional module 9 that solves this problem. Specifically, torch.autograd.functional.jacobian 194, given a function and input variables, returns the Jacobian. There are also functions to compute the Hessian, Jacobian-vector-product, etc.