MoMo
Pytorch implementation of MoMo methods. Adaptive learning rates for SGD with momentum (SGD-M) and Adam.
Installation
You can install the package with
pip install momo-opt
Usage
Import the optimizers in Python with
from momo import Momo
opt = Momo(model.parameters(), lr=1)
or
from momo import MomoAdam
opt = MomoAdam(model.parameters(), lr=1e-2)
Note that Momo needs access to the value of the batch loss.
In the .step() method, you need to pass either
- the loss tensor (when backward has already been done) to the argument
loss - or a callable
closureto the argumentclosurethat computes gradients and returns the loss.
For example:
def compute_loss(output, labels):
loss = criterion(output, labels)
loss.backward()
return loss
# in each training step, use:
closure = lambda: compute_loss(output,labels)
opt.step(closure=closure)
For more details, see a full example script.
Examples
ResNet110 for CIFAR100
ResNet20 for CIFAR10
Recommendations
In general, if you expect SGD-M to work well on your task, then use Momo. If you expect Adam to work well on your problem, then use MomoAdam.
- The option
lrandweight_decayare the same as in standard optimizers. As Momo and MomoAdam automatically adapt the learning rate, you should get good preformance without heavy tuning oflrand setting a schedule. Settinglrconstant should work fine. For Momo, our experiments work well withlr=1, for MomoAdamlr=1e-2(or slightly smaller) should work well.
One of the main goals of Momo optimizers is to reduce the tuning effort for the learning-rate schedule and get good performance for a wide range of learning rates.
-
For Momo, the argument
betarefers to the momentum parameter. The default isbeta=0.9. For MomoAdam,(beta1,beta2)have the same role as in Adam. -
The option
lbrefers to a lower bound of your loss function. In many cases,lb=0will be a good enough estimate. If your loss converges to a large positive number (and you roughly know the value), then setlbto this value (or slightly smaller). -
If you can not estimate a lower bound before training, use the option
use_fstar=True. This will activate an online estimation of the lower bound.
Release files for momo-opt 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| momo-opt-0.1.0.tar.gz | 7.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| momo_opt-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.6 kB
Release files / momo-opt-0.1.0.tar.gz
| Download URL | momo-opt-0.1.0.tar.gz |
|---|---|
| Size | 7.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4c4e9336652d68d0cad4dfddbc8f7a38acaa9e4e6fd8e83262294d547f737352
|
|
BLAKE2b-256 checksum How to use checksums |
ee0923651f542e8ac27e2ae63aa7b38365ff1d6b289b39254ada4c58f39e0e57
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Release files / momo_opt-0.1.0-py3-none-any.whl
| Download URL | momo_opt-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
90648b8189bfc34cf183d8f2f286baa78c2ca1f0541ef332d3ff13cde77728c1
|
|
BLAKE2b-256 checksum How to use checksums |
f3f604626a49f15cb3608f02ab84bcebdd7ca647f0b92fef7c2c5fe6c57eb4cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|