Solved by albanD in post #2 
              
              
                Hi, 
Why do you have this line: loss = Variable(loss, requires_grad=True) ? 
Variable should not be used anymore. 
So the line above should be deleted and to mark a Tensor for which you want gradients, you can use: 
input = input.cuda().requires_grad_().