When testing a network in PyTorch one can use with torch.no_grad():
. What is the Libtorch (C++) equivalent?
Thanks!
Asked
Active
Viewed 2,526 times
1 Answers
8
The equivalent in LibTorch is torch::NoGradGuard no_grad
, see documentation.

Ivan
- 34,531
- 8
- 55
- 100
-
1So I can just use it like this ```torch::NoGradGuard no_grad;``` and every following line operates with no grad? – MD98 Jan 27 '21 at 14:07
-
2Yes. It will affect the current scope you're in by disabling the gradient computation. – Ivan Jan 27 '21 at 14:09