Hi,

You should not modify the input inplace in the backward pass before returning it. Do input = input.clone() before using it.
The backward pass works with Variable, with you extract the saved_tensors and so you work with a mix of Variable and Tensor. You should use saved_variables.