Optimizer.optimizer(优化器) 模块¶
ppsci.optimizer.optimizer
¶
SGD
¶
Stochastic Gradient Descent.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
learning_rate |
Union[float, LRScheduler]
|
The learning rate used to update parameter(s). Defaults to 0.001. |
0.001
|
weight_decay |
Optional[Union[float, L1Decay, L2Decay]]
|
Regularization strategy. Defaults to None. |
None
|
grad_clip |
Optional[Union[ClipGradByNorm, ClipGradByValue, ClipGradByGlobalNorm]]
|
Gradient clipping strategy. Defaults to None. |
None
|
Examples:
>>> import ppsci
>>> model = ppsci.arch.MLP(("x",), ("u",), 5, 20)
>>> opt = ppsci.optimizer.SGD(1e-3)(model)
Source code in ppsci/optimizer/optimizer.py
Momentum
¶
Simple Momentum optimizer with velocity state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
learning_rate |
Union[float, LRScheduler]
|
The learning rate used to update parameter(s). |
required |
momentum |
float
|
Momentum factor. |
required |
weight_decay |
Optional[Union[float, L1Decay, L2Decay]]
|
Regularization strategy. Defaults to None. |
None
|
grad_clip |
Optional[Union[ClipGradByNorm, ClipGradByValue, ClipGradByGlobalNorm]]
|
Gradient clipping strategy. Defaults to None. |
None
|
use_nesterov |
bool
|
Whether to use nesterov momentum. Defaults to False. |
False
|
no_weight_decay_name |
Optional[str]
|
List of names of no weight decay parameters split by white space. Defaults to None. |
None
|
Examples:
>>> import ppsci
>>> model = ppsci.arch.MLP(("x",), ("u",), 5, 20)
>>> opt = ppsci.optimizer.Momentum(1e-3, 0.9)(model)
Source code in ppsci/optimizer/optimizer.py
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 |
|
Adam
¶
Adam: A Method for Stochastic Optimization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
learning_rate |
Union[float, LRScheduler]
|
The learning rate used to update parameter(s). Defaults to 0.001. |
0.001
|
beta1 |
float
|
The exponential decay rate for the 1st moment estimates. Defaults to 0.9. |
0.9
|
beta2 |
float
|
The exponential decay rate for the 2nd moment estimates. Defaults to 0.999. |
0.999
|
epsilon |
float
|
A small float value for numerical stability. Defaults to 1e-08. |
1e-08
|
weight_decay |
Optional[Union[float, L1Decay, L2Decay]]
|
Regularization strategy. Defaults to None. |
None
|
grad_clip |
Optional[Union[ClipGradByNorm, ClipGradByValue, ClipGradByGlobalNorm]]
|
Gradient clipping strategy. Defaults to None. |
None
|
lazy_mode |
bool
|
Whether to enable lazy mode for moving-average. Defaults to False. |
False
|
Examples:
>>> import ppsci
>>> model = ppsci.arch.MLP(("x",), ("u",), 5, 20)
>>> opt = ppsci.optimizer.Adam(1e-3)(model)
Source code in ppsci/optimizer/optimizer.py
AdamW
¶
AdamW is implemented based on DECOUPLED WEIGHT DECAY REGULARIZATION.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
learning_rate |
Union[float, LRScheduler]
|
The learning rate used to update parameter(s). Defaults to 0.001. |
0.001
|
beta1 |
float
|
The exponential decay rate for the 1st moment estimates. Defaults to 0.9. |
0.9
|
beta2 |
float
|
The exponential decay rate for the 2nd moment estimates. Defaults to 0.999. |
0.999
|
epsilon |
float
|
A small float value for numerical stability. Defaults to 1e-8. |
1e-08
|
weight_decay |
float
|
Regularization coefficient. Defaults to 0.01. |
0.001
|
grad_clip |
Optional[Union[ClipGradByNorm, ClipGradByValue, ClipGradByGlobalNorm]]
|
Gradient clipping strategy. Defaults to None. |
None
|
no_weight_decay_name |
Optional[str]
|
List of names of no weight decay parameters split by white space. Defaults to None. |
None
|
one_dim_param_no_weight_decay |
bool
|
Apply no weight decay on 1-D parameter(s). Defaults to False. |
False
|
Examples:
>>> import ppsci
>>> model = ppsci.arch.MLP(("x",), ("u",), 5, 20)
>>> opt = ppsci.optimizer.AdamW(1e-3)(model)
Source code in ppsci/optimizer/optimizer.py
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 |
|
RMSProp
¶
Root Mean Squared Propagation (RMSProp) is an unpublished, adaptive learning rate method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
learning_rate |
Union[float, LRScheduler]
|
The learning rate used to update parameter(s) |
required |
rho |
float
|
Factor ρ in equation. Defaults to 0.95. |
0.95
|
epsilon |
float
|
Factor ϵ in equation as a smoothing term. Defaults to 1e-6. |
1e-06
|
momentum |
float
|
β in equation is the momentum term. Defaults to 0.0. |
0.0
|
weight_decay |
Optional[Union[float, L1Decay, L2Decay]]
|
Regularization strategy. Defaults to None. |
None
|
grad_clip |
Optional[Union[ClipGradByNorm, ClipGradByValue, ClipGradByGlobalNorm]]
|
Gradient clipping strategy. Defaults to None. |
None
|
Examples:
>>> import ppsci
>>> model = ppsci.arch.MLP(("x",), ("u",), 5, 20)
>>> opt = ppsci.optimizer.RMSProp(1e-3)(model)
Source code in ppsci/optimizer/optimizer.py
LBFGS
¶
The L-BFGS is a quasi-Newton method for solving an unconstrained optimization problem over a differentiable function. Closely related is the Newton method for minimization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
learning_rate |
float
|
The learning rate used to update parameter(s). Defaults to 1.0. |
1.0
|
max_iter |
int
|
Maximal number of iterations per optimization step. Defaults to 1. |
1
|
max_eval |
Optional[int]
|
Maximal number of function evaluations per optimization step. Defaults to None. |
None
|
tolerance_grad |
float
|
Termination tolerance on first order optimality. Defaults to 1e-07. |
1e-07
|
tolerance_change |
float
|
Termination tolerance on function value/parameter changes. Defaults to 1e-09. |
1e-09
|
history_size |
int
|
Update history size. Defaults to 100. |
100
|
line_search_fn |
Optional[Literal['strong_wolfe']]
|
Either 'strong_wolfe' or None. Defaults to "strong_wolfe". |
'strong_wolfe'
|
Examples:
>>> import ppsci
>>> model = ppsci.arch.MLP(("x",), ("u",), 5, 20)
>>> opt = ppsci.optimizer.LBFGS(1e-3)(model)
Source code in ppsci/optimizer/optimizer.py
OptimizerList
¶
OptimizerList which wrap more than one optimizer. NOTE: LBFGS is not supported yet.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
optimizer_list |
Tuple[Optimizer, ...]
|
Optimizers listed in a tuple. |
required |
Examples:
>>> import ppsci
>>> model1 = ppsci.arch.MLP(("x",), ("u",), 5, 20)
>>> opt1 = ppsci.optimizer.Adam(1e-3)(model1)
>>> model2 = ppsci.arch.MLP(("y",), ("v",), 5, 20)
>>> opt2 = ppsci.optimizer.Adam(1e-3)(model2)
>>> opt = ppsci.optimizer.OptimizerList((opt1, opt2))