I think you should try to set Variable with volatile = True and try this code again, because by default, the framework will track your usage of variable to calculate the gradient when you call backward function.