Name | GAF-microbatch-pytorch JSON |
Version |
0.0.5
JSON |
| download |
home_page | None |
Summary | Gradient Agreement Filtering |
upload_time | 2025-01-21 16:54:54 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.9 |
license | MIT License Copyright (c) 2025 Phil Wang Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
artificial intelligence
deep learning
gradient filtering
label noise
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
<img src="./figure6.png" width="400px"></img>
## Gradient Agreement Filtering - Pytorch
Implementation of [Gradient Agreement Filtering](https://arxiv.org/abs/2412.18052), 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](https://github.com/Fchaubard/gradient_agreement_filtering)
## Install
```bash
$ pip install GAF-microbatch-pytorch
```
## Usage
```python
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
```python
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
- [x] allow for excluding certain parameters from being filtered
## Citations
```bibtex
@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}
}
```
Raw data
{
"_id": null,
"home_page": null,
"name": "GAF-microbatch-pytorch",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "artificial intelligence, deep learning, gradient filtering, label noise",
"author": null,
"author_email": "Phil Wang <lucidrains@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/a6/22/f712b70479414f3518d120582bcfef38959776c4ac9d00bf790afc5281ee/gaf_microbatch_pytorch-0.0.5.tar.gz",
"platform": null,
"description": "<img src=\"./figure6.png\" width=\"400px\"></img>\n\n## Gradient Agreement Filtering - Pytorch\n\nImplementation of [Gradient Agreement Filtering](https://arxiv.org/abs/2412.18052), from Chaubard et al. of Stanford, but done for single machine microbatches, in Pytorch.\n\nThe official repository that does filtering for macrobatches across machines is [here](https://github.com/Fchaubard/gradient_agreement_filtering)\n\n## Install\n\n```bash\n$ pip install GAF-microbatch-pytorch\n```\n\n## Usage\n\n```python\nimport torch\n\n# mock network\n\nfrom torch import nn\n\nnet = nn.Sequential(\n nn.Linear(512, 256),\n nn.SiLU(),\n nn.Linear(256, 128)\n)\n\n# import the gradient agreement filtering (GAF) wrapper\n\nfrom GAF_microbatch_pytorch import GAFWrapper\n\n# just wrap your neural net\n\ngaf_net = GAFWrapper(\n net,\n filter_distance_thres = 0.97\n)\n\n# your batch of data\n\nx = torch.randn(16, 1024, 512)\n\n# forward and backwards as usual\n\nout = gaf_net(x)\n\nout.sum().backward()\n\n# gradients should be filtered by set threshold comparing per sample gradients within batch, as in paper\n\n```\n\nYou can supply your own gradient filtering method as a `Callable[[Tensor], Tensor]` with the `filter_gradients_fn` kwarg as so\n\n```python\n\ndef filtering_fn(grads):\n # make your big discovery here\n return grads\n \ngaf_net = GAFWrapper(\n net = net,\n filter_gradients_fn = filtering_fn\n)\n\n```\n\n## Todo\n\n- [ ] replicate cifar results on single machine\n- [x] allow for excluding certain parameters from being filtered\n\n## Citations\n\n```bibtex\n@inproceedings{Chaubard2024BeyondGA,\n title = {Beyond Gradient Averaging in Parallel Optimization: Improved Robustness through Gradient Agreement Filtering},\n author = {Francois Chaubard and Duncan Eddy and Mykel J. Kochenderfer},\n year = {2024},\n url = {https://api.semanticscholar.org/CorpusID:274992650}\n}\n```\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2025 Phil Wang Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
"summary": "Gradient Agreement Filtering",
"version": "0.0.5",
"project_urls": {
"Homepage": "https://pypi.org/project/GAF-microbatch-pytorch/",
"Repository": "https://github.com/lucidrains/GAF-microbatch-pytorch"
},
"split_keywords": [
"artificial intelligence",
" deep learning",
" gradient filtering",
" label noise"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "034f440dfa1dd529e81f4937dfe0986bed7fe3e1116df175d685dbfec4a11a56",
"md5": "a28224e1d4113b8709e9bd4db605c59b",
"sha256": "2d55554f27f2a7a925d9ecc681a4b8484c9d5eb6e39d81b0d25c54910ad9f49e"
},
"downloads": -1,
"filename": "gaf_microbatch_pytorch-0.0.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a28224e1d4113b8709e9bd4db605c59b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 6215,
"upload_time": "2025-01-21T16:54:52",
"upload_time_iso_8601": "2025-01-21T16:54:52.876769Z",
"url": "https://files.pythonhosted.org/packages/03/4f/440dfa1dd529e81f4937dfe0986bed7fe3e1116df175d685dbfec4a11a56/gaf_microbatch_pytorch-0.0.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a622f712b70479414f3518d120582bcfef38959776c4ac9d00bf790afc5281ee",
"md5": "bc2021d24b8c11333f1f76c83f160fae",
"sha256": "b992d740e13e0e3e6c748fd1c68d9fe2c23476daf944035de01d2e8c181ac04c"
},
"downloads": -1,
"filename": "gaf_microbatch_pytorch-0.0.5.tar.gz",
"has_sig": false,
"md5_digest": "bc2021d24b8c11333f1f76c83f160fae",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 142201,
"upload_time": "2025-01-21T16:54:54",
"upload_time_iso_8601": "2025-01-21T16:54:54.666828Z",
"url": "https://files.pythonhosted.org/packages/a6/22/f712b70479414f3518d120582bcfef38959776c4ac9d00bf790afc5281ee/gaf_microbatch_pytorch-0.0.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-21 16:54:54",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "lucidrains",
"github_project": "GAF-microbatch-pytorch",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "gaf-microbatch-pytorch"
}