Softmax Attention with Constant Cost per Token

Franz A. Heinsen
4/8/2024
cs.LGcs.CL

No official code found. Best implementation: glassroom/heinsen_attention (25 stars, MIT, last commit 2024-06-06).

Abstract

We propose a simple modification to the conventional attention mechanism applied by Transformers: Instead of quantifying pairwise query-key similarity with scaled dot-products, we quantify it with the logarithms of scaled dot-products of exponentials. Our modification linearizes attention with exponential kernel feature maps, whose corresponding feature function is infinite dimensional. We show that our modification is expressible as a composition of log-sums of exponentials, with a latent space of constant size, enabling application with constant time and space complexity per token. We implement our modification, verify that it works in practice, and conclude that it is a promising alternative to conventional attention.

View on arXivView PDF

Code Implementations(1)

MIT

Reference implementation of "Softmax Attention with Constant Cost per Token" (Heinsen, 2024)

251PythonApr 8, 20242 years agoMIT
attentionattention-mechanismattention-modelheinsen-attentionlinear-attention+1 more

Similar Papers

Cite this paper

@article{heinsen2024softmax,
  title  = {Softmax Attention with Constant Cost per Token},
  author = {Franz A. Heinsen},
  year   = {2024},
  eprint = {2404.05843},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2404.05843v2}
}

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/2404.05843.svg)](https://codeofpaper.com/paper/2404.05843)

Discussion