fn
set_detect_anomaly
→Noneset_detect_anomaly(mode: bool, check_nan: bool = True)Programmatic global toggle for autograd anomaly detection.
Equivalent to entering detect_anomaly once and never
exiting — flips the process-wide flag that backward
consults at the end of each pass. Prefer the with-block form
when the scope is bounded; use this free function when the flag
is controlled by a CLI argument or an environment variable read
once at start-up.
Parameters
modeboolTrue enables NaN / Inf checking on every backward;
False disables it.check_nanbool= TrueForwarded to the underlying flag. Currently the only supported
check is for non-finite values; the parameter exists for API
symmetry and forward compatibility.
Returns
NoneThe function mutates a module-level flag; it has no return value.
Notes
The effective flag is :
setting either to False disables checking. There is no stack of
saved states — once changed, the flag stays until the next call.
Examples
Enable checks at start-up:
>>> import lucid
>>> from lucid.autograd import set_detect_anomaly, is_anomaly_enabled
>>> set_detect_anomaly(True)
>>> is_anomaly_enabled()
True
>>> set_detect_anomaly(False)