-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Support Sophia optimizers (#1170)
- Loading branch information
Showing
7 changed files
with
212 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Better performance optimizers | ||
|
||
This document provides some third-party optimizers supported by MMEngine, which may bring faster convergence speed or higher performance. | ||
|
||
## D-Adaptation | ||
|
||
[D-Adaptation](https://github.com/facebookresearch/dadaptation) provides `DAdaptAdaGrad`, `DAdaptAdam` and `DAdaptSGD` optimziers。 | ||
|
||
```{note} | ||
If you use the optimizer provided by D-Adaptation, you need to upgrade mmengine to `0.6.0`. | ||
``` | ||
|
||
- Installation | ||
|
||
```bash | ||
pip install dadaptation | ||
``` | ||
|
||
- Usage | ||
|
||
Take the `DAdaptAdaGrad` as an example. | ||
|
||
```python | ||
runner = Runner( | ||
model=ResNet18(), | ||
work_dir='./work_dir', | ||
train_dataloader=train_dataloader_cfg, | ||
# To view the input parameters for DAdaptAdaGrad, you can refer to | ||
# https://github.com/facebookresearch/dadaptation/blob/main/dadaptation/dadapt_adagrad.py | ||
optim_wrapper=dict(optimizer=dict(type='DAdaptAdaGrad', lr=0.001, momentum=0.9)), | ||
train_cfg=dict(by_epoch=True, max_epochs=3), | ||
) | ||
runner.train() | ||
``` | ||
|
||
## Lion-Pytorch | ||
|
||
[lion-pytorch](https://github.com/lucidrains/lion-pytorch) provides the `Lion` optimizer。 | ||
|
||
```{note} | ||
If you use the optimizer provided by Lion-Pytorch, you need to upgrade mmengine to `0.6.0`. | ||
``` | ||
|
||
- Installation | ||
|
||
```bash | ||
pip install lion-pytorch | ||
``` | ||
|
||
- Usage | ||
|
||
```python | ||
runner = Runner( | ||
model=ResNet18(), | ||
work_dir='./work_dir', | ||
train_dataloader=train_dataloader_cfg, | ||
# To view the input parameters for Lion, you can refer to | ||
# https://github.com/lucidrains/lion-pytorch/blob/main/lion_pytorch/lion_pytorch.py | ||
optim_wrapper=dict(optimizer=dict(type='Lion', lr=1e-4, weight_decay=1e-2)), | ||
train_cfg=dict(by_epoch=True, max_epochs=3), | ||
) | ||
runner.train() | ||
``` | ||
|
||
## Sophia | ||
|
||
[Sophia](https://github.com/kyegomez/Sophia) provides `Sophia`, `SophiaG`, `DecoupledSophia` and `Sophia2` optimizers. | ||
|
||
```{note} | ||
If you use the optimizer provided by Sophia, you need to upgrade mmengine to `0.7.4`. | ||
``` | ||
|
||
- Installation | ||
|
||
```bash | ||
pip install Sophia-Optimizer | ||
``` | ||
|
||
- Usage | ||
|
||
```python | ||
runner = Runner( | ||
model=ResNet18(), | ||
work_dir='./work_dir', | ||
train_dataloader=train_dataloader_cfg, | ||
# To view the input parameters for SophiaG, you can refer to | ||
# https://github.com/kyegomez/Sophia/blob/main/Sophia/Sophia.py | ||
optim_wrapper=dict(optimizer=dict(type='SophiaG', lr=2e-4, betas=(0.965, 0.99), rho = 0.01, weight_decay=1e-1)), | ||
train_cfg=dict(by_epoch=True, max_epochs=3), | ||
) | ||
runner.train() | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# 性能更优的优化器 | ||
|
||
本文档提供了一些 MMEngine 支持的第三方优化器,它们可能会带来更快的收敛速度或者更高的性能。 | ||
|
||
## D-Adaptation | ||
|
||
[D-Adaptation](https://github.com/facebookresearch/dadaptation) 提供了 `DAdaptAdaGrad`、`DAdaptAdam` 和 `DAdaptSGD` 优化器。 | ||
|
||
```{note} | ||
如使用 D-Adaptation 提供的优化器,需将 mmengine 升级至 `0.6.0`。 | ||
``` | ||
|
||
- 安装 | ||
|
||
```bash | ||
pip install dadaptation | ||
``` | ||
|
||
- 使用 | ||
|
||
以使用 `DAdaptAdaGrad` 为例。 | ||
|
||
```python | ||
runner = Runner( | ||
model=ResNet18(), | ||
work_dir='./work_dir', | ||
train_dataloader=train_dataloader_cfg, | ||
# 如需查看 DAdaptAdaGrad 的输入参数,可查看 | ||
# https://github.com/facebookresearch/dadaptation/blob/main/dadaptation/dadapt_adagrad.py | ||
optim_wrapper=dict(optimizer=dict(type='DAdaptAdaGrad', lr=0.001, momentum=0.9)), | ||
train_cfg=dict(by_epoch=True, max_epochs=3), | ||
) | ||
runner.train() | ||
``` | ||
|
||
## Lion | ||
|
||
[lion-pytorch](https://github.com/lucidrains/lion-pytorch) 提供了 `Lion` 优化器。 | ||
|
||
```{note} | ||
如使用 Lion 提供的优化器,需将 mmengine 升级至 `0.6.0`。 | ||
``` | ||
|
||
- 安装 | ||
|
||
```bash | ||
pip install lion-pytorch | ||
``` | ||
|
||
- 使用 | ||
|
||
```python | ||
runner = Runner( | ||
model=ResNet18(), | ||
work_dir='./work_dir', | ||
train_dataloader=train_dataloader_cfg, | ||
# 如需查看 Lion 的输入参数,可查看 | ||
# https://github.com/lucidrains/lion-pytorch/blob/main/lion_pytorch/lion_pytorch.py | ||
optim_wrapper=dict(optimizer=dict(type='Lion', lr=1e-4, weight_decay=1e-2)), | ||
train_cfg=dict(by_epoch=True, max_epochs=3), | ||
) | ||
runner.train() | ||
``` | ||
|
||
## Sophia | ||
|
||
[Sophia](https://github.com/kyegomez/Sophia) 提供了 `Sophia`、`SophiaG`、`DecoupledSophia` 和 `Sophia2` 优化器。 | ||
|
||
```{note} | ||
如使用 Sophia 提供的优化器,需将 mmengine 升级至 `0.7.4`。 | ||
``` | ||
|
||
- 安装 | ||
|
||
```bash | ||
pip install Sophia-Optimizer | ||
``` | ||
|
||
- 使用 | ||
|
||
```python | ||
runner = Runner( | ||
model=ResNet18(), | ||
work_dir='./work_dir', | ||
train_dataloader=train_dataloader_cfg, | ||
# 如需查看 SophiaG 的输入参数,可查看 | ||
# https://github.com/kyegomez/Sophia/blob/main/Sophia/Sophia.py | ||
optim_wrapper=dict(optimizer=dict(type='SophiaG', lr=2e-4, betas=(0.965, 0.99), rho = 0.01, weight_decay=1e-1)), | ||
train_cfg=dict(by_epoch=True, max_epochs=3), | ||
) | ||
runner.train() | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters