SWAG in Optax
This package implements SWAG as an Optax transform to allow usage with JAX.
Installation
Install from pip as:
pip install optax-swag
To install the latest directly from source, run
pip install git+https://github.com/activatedgeek/optax-swag.git
Usage
To start updating the iterate statistics, use chaining as
import optax
from optax_swag import swag
optimizer = optax.chain(
... ## Other optimizer and transform config.
swag(freq, rank) ## Always add as the last transform.
)
The SWAGState object can be accessed from the optimizer state list for downstream usage.
Sampling
A reference code to generate samples from the collected statistics is provided below.
import jax
import jax.numpy as jnp
from optax_swag import sample_swag
swa_opt_state = # Reference to a SWAGState object from the optimizer.
n_samples = 10
rng = jax.random.PRNGKey(42)
rng, *samples_rng = jax.random.split(rng, 1 + n_samples)
swag_sample_params = jax.vmap(sample_swag, in_axes=(0, None))(
jnp.array(samples_rng), swa_opt_state)
The resulting swag_sample_params can now be used for downstream evaluation.
NOTE: Make sure to update non-parameter variables (e.g. BatchNorm running statistics) for each generated sample.
License
Apache 2.0
Metadata
Release files for optax-swag 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| optax-swag-0.1.0.tar.gz | 7.8 kB | Without provenance | Details for optax-swag-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| optax_swag-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for optax_swag-0.1.0-py3-none-any.whl |
Total release size: 16.4 kB
Release files / optax-swag-0.1.0.tar.gz
| Download URL | optax-swag-0.1.0.tar.gz |
|---|---|
| Size | 7.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bf8826a07314c25b917c091e65acf75db09f179658c4fe1cbf0f2625127d9ed5
|
|
BLAKE2b-256 checksum How to use checksums |
31de4fc302bf37918613fbc4242840f9478672c0c8ae4f303d3fb962d0b362dd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.2
|
Release files / optax_swag-0.1.0-py3-none-any.whl
| Download URL | optax_swag-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
399ccc8afd93979765a604e440fa5aa036e956d4f342b17a489c2f643bf2fc30
|
|
BLAKE2b-256 checksum How to use checksums |
9783f15fbd3d7ad164c976b798395cebb8bbd27e5003403fce6adb5230f16bd5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.2
|
Security for optax-swag 0.1.0
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.