plenoptic.remove_grad#

plenoptic.remove_grad(model)[source]#

Detach all parameters and buffers of model (in place).

Because models in plenoptic are fixed (i.e., we don’t change their parameters), we want to remove the gradients from their parameters to avoid unnecessary computation.

Parameters:

model (Module) – Torch Module with learnable parameters.

Examples

>>> import plenoptic as po
>>> model = po.models.OnOff(31, pretrained=True, cache_filt=True).eval()
>>> po.validate.validate_model(model)
Traceback (most recent call last):
ValueError: model adds gradient to input, ...
>>> po.remove_grad(model)
>>> po.validate.validate_model(model)