RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.FloatTensor [64, 50]], which is output 0 of AsStridedBackward0, is at version 2; expected version 1 instead

Hi Jun!

Assigning into a tensor using indexing is an inplace operation, and this
is likely the cause of your error.

Try replacing the code I quoted with

h_0 = self.gru_0(x, h_in[0])
h_out = torch.stack (h_0, self.gru_1(h_0, h_in[1])

If that doesn’t fix your problem, take a look at this post that gives some
suggestions for debugging inplace-modification errors:

Best.

K. Frank