The torch.cuda.empty_cache() is not placed properly. When you call it, the net has been moved out but not out and inten. You need to call it after the function call as it is when exiting the function call that these will be cleaned out properly.
fun()
torch.cuda.empty_cache()
_ = input()