I see that in your code you unpacked the .data multiple times. Remember that every time you do that, you won’t save that part of the computation in autograd and it might break the backprop. For example, if you meant _write_to_mem to be differentiable, then it’s not. You unpacked the Variable that contained the whole history and then repacked it in a new one, that won’t backprop gradients to the graph that created the data. The problem is in here 20.