Thank you for your reply.
I tried with torch.no_grad(). The result is that GPU memory usage will fluctuate up and down, and the program can run normally at first. But after running for a period of time, the GPU memory will be full in the later stage.
Moreover, “GPU memory is full” is not always full, but still “fluctuates up and down”, that is to say, it can work occasionally.