Skip to main content

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)

Source distribution for GAF-microbatch-pytorch 0.0.5
File Size Uploaded
gaf_microbatch_pytorch-0.0.5.tar.gz 142.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for GAF-microbatch-pytorch 0.0.5
File Interpreter ABI Platform
gaf_microbatch_pytorch-0.0.5-py3-none-any.whl Python 3 none any Details

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

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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