Thread-local switch controlling whether autograd records ops on the current thread.
All methods are static: there is no instance state — the class is
a namespace-style holder over a single thread_local bool defined
in GradMode.cpp. Querying or setting the flag is a single
TLS load/store with no synchronisation cost.
See Also
NoGradGuard — RAII helper for scoped disabling.
Notes
The default value at thread startup is true (gradients tracked).
Threads created via std::thread or worker pools each begin
with their own fresh true-valued flag.
Static methods
2Returns whether autograd is currently active on the calling thread.
Returns
booltrue when ops should build autograd nodes, false when they should run in pure-inference mode.
Notes
The value defaults to true for every newly-spawned thread.
Sets the autograd activity flag for the calling thread.
See Also
NoGradGuard — exception-safe scoped toggle.
Parameters
valuebooltrue to enable autograd recording, false to suppress it. The change is only visible to the calling thread.Notes
Prefer NoGradGuard over manual paired set_enabled
calls — the RAII form correctly restores the previous flag when
an exception unwinds the stack.