Efficient Optimizers
Project description
heavyball
High-performance, extensible, chainable optimizers for PyTorch.
Why heavyball
- Lightning-Fast Training: Batched
foreachoperations deliver significant speedups on large models. - Adaptive & Extensible: Built-in AdamW, RMSprop, Schedule-Free algorithms, and PaLM-inspired schedules.
- Plug-and-Play: Drop-in replacements for
torch.optimwith seamless integration. - Customizable: Chainable API lets you compose optimizers and transforms (MARS correction, cautious updates, orthogonal updates).
- Battle-Tested: Extensive benchmarks and real-world examples included.
Key Features
- Foreach-based optimizers:
ForeachAdamW,ForeachRMSprop,ForeachSFAdamW,Muon,ADOPT,MSAM(Momentum SAM), … - Schedule-Free optimizers with dynamic learning rate adaptation.
- Advanced update rules: MARS correction, cautious updates, PaLM beta2 scheduling.
- Chainable transforms for custom optimization recipes.
- Comprehensive benchmark suite packaged separately as LightBench (
../LightBench). - Detailed documentation and example-driven tutorials.
Quickstart
Install:
pip install heavyball
Basic usage:
import torch
from torch import nn
from heavyball import ForeachAdamW
model = nn.Sequential(
nn.Linear(128, 64), nn.ReLU(), nn.Linear(64, 10)
)
optimizer = ForeachAdamW(model.parameters(), lr=1e-3)
for data, target in dataloader:
optimizer.zero_grad()
output = model(data)
loss = torch.nn.functional.cross_entropy(output, target)
loss.backward()
optimizer.step()
Benchmarks
Reproduce benchmarks with LightBench (install it via
pip install -e ../LightBenchfrom the repo root):python3 -m lightbench.run_all_benchmarks --opt ForeachSOAP --opt LaProp --opt AdamW --opt Muon --opt ForeachCachedNewtonPSGD --opt RMSprop --opt OrthoLaProp --opt ForeachSFAdamW --opt ForeachADOPT --opt LaPropOrtho --opt CachedPSGDKron --opt SignLaProp --opt ForeachSOLP --opt PSGDLRA --opt NewtonPSGDLRA --opt NewtonHybrid2PSGDKron --opt NewtonHybrid2PSGDLRA --opt mars-NewtonHybrid2PSGDLRA --opt MSAMLaProp --opt mars-adaptive-NewtonHybrid2PSGDKron --opt mars-ortho-NewtonHybrid2PSGDKron --opt MuonLaProp --opt mars-unscaled-NewtonHybrid2PSGDKron --opt mars-NewtonHybrid2PSGDKron --opt cautious-AdamW --opt unscaled_cautious-AdamW --opt mars-AdamW --dtype float32 --steps 1000000 --trials 1000 --parallelism 256 --seeds 1 --difficulties trivial --difficulties easy --difficulties medium --difficulties hard --difficulties extreme --difficulties nightmare --timeout 2880
Migrating from HeavyBall 1.x
- Read the detailed 2.0.0 migration notes for an end-to-end checklist, including guidance for restoring legacy behaviour when needed.
- Use
scripts/migrate_optimizer_state.pyto rewrite pre-2.0 optimizer checkpoints:python scripts/migrate_optimizer_state.py path/to/checkpoint.pt heavyball.ForeachAdamW --state-key optimizer
The utility renames legacy state entries, fans them out per parameter view, and injects the HeavyBall metadata block expected by 2.0.0.
Contributing
We welcome contributions! Please check the issue tracker and follow these steps:
- Fork the repo and create a feature branch.
- Install dev dependencies:
pip install -e .[dev]. - Run tests:
pytest. - Submit a pull request.
License
BSD 3-Clause — see the LICENSE file.
Made by the HeavyBall team.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file heavyball-2.3.0.tar.gz.
File metadata
- Download URL: heavyball-2.3.0.tar.gz
- Upload date:
- Size: 89.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43c640f0da22ec2f6e0ff6db91475bf8c763ca98bd1e3723c7876996f3eb7fe2
|
|
| MD5 |
bdb25cb8c910613ec9a9e09eea97e641
|
|
| BLAKE2b-256 |
c6ec69d7da1dcf5df0382874626f09b7736d98e6dc7e3aeefffb6fd31dbd035c
|
Provenance
The following attestation bundles were made for heavyball-2.3.0.tar.gz:
Publisher:
release.yaml on HomebrewML/HeavyBall
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
heavyball-2.3.0.tar.gz -
Subject digest:
43c640f0da22ec2f6e0ff6db91475bf8c763ca98bd1e3723c7876996f3eb7fe2 - Sigstore transparency entry: 1077074099
- Sigstore integration time:
-
Permalink:
HomebrewML/HeavyBall@9d7dd405daeef7671ff87bb6856048c27a5869b7 -
Branch / Tag:
refs/tags/v2.3.0 - Owner: https://github.com/HomebrewML
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@9d7dd405daeef7671ff87bb6856048c27a5869b7 -
Trigger Event:
release
-
Statement type:
File details
Details for the file heavyball-2.3.0-py3-none-any.whl.
File metadata
- Download URL: heavyball-2.3.0-py3-none-any.whl
- Upload date:
- Size: 60.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
031fbed35fe37b0e62f138220787ce9a0b5f3f1f839f3621b301457f506aca23
|
|
| MD5 |
f169bc98b64d617f7fb8be24c684e683
|
|
| BLAKE2b-256 |
3b832ff550ffe433dc337dbd4a300db1e0b939ce881836c821ae0629d8100baa
|
Provenance
The following attestation bundles were made for heavyball-2.3.0-py3-none-any.whl:
Publisher:
release.yaml on HomebrewML/HeavyBall
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
heavyball-2.3.0-py3-none-any.whl -
Subject digest:
031fbed35fe37b0e62f138220787ce9a0b5f3f1f839f3621b301457f506aca23 - Sigstore transparency entry: 1077074142
- Sigstore integration time:
-
Permalink:
HomebrewML/HeavyBall@9d7dd405daeef7671ff87bb6856048c27a5869b7 -
Branch / Tag:
refs/tags/v2.3.0 - Owner: https://github.com/HomebrewML
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@9d7dd405daeef7671ff87bb6856048c27a5869b7 -
Trigger Event:
release
-
Statement type: