Accumulator

class Accumulator[source]

Bases: Module

Used to accumulate updates for a parameter.

clear(**kwargs) None[source]

Clears the accumulator’s state.

forward(param: Tensor, **kwargs) Tensor[source]

Computes the update and returns a tensor with it applied.

Parameters:

param (torch.Tensor) – parameter being updated.

Returns:

parameter with the update applied.

Return type:

torch.Tensor

fullbound(bound: FullBounding | None, max: float | None = None, min: float | None = None, /, **kwargs: Any) None[source]

Sets the function used for parameter bounding on the upper and lower limits.

When bound is None, no full bound will be applied (and will remove any upper or lower bound present). When bound is not None, then max or min cannot be None.

Parameters:
  • bound (FullBounding | None) – bounding function.

  • max (float | None, optional) – upper bound. Defaults to None.

  • min (float | None, optional) – lower bound. Defaults to None.

  • **kwargs (Any) – keyword arguments for the bounding function.

lowerbound(bound: HalfBounding | None, min: float | None = None, /, **kwargs: Any) None[source]

Sets the function used for parameter bounding on the lower limit.

When bound is None, no lower bound will be applied (and will remove any full bound present). When bound is not None, them min cannot be None.

Parameters:
  • bound (HalfBounding | None) – bounding function.

  • min (float | None, optional) – lower bound. Defaults to None.

  • **kwargs (Any) – keyword arguments for the bounding function.

property neg: Tensor | None

Negative update component.

Parameters:

value (torch.Tensor | None) – appends to update component.

Returns:

accumulated update component.

Return type:

torch.Tensor | None

property pos: Tensor | None

Positive update component.

Parameters:

value (torch.Tensor | None) – appends to update component.

Returns:

accumulated update component.

Return type:

torch.Tensor | None

reduction(fn: Callable[[Tensor, int], Tensor] | None = None) None[source]

Sets the function used for reducing multiple updates.

When fn is None, it sets the default reducer, torch.sum().

Parameters:

fn (Callable[[torch.Tensor, int], torch.Tensor] | None, optional) – function for reducing updates. Defaults to None.

update(param: Tensor, **kwargs) Tensor | None[source]

Computes the update.

Parameters:

param (torch.Tensor) – parameter being updated.

Returns:

value of the update.

Return type:

torch.Tensor | None

upperbound(bound: HalfBounding | None, max: float | None = None, /, **kwargs: Any) None[source]

Sets the function used for parameter bounding on the upper limit.

When bound is None, no upper bound will be applied (and will remove any full bound present). When bound is not None, them max cannot be None.

Parameters:
  • bound (HalfBounding | None) – bounding function.

  • max (float | None, optional) – upper bound. Defaults to None.

  • **kwargs (Any) – keyword arguments for the bounding function.