How not to consider gradient for specific operation without copying tensors?

Hi, you can detach a tensor from the computational graph with latent2.detach(). You can find more details here.

loss = F.mse_loss(x2, x) + F.mse_loss(latent2.detach(), latent)