AlexLuya:

import torch


Let you try to move the import to outside of the loop.
Your program does import every time in every iteration.
And tell me reason why use with torch.no_grad():.
When removing the “import” and the “with” statement, what happen?