how to apply gradients manually in pytorch
问题 Starting to learn pytorch and was trying to do something very simple, trying to move a randomly initialized vector of size 5 to a target vector of value [1,2,3,4,5]. But my distance is not decreasing!! And my vector x just goes crazy. No idea what I am missing. import torch import numpy as np from torch.autograd import Variable # regress a vector to the goal vector [1,2,3,4,5] dtype = torch.cuda.FloatTensor # Uncomment this to run on GPU x = Variable(torch.rand(5).type(dtype), requires_grad