Skip to main content

AdamW optimizer for bfloat16 in PyTorch

This is a version of the AdamW optimizer for use in torch that achieves the same results in ViT training tests as training with the weights in float32 with operations in float32 or bfloat16 (autocast). By keeping your weights in bfloat16, you can save approximately half the weights they would normally take up in memory. It uses stochastic rounding and a correction term to achieve this.

There is a small (~10-20%) performance hit depending on your hardware.

To install:

pip install adamw-bf16

To use:

from adamw_bf16 import AdamWBF16

model = model.to(dtype=torch.bfloat16)
optimizer = AdamWBF16(model.parameters(), ...)

# Train your model

This repository was created using code from the following two projects. It was found that insights from both could be combined to match the performance with the model weights stored in float32.

Metadata

Release files for adamw-bf16 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for adamw-bf16 0.0.3
File Size Uploaded Provenance
adamw_bf16-0.0.3.tar.gz 16.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for adamw-bf16 0.0.3
File Interpreter ABI Platform
adamw_bf16-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 33.3 kB

Release files / adamw_bf16-0.0.3.tar.gz

Download URL adamw_bf16-0.0.3.tar.gz
Size 16.4 kB
Tags Source
SHA-256 checksum
How to use checksums
826b046e23ebd34ab1fd0e8700ea4e3f419d0d66e6211b814cf120440796cc0a
BLAKE2b-256 checksum
How to use checksums
2d2f5eb18ee927565eb420583a7b5c95779e196b3e14b958e98a1ee44bfe2b18
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.12

Release files / adamw_bf16-0.0.3-py3-none-any.whl

Download URL adamw_bf16-0.0.3-py3-none-any.whl
Size 16.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6795187b69b92cc962d0b02471173b997e6fb15b9ffc36825e9de3a207bebeec
BLAKE2b-256 checksum
How to use checksums
7c4c195a2835e02f862b6fe4d7067142ce66cde47a45274840c4e1b4b81fcc18
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.12

Security for adamw-bf16 0.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page