Hi,
The error
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.FloatTensor [100, 300]], which is output 0 of TBackward, is at version 2; expected version 1 instead. Hint: the backtrace further above shows the operation that failed to compute its gradient. The variable in question was changed in there or anywhere later. Good luck!

Comes from the fact that when you run     loss_gru2.backward() (note that the retain_graph is not needed here), you actually backprop all the wait to gru1. But gru1's paramters where modified inplace by gre1_opt.step(). Thus the error you’re seeing.
If you want the second part to only consider gru2, then you can detach the output from gru1 to make them independent:
    gru2_output, _ = gru2(gru1_output.detach())  # (15, 100, 2)

This will prevent the backprop from going all the way to gru1.
Note that it will also remove the need from retain_graph=True in the first backward of gru1 because now you don’t backprop through it again !