I add the line for Variable, since otherwise it asked for
retain_graph=True
for backward.
It seems Variable will register the gradient of weights in the backward method.
This code and yours produce completely different results.