Loki: Low-rank Keys for Efficient Sparse Attention

Prajwal Singhania, Siddharth Singh, Shwai He, Soheil Feizi, Abhinav Bhatele
6/4/2024
cs.LG

No official code found. Best implementation: hpcgroup/loki (22 stars, MIT, last commit 2025-04-14).

Abstract

Inference on large language models (LLMs) can be expensive in terms of the compute and memory costs involved, especially when long sequence lengths are used. In particular, the self-attention mechanism used in LLM inference contributes significantly to these costs, which has sparked an interest in approximating the self-attention computation to reduce such costs. In this work, we propose to approximate self-attention by focusing on the dimensionality of key vectors computed in the attention block. Our analysis reveals that key vectors lie in a significantly lower-dimensional space, consistently across several datasets and models. Exploiting this observation, we propose Loki, a novel sparse attention method that ranks and selects tokens in the KV-cache based on attention scores computed in low-dimensional space. Our evaluations show that Loki is able to speed up the attention computation due to reduced data movement (load/store) and compute costs while maintaining the efficacy of the models better than other popular approximation methods.

View on arXivView PDF

Code Implementations(1)

hpcgroup/lokiCommunity100%
MIT

Algorithms for approximate attention in LLMs

223Shell, PythonNov 19, 20231 years agoMIT

Similar Papers

Cite this paper

@article{singhania2024loki,
  title  = {Loki: Low-rank Keys for Efficient Sparse Attention},
  author = {Prajwal Singhania and Siddharth Singh and Shwai He and Soheil Feizi and Abhinav Bhatele},
  year   = {2024},
  eprint = {2406.02542},
  archivePrefix = {arXiv},
  doi    = {10.48550/arXiv.2406.02542},
  url    = {http://arxiv.org/abs/2406.02542v2},
  journal = {NEURIPS 2024 2024}
}

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

Discussion