Hi

i have created a simple Linear AE and using adam optimizer

i have two functions to minimize

loss1 = reconstruction loss

loss 2 = centroids and encoded space euclidean distance

so I created something like below pytorch version 1.9.0+cu102

```
loss1 = 0.8*criterion(decoded, image)
loss2 = torch.sum(torch.cdist(encoded, dist_matrix.to(device))**2)
loss = loss1 + loss2
loss.backward(retain_graph=True)
optimizer.step()
optimizer.zero_grad()
```

Auto encoder code

```
class LAE3d(nn.Module):
def __init__(self):
# N, 784(28*28)
super(LAE3d, self).__init__()
self.encoder = nn.Sequential(
nn.Linear(1*28 * 28, 1000),
nn.ReLU(),
nn.Linear(1000, 250),
nn.ReLU(),
nn.Linear(250, 50),
nn.ReLU()
)
self.decoder = nn.Sequential(
nn.Linear(50, 250),
nn.ReLU(),
nn.Linear(250, 1000),
nn.ReLU(),
nn.Linear(1000, 1*28*28),
nn.ReLU()
)
def forward(self, x):
encoded = self.encoder(x)
decoded = self.decoder(encoded)
return encoded, decoded
model = LAE3d()
model.to(device)
criterion = nn.MSELoss()
optimizer = torch.optim.Adam(model.parameters(), lr=0.001)
print(summary(model, input_size=(1, 1*28*28)))
```

basically trying to recreate Paper

I get the following error

RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [250, 50]], which is output 0 of TBackward, is at version 305; expected version 304 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!