Name | strassen-attention JSON |
Version |
0.1.5
JSON |
| download |
home_page | None |
Summary | Strassen Attention |
upload_time | 2025-07-08 20:21:34 |
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
attention mechanisms
deep learning
higher order attention
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
<img src="./fig1.png" width="500px"></img>
## Strassen Attention
Implementation of [Strassen attention](https://arxiv.org/abs/2501.19215), from Kozachinskiy et al. of [National Center of AI](https://cenia.cl/) in Chile 🇨🇱
## Install
```shell
$ pip install strassen-attention
```
## Usage
```python
import torch
from strassen_attention import strassen_attend
q = torch.randn(1, 8, 32, 16)
k = torch.randn(1, 8, 32, 16)
v = torch.randn(1, 8, 32, 16)
attended = strassen_attend(
q,
k,
k.clone(),
v,
v.clone()
)
assert attended.shape == q.shape
```
For the multi-head attention module
```python
import torch
from strassen_attention.strassen_mha import StrassenMHA
mha = StrassenMHA(dim = 512, causal = True)
tokens = torch.randn(1, 256, 512)
assert mha(tokens).shape == tokens.shape
```
Strassen attention transformer
```python
import torch
import torch
from strassen_attention.strassen_transformer import StrassenTransformer
transformer = StrassenTransformer(dim = 512, depth = 4)
x = torch.randn(1, 16 * 16, 512)
assert transformer(x).shape == x.shape
```
## Citations
```bibtex
@misc{kozachinskiy2025strassenattentionunlockingcompositional,
title = {Strassen Attention: Unlocking Compositional Abilities in Transformers Based on a New Lower Bound Method},
author = {Alexander Kozachinskiy and Felipe Urrutia and Hector Jimenez and Tomasz Steifer and Germán Pizarro and Matías Fuentes and Francisco Meza and Cristian B. Calderon and Cristóbal Rojas},
year = {2025},
eprint = {2501.19215},
archivePrefix = {arXiv},
primaryClass = {cs.LG},
url = {https://arxiv.org/abs/2501.19215},
}
```
```bibtex
@article{Peng2024OnLO,
title = {On Limitations of the Transformer Architecture},
author = {Binghui Peng and Srini Narayanan and Christos Papadimitriou},
journal = {ArXiv},
year = {2024},
volume = {abs/2402.08164},
url = {https://api.semanticscholar.org/CorpusID:267636545}
}
```
Raw data
{
"_id": null,
"home_page": null,
"name": "strassen-attention",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "artificial intelligence, attention mechanisms, deep learning, higher order attention",
"author": null,
"author_email": "Phil Wang <lucidrains@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/14/4c/4e19651cfaa8bc96e7fb0808eed957052ea80daec4908a487a12db4ce5e5/strassen_attention-0.1.5.tar.gz",
"platform": null,
"description": "<img src=\"./fig1.png\" width=\"500px\"></img>\n\n## Strassen Attention\n\nImplementation of [Strassen attention](https://arxiv.org/abs/2501.19215), from Kozachinskiy et al. of [National Center of AI](https://cenia.cl/) in Chile \ud83c\udde8\ud83c\uddf1\n\n## Install\n\n```shell\n$ pip install strassen-attention\n```\n\n## Usage\n\n```python\nimport torch\nfrom strassen_attention import strassen_attend\n\nq = torch.randn(1, 8, 32, 16)\nk = torch.randn(1, 8, 32, 16)\nv = torch.randn(1, 8, 32, 16)\n\nattended = strassen_attend(\n q,\n k,\n k.clone(),\n v,\n v.clone()\n)\n\nassert attended.shape == q.shape\n```\n\nFor the multi-head attention module\n\n```python\nimport torch\nfrom strassen_attention.strassen_mha import StrassenMHA\n\nmha = StrassenMHA(dim = 512, causal = True)\n\ntokens = torch.randn(1, 256, 512)\n\nassert mha(tokens).shape == tokens.shape\n```\n\nStrassen attention transformer\n\n```python\nimport torch\nimport torch\nfrom strassen_attention.strassen_transformer import StrassenTransformer\n\ntransformer = StrassenTransformer(dim = 512, depth = 4)\n\nx = torch.randn(1, 16 * 16, 512)\nassert transformer(x).shape == x.shape\n```\n\n## Citations\n\n```bibtex\n@misc{kozachinskiy2025strassenattentionunlockingcompositional,\n title = {Strassen Attention: Unlocking Compositional Abilities in Transformers Based on a New Lower Bound Method}, \n author = {Alexander Kozachinskiy and Felipe Urrutia and Hector Jimenez and Tomasz Steifer and Germ\u00e1n Pizarro and Mat\u00edas Fuentes and Francisco Meza and Cristian B. Calderon and Crist\u00f3bal Rojas},\n year = {2025},\n eprint = {2501.19215},\n archivePrefix = {arXiv},\n primaryClass = {cs.LG},\n url = {https://arxiv.org/abs/2501.19215}, \n}\n```\n\n```bibtex\n@article{Peng2024OnLO,\n title = {On Limitations of the Transformer Architecture},\n author = {Binghui Peng and Srini Narayanan and Christos Papadimitriou},\n journal = {ArXiv},\n year = {2024},\n volume = {abs/2402.08164},\n url = {https://api.semanticscholar.org/CorpusID:267636545}\n}\n```\n",
"bugtrack_url": null,
"license": "MIT License\n \n Copyright (c) 2025 Phil Wang\n \n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n \n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n \n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.",
"summary": "Strassen Attention",
"version": "0.1.5",
"project_urls": {
"Homepage": "https://pypi.org/project/strassen-attention/",
"Repository": "https://github.com/lucidrains/strassen-attention"
},
"split_keywords": [
"artificial intelligence",
" attention mechanisms",
" deep learning",
" higher order attention"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "feae096c7d0031668770fde5482757d06ee1b84595f38998a8056433d5370cbd",
"md5": "57f0c8f16a51f9048fa4c6f907f21511",
"sha256": "827eb2d83b00fbee1ad9f3d24d7d12ee7809b5840b466fa6dfcdba597b7a397a"
},
"downloads": -1,
"filename": "strassen_attention-0.1.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "57f0c8f16a51f9048fa4c6f907f21511",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 7124,
"upload_time": "2025-07-08T20:21:33",
"upload_time_iso_8601": "2025-07-08T20:21:33.104881Z",
"url": "https://files.pythonhosted.org/packages/fe/ae/096c7d0031668770fde5482757d06ee1b84595f38998a8056433d5370cbd/strassen_attention-0.1.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "144c4e19651cfaa8bc96e7fb0808eed957052ea80daec4908a487a12db4ce5e5",
"md5": "ff99555ec222cdc2ec8f78b9849e1abb",
"sha256": "f43e363cb47d193343dad07ff4ec3c8343c6d733973cb10e2773045ff5b6c212"
},
"downloads": -1,
"filename": "strassen_attention-0.1.5.tar.gz",
"has_sig": false,
"md5_digest": "ff99555ec222cdc2ec8f78b9849e1abb",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 37025444,
"upload_time": "2025-07-08T20:21:34",
"upload_time_iso_8601": "2025-07-08T20:21:34.617443Z",
"url": "https://files.pythonhosted.org/packages/14/4c/4e19651cfaa8bc96e7fb0808eed957052ea80daec4908a487a12db4ce5e5/strassen_attention-0.1.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-08 20:21:34",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "lucidrains",
"github_project": "strassen-attention",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "strassen-attention"
}