Strassen Attention
Implementation of Strassen attention, from Kozachinskiy et al. of National Center of AI in Chile 🇨🇱
Install
$ pip install strassen-attention
Usage
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
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
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
@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},
}
@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}
}
Metadata
Release files for strassen-attention 0.1.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 |
|---|---|---|---|---|
| strassen_attention-0.1.5.tar.gz | 37.0 MB | Without provenance | Details for strassen_attention-0.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| strassen_attention-0.1.5-py3-none-any.whl | Python 3 | none | any | Details for strassen_attention-0.1.5-py3-none-any.whl |
Total release size: 37.0 MB
Release files / strassen_attention-0.1.5.tar.gz
| Download URL | strassen_attention-0.1.5.tar.gz |
|---|---|
| Size | 37.0 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f43e363cb47d193343dad07ff4ec3c8343c6d733973cb10e2773045ff5b6c212
|
|
BLAKE2b-256 checksum How to use checksums |
144c4e19651cfaa8bc96e7fb0808eed957052ea80daec4908a487a12db4ce5e5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.23
|
Release files / strassen_attention-0.1.5-py3-none-any.whl
| Download URL | strassen_attention-0.1.5-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
827eb2d83b00fbee1ad9f3d24d7d12ee7809b5840b466fa6dfcdba597b7a397a
|
|
BLAKE2b-256 checksum How to use checksums |
feae096c7d0031668770fde5482757d06ee1b84595f38998a8056433d5370cbd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.23
|
Security for strassen-attention 0.1.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.