Search code examples
pythonc++pytorchautogradlibtorch

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


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


Solution

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