We’re aware of that issue. Right now there’s an error in RNNs that occurs when you try to backprop through them multiple times. However, your code doesn’t need to do that, and would be much more efficient if it didn’t.
Replacing
for k in range(self.hidden_size):
    self.loss_tot[k].backward(retain_variables=True)

with
sum(self.loss_tot).backward()

will be much better. Backproping from a number of losses is equal to backproping from their sum (the gradients are accumulated). Additionally, this will save a lot of computation, because the backward will batch all operations for all the losses and execute them in one go.