autograd.grad itself is a batch version. So if you use @pascal_notsawo method, you just need to iterate n times (n is your variable dimension rather than the batch dimension). So maybe if your variable dimension is smaller, you can iterate over that.