pydpf.base.cached_property#

class pydpf.base.cached_property(function: Callable)#

Bases: object

Wrapper for caching functions of parameters. The wrapped function must belong to a Module and should take only a reference to its parent Module and tensor containing the new value that will be stored.

cached_property applies its map out-of-place, creating a new tensor. Gradient tracking is permitted through the map.

The cached_property is calculated lazily; when it is first accessed it is calculated and cached. Calling Module.update() resets the value so that it will be recomputed on next access.

Warning

PyTorch generally expects the gradient graph to be created on each forward pass, and destroys it on backwards passes. Therefore, it is recommended to call .update() on the top level Module whenever running a script with gradient tracking even if it is known that the parameters have not changed.

__init__(function: Callable)#

Methods

__init__(function)