Conv-Basis: A New Paradigm for Efficient Attention Inference and Gradient Computation in Transformers

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Liang, Yingyu, Liu, Heshan, Shi, Zhenmei, Song, Zhao, Xu, Zhuoyan, Yin, Junze
Format: Preprint
Published: 2024
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866913548551061504
author Liang, Yingyu
Liu, Heshan
Shi, Zhenmei
Song, Zhao
Xu, Zhuoyan
Yin, Junze
author_facet Liang, Yingyu
Liu, Heshan
Shi, Zhenmei
Song, Zhao
Xu, Zhuoyan
Yin, Junze
contents The self-attention mechanism is the key to the success of transformers in recent Large Language Models (LLMs). However, the quadratic computational cost $O(n^2)$ in the input sequence length $n$ 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 $\mathsf{conv}$ 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 $k$ convolution matrices. This allows us to compute the attention {\it inference} via Fast Fourier Transforms (FFT) in $O(knd \log n)$ time, where $d$ is the hidden dimension, and thus achieve almost linear time $n^{1+o(1)}$ in the practical scenario where $kd = n^{o(1)}$. Furthermore, the attention {\it training forward} and {\it backward gradient} can be computed in $n^{1+o(1)}$ 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.
format Preprint
id arxiv_https___arxiv_org_abs_2405_05219
institution arXiv
publishDate 2024
record_format arxiv
spellingShingle Conv-Basis: A New Paradigm for Efficient Attention Inference and Gradient Computation in Transformers
Liang, Yingyu
Liu, Heshan
Shi, Zhenmei
Song, Zhao
Xu, Zhuoyan
Yin, Junze
Machine Learning
Artificial Intelligence
The self-attention mechanism is the key to the success of transformers in recent Large Language Models (LLMs). However, the quadratic computational cost $O(n^2)$ in the input sequence length $n$ 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 $\mathsf{conv}$ 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 $k$ convolution matrices. This allows us to compute the attention {\it inference} via Fast Fourier Transforms (FFT) in $O(knd \log n)$ time, where $d$ is the hidden dimension, and thus achieve almost linear time $n^{1+o(1)}$ in the practical scenario where $kd = n^{o(1)}$. Furthermore, the attention {\it training forward} and {\it backward gradient} can be computed in $n^{1+o(1)}$ 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.
title Conv-Basis: A New Paradigm for Efficient Attention Inference and Gradient Computation in Transformers
topic Machine Learning
Artificial Intelligence
url https://arxiv.org/abs/2405.05219