NoGradGuard should do the same as with torch.no_grad() as explained here.
NoGradGuard
with torch.no_grad()