I’m trying to train a model on sequences of data, where the current output depends on both the current input and the first output. My in-sequence training loop looks something like this.:
         for i in range(time):
                if i == 0:
                    output, other_par = model(data)
                    other_par = other_par.detach().clone()
                    other_par = other_par.to(device)
                else:
                    output, _ = model(data, other_par)
                loss += loss_function(output, data)

When I call backward at the end of the loop, it returns the error: “one of the variables needed for gradient computation has been modified by an inplace operation”. Recycling the output other_par is causing the issue, and ideally I’d like autograd to treat it as a fixed input. I thought detach().clone() would make autograd ‘forget’ its dependency, but it doesn’t seem to be working. I’m not sure what’s going on, and any help would be appreciated.