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

I cannot debug the code as it’s not executable, but you should check these operations:

t[i,time_idx+1]=t[i,time_idx]+Time_res+ torch.sum(torch.dot(self.network_output[i,:], diff))

sumerror[i]=torch.log(torch.tensor(2+time_idx))*error

Nodein[b,:]=Node

as they are all assigning tensors inplace and try to replace them with a new tensor creation, if possible.