What is the LibTorch equivalent to PyTorch's torch.no_grad?
Asked Answered
O

1

9

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

Oestriol answered 27/1, 2021 at 14:0 Comment(0)
D
11

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

Distefano answered 27/1, 2021 at 14:4 Comment(2)
So I can just use it like this torch::NoGradGuard no_grad; and every following line operates with no grad?Oestriol
Yes. It will affect the current scope you're in by disabling the gradient computation.Distefano

© 2022 - 2024 — McMap. All rights reserved.