{"id":15601099,"url":"https://github.com/lucidrains/isab-pytorch","last_synced_at":"2025-04-16T05:26:27.454Z","repository":{"id":62571735,"uuid":"307490034","full_name":"lucidrains/isab-pytorch","owner":"lucidrains","description":"An implementation of (Induced) Set Attention Block, from the Set Transformers paper","archived":false,"fork":false,"pushed_at":"2023-01-10T21:02:50.000Z","size":56,"stargazers_count":53,"open_issues_count":1,"forks_count":5,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-05-02T01:14:21.599Z","etag":null,"topics":["artificial-intelligence","attention","attention-mechanism","deep-learning"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lucidrains.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-26T20:00:39.000Z","updated_at":"2024-01-04T16:51:46.000Z","dependencies_parsed_at":"2023-02-08T20:05:13.546Z","dependency_job_id":null,"html_url":"https://github.com/lucidrains/isab-pytorch","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2Fisab-pytorch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2Fisab-pytorch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2Fisab-pytorch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2Fisab-pytorch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lucidrains","download_url":"https://codeload.github.com/lucidrains/isab-pytorch/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249199734,"owners_count":21228994,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["artificial-intelligence","attention","attention-mechanism","deep-learning"],"created_at":"2024-10-03T02:14:33.767Z","updated_at":"2025-04-16T05:26:27.419Z","avatar_url":"https://github.com/lucidrains.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"./isab.png\"\u003e\u003c/img\u003e\n\n## Induced Set Attention Block (ISAB) - Pytorch\n\nA 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).\n\nUpdate: Interesting enough, \u003ca href=\"https://arxiv.org/abs/2212.11972\"\u003ea new paper\u003c/a\u003e has used the ISAB block successfully, in the domain of denoising diffusion for efficient generation of images and video.\n\n## Install\n\n```bash\n$ pip install isab-pytorch\n```\n\n## Usage\n\nYou can either set the number of latents, in which the parameters will be instantiated and returned on completion of cross attention.\n\n```python\nimport torch\nfrom isab_pytorch import ISAB\n\nattn = ISAB(\n    dim = 512,\n    heads = 8,\n    num_latents = 128,\n    latent_self_attend = True\n)\n\nseq = torch.randn(1, 16384, 512) # (batch, seq, dim)\nmask = torch.ones((1, 16384)).bool()\n\nout, latents = attn(seq, mask = mask) # (1, 16384, 512), (1, 128, 512)\n```\n\nOr 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)\n\n```python\nimport torch\nfrom isab_pytorch import ISAB\n\nattn = ISAB(\n    dim = 512,\n    heads = 8\n)\n\nseq = torch.randn(1, 16384, 512) # (batch, seq, dim)\nlatents = torch.nn.Parameter(torch.randn(128, 512)) # some memory, passed through multiple ISABs\n\nout, new_latents = attn(seq, latents) # (1, 16384, 512), (1, 128, 512)\n```\n\n## Citations\n\n```bibtex\n@misc{lee2019set,\n    title   = {Set Transformer: A Framework for Attention-based Permutation-Invariant Neural Networks},\n    author  = {Juho Lee and Yoonho Lee and Jungtaek Kim and Adam R. Kosiorek and Seungjin Choi and Yee Whye Teh},\n    year    = {2019},\n    eprint  = {1810.00825},\n    archivePrefix = {arXiv},\n    primaryClass = {cs.LG}\n}\n```\n\n```bibtex\n@article{Alayrac2022Flamingo,\n    title   = {Flamingo: a Visual Language Model for Few-Shot Learning},\n    author  = {Jean-Baptiste Alayrac et al},\n    year    = {2022}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucidrains%2Fisab-pytorch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucidrains%2Fisab-pytorch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucidrains%2Fisab-pytorch/lists"}