because you redefined x0. the second x0 is not really the x0 you defined the first time. it is not really reusing thje same variable, but redefining a symbol to be a different variable. your new variable here is an intermediate results, which do not retain gradients by default. you can call retain_grad() on it to get grad http://pytorch.org/docs/master/autograd.html#torch.autograd.Variable.retain_grad 6.