Solved by viswanatha_reddy in post #3 
              
              
                I was able to solve the error. Some of the tensors are placed on cpu others on gpu. To solve the issue I have moved all the tensors to gpu. 
torch.tensor(1, dtype=torch.float, requires_grad=True) 
#changed to 
torch.tensor(1, dtype=torch.float, requires_grad=True).cuda()