Solved by shane-carroll in post #4 
              
              
                The c++ equivalent of torch.no_grad() would be NoGradGuard from 
torch/csrc/api/include/torch/utils.h. From the current comments you can see that it is a thread-local guard to disable gradients. 
torch::NoGradGuard no_grad_guard; 
[rest of your code with no grad]