Poly Attention
Implementation of Poly-Attention, a general scheme for higher-order self-attention
Install
$ pip install poly-attention
Usage
import torch
from poly_attention import PolyAttention
attn = PolyAttention(
dim = 512,
heads = 8,
dim_head = 64,
causal = False
)
tokens = torch.randn(1, 1024, 512)
out = attn(tokens) # (1, 1024, 512)
A Vision Transformer based on Poly-Attention
import torch
from poly_attention import PolyViT
vit = PolyViT(
image_size = 256,
patch_size = 32,
num_classes = 1000,
dim = 1024,
depth = 6,
heads = 16,
mlp_dim = 2048,
order = 2 # standard poly attention order 2
)
images = torch.randn(1, 3, 256, 256)
preds = vit(images) # (1, 1000)
Quick test
python train_function_composition.py --poly_layers=1 --base_layers=2
Appreciation
-
@dillfrescott for submitting a stability fix
-
@pranoyr for adding key value caching for n-order poly attention as well as more efficient GQA caching for poly attention!
Citations
@inproceedings{chakrabarti2026poly,
title = {Poly-attention: a general scheme for higher-order self-attention},
author = {Chakrabarti, Sayak and Pitassi, Toniann and Alman, Josh},
booktitle = {International Conference on Learning Representations (ICLR)},
year = {2026}
}
@misc{kayyam2026transformersneedprojectionssystematic,
title = {Do Transformers Need Three Projections? Systematic Study of QKV Variants},
author = {Ali Kayyam and Anusha Madan Gopal and M Anthony Lewis},
year = {2026},
eprint = {2606.04032},
archivePrefix = {arXiv},
primaryClass = {cs.LG},
url = {https://arxiv.org/abs/2606.04032},
}
@misc{kimiteam2026attentionresiduals,
title = {Attention Residuals},
author = {Kimi Team and Guangyu Chen and Yu Zhang and Jianlin Su and Weixin Xu and Siyuan Pan and Yaoyu Wang and Yucheng Wang and Guanduo Chen and Bohong Yin and Yutian Chen and Junjie Yan and Ming Wei and Y. Zhang and Fanqing Meng and Chao Hong and Xiaotong Xie and Shaowei Liu and Enzhe Lu and Yunpeng Tai and Yanru Chen and Xin Men and Haiqing Guo and Y. Charles and Haoyu Lu and Lin Sui and Jinguo Zhu and Zaida Zhou and Weiran He and Weixiao Huang and Xinran Xu and Yuzhi Wang and Guokun Lai and Yulun Du and Yuxin Wu and Zhilin Yang and Xinyu Zhou},
year = {2026},
eprint = {2603.15031},
archivePrefix = {arXiv},
primaryClass = {cs.CL},
url = {https://arxiv.org/abs/2603.15031},
}
@misc{heddes2025deepcrossattentionsuperchargingtransformerresidual,
title = {DeepCrossAttention: Supercharging Transformer Residual Connections},
author = {Mike Heddes and Adel Javanmard and Kyriakos Axiotis and Gang Fu and MohammadHossein Bateni and Vahab Mirrokni},
year = {2025},
eprint = {2502.06785},
archivePrefix = {arXiv},
primaryClass = {cs.LG},
url = {https://arxiv.org/abs/2502.06785},
}
Metadata
Release files for poly-attention 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| poly_attention-0.4.0.tar.gz | 15.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| poly_attention-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 34.3 kB
Release files / poly_attention-0.4.0.tar.gz
| Download URL | poly_attention-0.4.0.tar.gz |
|---|---|
| Size | 15.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4dad3e1fbcbc9e13bea1d4a68fccad94267174ae0aee44360111dae290b8c603
|
|
BLAKE2b-256 checksum How to use checksums |
64b2bdfa874675044bf3f6e5845459eb5ce29350000c1fd228a770705fc6c26b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.17
|
Release files / poly_attention-0.4.0-py3-none-any.whl
| Download URL | poly_attention-0.4.0-py3-none-any.whl |
|---|---|
| Size | 19.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a7bfa13ba7140ebcb865d2dd2b33bad0c483a66f9dbfa8f752edcac3d0f28b7f
|
|
BLAKE2b-256 checksum How to use checksums |
fcf9ac95961aeacbc9bbbf6e9044f93f8e22dd5c9d5cef322a4b4f1f9a96f258
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.17
|