A very typical problem for those who use RNNs/LSTMs etc. What happens is this…
The first batch is predicted, the loss backpropagates through time to the beginning of the batch. That works.
The second batch is predicted, the loss backpropagates through time to the beginning of the batch AND tries to backpropagate through time to the beginning of the first batch, but the graph for the first batch has been discarded, so it throws an error.
The solution is to detach/repackage the hidden state after each batch. Something like this.
G.hidden[0].detach_()
G.hidden[1].detach_()

and the same for D.