Weight decay¶
This subpackage contains weight decay modules.
Classes:
-
DirectWeightDecay
–Directly applies weight decay to parameters.
-
RelativeWeightDecay
–Weight decay relative to the mean absolute value of update, gradient or parameters depending on value of
norm_input
argument. -
WeightDecay
–Weight decay.
Functions:
-
decay_weights_
–directly decays weights in-place
DirectWeightDecay ¶
Bases: torchzero.core.module.Module
Directly applies weight decay to parameters.
Parameters:
-
weight_decay
(float
) –weight decay scale.
-
ord
(int
, default:2
) –order of the penalty, e.g. 1 for L1 and 2 for L2. Defaults to 2.
Source code in torchzero/modules/weight_decay/weight_decay.py
RelativeWeightDecay ¶
Bases: torchzero.core.transform.Transform
Weight decay relative to the mean absolute value of update, gradient or parameters depending on value of norm_input
argument.
Parameters:
-
weight_decay
(float
, default:0.1
) –relative weight decay scale.
-
ord
(int
, default:2
) –order of the penalty, e.g. 1 for L1 and 2 for L2. Defaults to 2.
-
norm_input
(str
, default:'update'
) –determines what should weight decay be relative to. "update", "grad" or "params". Defaults to "update".
-
metric
(Ords
, default:'mad'
) –metric (norm, etc) that weight decay should be relative to. defaults to 'mad' (mean absolute deviation).
-
target
(Literal
, default:'update'
) –what to set on var. Defaults to 'update'.
Examples:¶
Adam with non-decoupled relative weight decay
Adam with decoupled relative weight decay
Source code in torchzero/modules/weight_decay/weight_decay.py
WeightDecay ¶
Bases: torchzero.core.transform.Transform
Weight decay.
Parameters:
-
weight_decay
(float
) –weight decay scale.
-
ord
(int
, default:2
) –order of the penalty, e.g. 1 for L1 and 2 for L2. Defaults to 2.
-
target
(Literal
, default:'update'
) –what to set on var. Defaults to 'update'.
Examples:¶
Adam with non-decoupled weight decay
Adam with decoupled weight decay that still scales with learning rate
Adam with fully decoupled weight decay that doesn't scale with learning rate
Source code in torchzero/modules/weight_decay/weight_decay.py
decay_weights_ ¶
directly decays weights in-place