# davda54/sam

SAM: Sharpness-Aware Minimization (PyTorch)

Repository: https://github.com/davda54/sam
Canonical: https://ross.abutalabs.com/products/sam
Language: Python
License: MIT
License Family: permissive
Topics: optimizer, pytorch, sam, sharpness-aware
Last push: 2024-02-21T12:34:27+00:00

## Health v2 (maintenance only)
Score: 32/100 (v2, computed 2026-09-03T02:20:16.233290+00:00)
- activity 0, release rhythm 35, longevity 100
- inputs: {"age_days": 2138, "days_push": 924, "days_rel": null, "gap_med": null, "n_releases_24m": 0}
- flags: no_releases
- formula: round(0.45*activity + 0.35*rhythm + 0.20*longevity); archived -> min(score, 10)

## Adoption (not part of the score)
Stars 1980, forks 208 (observed 2026-08-28T04:06:01.658550+00:00)

## What it is
An unofficial PyTorch implementation of Sharpness-Aware Minimization (SAM) and its adaptive variant ASAM, provided as an optimizer wrapper around base optimizers like SGD. It minimizes both loss value and loss sharpness to improve model generalization and robustness to label noise.

## Use cases
- improve generalization of deep neural networks in pytorch
- train models that find flat minima instead of sharp ones
- make training robust to noisy labels
- reproduce SAM paper results on cifar10
- wrap SGD or Adam with sharpness-aware gradient updates

## When to choose
- you train PyTorch models and want better generalization at the cost of ~2x training time
- you need an easy drop-in optimizer wrapper implementing SAM or ASAM
- your dataset suffers from label noise

## When to avoid
- training speed is critical, since SAM requires two forward-backward passes per step
- you use frameworks other than PyTorch
- you need an officially maintained implementation with frequent updates

## Facets
- artifact type: library
- maturity: stable
- function: machine-learning, deep-learning
- domain: machine-learning, deep-learning
- platform: python
- tags: optimizer, pytorch, sharpness-aware-minimization, asam, generalization

## Member repositories
- davda54/sam (main) score 32

## Provenance
- Observed fields: from GitHub, fetched 2026-08-28T04:06:01.658550+00:00.
- Health v2: computed from the inputs above; adoption is never an input.
- Inferred fields (summary, facets, guidance): AI-extracted, prompt v1, taxonomy v1, on 2026-08-30T03:04:00.231569+00:00, confidence not recorded.
  - readme: https://github.com/davda54/sam (fetched 2026-08-28T04:06:01.658550+00:00, sha 7a103d4abecf)
- Data as of 2026-08-30T08:39:29.467469+00:00.
