Im trying to manage a time series update for Reinforcement Learning in PyTorch. The involves updating operations on a 3D Tensor in the following way:
 self.state[batch, time_index, 0] = (self.state[batch, time_index, 0] + prediction[batch]).clone()
 self.state[batch, time_index + 1] = (self.state[batch, time_index + 1] + self.state[batch, time_index]).clone()
 rew = compute_reward(self.state[batch, time_index], y)
 self.state[batch, time_index] = (self.state[batch, time_index] - y).clone()

compute_reward does another operation that could be culprit:
points = torch.min(state, y)

This gives the error:
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.FloatTensor [2000, 1]], which is output 0 of SelectBackward, is at version 412206; expected version 410204 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!

Does anyone know any tricks to be able to do this without creating an in-place operations?