Solved by rainbow_soup in post #4 
              
              
                Solution: change x = torch.tensor([5., 4, 3, 2, 1], requires_grad=True) to x = torch.tensor([5., 4, 3, 2, 1], requires_grad=True).float()