← Open Source
google-research

sam

google-research/sam on GitHub: Python, Model Development, Training toolkits.

Model DevelopmentTraining toolkitsPython
Open on GitHub
Momentum
+0stars in 24 hours0.0%
647
Stars
78
Forks
+0
This week
1
Contributors
Created 2020-12-04 · Updated 2026-09-28 · #15556 today
Top developers
PForet

google-research/sam is ranked 15,556 with 647 stars.

Same-category comparison

google-research/sam is ranked 15,556 among these 8 peers; daniilrobnikov/vits2 is ranked 15,553.

Same-category comparison
NameRankMetrics
maum-ai/faceshifter15,538
Language:
Python
Stars:
648
Forks:
118
Description:
Unofficial PyTorch Implementation for FaceShifter (https://arxiv.org/abs/1912.13457).
HazyResearch/legalbench15,545
Language:
Python
Stars:
647
Forks:
97
Description:
An open science effort to benchmark legal reasoning in foundation models.
YuliangXiu/MobilePose15,550
Language:
Jupyter Notebook
Stars:
647
Forks:
149
Description:
Light-weight Single Person Pose Estimator.
daniilrobnikov/vits215,553
Language:
Jupyter Notebook
Stars:
647
Forks:
74
Description:
VITS2: Improving Quality and Efficiency of Single-Stage Text-to-Speech with Adversarial Learning and Architecture Design.
lucidrains/memorizing-transformers-pytorch15,559
Language:
Python
Stars:
647
Forks:
49
Description:
Implementation of Memorizing Transformers (ICLR 2022), attention net augmented with indexing and retrieval of memories using approximate nearest neighbors, in Pytorch.
nekhtiari/image-similarity-measures15,562
Language:
Python
Stars:
647
Forks:
70
Description:
:chart_with_upwards_trend: Implementation of eight evaluation metrics to access the similarity between two images. The eight metrics are as follows: RMSE, PSNR, SSIM, ISSM, FSIM, SRE, SAM, and UIQ.
suragnair/seqGAN15,563
Language:
Python
Stars:
647
Forks:
146
Description:
A simplified PyTorch implementation of "SeqGAN: Sequence Generative Adversarial Nets with Policy Gradient.". (Yu, Lantao, et al.).
w86763777/pytorch-ddpm15,564
Language:
Python
Stars:
647
Forks:
75
Description:
Unofficial PyTorch implementation of Denoising Diffusion Probabilistic Models.
Key parameters and specifications
Key parameters and specifications
ParameterValue
LanguagePython
CategoryModel Development
SubcategoryTraining toolkits
Stars647
Forks78
Contributors1
Created date2020-12-04
Updated date2026-09-28
Stars in 1 day0
Stars in 7 days0
Rank15,556
Previous rank15,365
Rank change-191
7-day stars rank15,052
Previous 7-day stars rank15,056
7-day stars rank change4
Total stars rank15,829
Previous total stars rank15,801
Total stars rank change-28
CountryUSA
README summary

SAM: Sharpness-Aware Minimization for Efficiently Improving Generalization by Pierre Foret, Ariel Kleiner, Hossein Mobahi and Behnam Neyshabur. SAM in a few words **Abstract**: In today's heavily overparameterized models, the value of the training loss provides few guarantees on model generalization ability. Indeed, optimizing only the training loss value, as is commonly done, can easily lead to suboptimal model quality. In particular, our procedure, Sharpness-Aware Minimization (SAM), seeks parameters that lie in neighborhoods having uniformly low loss; this formulation

results in a min-max optimization problem on which gradient descent can be performed efficiently. We present empirical results showing that SAM improves model generalization across a variety of benchmark datasets (e. , CIFAR-{10, 100}, ImageNet, finetuning tasks) and models, yielding novel state-of-the-art performance for several. Additionally, we find that SAM natively provides robustness to label noise on par with that provided by state-of-the-art procedures that specifically target learning with noisy labels. Each point

is a different dataset / model / data augmentation | A sharp minimum to which a ResNet trained with SGD converged | A wide minimum to which the same ResNet trained with SAM converged. | About this repo This code allows the user to replicate most of the experiments of the paper, including: Training from scratch Wideresnets and Pyramidnets (with shake shake / shake drop) on CIFAR10/CIFAR100/SVHN/Fashion MNIST, with or without SAM, with or without cutout and AutoAugment. Training Resnets and Efficientnet on

Imagenet, with or without SAM or RandAugment. Finetuning Efficientnet from checkpoints trained on Imagenet/JFT on imagenet. How to train from scratch Once the repo is cloned, experiments can be launched using sam. py: Note that our code uses all available GPUs/TPUs for training. To see a detailed list of all available flags, run python3 -m sam. Output Training curves can be loaded using TensorBoard. TensorBoard events will be saved in the output_dir, and their path will contain

the learning_rate, the weight_decay, rho and the random_seed. 1% (ckpt) | | || | | | AutoAugment (AA) | 77. 3% (ckpt) || | | RandAugment (RA) | | | | | | 83. 4% (ckpt) | We report in this table the scores as found here. If you use these checkpoints with another codebase, you might obtain some slightly different scores based on the type of accelerator you use and your data processing pipeline (resizing algorithm in particular). Advprop requires some slight modification of the input pipeline. Please refer to the README of

the official tensorflow efficientnet implementation to see which paper should be cited for which checkpoint. Once the checkpoint is downloaded and uncompressed, it can be finetuned on any of the datasets: Bibtex **This is not an official Google product.

Frequently asked questions

How many stars and forks are recorded?

google-research/sam has 647 stars and 78 forks.

What is the repository rank?

google-research/sam is ranked 15,556.

What language and category are recorded?

google-research/sam has 647 stars, uses Python and belongs to Model Development.

Which repository is closest in rank?

google-research/sam is compared with daniilrobnikov/vits2, ranked 15,553 with 647 stars.

README

SAM: Sharpness-Aware Minimization for Efficiently Improving Generalization

by Pierre Foret, Ariel Kleiner, Hossein Mobahi and Behnam Neyshabur.

SAM in a few words

Abstract: In today's heavily overparameterized models, the value of the training loss provides few guarantees on model generalization ability. Indeed, optimizing only the training loss value, as is commonly done, can easily lead to suboptimal model quality. Motivated by the connection between geometry of the loss landscape and generalization---including a generalization bound that we prove here---we introduce a novel, effective procedure for instead simultaneously minimizing loss value and loss sharpness. In particular, our procedure, Sharpness-Aware Minimization (SAM), seeks parameters that lie in neighborhoods having uniformly low loss; this formulation results in a min-max optimization problem on which gradient descent can be performed efficiently. We present empirical results showing that SAM improves model generalization across a variety of benchmark datasets (e.g., CIFAR-{10, 100}, ImageNet, finetuning tasks) and models, yielding novel state-of-the-art performance for several. Additionally, we find that SAM natively provides robustness to label noise on par with that provided by state-of-the-art procedures that specifically target learning with noisy labels.

Error rate reduction obtained by switching to SAM. Each point is a different dataset / model / data augmentation A sharp minimum to which a ResNet trained with SGD converged A wide minimum to which the same ResNet trained with SAM converged.

About this repo

This code allows the user to replicate most of the experiments of the paper, including:

  • Training from scratch Wideresnets and Pyramidnets (with shake shake / shake drop) on CIFAR10/CIFAR100/SVHN/Fashion MNIST, with or without SAM, with or without cutout and AutoAugment.
  • Training Resnets and Efficientnet on Imagenet, with or without SAM or RandAugment.
  • Finetuning Efficientnet from checkpoints trained on Imagenet/JFT on imagenet.

How to train from scratch

Once the repo is cloned, experiments can be launched using sam.sam_jax.train.py:

python3 -m sam.sam_jax.train --dataset cifar10 --model_name WideResnet28x10 \
--output_dir /tmp/my_experiment --image_level_augmentations autoaugment \
--num_epochs 1800 --sam_rho 0.05

Note that our code uses all available GPUs/TPUs for training.

To see a detailed list of all available flags, run python3 -m sam.sam_jax.train --help.

Output

Training curves can be loaded using TensorBoard. TensorBoard events will be saved in the output_dir, and their path will contain the learning_rate, the weight_decay, rho and the random_seed.

Finetuning EfficientNet:

We provide a FLAX checkpoint compatible with our implementation for all checkpoints available on official tensorflow efficientnet implementation:

B0 B1 B2 B3 B4 B5 B6 B7 B8 L2
Baseline preprocessing 76.7% (ckpt) 78.7% (ckpt) 79.8% (ckpt) 81.1% (ckpt) 82.5% (ckpt) 83.1% (ckpt)
AutoAugment (AA) 77.1% (ckpt) 79.1% (ckpt) 80.1% (ckpt) 81.6% (ckpt) 82.9% (ckpt) 83.6% (ckpt) 84.0% (ckpt) 84.3% (ckpt)
RandAugment (RA) 83.7% (ckpt) 84.7% (ckpt)
AdvProp + AA 77.6% (ckpt) 79.6% (ckpt) 80.5% (ckpt) 81.9% (ckpt) 83.3% (ckpt) 84.3% (ckpt) 84.8% (ckpt) 85.2% (ckpt) 85.5% (ckpt)
NoisyStudent + RA 78.8% (ckpt) 81.5% (ckpt) 82.4% (ckpt) 84.1% (ckpt) 85.3% (ckpt) 86.1% (ckpt) 86.4% (ckpt) 86.9% (ckpt) - 88.4% (ckpt)
  • We report in this table the scores as found here. If you use these checkpoints with another codebase, you might obtain some slightly different scores based on the type of accelerator you use and your data processing pipeline (resizing algorithm in particular).

  • Advprop requires some slight modification of the input pipeline. See here for more details.

  • Please refer to the README of the official tensorflow efficientnet implementation to see which paper should be cited for which checkpoint.

Once the checkpoint is downloaded and uncompressed, it can be finetuned on any of the datasets:

python3 -m sam.sam_jax.train --output_dir /tmp/my_finetuning_experiment \
--dataset imagenet --from_pretrained_checkpoint true \
--efficientnet_checkpoint_path /tmp/path_to_efficientnet_checkpoint_to_finetune \
--learning_rate 0.1 --model_name efficientnet-l2-475 --batch_size 512 \
--num_epochs 10 --gradient_clipping 1.0 --label_smoothing 0.1 --sam_rho 0.1

Bibtex

@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},
}

This is not an official Google product.

Nearby in the ranking
Similar items