I am trying this out now. It works for batch_size= 1 but for batch_size > 1 I get the following error:
RuntimeError: grad can be implicitly created only for scalar outputs

Is there any efficient way to use the autograd for batch_size more than 1?