The c++ equivalent of torch.no_grad() would be NoGradGuard from
torch/csrc/api/include/torch/utils.h 123. 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]