fn
set_grad_enabled
→Noneset_grad_enabled(flag: bool)Globally set the autograd gradient-tracking flag.
Imperative counterpart of no_grad and
enable_grad: flips the process-wide flag without a
with block. Useful when the desired state is determined
by configuration (e.g. an inference server that disables
grad once at start-up).
Parameters
flagboolTrue to enable gradient tracking on subsequent ops,
False to disable it. The change persists until
another call to set_grad_enabled or until a
context-manager-based override.Notes
Unlike the context-manager forms, this function does not
stack previous states — repeated calls simply overwrite the
flag. Pair it with is_grad_enabled to save and
restore manually if needed.
Examples
>>> import lucid
>>> from lucid.autograd import set_grad_enabled, is_grad_enabled
>>> set_grad_enabled(False)
>>> is_grad_enabled()
False
>>> set_grad_enabled(True)