memorax.utils.periodic_incremental_update#
- memorax.utils.periodic_incremental_update(new_tensors, old_tensors, steps, update_period, step_size)[source]#
Periodically perform Polyak-style incremental updates.
Combines the ideas of periodic_update and incremental_update: every update_period steps, the slow copy is updated with an exponential moving average of the fast parameters; otherwise it stays unchanged.
- Parameters:
new_tensors (
Union[Array,ndarray,bool,number,Iterable[ArrayTree],Mapping[Any, ArrayTree]]) – the latest value of the tensors.old_tensors (
Union[Array,ndarray,bool,number,Iterable[ArrayTree],Mapping[Any, ArrayTree]]) – a slow copy of the model’s parameters.steps (
Array) – current number of update steps on the “online” network.update_period (
int) – every how many steps to refresh the slow copy.step_size (
int) – Polyak averaging factor used when the refresh occurs.
- Return type:
Union[Array,ndarray,bool,number,Iterable[ArrayTree],Mapping[Any, ArrayTree]]- Returns:
a slow copy of the model’s parameters that is incrementally updated every update_period steps: step_size * new_tensors + (1 - step_size) * old_tensors.