Conv-Basis: A New Paradigm for Efficient Attention Inference and Gradient Computation in Transformers
Abstract
The self-attention mechanism is the key to the success of transformers in recent Large Language Models (LLMs). However, the quadratic computational cost in the input sequence length is a notorious obstacle for further improvement and scalability in longer contexts. In this work, we leverage the convolution-like structure of attention matrices to develop an efficient approximation method for attention computation using convolution matrices. We propose a basis system, analogous to the rank basis, and show that any lower triangular matrix can always be decomposed as a sum of structured convolution matrices in this basis. We then design a fast algorithm to approximate the attention matrix via a sum of such convolution matrices. This allows us to compute the attention {\it inference} via Fast Fourier Transforms (FFT) in time, where is the hidden dimension, and thus achieve almost linear time in the practical scenario where . Furthermore, the attention {\it training forward} and {\it backward gradient} can be computed in as well. We provide theoretical guarantees on the run time and approximation error and conduct preliminary experiments to evaluate its effectiveness. We hope our new paradigm for accelerating attention computation in transformer models can help their application to longer contexts.
Cite
@article{arxiv.2405.05219,
title = {Conv-Basis: A New Paradigm for Efficient Attention Inference and Gradient Computation in Transformers},
author = {Yingyu Liang and Heshan Liu and Zhenmei Shi and Zhao Song and Zhuoyan Xu and Junze Yin},
journal= {arXiv preprint arXiv:2405.05219},
year = {2024}
}