Thanks, that works. Though for others who are reading, a better solution would be to detach the hidden state at the start of each batch rather than to re-initialize, allowing the RNN to “carry-over” the final state from previous batch - this is standard BPTT.