Hi. I have to implement an autoencoder network with a SVM as classifier. The input of the classifier is the latent space generated by the autoencoder. Also, I have to sum the loss of the AE and that of the SVM. I used this code:

for epoch in range(NUM_EPOCHS):
for batch_tr, (XTrain, YTrain) in enumerate(train_loader):
XTrain = XTrain.to(device)
optimizer.zero_grad()
recon_batch, mu, logvar, latent_space = model(XTrain)
predictions = svm_model(latent_space)
loss_svm_train = svm_loss_criteria(predictions, YTrain)
loss = loss_mse(recon_batch, XTrain, mu, logvar) + loss_svm_train
svm_optimizer.zero_grad()
svm_optimizer.step()
loss.backward()

It generates the following error: RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.FloatTensor [128, 2]], which is output 0 of AsStridedBackward0, is at version 2; expected version 1 instead. How can I fix it?