I used torch.no_grad() as you mentioned, but now I am getting the error in loss.backward():
element 0 of tensors does not require grad and does not have a grad_fn.
Instead of inputs = Variable(inputs, volatile=True), I used:
inputs = Variable(inputs, requires_grad=True)

it doesn’t show any errors, but I am not sure that is correct?