Optimizers
A2Grad
Bases: Optimizer
, BaseOptimizer
Optimal Adaptive and Accelerated Stochastic Gradient Descent.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
Optional[float]
|
Optional[float]. learning rate. no needed. |
None
|
beta |
float
|
float. beta. |
10.0
|
lips |
float
|
float. Lipschitz constant. |
10.0
|
rho |
float
|
float. represents the degree of weighting decrease, a constant smoothing factor between 0 and 1. |
0.5
|
variant |
str
|
str. type of A2Grad optimizer. 'uni', 'inc', 'exp'. |
'uni'
|
Source code in pytorch_optimizer/optimizer/a2grad.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
AdaBelief
Bases: Optimizer
, BaseOptimizer
Adapting Step-sizes by the Belief in Observed Gradients.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. |
(0.9, 0.999)
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
True
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
rectify |
bool
|
bool. perform the rectified update similar to RAdam. |
False
|
n_sma_threshold |
int
|
number of SMA threshold (recommended is 5). |
5
|
degenerated_to_sgd |
bool
|
bool. perform SGD update when variance of gradient is high. |
True
|
ams_bound |
bool
|
bool. whether to use the AMSBound variant. |
False
|
r |
float
|
float. EMA factor. between 0.9 ~ 0.99 is preferred. |
0.95
|
adanorm |
bool
|
bool. whether to use the AdaNorm variant. |
False
|
adam_debias |
bool
|
bool. Only correct the denominator to avoid inflating step sizes early in training. |
False
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-16
|
Source code in pytorch_optimizer/optimizer/adabelief.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
|
AdaBound
Bases: Optimizer
, BaseOptimizer
Adaptive Gradient Methods with Dynamic Bound of Learning Rate.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
final_lr |
float
|
float. final learning rate. |
0.1
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. |
(0.9, 0.999)
|
gamma |
float
|
float. convergence speed of the bound functions. |
0.001
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
True
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
ams_bound |
bool
|
bool. whether to use the AMSBound variant. |
False
|
adam_debias |
bool
|
bool. Only correct the denominator to avoid inflating step sizes early in training. |
False
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-08
|
Source code in pytorch_optimizer/optimizer/adabound.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
|
AdaDelta
Bases: Optimizer
, BaseOptimizer
An Adaptive Learning Rate Method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
1.0
|
rho |
float
|
float. coefficient used for computing a running average of squared gradients. |
0.9
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
False
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-06
|
Source code in pytorch_optimizer/optimizer/adadelta.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
|
AdaFactor
Bases: Optimizer
, BaseOptimizer
Adaptive Learning Rates with Sublinear Memory Cost.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
Optional[float]
|
float. learning rate. |
0.001
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. |
(0.9, 0.999)
|
decay_rate |
float
|
float. coefficient used to compute running averages of square gradient. |
-0.8
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
True
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
clip_threshold |
float
|
float. threshold of root-mean-square of final gradient update. |
1.0
|
ams_bound |
bool
|
bool. whether to use the AMSBound variant. |
False
|
scale_parameter |
bool
|
bool. if true, learning rate is scaled by root-mean-square of parameter. |
True
|
relative_step |
bool
|
bool. if true, time-dependent learning rate is computed instead of external learning rate. |
True
|
warmup_init |
bool
|
bool. time-dependent learning rate computation depends on whether warm-up initialization is being used. |
False
|
eps1 |
float
|
float. term added to the denominator to improve numerical stability. |
1e-30
|
eps2 |
float
|
float. term added to the denominator to improve numerical stability. |
0.001
|
Source code in pytorch_optimizer/optimizer/adafactor.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
|
approximate_sq_grad(exp_avg_sq_row, exp_avg_sq_col, output)
staticmethod
Get approximation of EMA of squared gradient.
Source code in pytorch_optimizer/optimizer/adafactor.py
128 129 130 131 132 133 134 135 136 137 |
|
get_lr(lr, step, rms, relative_step, warmup_init, scale_parameter)
Get AdaFactor learning rate.
Source code in pytorch_optimizer/optimizer/adafactor.py
105 106 107 108 109 110 111 112 113 114 115 116 |
|
get_options(shape)
staticmethod
Get factored
.
Source code in pytorch_optimizer/optimizer/adafactor.py
118 119 120 121 |
|
get_rms(x)
staticmethod
Get RMS.
Source code in pytorch_optimizer/optimizer/adafactor.py
123 124 125 126 |
|
AdaHessian
Bases: Optimizer
, BaseOptimizer
An Adaptive Second Order Optimizer for Machine Learning.
Requires `loss.backward(create_graph=True)` in order to calculate hessians.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.1
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. |
(0.9, 0.999)
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
True
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
hessian_power |
float
|
float. exponent of the hessian trace. |
1.0
|
update_period |
int
|
int. number of steps after which to apply hessian approximation. |
1
|
num_samples |
int
|
int. times to sample |
1
|
hessian_distribution |
HUTCHINSON_G
|
HUTCHINSON_G. type of distribution to initialize hessian. |
'rademacher'
|
adam_debias |
bool
|
bool. Only correct the denominator to avoid inflating step sizes early in training. |
False
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-16
|
Source code in pytorch_optimizer/optimizer/adahessian.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
|
Adai
Bases: Optimizer
, BaseOptimizer
Disentangling the Effects of Adaptive Learning Rate and Momentum.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. |
(0.1, 0.99)
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
False
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
stable_weight_decay |
bool
|
bool. perform stable weight decay. |
False
|
dampening |
float
|
float. dampening for momentum. where dampening < 1, it will show some adaptive-moment behavior. |
1.0
|
use_gc |
bool
|
bool. use gradient centralization. |
False
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
0.001
|
Source code in pytorch_optimizer/optimizer/adai.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
|
Adalite
Bases: Optimizer
, BaseOptimizer
Adalite optimizer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. |
(0.9, 0.999)
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.01
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
False
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
g_norm_min |
float
|
float. |
1e-10
|
ratio_min |
float
|
float. |
0.0001
|
tau |
float
|
float. |
1.0
|
eps1 |
float
|
float. term added to the denominator to improve numerical stability. |
1e-06
|
eps2 |
float
|
float. term added to the denominator to improve numerical stability. |
1e-10
|
Source code in pytorch_optimizer/optimizer/adalite.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
|
AdaMax
Bases: Optimizer
, BaseOptimizer
An Adaptive and Momental Bound Method for Stochastic Learning.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. |
(0.9, 0.999)
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
False
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
r |
float
|
float. EMA factor. between 0.9 ~ 0.99 is preferred. |
0.95
|
adanorm |
bool
|
bool. whether to use the AdaNorm variant. |
False
|
adam_debias |
bool
|
bool. Only correct the denominator to avoid inflating step sizes early in training. |
False
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-08
|
Source code in pytorch_optimizer/optimizer/adamax.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
|
AdaMod
Bases: Optimizer
, BaseOptimizer
An Adaptive and Momental Bound Method for Stochastic Learning.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. beta3 is for smoothing coefficient for adaptive learning rates. |
(0.9, 0.99, 0.9999)
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
True
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
adam_debias |
bool
|
bool. Only correct the denominator to avoid inflating step sizes early in training. |
False
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-08
|
Source code in pytorch_optimizer/optimizer/adamod.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
AdamP
Bases: Optimizer
, BaseOptimizer
Slowing Down the Slowdown for Momentum Optimizers on Scale-invariant Weights.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. |
(0.9, 0.999)
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
True
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
delta |
float
|
float. threshold that determines whether a set of parameters is scale invariant or not. |
0.1
|
wd_ratio |
float
|
float. relative weight decay applied on scale-invariant parameters compared to that applied on scale-variant parameters. |
0.1
|
use_gc |
bool
|
bool. use gradient centralization. |
False
|
nesterov |
bool
|
bool. enables Nesterov momentum. |
False
|
r |
float
|
float. EMA factor. between 0.9 ~ 0.99 is preferred. |
0.95
|
adanorm |
bool
|
bool. whether to use the AdaNorm variant. |
False
|
adam_debias |
bool
|
bool. Only correct the denominator to avoid inflating step sizes early in training. |
False
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-08
|
Source code in pytorch_optimizer/optimizer/adamp.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
|
AdamS
Bases: Optimizer
, BaseOptimizer
Adam with stable weight decay.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. |
(0.9, 0.999)
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0001
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
True
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
ams_bound |
bool
|
bool. whether to use the AMSBound variant. |
False
|
r |
float
|
float. EMA factor. between 0.9 ~ 0.99 is preferred. |
0.95
|
adanorm |
bool
|
bool. whether to use the AdaNorm variant. |
False
|
adam_debias |
bool
|
bool. Only correct the denominator to avoid inflating step sizes early in training. |
False
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-08
|
Source code in pytorch_optimizer/optimizer/adams.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
|
Adan
Bases: Optimizer
, BaseOptimizer
Adaptive Nesterov Momentum Algorithm for Faster Optimizing Deep Models.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. |
(0.98, 0.92, 0.99)
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. decoupled weight decay. |
False
|
max_grad_norm |
float
|
float. max gradient norm to clip. |
0.0
|
use_gc |
bool
|
bool. use gradient centralization. |
False
|
r |
float
|
float. EMA factor. between 0.9 ~ 0.99 is preferred. |
0.95
|
adanorm |
bool
|
bool. whether to use the AdaNorm variant. |
False
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-08
|
Source code in pytorch_optimizer/optimizer/adan.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
|
AdaNorm
Bases: Optimizer
, BaseOptimizer
Symbolic Discovery of Optimization Algorithms.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. |
(0.9, 0.99)
|
r |
float
|
float. EMA factor. between 0.9 ~ 0.99 is preferred. |
0.95
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
True
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
ams_bound |
bool
|
bool. whether to use the AMSBound variant. |
False
|
adam_debias |
bool
|
bool. Only correct the denominator to avoid inflating step sizes early in training. |
False
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-08
|
Source code in pytorch_optimizer/optimizer/adanorm.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
|
AdaPNM
Bases: Optimizer
, BaseOptimizer
Adam + Positive-Negative Momentum Optimizers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. |
(0.9, 0.999, 1.0)
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. use weight_decouple. |
True
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
ams_bound |
bool
|
bool. whether to use the ams_bound variant. |
True
|
r |
float
|
float. EMA factor. between 0.9 ~ 0.99 is preferred. |
0.95
|
adanorm |
bool
|
bool. whether to use the AdaNorm variant. |
False
|
adam_debias |
bool
|
bool. Only correct the denominator to avoid inflating step sizes early in training. |
False
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-08
|
Source code in pytorch_optimizer/optimizer/adapnm.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
|
AdaShift
Bases: Optimizer
, BaseOptimizer
Decorrelation and Convergence of Adaptive Learning Rate Methods.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. |
(0.9, 0.999)
|
keep_num |
int
|
int. number of gradients used to compute first moment estimation. |
10
|
reduce_func |
Optional[Callable]
|
Optional[Callable]. function applied to squared gradients to further reduce the correlation. If None, no function is applied. |
max
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-10
|
Source code in pytorch_optimizer/optimizer/adashift.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
AdaSmooth
Bases: Optimizer
, BaseOptimizer
An Adaptive Learning Rate Method based on Effective Ratio.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. |
(0.5, 0.99)
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
False
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-06
|
Source code in pytorch_optimizer/optimizer/adasmooth.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
agc(p, grad, agc_eps, agc_clip_val, eps=1e-06)
Clip gradient values in excess of the unit wise norm.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
p |
Tensor
|
torch.Tensor. parameter. |
required |
grad |
Tensor
|
torch.Tensor, gradient. |
required |
agc_eps |
float
|
float. agc epsilon to clip the norm of parameter. |
required |
agc_clip_val |
float
|
float. norm clip. |
required |
eps |
float
|
float. simple stop from div by zero and no relation to standard optimizer eps. |
1e-06
|
Source code in pytorch_optimizer/optimizer/agc.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
AggMo
Bases: Optimizer
, BaseOptimizer
Aggregated Momentum: Stability Through Passive Damping.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. |
(0.0, 0.9, 0.99)
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
False
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
Source code in pytorch_optimizer/optimizer/aggmo.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
Aida
Bases: Optimizer
, BaseOptimizer
A DNN Optimizer that Improves over AdaBelief by Suppression of the Adaptive Stepsize Range.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. |
(0.9, 0.999)
|
k |
int
|
int. number of vector projected per iteration. |
2
|
xi |
float
|
float. term used in vector projections to avoid division by zero. |
1e-20
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
False
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
rectify |
bool
|
bool. perform the rectified update similar to RAdam. |
False
|
n_sma_threshold |
int
|
number of SMA threshold (recommended is 5). |
5
|
degenerated_to_sgd |
bool
|
bool. perform SGD update when variance of gradient is high. |
True
|
ams_bound |
bool
|
bool. whether to use the AMSBound variant. |
False
|
r |
float
|
float. EMA factor. between 0.9 ~ 0.99 is preferred. |
0.95
|
adanorm |
bool
|
bool. whether to use the AdaNorm variant. |
False
|
adam_debias |
bool
|
bool. Only correct the denominator to avoid inflating step sizes early in training. |
False
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-08
|
Source code in pytorch_optimizer/optimizer/aida.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
|
AliG
Bases: Optimizer
, BaseOptimizer
Adaptive Learning Rates for Interpolation with Gradients.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
max_lr |
Optional[float]
|
Optional[float]. max learning rate. |
None
|
projection_fn |
Optional[Callable]
|
Callable. projection function to enforce constraints. |
None
|
momentum |
float
|
float. momentum. |
0.0
|
adjusted_momentum |
bool
|
bool. if True, use pytorch-like momentum, instead of standard Nesterov momentum. |
False
|
Source code in pytorch_optimizer/optimizer/alig.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
|
compute_step_size(loss)
Compute step_size.
Source code in pytorch_optimizer/optimizer/alig.py
53 54 55 56 57 58 59 |
|
Amos
Bases: Optimizer
, BaseOptimizer
An Adam-style Optimizer with Adaptive Weight Decay towards Model-Oriented Scale.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
beta |
float
|
float. A float slightly < 1. We recommend setting |
0.999
|
momentum |
float
|
float. Exponential decay rate for optional moving average of updates. |
0.0
|
extra_l2 |
float
|
float. Additional L2 regularization. |
0.0
|
c_coef |
float
|
float. Coefficient for decay_factor_c. |
0.25
|
d_coef |
float
|
float. Coefficient for decay_factor_d. |
0.25
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-18
|
Source code in pytorch_optimizer/optimizer/amos.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
|
get_scale(p)
staticmethod
Get expected scale for model weights.
Source code in pytorch_optimizer/optimizer/amos.py
70 71 72 73 74 75 76 77 |
|
Apollo
Bases: Optimizer
, BaseOptimizer
An Adaptive Parameter-wise Diagonal Quasi-Newton Method for Nonconvex Stochastic Optimization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
init_lr |
Optional[float]
|
Optional[float]. initial learning rate (default lr / 1000). |
None
|
beta |
float
|
float. coefficient used for computing running averages of gradient. |
0.9
|
rebound |
str
|
str. rectified bound for diagonal hessian. (constant, belief). |
'constant'
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decay_type |
str
|
str. type of weight decay. (l2, decoupled, stable). |
'l2'
|
warmup_steps |
int
|
int. number of warmup steps. |
500
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
0.0001
|
Source code in pytorch_optimizer/optimizer/apollo.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
AvaGrad
Bases: Optimizer
, BaseOptimizer
Domain-independent Dominance of Adaptive Methods.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.1
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. |
(0.9, 0.999)
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
True
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
adam_debias |
bool
|
bool. Only correct the denominator to avoid inflating step sizes early in training. |
False
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
0.1
|
Source code in pytorch_optimizer/optimizer/avagrad.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
|
CAME
Bases: Optimizer
, BaseOptimizer
Confidence-guided Adaptive Memory Efficient Optimization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.0002
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. |
(0.9, 0.999, 0.9999)
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
True
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
clip_threshold |
float
|
float. threshold of root-mean-square of final gradient update. |
1.0
|
ams_bound |
bool
|
bool. whether to use the AMSBound variant. |
False
|
eps1 |
float
|
float. term added to the denominator to improve numerical stability. |
1e-30
|
eps2 |
float
|
float. term added to the denominator to improve numerical stability. |
1e-16
|
Source code in pytorch_optimizer/optimizer/came.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
|
approximate_sq_grad(exp_avg_sq_row, exp_avg_sq_col, output)
staticmethod
Get approximation of EMA of squared gradient.
Source code in pytorch_optimizer/optimizer/came.py
106 107 108 109 110 111 112 113 114 115 |
|
get_options(shape)
staticmethod
Get factored
.
Source code in pytorch_optimizer/optimizer/came.py
96 97 98 99 |
|
get_rms(x)
staticmethod
Get RMS.
Source code in pytorch_optimizer/optimizer/came.py
101 102 103 104 |
|
DAdaptAdaGrad
Bases: Optimizer
, BaseOptimizer
AdaGrad with D-Adaptation. Leave LR set to 1 unless you encounter instability.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
1.0
|
momentum |
float
|
float. momentum. |
0.0
|
d0 |
float
|
float. initial D estimate for D-adaptation (default 1e-6). Rarely needs changing. |
1e-06
|
growth_rate |
float
|
float. prevent the D estimate from growing faster than this multiplicative rate. |
float('inf')
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
False
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
0.0
|
Source code in pytorch_optimizer/optimizer/dadapt.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
|
DAdaptAdam
Bases: Optimizer
, BaseOptimizer
Adam with D-Adaptation. Leave LR set to 1 unless you encounter instability. This implementation is based on V3.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
1.0
|
betas |
BETAS
|
BETAS. betas. |
(0.9, 0.999)
|
d0 |
float
|
float. initial D estimate for D-adaptation (default 1e-6). Rarely needs changing. |
1e-06
|
growth_rate |
float
|
float. prevent the D estimate from growing faster than this multiplicative rate. |
float('inf')
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. use AdamW style weight decay. |
False
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
bias_correction |
bool
|
bool. Turn on Adam's bias correction. |
False
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-08
|
Source code in pytorch_optimizer/optimizer/dadapt.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
|
DAdaptSGD
Bases: Optimizer
, BaseOptimizer
SGD with D-Adaptation. Leave LR set to 1 unless you encounter instability. This implementation is based on V3.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
1.0
|
momentum |
float
|
float. momentum. |
0.9
|
d0 |
float
|
float. initial D estimate for D-adaptation (default 1e-6). Rarely needs changing. |
1e-06
|
growth_rate |
float
|
float. prevent the D estimate from growing faster than this multiplicative rate. |
float('inf')
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
False
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
Source code in pytorch_optimizer/optimizer/dadapt.py
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 |
|
DAdaptAdan
Bases: Optimizer
, BaseOptimizer
Adan with D-Adaptation. Leave LR set to 1 unless you encounter instability.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
1.0
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. |
(0.98, 0.92, 0.99)
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. decoupled weight decay. |
False
|
d0 |
float
|
float. initial D estimate for D-adaptation (default 1e-6). Rarely needs changing. |
1e-06
|
growth_rate |
float
|
float. prevent the D estimate from growing faster than this multiplicative rate. Default is inf, for unrestricted. |
float('inf')
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-08
|
Source code in pytorch_optimizer/optimizer/dadapt.py
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 |
|
DAdaptLion
Bases: Optimizer
, BaseOptimizer
Lion with D-Adaptation. Leave LR set to 1 unless you encounter instability. This implementation is based on V3.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
1.0
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. |
(0.9, 0.999)
|
d0 |
float
|
float. initial D estimate for D-adaptation (default 1e-6). Rarely needs changing. |
1e-06
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
False
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
Source code in pytorch_optimizer/optimizer/dadapt.py
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 |
|
DiffGrad
Bases: Optimizer
, BaseOptimizer
An Optimization Method for Convolutional Neural Networks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. |
(0.9, 0.999)
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
True
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
rectify |
bool
|
bool. perform the rectified update similar to RAdam. |
False
|
n_sma_threshold |
int
|
int. (recommended is 5). |
5
|
degenerated_to_sgd |
bool
|
bool. degenerated to SGD. |
True
|
ams_bound |
bool
|
bool. whether to use the AMSBound variant. |
False
|
r |
float
|
float. EMA factor. between 0.9 ~ 0.99 is preferred. |
0.95
|
adanorm |
bool
|
bool. whether to use the AdaNorm variant. |
False
|
adam_debias |
bool
|
bool. Only correct the denominator to avoid inflating step sizes early in training. |
False
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-08
|
Source code in pytorch_optimizer/optimizer/diffgrad.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
DynamicLossScaler
Dynamically adjusts the loss scaling factor.
Dynamic loss scalers are important in mixed-precision training.
They help us avoid underflows and overflows in low-precision gradients.
See here for information:
<https://docs.nvidia.com/deeplearning/performance/mixed-precision-training/index.html#lossscaling>
Shamelessly stolen and adapted from FairSeq.
<https://github.com/pytorch/fairseq/blob/main/fairseq/optim/fp16_optimizer.py>
Reference : 'https://github.com/facebookresearch/ParlAI/blob/main/parlai/utils/fp16.py'
Parameters:
Name | Type | Description | Default |
---|---|---|---|
init_scale |
float
|
Initial loss scale. |
2.0 ** 15
|
scale_factor |
float
|
Factor by which to increase or decrease loss scale. |
2.0
|
scale_window |
int
|
If we do not experience overflow in scale_window iterations, loss scale will increase by scale_factor. |
2000
|
tolerance |
float
|
Pct of iterations that have overflowed after which we must decrease the loss scale. |
0.0
|
threshold |
Optional[float]
|
If not None, loss scale will decrease below this threshold. |
None
|
Source code in pytorch_optimizer/optimizer/fp16.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|
decrease_loss_scale()
Decrease the loss scale by self.scale_factor.
NOTE: the loss_scale will not go below self.threshold
.
Source code in pytorch_optimizer/optimizer/fp16.py
83 84 85 86 87 88 89 90 |
|
update_scale(overflow)
Update the loss scale.
If overflow exceeds our tolerance, we decrease the loss scale.
If the number of iterations since the last overflow exceeds the scale window, we increase the loss scale.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
overflow |
bool
|
bool. adjust scales to prevent overflow. |
required |
Source code in pytorch_optimizer/optimizer/fp16.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
|
SafeFP16Optimizer
Bases: Optimizer
Safe FP16 Optimizer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
optimizer |
OPTIMIZER
|
OPTIMIZER. |
required |
aggregate_g_norms |
bool
|
bool. aggregate_g_norms. |
False
|
min_loss_scale |
float
|
float. min_loss_scale. |
2 ** -5
|
Source code in pytorch_optimizer/optimizer/fp16.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
|
loss_scale: float
property
Convenience function which TorchAgent calls to get current scale value.
backward(loss, update_main_grads=False)
Compute the sum of gradients of the given tensor w.r.t. graph leaves.
Compared to :func:`fairseq.optim.FairseqOptimizer.backward`, this function
additionally dynamically scales the loss to avoid gradient underflow.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
loss |
float. loss. |
required | |
update_main_grads |
bool
|
bool. update main gradient. |
False
|
Source code in pytorch_optimizer/optimizer/fp16.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
clip_main_grads(max_norm)
Clip gradient norm and updates dynamic loss scaler.
Source code in pytorch_optimizer/optimizer/fp16.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
|
get_lr()
Get learning rate.
Source code in pytorch_optimizer/optimizer/fp16.py
278 279 280 |
|
load_state_dict(state_dict)
Load an optimizer state dict.
In general, we should prefer the configuration of the existing optimizer instance
(e.g., learning rate) over that found in the state_dict. This allows us to
resume training from a checkpoint using a new set of optimizer args.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state_dict |
Dict
|
Dict. state_dict. |
required |
Source code in pytorch_optimizer/optimizer/fp16.py
168 169 170 171 172 173 174 175 176 177 178 179 |
|
multiply_grads(c)
Multiply grads by a constant c.
Source code in pytorch_optimizer/optimizer/fp16.py
219 220 221 222 223 224 225 |
|
set_lr(lr)
Set learning rate.
Source code in pytorch_optimizer/optimizer/fp16.py
282 283 284 |
|
state_dict()
Return the optimizer state dict.
Source code in pytorch_optimizer/optimizer/fp16.py
161 162 163 164 165 166 |
|
step(closure=None)
Perform a single optimization step.
Source code in pytorch_optimizer/optimizer/fp16.py
259 260 261 262 263 264 265 266 267 268 |
|
sync_fp16_grads_to_fp32(multiply_grads=1.0)
Sync fp16 to fp32 gradients.
Source code in pytorch_optimizer/optimizer/fp16.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
|
zero_grad()
Clear the gradients of all optimized parameters.
Source code in pytorch_optimizer/optimizer/fp16.py
270 271 272 273 274 275 276 |
|
Fromage
Bases: Optimizer
, BaseOptimizer
On the distance between two neural networks and the stability of learning.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.01
|
p_bound |
Optional[float]
|
Optional[float]. Restricts the optimisation to a bounded set. A value of 2.0 restricts parameter norms to lie within 2x their initial norms. This regularises the model class. |
None
|
Source code in pytorch_optimizer/optimizer/fromage.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
GaLoreProjector
Memory-Efficient LLM Training by Gradient Low-Rank Projection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rank |
int
|
int. low rank to project. |
128
|
update_proj_gap |
int
|
int. num steps to update the projection. |
50
|
scale |
float
|
float. scale factor. |
1.0
|
projection_type |
PROJECTION_TYPE
|
PROJECTION_TYPE. type of projection. 'std', 'reverse_std', 'right', 'left', 'full' are supported. |
'std'
|
Source code in pytorch_optimizer/optimizer/galore.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
|
centralize_gradient(x, gc_conv_only=False)
Gradient Centralization (GC).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
Tensor
|
torch.Tensor. gradient. |
required |
gc_conv_only |
bool
|
bool. 'False' for both conv & fc layers. |
False
|
Source code in pytorch_optimizer/optimizer/gc.py
4 5 6 7 8 9 10 11 12 |
|
Gravity
Bases: Optimizer
, BaseOptimizer
a Kinematic Approach on Optimization in Deep Learning.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.01
|
alpha |
float
|
float. alpha controls the V initialization. |
0.01
|
beta |
float
|
float. beta will be used to compute running average of V. |
0.9
|
Source code in pytorch_optimizer/optimizer/gravity.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
GSAM
Bases: Optimizer
, BaseOptimizer
Surrogate Gap Guided Sharpness-Aware Minimization.
Example:
Here's an example::
model = YourModel()
base_optimizer = AdamP(model.parameters())
lr_scheduler = LinearScheduler(base_optimizer, t_max=num_total_steps)
rho_scheduler = ProportionScheduler(lr_scheduler, max_lr=max_lr)
optimizer = GSAM(model.parameters(), base_optimizer, model, rho_scheduler)
def loss_fn(predictions, targets):
return F.cross_entropy(predictions, targets)
for inputs, targets in data:
optimizer.set_closure(loss_fn, inputs, targets)
predictions, loss = optimizer.step()
lr_scheduler.step()
optimizer.update_rho_t()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
base_optimizer |
OPTIMIZER
|
Optimizer. base optimizer. |
required |
model |
Module
|
nn.Module. model. |
required |
alpha |
float
|
float. rho alpha. |
0.4
|
rho_scheduler |
rho scheduler. |
required | |
adaptive |
bool
|
bool. element-wise Adaptive SAM. |
False
|
perturb_eps |
float
|
float. epsilon for perturbation. |
1e-12
|
kwargs |
Dict. parameters for optimizer. |
{}
|
Source code in pytorch_optimizer/optimizer/sam.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
|
set_closure(loss_fn, inputs, targets, **kwargs)
Set closure.
Create `self.forward_backward_func`, which is a function such that `self.forward_backward_func()`
automatically performs forward and backward passes. This function does not take any arguments,
and the inputs and targets data should be pre-set in the definition of partial-function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
loss_fn |
Module
|
nn.Module. loss function. |
required |
inputs |
Tensor
|
torch.Tensor. inputs. |
required |
targets |
Tensor
|
torch.Tensor. targets. |
required |
Source code in pytorch_optimizer/optimizer/sam.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
|
Lamb
Bases: Optimizer
, BaseOptimizer
Large Batch Optimization for Deep Learning.
This Lamb implementation is based on the paper v3, which does not use de-biasing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. |
(0.9, 0.999)
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
True
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
rectify |
bool
|
bool. perform the rectified update similar to RAdam. |
False
|
degenerated_to_sgd |
bool
|
bool. degenerated to SGD. |
False
|
n_sma_threshold |
int
|
int. (recommended is 5). |
5
|
grad_averaging |
bool
|
bool. whether apply (1 - beta2) to gradient when calculating running averages of gradient. |
True
|
max_grad_norm |
float
|
float. max gradient norm to clip. |
1.0
|
r |
float
|
float. EMA factor. between 0.9 ~ 0.99 is preferred. |
0.95
|
adanorm |
bool
|
bool. whether to use the AdaNorm variant. |
False
|
adam_debias |
bool
|
bool. Only correct the denominator to avoid inflating step sizes early in training. |
False
|
adam |
bool
|
bool. always use trust ratio = 1, which turns this into Adam. Useful for comparison purposes. |
False
|
pre_norm |
bool
|
bool. perform pre-normalization of all gradients. |
False
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-06
|
Source code in pytorch_optimizer/optimizer/lamb.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
|
LARS
Bases: Optimizer
, BaseOptimizer
Layer-wise Adaptive Rate Scaling (no rate scaling or weight decay for parameters <= 1D).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
momentum |
float
|
float. momentum. |
0.9
|
dampening |
float
|
float. dampening for momentum. |
0.0
|
trust_coefficient |
float
|
float. trust_coefficient. |
0.001
|
nesterov |
bool
|
bool. enables nesterov momentum. |
False
|
Source code in pytorch_optimizer/optimizer/lars.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
Lion
Bases: Optimizer
, BaseOptimizer
Symbolic Discovery of Optimization Algorithms.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.0001
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. |
(0.9, 0.99)
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
True
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
use_gc |
bool
|
bool. use gradient centralization. |
False
|
r |
float
|
float. EMA factor. between 0.9 ~ 0.99 is preferred. |
0.95
|
adanorm |
bool
|
bool. whether to use the AdaNorm variant. |
False
|
Source code in pytorch_optimizer/optimizer/lion.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
|
LOMO
Bases: BaseOptimizer
, Optimizer
Full Parameter Fine-tuning for Large Language Models with Limited Resources.
Reference : https://github.com/OpenLMLab/LOMO/blob/main/src/lomo.py Check the usage from here : https://github.com/OpenLMLab/LOMO/blob/main/src/lomo_trainer.py
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
Module
|
nn.Module. pytorch model. |
required |
lr |
float
|
float. learning rate. |
0.001
|
clip_grad_norm |
Optional[float]
|
Optional[float]. clip grad norm. |
None
|
clip_grad_value |
Optional[float]
|
Optional[float]. clip grad value. |
None
|
Source code in pytorch_optimizer/optimizer/lomo.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
|
Lookahead
Bases: Optimizer
, BaseOptimizer
k steps forward, 1 step back.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
optimizer |
OPTIMIZER
|
OPTIMIZER. base optimizer. |
required |
k |
int
|
int. number of lookahead steps. |
5
|
alpha |
float
|
float. linear interpolation factor. |
0.5
|
pullback_momentum |
str
|
str. change to inner optimizer momentum on interpolation update. |
'none'
|
Source code in pytorch_optimizer/optimizer/lookahead.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
|
backup_and_load_cache()
Backup cache parameters.
Source code in pytorch_optimizer/optimizer/lookahead.py
75 76 77 78 79 80 81 82 |
|
clear_and_load_backup()
Load backup parameters.
Source code in pytorch_optimizer/optimizer/lookahead.py
84 85 86 87 88 89 90 |
|
load_state_dict(state)
Load state.
Source code in pytorch_optimizer/optimizer/lookahead.py
95 96 97 |
|
MADGRAD
Bases: Optimizer
, BaseOptimizer
A Momentumized, Adaptive, Dual Averaged Gradient Method for Stochastic (slightly modified).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-06
|
weight_decay |
float
|
float. weight decay (L2 penalty). MADGRAD optimizer requires less weight decay than other methods, often as little as zero. On sparse problems both weight_decay and momentum should be set to 0. |
0.0
|
weight_decouple |
bool
|
float. Apply AdamW style decoupled weight decay. |
False
|
Source code in pytorch_optimizer/optimizer/madgrad.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
|
MSVAG
Bases: Optimizer
, BaseOptimizer
Dissecting Adam: The Sign, Magnitude and Variance of Stochastic Gradients.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.01
|
beta |
float
|
float. Moving average (momentum) constant (scalar tensor or float value). |
0.9
|
Source code in pytorch_optimizer/optimizer/msvag.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
get_rho(beta_power, beta)
staticmethod
Get rho.
Source code in pytorch_optimizer/optimizer/msvag.py
37 38 39 40 41 42 |
|
Nero
Bases: Optimizer
, BaseOptimizer
Learning by Turning: Neural Architecture Aware Optimisation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.01
|
beta |
float
|
float. coefficients used for computing running averages of gradient and the squared hessian trace. |
0.999
|
constraints |
bool
|
bool. |
True
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-08
|
Source code in pytorch_optimizer/optimizer/nero.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
|
NovoGrad
Bases: Optimizer
, BaseOptimizer
Stochastic Gradient Methods with Layer-wise Adaptive Moments for Training of Deep Networks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. |
(0.95, 0.98)
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
False
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
grad_averaging |
bool
|
bool. multiply ck (1 - momentum). |
False
|
adam_debias |
bool
|
bool. Only correct the denominator to avoid inflating step sizes early in training. |
False
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-08
|
Source code in pytorch_optimizer/optimizer/novograd.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
|
PAdam
Bases: Optimizer
, BaseOptimizer
Closing the Generalization Gap of Adaptive Gradient Methods in Training Deep Neural Networks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.1
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. |
(0.9, 0.999)
|
partial |
float
|
float. partially adaptive parameter. |
0.25
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
False
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-08
|
Source code in pytorch_optimizer/optimizer/padam.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
|
PCGrad
Bases: BaseOptimizer
Gradient Surgery for Multi-Task Learning.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
optimizer |
OPTIMIZER
|
OPTIMIZER: optimizer instance. |
required |
reduction |
str
|
str. reduction method. |
'mean'
|
Source code in pytorch_optimizer/optimizer/pcgrad.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
|
pack_grad(objectives)
Pack the gradient of the parameters of the network for each objective.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
objectives |
Iterable
|
Iterable[nn.Module]. a list of objectives. |
required |
Returns:
Type | Description |
---|---|
Tuple[List[Tensor], List[List[int]], List[Tensor]]
|
torch.Tensor. packed gradients. |
Source code in pytorch_optimizer/optimizer/pcgrad.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
|
pc_backward(objectives)
Calculate the gradient of the parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
objectives |
Iterable[Module]
|
Iterable[nn.Module]. a list of objectives. |
required |
Source code in pytorch_optimizer/optimizer/pcgrad.py
108 109 110 111 112 113 114 115 116 117 118 |
|
project_conflicting(grads, has_grads)
Project conflicting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
grads |
List[Tensor]
|
a list of the gradient of the parameters. |
required |
has_grads |
List[Tensor]
|
a list of mask represent whether the parameter has gradient. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor. merged gradients. |
Source code in pytorch_optimizer/optimizer/pcgrad.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
|
retrieve_grad()
Get the gradient of the parameters of the network with specific objective.
Source code in pytorch_optimizer/optimizer/pcgrad.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
PID
Bases: Optimizer
, BaseOptimizer
A PID Controller Approach for Stochastic Optimization of Deep Networks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
momentum |
float
|
float. momentum factor. |
0.0
|
dampening |
float
|
float. dampening for momentum. |
0.0
|
derivative |
float
|
float. D part of the PID. |
10.0
|
integral |
float
|
float. I part of the PID. |
5.0
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
False
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
Source code in pytorch_optimizer/optimizer/pid.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
PNM
Bases: Optimizer
, BaseOptimizer
Positive-Negative Momentum Optimizers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. |
(0.9, 1.0)
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. use weight_decouple. |
True
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-08
|
Source code in pytorch_optimizer/optimizer/pnm.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
Prodigy
Bases: Optimizer
, BaseOptimizer
An Expeditiously Adaptive Parameter-Free Learner.
Leave LR set to 1 unless you encounter instability.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
1.0
|
betas |
BETAS
|
BETAS. betas. |
(0.9, 0.999)
|
beta3 |
Optional[float]
|
float. coefficients for computing the Prodidy step-size using running averages. If set to None, uses the value of square root of beta2. |
None
|
d0 |
float
|
float. initial D estimate for D-adaptation (default 1e-6). Rarely needs changing. |
1e-06
|
d_coef |
float
|
float. Coefficient in the expression for the estimate of d. |
1.0
|
growth_rate |
float
|
float. prevent the D estimate from growing faster than this multiplicative rate. |
float('inf')
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. use AdamW style weight decay. |
True
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
bias_correction |
bool
|
bool. turn on Adam's bias correction. |
False
|
safeguard_warmup |
bool
|
bool. remove lr from the denominator of D estimate to avoid issues during warm-up stage. |
False
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-08
|
Source code in pytorch_optimizer/optimizer/prodigy.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
|
QHAdam
Bases: Optimizer
, BaseOptimizer
Quasi-hyperbolic momentum and Adam for deep learning.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. |
(0.9, 0.999)
|
nus |
Tuple[float, float]
|
Tuple[float, float]. immediate discount factors used to estimate the gradient and its square. |
(1.0, 1.0)
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
False
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-08
|
Source code in pytorch_optimizer/optimizer/qhadam.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
|
QHM
Bases: Optimizer
, BaseOptimizer
Quasi-hyperbolic momentum (QHM) optimization algorithm.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
momentum |
float
|
float. momentum factor. |
0.0
|
nu |
float
|
float. immediate discount factor used to estimate the gradient and its square. |
1.0
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
False
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
Source code in pytorch_optimizer/optimizer/qhm.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
|
RAdam
Bases: Optimizer
, BaseOptimizer
Rectified Adam.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. |
(0.9, 0.999)
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
True
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
n_sma_threshold |
int
|
int. (recommended is 5). |
5
|
degenerated_to_sgd |
bool
|
float. degenerated to SGD. |
False
|
r |
float
|
float. EMA factor. between 0.9 ~ 0.99 is preferred. |
0.95
|
adanorm |
bool
|
bool. whether to use the AdaNorm variant. |
False
|
adam_debias |
bool
|
bool. Only correct the denominator to avoid inflating step sizes early in training. |
False
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-08
|
Source code in pytorch_optimizer/optimizer/radam.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
Ranger
Bases: Optimizer
, BaseOptimizer
a synergistic optimizer combining RAdam and LookAhead, and now GC in one optimizer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. |
(0.95, 0.999)
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
True
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
n_sma_threshold |
int
|
int. (recommended is 5). |
5
|
degenerated_to_sgd |
bool
|
bool. perform SGD update when variance of gradient is high. |
False
|
use_gc |
bool
|
bool. use Gradient Centralization (both convolution & fc layers). |
True
|
gc_conv_only |
bool
|
bool. use Gradient Centralization (only convolution layer). |
False
|
r |
float
|
float. EMA factor. between 0.9 ~ 0.99 is preferred. |
0.95
|
adanorm |
bool
|
bool. whether to use the AdaNorm variant. |
False
|
adam_debias |
bool
|
bool. Only correct the denominator to avoid inflating step sizes early in training. |
False
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-05
|
Source code in pytorch_optimizer/optimizer/ranger.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
|
Ranger21
Bases: Optimizer
, BaseOptimizer
Integrating the latest deep learning components into a single optimizer.
Here's the components
* uses the AdamW optimizer as its core (or, optionally, MadGrad)
* Adaptive gradient clipping
* Gradient centralization
* Positive-Negative momentum
* Norm loss
* Stable weight decay
* Linear learning rate warm-up
* Explore-exploit learning rate schedule
* Lookahead
* Softplus transformation
* Gradient Normalization
* Corrects the denominator (AdamD).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
num_iterations |
int
|
int. number of the total training steps. Ranger21 optimizer schedules the learning rate with its own recipes. |
required |
lr |
float
|
float. learning rate. |
0.001
|
beta0 |
float
|
float. Manages the amplitude of the noise introduced by positive negative momentum While 0.9 is a recommended default value, you can use -0.5 to minimize the noise. |
0.9
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. |
(0.9, 0.999)
|
use_softplus |
bool
|
bool. use softplus to smooth. |
True
|
beta_softplus |
float
|
float. beta. |
50.0
|
num_warm_up_iterations |
Optional[int]
|
Optional[int]. number of warm-up iterations. Ranger21 performs linear learning rate warmup. |
None
|
num_warm_down_iterations |
Optional[int]
|
Optional[int]. number of warm-down iterations. Ranger21 performs Explore-exploit learning rate scheduling. |
None
|
agc_clipping_value |
float
|
float. |
0.01
|
agc_eps |
float
|
float. eps for AGC |
0.001
|
centralize_gradients |
bool
|
bool. use GC both convolution & fc layers. |
True
|
normalize_gradients |
bool
|
bool. use gradient normalization. |
True
|
lookahead_merge_time |
int
|
int. merge time. |
5
|
lookahead_blending_alpha |
float
|
float. blending alpha. |
0.5
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0001
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
True
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
norm_loss_factor |
float
|
float. norm loss factor. |
0.0001
|
adam_debias |
bool
|
bool. Only correct the denominator to avoid inflating step sizes early in training. |
False
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-08
|
Source code in pytorch_optimizer/optimizer/ranger21.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
|
RotoGrad
Bases: RotateOnly
Implementation of RotoGrad as described in the original paper.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
backbone |
Module
|
nn.Module. shared module. |
required |
heads |
Sequence[Module]
|
List[nn.Module]. task-specific modules. |
required |
latent_size |
int
|
int. size of the shared representation, size of the output of the backbone.z. |
required |
burn_in_period |
int
|
int. When back-propagating towards the shared parameters, each task loss is normalized dividing by its initial value, :math: |
20
|
normalize_losses |
bool
|
bool. Whether to use this normalized losses to back-propagate through the task-specific parameters as well. |
False
|
Source code in pytorch_optimizer/optimizer/rotograd.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
|
SAM
Bases: Optimizer
, BaseOptimizer
Sharpness-Aware Minimization for Efficiently Improving Generalization.
Example:
Here's an example::
model = YourModel()
base_optimizer = Ranger21
optimizer = SAM(model.parameters(), base_optimizer)
for input, output in data:
# first forward-backward pass
loss = loss_function(output, model(input))
loss.backward()
optimizer.first_step(zero_grad=True)
# second forward-backward pass
# make sure to do a full forward pass
loss_function(output, model(input)).backward()
optimizer.second_step(zero_grad=True)
Alternative example with a single closure-based step function::
model = YourModel()
base_optimizer = Ranger21
optimizer = SAM(model.parameters(), base_optimizer)
def closure():
loss = loss_function(output, model(input))
loss.backward()
return loss
for input, output in data:
loss = loss_function(output, model(input))
loss.backward()
optimizer.step(closure)
optimizer.zero_grad()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
base_optimizer |
OPTIMIZER
|
Optimizer. base optimizer. |
required |
rho |
float
|
float. size of the neighborhood for computing the max loss. |
0.05
|
adaptive |
bool
|
bool. element-wise Adaptive SAM. |
False
|
kwargs |
Dict. parameters for optimizer. |
{}
|
Source code in pytorch_optimizer/optimizer/sam.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
|
AccSGD
Bases: Optimizer
, BaseOptimizer
Accelerating Stochastic Gradient Descent For Least Squares Regression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
kappa |
float
|
float. ratio of long to short step. |
1000.0
|
xi |
float
|
float. statistical advantage parameter. |
10.0
|
constant |
float
|
float. any small constant under 1. |
0.7
|
weight_decay |
float
|
float. weight decay. |
0.0
|
Source code in pytorch_optimizer/optimizer/sgd.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
SGDW
Bases: Optimizer
, BaseOptimizer
Decoupled Weight Decay Regularization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.0001
|
momentum |
float
|
float. momentum factor. |
0.0
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
True
|
dampening |
float
|
float. dampening for momentum. |
0.0
|
nesterov |
bool
|
bool. enables Nesterov momentum |
False
|
Source code in pytorch_optimizer/optimizer/sgd.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
|
ASGD
Bases: Optimizer
, BaseOptimizer
Adaptive SGD with estimation of the local smoothness (curvature).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.01
|
amplifier |
float
|
float. amplifier. |
0.02
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
True
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
theta |
float
|
float. theta. |
1.0
|
dampening |
float
|
float. dampening for momentum. |
1.0
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-05
|
Source code in pytorch_optimizer/optimizer/sgd.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
|
get_norms_by_group(group, device)
staticmethod
Get parameter & gradient norm by group.
Source code in pytorch_optimizer/optimizer/sgd.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
|
SignSGD
Bases: Optimizer
, BaseOptimizer
Compressed Optimisation for Non-Convex Problems.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
momentum |
float
|
float. momentum factor (0.0 = SignSGD, >0 = Signum). |
0.9
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
True
|
Source code in pytorch_optimizer/optimizer/sgd.py
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
|
SGDP
Bases: Optimizer
, BaseOptimizer
SGD + Slowing Down the Slowdown for Momentum Optimizers on Scale-invariant Weights.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
momentum |
float
|
float. momentum factor. |
0.0
|
dampening |
float
|
float. dampening for momentum. |
0.0
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
True
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
delta |
float
|
float. threshold that determines whether a set of parameters is scale invariant or not. |
0.1
|
wd_ratio |
float
|
float. relative weight decay applied on scale-invariant parameters compared to that applied on scale-variant parameters. |
0.1
|
nesterov |
bool
|
bool. enables nesterov momentum. |
False
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-08
|
Source code in pytorch_optimizer/optimizer/sgdp.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
Shampoo
Bases: Optimizer
, BaseOptimizer
Preconditioned Stochastic Tensor Optimization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
momentum |
float
|
float. momentum. |
0.0
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
False
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
preconditioning_compute_steps |
int
|
int. performance tuning params for controlling memory and compute requirements. How often to compute pre-conditioner. |
1
|
matrix_eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-06
|
Source code in pytorch_optimizer/optimizer/shampoo.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
ScalableShampoo
Bases: Optimizer
, BaseOptimizer
Scalable Preconditioned Stochastic Tensor Optimization.
This version of Scalable Shampoo Optimizer aims for a single GPU environment, not for a distributed environment
or XLA devices. So, the original intention is to compute pre-conditioners asynchronously on the distributed
CPUs, but this implementation calculates them which takes 99% of the optimization time on a GPU synchronously.
Still, it is much faster than the previous Shampoo Optimizer because using coupled Newton iteration when
computing G^{-1/p} matrices while the previous one uses SVD which is really slow.
Also, this implementation offers
1. lots of plug-ins (e.g. gradient grafting, type of pre-conditioning, etc)
2. not-yet implemented features in the official Pytorch code.
3. readable, organized, clean code.
Reference : https://github.com/google-research/google-research/blob/master/scalable_shampoo/pytorch/shampoo.py.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
betas |
BETAS
|
BETAS. beta1, beta2. |
(0.9, 0.999)
|
moving_average_for_momentum |
bool
|
bool. perform moving_average for momentum (beta1). |
False
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
decoupled_weight_decay |
bool
|
bool. use decoupled weight_decay. |
False
|
decoupled_learning_rate |
bool
|
bool. use decoupled lr, otherwise couple it w/ preconditioned gradient. |
True
|
inverse_exponent_override |
int
|
int. fixed exponent for pre-conditioner, if > 0. |
0
|
start_preconditioning_step |
int
|
int. |
25
|
preconditioning_compute_steps |
int
|
int. performance tuning params for controlling memory and compute requirements. How often to compute pre-conditioner. Ideally, 1 is the best. However, the current implementation doesn't work on the distributed environment (there are no statistics & pre-conditioners sync among replicas), compute on the GPU (not CPU) and the precision is fp32 (not fp64). Also, followed by the paper, |
1000
|
statistics_compute_steps |
int
|
int. How often to compute statistics. usually set to 1 (or 10). |
1
|
block_size |
int
|
int. Block size for large layers (if > 0). Block size = 1 ==> AdaGrad (Don't do this, extremely inefficient!) Block size should be as large as feasible under memory/time constraints. |
512
|
skip_preconditioning_rank_lt |
int
|
int. Skips preconditioning for parameters with rank less than this value. |
1
|
no_preconditioning_for_layers_with_dim_gt |
int
|
int. avoid preconditioning large layers to reduce overall memory. |
8192
|
shape_interpretation |
bool
|
bool. Automatic shape interpretation (for eg: [4, 3, 1024, 512] would result in 12 x [1024, 512] L and R statistics. Disabled by default which results in Shampoo constructing statistics [4, 4], [3, 3], [1024, 1024], [512, 512]. |
True
|
graft_type |
int
|
int. type of grafting (SGD or AdaGrad or RMSProp or SQRT_N or None). |
SGD
|
pre_conditioner_type |
int
|
int. type of pre-conditioner. |
ALL
|
nesterov |
bool
|
bool. Nesterov momentum. |
True
|
diagonal_eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-10
|
matrix_eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-06
|
use_svd |
bool
|
bool. use SVD instead of Schur-Newton method to calculate M^{-1/p}. Theoretically, Schur-Newton method is faster than SVD method. However, the inefficiency of the loop code and proper svd kernel, SVD is much faster in some cases (usually in case of small models). see https://github.com/kozistr/pytorch_optimizer/pull/103 |
False
|
Source code in pytorch_optimizer/optimizer/shampoo.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
|
SM3
Bases: Optimizer
, BaseOptimizer
Memory-Efficient Adaptive Optimization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.1
|
momentum |
float
|
float. coefficient used to scale prior updates before adding. This drastically increases memory usage if |
0.0
|
beta |
float
|
float. coefficient used for exponential moving averages. |
0.0
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-30
|
Source code in pytorch_optimizer/optimizer/sm3.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
|
SophiaH
Bases: Optimizer
, BaseOptimizer
Second-order Clipped Stochastic Optimization.
Requires `loss.backward(create_graph=True)` in order to calculate hessians.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.06
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. |
(0.96, 0.99)
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
True
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
p |
float
|
float. clip effective (applied) gradient (p). |
0.01
|
update_period |
int
|
int. number of steps after which to apply hessian approximation. |
10
|
num_samples |
int
|
int. times to sample |
1
|
hessian_distribution |
HUTCHINSON_G
|
HUTCHINSON_G. type of distribution to initialize hessian. |
'gaussian'
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-12
|
Source code in pytorch_optimizer/optimizer/sophia.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
SRMM
Bases: Optimizer
, BaseOptimizer
Stochastic regularized majorization-minimization with weakly convex and multi-convex surrogates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.01
|
beta |
float
|
float. adaptivity weight. |
0.5
|
memory_length |
Optional[int]
|
Optional[int]. internal memory length for moving average. None for no refreshing. |
100
|
Source code in pytorch_optimizer/optimizer/srmm.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
|
SWATS
Bases: Optimizer
, BaseOptimizer
Improving Generalization Performance by Switching from Adam to SGD.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. |
(0.9, 0.999)
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
False
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
ams_bound |
bool
|
bool. whether to use the ams_bound variant of this algorithm from the paper. |
False
|
nesterov |
bool
|
bool. enables Nesterov momentum. |
False
|
r |
float
|
float. EMA factor. between 0.9 ~ 0.99 is preferred. |
0.95
|
adanorm |
bool
|
bool. whether to use the AdaNorm variant. |
False
|
adam_debias |
bool
|
bool. Only correct the denominator to avoid inflating step sizes early in training. |
False
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
1e-06
|
Source code in pytorch_optimizer/optimizer/swats.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
Tiger
Bases: Optimizer
, BaseOptimizer
A Tight-fisted Optimizer, an optimizer that is extremely budget-conscious.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.001
|
beta |
float
|
float. coefficients used for computing running averages of gradient and the squared hessian trace. |
0.965
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.01
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
True
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
Source code in pytorch_optimizer/optimizer/tiger.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|
WSAM
Bases: Optimizer
, BaseOptimizer
Sharpness-Aware Minimization Revisited: Weighted Sharpness as a Regularization Term.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
Union[Module, DistributedDataParallel]
|
Union[torch.nn.Module, torch.nn.DataParallel]. the model instance. DDP model is recommended to make |
required |
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
base_optimizer |
OPTIMIZER
|
Optimizer. base optimizer. |
required |
rho |
float
|
float. size of the neighborhood for computing the max loss. |
0.05
|
gamma |
float
|
float. weighted factor gamma / (1 - gamma) of the sharpness term. 0.8 ~ 0.95 is the optimal. |
0.9
|
adaptive |
bool
|
bool. element-wise adaptive SAM. |
False
|
decouple |
bool
|
bool. whether to perform a decoupled sharpness regularization. |
True
|
max_norm |
Optional[float]
|
Optional[float]. max norm of the gradients. |
None
|
eps |
float
|
float. term added to the denominator of WSAM to improve numerical stability. |
1e-12
|
kwargs |
Dict. parameters for optimizer. |
{}
|
Source code in pytorch_optimizer/optimizer/sam.py
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 |
|
Yogi
Bases: Optimizer
, BaseOptimizer
Decoupled Weight Decay Regularization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PARAMETERS
|
PARAMETERS. iterable of parameters to optimize or dicts defining parameter groups. |
required |
lr |
float
|
float. learning rate. |
0.01
|
betas |
BETAS
|
BETAS. coefficients used for computing running averages of gradient and the squared hessian trace. |
(0.9, 0.999)
|
initial_accumulator |
float
|
float. initial values for first and second moments. |
1e-06
|
weight_decay |
float
|
float. weight decay (L2 penalty). |
0.0
|
weight_decouple |
bool
|
bool. the optimizer uses decoupled weight decay as in AdamW. |
True
|
fixed_decay |
bool
|
bool. fix weight decay. |
False
|
r |
float
|
float. EMA factor. between 0.9 ~ 0.99 is preferred. |
0.95
|
adanorm |
bool
|
bool. whether to use the AdaNorm variant. |
False
|
adam_debias |
bool
|
bool. Only correct the denominator to avoid inflating step sizes early in training. |
False
|
eps |
float
|
float. term added to the denominator to improve numerical stability. |
0.001
|
Source code in pytorch_optimizer/optimizer/yogi.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
|