I have the following code. It gives me the following error
one of the variables needed for gradient computation has been modified by an inplace operation
lam = 0  # lambda
c = 0  # penalty
mu = 0 # other parameters
# outer loop
 while outer_step < self.max_outer_iter:
            inner_step = 0
            # inner loop
            while inner_step < self.max_inner_iter:
                epochs += 1
                inner_step += 1
                trainning_data ...

                # compute the loss
                loss = self.entire_l(trainning_data, lam,c, mu)

                # Zero Gradient Container
                optimizer.zero_grad()
                # Optimize step
                loss.backward(retain_graph=True)
                optimizer.step()

                # Decay Learning Rate
                scheduler.step()

            # update the slack variable
            lam = lam + c * something
            outer_step += 1

I am new to Pytorch, but I do not know what what’s wrong with this code.