Context management in libtorch

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