Caffe2 - C++ API
A deep learning, cross platform ML framework
grad_mode.h
1 #pragma once
2 
3 #include <torch/csrc/WindowsTorchApiMacro.h>
4 
5 namespace torch { namespace autograd {
6 
7 struct TORCH_API GradMode {
8  static bool is_enabled();
9  static void set_enabled(bool enabled);
10 };
11 
12 // A RAII, thread local (!) guard that enables or disables grad mode upon
13 // construction, and sets it back to the original value upon destruction.
14 struct TORCH_API AutoGradMode {
15  AutoGradMode(bool enabled) : prev_mode(GradMode::is_enabled()) {
16  GradMode::set_enabled(enabled);
17  }
18  ~AutoGradMode() {
19  GradMode::set_enabled(prev_mode);
20  }
21  bool prev_mode;
22 };
23 
24 }}
Definition: jit_type.h:17