Is your error something along the lines of?
RuntimeError: Trying to backward through the graph a second time ...

?
That’s because the graph gets deleted after it’s been evaluated via .backward(). If you want to backpropate through the graph a second time. You can set the argument "retain_graph=True in your first backward call.
Also, please note that Variable has been deprecated since PyTorch 0.4 (multiple versions ago) and it’s better to use the torch.tensor constructor. E.g., the following should work:
x = torch.tensor(torch.arange(0, 4).double(), requires_grad=True)

y = x.detach().requires_grad_(True)*2

z = y * x

z.backward(torch.ones(y.size()).double(), retain_graph=True)

y.sum().backward()

print(x.grad, 2*x)