Gradient Agreement Filtering - Pytorch
Implementation of Gradient Agreement Filtering, from Chaubard et al. of Stanford, but done for single machine microbatches, in Pytorch.
The official repository that does filtering for macrobatches across machines is here
Install
$ pip install GAF-microbatch-pytorch
Usage
import torch
# mock network
from torch import nn
net = nn.Sequential(
nn.Linear(512, 256),
nn.SiLU(),
nn.Linear(256, 128)
)
# import the gradient agreement filtering (GAF) wrapper
from GAF_microbatch_pytorch import GAFWrapper
# just wrap your neural net
gaf_net = GAFWrapper(
net,
filter_distance_thres = 0.97
)
# your batch of data
x = torch.randn(16, 1024, 512)
# forward and backwards as usual
out = gaf_net(x)
out.sum().backward()
# gradients should be filtered by set threshold comparing per sample gradients within batch, as in paper
You can supply your own gradient filtering method as a Callable[[Tensor], Tensor] with the filter_gradients_fn kwarg as so
def filtering_fn(grads):
# make your big discovery here
return grads
gaf_net = GAFWrapper(
net = net,
filter_gradients_fn = filtering_fn
)
Todo
- replicate cifar results on single machine
- allow for excluding certain parameters from being filtered
Citations
@inproceedings{Chaubard2024BeyondGA,
title = {Beyond Gradient Averaging in Parallel Optimization: Improved Robustness through Gradient Agreement Filtering},
author = {Francois Chaubard and Duncan Eddy and Mykel J. Kochenderfer},
year = {2024},
url = {https://api.semanticscholar.org/CorpusID:274992650}
}
Metadata
Release files for GAF-microbatch-pytorch 0.0.5
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 |
|---|---|---|---|---|
| gaf_microbatch_pytorch-0.0.5.tar.gz | 142.2 kB | Without provenance | Details for gaf_microbatch_pytorch-0.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gaf_microbatch_pytorch-0.0.5-py3-none-any.whl | Python 3 | none | any | Details for gaf_microbatch_pytorch-0.0.5-py3-none-any.whl |
Total release size: 148.4 kB
Release files / gaf_microbatch_pytorch-0.0.5.tar.gz
| Download URL | gaf_microbatch_pytorch-0.0.5.tar.gz |
|---|---|
| Size | 142.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b992d740e13e0e3e6c748fd1c68d9fe2c23476daf944035de01d2e8c181ac04c
|
|
BLAKE2b-256 checksum How to use checksums |
a622f712b70479414f3518d120582bcfef38959776c4ac9d00bf790afc5281ee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.9.21
|
Release files / gaf_microbatch_pytorch-0.0.5-py3-none-any.whl
| Download URL | gaf_microbatch_pytorch-0.0.5-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2d55554f27f2a7a925d9ecc681a4b8484c9d5eb6e39d81b0d25c54910ad9f49e
|
|
BLAKE2b-256 checksum How to use checksums |
034f440dfa1dd529e81f4937dfe0986bed7fe3e1116df175d685dbfec4a11a56
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.9.21
|
Security for GAF-microbatch-pytorch 0.0.5
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.