Thank you! gc.collect() is still unreliable. It seems that Python frees an object immediately when del is used anyway.
Is there perhaps a way to synchronize with the PyTorch thread that checks whether something is deleted and resets autograd information?
I have also tried x.detach_().requires_grad_() and it doesn’t work either.