Induced Set Attention Block (ISAB) - Pytorch
A concise implementation of (Induced) Set Attention Block, from the Set Transformers paper. It proposes to reduce attention from O(n²) to O(mn), where m is the number of inducing points (learned latents).
Update: Interesting enough, a new paper has used the ISAB block successfully, in the domain of denoising diffusion for efficient generation of images and video.
Install
$ pip install isab-pytorch
Usage
You can either set the number of latents, in which the parameters will be instantiated and returned on completion of cross attention.
import torch
from isab_pytorch import ISAB
attn = ISAB(
dim = 512,
heads = 8,
num_latents = 128,
latent_self_attend = True
)
seq = torch.randn(1, 16384, 512) # (batch, seq, dim)
mask = torch.ones((1, 16384)).bool()
out, latents = attn(seq, mask = mask) # (1, 16384, 512), (1, 128, 512)
Or you can choose not to set the number of latents, and pass in the latents yourself (some persistent latent that propagates down the transformer, as an example)
import torch
from isab_pytorch import ISAB
attn = ISAB(
dim = 512,
heads = 8
)
seq = torch.randn(1, 16384, 512) # (batch, seq, dim)
latents = torch.nn.Parameter(torch.randn(128, 512)) # some memory, passed through multiple ISABs
out, new_latents = attn(seq, latents) # (1, 16384, 512), (1, 128, 512)
Inverted attention can be enabled with inverted_attention = True. In this mode, softmax is applied over the query dimension instead of the key dimension, allowing latents to compete for input tokens — as in the slot attention literature.
import torch
from isab_pytorch import ISAB
attn = ISAB(
dim = 512,
heads = 8,
num_latents = 128,
inverted_attention = True
)
seq = torch.randn(1, 16384, 512)
mask = torch.ones((1, 16384)).bool()
out, latents = attn(seq, mask = mask) # (1, 16384, 512), (1, 128, 512)
Citations
@misc{lee2019set,
title = {Set Transformer: A Framework for Attention-based Permutation-Invariant Neural Networks},
author = {Juho Lee and Yoonho Lee and Jungtaek Kim and Adam R. Kosiorek and Seungjin Choi and Yee Whye Teh},
year = {2019},
eprint = {1810.00825},
archivePrefix = {arXiv},
primaryClass = {cs.LG}
}
@article{Alayrac2022Flamingo,
title = {Flamingo: a Visual Language Model for Few-Shot Learning},
author = {Jean-Baptiste Alayrac et al},
year = {2022}
}
@inproceedings{Locatello2020SlotAttention,
title = {Object-Centric Learning with Slot Attention},
author = {Francesco Locatello and Dirk Weissenborn and Thomas Unterthiner and Aravindh Mahendran and Georg Heigold and Jakob Uszkoreit and Alexey Dosovitskiy and Thomas Kipf},
booktitle = {NeurIPS},
year = {2020}
}
@inproceedings{Luo2025InvertedAttention,
title = {Inverted Attention},
author = {Hanzhe Liang and Xinle Lyu and Jingze Shi and Hao Zhou and Changjian Li and Bo Dai and Jianbing Shen and Shuicheng Yan and Jiashi Feng and Zhenguo Li and Dit-Yan Yeung and Kwan-Yee K. Wong and Wanli Ouyang and Haian Luo},
booktitle = {ICLR},
year = {2025}
}
Metadata
Release files for isab-pytorch 0.3.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 | Provenance | Actions |
|---|---|---|---|---|
| isab_pytorch-0.3.0.tar.gz | 5.2 kB | Without provenance | Details for isab_pytorch-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| isab_pytorch-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for isab_pytorch-0.3.0-py3-none-any.whl |
Total release size: 10.7 kB
Release files / isab_pytorch-0.3.0.tar.gz
| Download URL | isab_pytorch-0.3.0.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7f10f24413c940b05720236ab0ec63914e73f7c0d978e4b1cceb5d82c5adec5a
|
|
BLAKE2b-256 checksum How to use checksums |
4262bf80c1760f1d4a32787a897c632e9539434618423c27a9962e6ba28f6e12
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.17
|
Release files / isab_pytorch-0.3.0-py3-none-any.whl
| Download URL | isab_pytorch-0.3.0-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9a14b23ce82d197457018253b42fb29551c0e1e32bb775147b5f27390d00949d
|
|
BLAKE2b-256 checksum How to use checksums |
d8f4c18083a1bdb40ebde2000ac32ad59313553f9477afacf54d0a6f6b9ad0da
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.17
|
Security for isab-pytorch 0.3.0
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.