Memory leak in LibTorch, extremely simple code

Thanks so much for your reply!

So after accumulating loss or getting gradients, what variables need to be detached?