My bad, I replied too quickly… As you found out, the following works
x.data -= 0.1 * x.grad.data

and as you aren’t using an optimizer, nor a model in your example code, you can zero gradients using
x.grad.data.fill_(0)

You will also get the following error on the second iteration. RuntimeError: Trying to backward through the graph a second time, but the buffers have already been freed. To avoid that you can add total.detach_() at the end of the for loop in order to tell pytorch where to stop backpropagating.