fn

inference_mode

Iterator[None]
inference_mode()
source

Context manager for inference-time autograd suppression.

Like no_grad but reserved for fully read-only inference paths: the user guarantees that no in-place mutation of autograd-tracked tensors will occur inside the scope. In the current Lucid implementation inference_mode is an alias for no_grad; the API exists so that future versions can add stricter optimisations (e.g. skipping version-counter tracking on in-place ops) without changing user code.

Parameters

None
No description.

Notes

Mathematically equivalent to wrapping the inference forward pass in

y=f(x),grad mode=off,y = f(x), \qquad \text{grad mode} = \text{off},

so no part of L/θ\partial \mathcal{L} / \partial \theta can be reconstructed afterwards.

Examples

>>> import lucid
>>> from lucid.autograd import inference_mode
>>> x = lucid.tensor([1.0, 2.0], requires_grad=True)
>>> with inference_mode():
...     y = x * 3
>>> y.requires_grad
False