Hello,
I am implementing a GRU rnn using grucells. I have N layers, so I store my hidden states as a N x hidden_dimension variable.
The thing is that after the output of my GRUcell, I want to update the values of the hidden state with the output of the GRUCell, but this makes backward() break.
So for example:
for idxLayer in range(self.n_layers):
    currentCell = self.grucells[idxLayer]
    output = currentCell(output, hiddenStates[idxLayer, :].view(1,-1))
    hiddenStates[idxLayer,:] = output #this operation makes the backward() operation fail
hiddenStates.sum().backward() #Runtime error

RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation

How can I solve the problem? Thanks!