All Projects → moskomule → sam.pytorch

moskomule / sam.pytorch

Licence: MIT License
A PyTorch implementation of Sharpness-Aware Minimization for Efficiently Improving Generalization

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to sam.pytorch

Sam
SAM: Sharpness-Aware Minimization (PyTorch)
Stars: ✭ 322 (+235.42%)
Mutual labels:  sam, optimizer
falcon
A WordPress cleanup and performance optimization plugin.
Stars: ✭ 17 (-82.29%)
Mutual labels:  optimizer
EAGO.jl
A development environment for robust and global optimization
Stars: ✭ 106 (+10.42%)
Mutual labels:  optimizer
fuc
Frequently used commands in bioinformatics
Stars: ✭ 23 (-76.04%)
Mutual labels:  sam
adamwr
Implements https://arxiv.org/abs/1711.05101 AdamW optimizer, cosine learning rate scheduler and "Cyclical Learning Rates for Training Neural Networks" https://arxiv.org/abs/1506.01186 for PyTorch framework
Stars: ✭ 130 (+35.42%)
Mutual labels:  optimizer
hts-python
pythonic wrapper for htslib
Stars: ✭ 18 (-81.25%)
Mutual labels:  sam
Cleaner
The only storage saving app that actually works! :D
Stars: ✭ 27 (-71.87%)
Mutual labels:  optimizer
pigosat
Go (golang) bindings for Picosat, the satisfiability solver
Stars: ✭ 15 (-84.37%)
Mutual labels:  optimizer
Windows11-Optimization
Community repository, to improve security and performance of Windows 10 and windows 11 with tweaks, commands, scripts, registry keys, configuration, tutorials and more
Stars: ✭ 17 (-82.29%)
Mutual labels:  optimizer
AdaBound-tensorflow
An optimizer that trains as fast as Adam and as good as SGD in Tensorflow
Stars: ✭ 44 (-54.17%)
Mutual labels:  optimizer
ToyDB
A ToyDB (for beginner) based on MIT 6.830 and CMU 15445
Stars: ✭ 25 (-73.96%)
Mutual labels:  optimizer
aws-sam-build-images
AWS SAM build images
Stars: ✭ 21 (-78.12%)
Mutual labels:  sam
postcss-clean
PostCss plugin to minify your CSS with clean-css
Stars: ✭ 41 (-57.29%)
Mutual labels:  optimizer
portfolio-optimizer
A library for portfolio optimization algorithms with python interface.
Stars: ✭ 19 (-80.21%)
Mutual labels:  optimizer
simplesam
Simple pure Python SAM parser and objects for working with SAM records
Stars: ✭ 50 (-47.92%)
Mutual labels:  sam
hts-python
pythonic wrapper for libhts (moved to: https://github.com/quinlan-lab/hts-python)
Stars: ✭ 48 (-50%)
Mutual labels:  sam
ada-hessian
Easy-to-use AdaHessian optimizer (PyTorch)
Stars: ✭ 59 (-38.54%)
Mutual labels:  optimizer
lookahead tensorflow
Lookahead optimizer ("Lookahead Optimizer: k steps forward, 1 step back") for tensorflow
Stars: ✭ 25 (-73.96%)
Mutual labels:  optimizer
rethinking-bnn-optimization
Implementation for the paper "Latent Weights Do Not Exist: Rethinking Binarized Neural Network Optimization"
Stars: ✭ 62 (-35.42%)
Mutual labels:  optimizer
goga
Go evolutionary algorithm is a computer library for developing evolutionary and genetic algorithms to solve optimisation problems with (or not) many constraints and many objectives. Also, a goal is to handle mixed-type representations (reals and integers).
Stars: ✭ 39 (-59.37%)
Mutual labels:  optimizer

sam.pytorch

A PyTorch implementation of Sharpness-Aware Minimization for Efficiently Improving Generalization ( Foret+2020) Paper, Official implementation .

Requirements

  • Python>=3.8
  • PyTorch>=1.7.1

To run the example, you further need

  • homura by pip install -U homura-core==2020.12.0
  • chika by pip install -U chika

Example

python cifar10.py [--optim.name {sam,sgd}] [--model {renst20, wrn28_2}] [--optim.rho 0.05]

Results: Test Accuracy (CIFAR-10)

Model SAM SGD
ResNet-20 93.5 93.2
WRN28-2 95.8 95.4
ResNeXT29 96.4 95.8

SAM needs double forward passes per each update, thus training with SAM is slower than training with SGD. In case of ResNet-20 training, 80 mins vs 50 mins on my environment. Additional options --use_amp --jit_model may slightly accelerates the training.

Usage

SAMSGD can be used as a drop-in replacement of PyTorch optimizers by using a closure as follows. Also, it is compatible with lr_scheduler and has state_dict and load_state_dict. Currently, this implementation does not support multiple parameter groups.

from sam import SAMSGD

optimizer = SAMSGD(model.parameters(), lr=1e-1, rho=0.05)

for input, target in dataset:
    def closure():
        optimizer.zero_grad()
        output = model(input)
        loss = loss_f(output, target)
        loss.backward()
        return loss


    loss = optimizer.step(closure)

Citation

@ARTICLE{2020arXiv201001412F,
    author = {{Foret}, Pierre and {Kleiner}, Ariel and {Mobahi}, Hossein and {Neyshabur}, Behnam},
    title = "{Sharpness-Aware Minimization for Efficiently Improving Generalization}",
    year = 2020,
    eid = {arXiv:2010.01412},
    eprint = {2010.01412},
}

@software{sampytorch
    author = {Ryuichiro Hataya},
    titile = {sam.pytorch},
    url    = {https://github.com/moskomule/sam.pytorch},
    year   = {2020}
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].