SMYRF: Efficient Attention using Asymmetric Clustering

Giannis Daras, Nikita Kitaev, Augustus Odena, Alexandros G. Dimakis
10/11/2020
cs.LG

Official code: giannisdaras/smyrf (50 stars, Python, GPL-3.0, last commit 2023-09-06).

Abstract

We propose a novel type of balanced clustering algorithm to approximate attention. Attention complexity is reduced from $O(N^2)$ to $O(N \log N)$, where $N$ is the sequence length.

Show full abstract

Our algorithm, SMYRF, uses Locality Sensitive Hashing (LSH) in a novel way by defining new Asymmetric transformations and an adaptive scheme that produces balanced clusters. The biggest advantage of SMYRF is that it can be used as a drop-in replacement for dense attention layers without any retraining. On the contrary, prior fast attention methods impose constraints (e.g. queries and keys share the same vector representations) and require re-training from scratch. We apply our method to pre-trained state-of-the-art Natural Language Processing and Computer Vision models and we report significant memory and speed benefits. Notably, SMYRF-BERT outperforms (slightly) BERT on GLUE, while using $50\%$ less memory. We also show that SMYRF can be used interchangeably with dense attention before and after training. Finally, we use SMYRF to train GANs with attention in high resolutions. Using a single TPU, we were able to scale attention to 128x128=16k and 256x256=65k tokens on BigGAN on CelebA-HQ.

View on arXivView PDF

Code Implementations(1)

giannisdaras/smyrfOfficial100%
GPL-3.0

[NeurIPS 2020] Official Implementation: "SMYRF: Efficient Attention using Asymmetric Clustering".

505Python, Jupyter NotebookFeb 21, 20203 years agoGPL-3.0

Similar Papers

Cite this paper

@article{daras2020smyrf,
  title  = {SMYRF: Efficient Attention using Asymmetric Clustering},
  author = {Giannis Daras and Nikita Kitaev and Augustus Odena and Alexandros G. Dimakis},
  year   = {2020},
  eprint = {2010.05315},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2010.05315}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2010.05315.svg)](https://codeofpaper.com/paper/2010.05315)

Discussion