pydpf.base.constrained_parameter#
- class pydpf.base.constrained_parameter(function: Callable[[Module], Tuple[Tensor, Tensor]])#
Bases:
objectWrapper for constraining parameters. The wrapped function must belong to a Module and should take only a reference to its parent Module and return a reference to the original parameter and a tensor containing the new value.
constrained_parameterapplies the change in-place; the underlying data of the parameter is modified. Necessarily, therefore this is done without gradient tracking.The constraint is applied on calling
Module.update(), so you should do this after every gradient update to preserve the constraint.Notes
constrained_parameterscan be applied to any parameter accessible from aModuleincluding as attributes of a childModule. This is safe as the parameter is changed in-place.Warning
@constrained_parametershould be used to impose constraints only, the underlying data is modified inplace and without gradient.@constrained_parametershould always act directly on the underlying parameter, they cannot be stacked or used to constrain functions of parameters.Methods
__init__(function)