I am not sure about the correctness of the loss functions. But as far as I can see, the operations are not breaking the computational graph. If you are not creating new tensors using the output of the network or going out of torch eco-system (.numpy()), you won’t be breaking the computational graph.