Thanks,after moving
import torch
outside of the loop,these two outputs are still totally different.
For why using “with torch.no_grad()”:
After commenting out the backward,the computation graph won’t be deleted,and I got a CUDA out of memory exception,so I use
torch.no_grad():
to tell pytorch don’t hold computation graph