7

When testing a network in PyTorch one can use with torch.no_grad():. What is the Libtorch (C++) equivalent? Thanks!

Ivan
  • 34,531
  • 8
  • 55
  • 100
MD98
  • 344
  • 2
  • 9

1 Answers1

8

The equivalent in LibTorch is torch::NoGradGuard no_grad, see documentation.

Ivan
  • 34,531
  • 8
  • 55
  • 100
  • 1
    So 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
  • 2
    Yes. It will affect the current scope you're in by disabling the gradient computation. – Ivan Jan 27 '21 at 14:09