Thank you for the extensive answer! It works as intended now! 
Also, if I could ask a quick question about torch.vmap, would such a function work with non-batchable functions like torch.autograd.functional.hessian? I’m currently using that function, and it’s a major bottleneck in the runtime of my code!
Thank you!