Fast Attention Requires Bounded Entries. Alman, J. & Zhao, S. arXiv.org, February, 2023. Place: Ithaca Publisher: Cornell University Library, arXiv.org
Paper abstract bibtex In modern machine learning, inner product attention computation is a fundamental task for training large language models such as Transformer, GPT-1, BERT, GPT-2, GPT-3 and ChatGPT. Formally, in this problem, one is given as input three matrices \(Q, K, V \in [-B,B]\textasciicircum\n \times d\\), and the goal is to construct the matrix \(\mathrm\Att\(Q,K,V) := \mathrm\diag\(A \\bf 1\_n)\textasciicircum\-1\ A V \in \mathbb\R\\textasciicircum\n \times d\\), where \(A = \exp(QK\textasciicircum\top/d)\) is the `attention matrix', and \(\exp\) is applied entry-wise. Straightforward methods for this problem explicitly compute the \(n \times n\) attention matrix \(A\), and hence require time \(\Omega(n\textasciicircum2)\) even when \(d = n\textasciicircum\o(1)\\) is small. In this paper, we investigate whether faster algorithms are possible by implicitly making use of the matrix \(A\). We present two results, showing that there is a sharp transition at \(B = \Theta(\sqrt\\log n\)\). \(\bullet\) If \(d = O(\log n)\) and \(B = o(\sqrt\\log n\)\), there is an \(n\textasciicircum\1+o(1)\\) time algorithm to approximate \(\mathrm\Att\(Q,K,V)\) up to \(1/\mathrm\poly\(n)\) additive error. \(\bullet\) If \(d = O(\log n)\) and \(B = \Theta (\sqrt\\log n\)\), assuming the Strong Exponential Time Hypothesis from fine-grained complexity theory, it is impossible to approximate \(\mathrm\Att\(Q,K,V)\) up to \(1/\mathrm\poly\(n)\) additive error in truly subquadratic time \(n\textasciicircum\2 - \Omega(1)\\). This gives a theoretical explanation for the phenomenon observed in practice that attention computation is much more efficient when the input matrices have smaller entries.
@article{alman_fast_2023,
title = {Fast {Attention} {Requires} {Bounded} {Entries}},
url = {https://www.proquest.com/working-papers/fast-attention-requires-bounded-entries/docview/2780572824/se-2},
abstract = {In modern machine learning, inner product attention computation is a fundamental task for training large language models such as Transformer, GPT-1, BERT, GPT-2, GPT-3 and ChatGPT. Formally, in this problem, one is given as input three matrices {\textbackslash}(Q, K, V {\textbackslash}in [-B,B]{\textasciicircum}\{n {\textbackslash}times d\}{\textbackslash}), and the goal is to construct the matrix {\textbackslash}({\textbackslash}mathrm\{Att\}(Q,K,V) := {\textbackslash}mathrm\{diag\}(A \{{\textbackslash}bf 1\}\_n){\textasciicircum}\{-1\} A V {\textbackslash}in {\textbackslash}mathbb\{R\}{\textasciicircum}\{n {\textbackslash}times d\}{\textbackslash}), where {\textbackslash}(A = {\textbackslash}exp(QK{\textasciicircum}{\textbackslash}top/d){\textbackslash}) is the `attention matrix', and {\textbackslash}({\textbackslash}exp{\textbackslash}) is applied entry-wise. Straightforward methods for this problem explicitly compute the {\textbackslash}(n {\textbackslash}times n{\textbackslash}) attention matrix {\textbackslash}(A{\textbackslash}), and hence require time {\textbackslash}({\textbackslash}Omega(n{\textasciicircum}2){\textbackslash}) even when {\textbackslash}(d = n{\textasciicircum}\{o(1)\}{\textbackslash}) is small. In this paper, we investigate whether faster algorithms are possible by implicitly making use of the matrix {\textbackslash}(A{\textbackslash}). We present two results, showing that there is a sharp transition at {\textbackslash}(B = {\textbackslash}Theta({\textbackslash}sqrt\{{\textbackslash}log n\}){\textbackslash}). {\textbackslash}({\textbackslash}bullet{\textbackslash}) If {\textbackslash}(d = O({\textbackslash}log n){\textbackslash}) and {\textbackslash}(B = o({\textbackslash}sqrt\{{\textbackslash}log n\}){\textbackslash}), there is an {\textbackslash}(n{\textasciicircum}\{1+o(1)\}{\textbackslash}) time algorithm to approximate {\textbackslash}({\textbackslash}mathrm\{Att\}(Q,K,V){\textbackslash}) up to {\textbackslash}(1/{\textbackslash}mathrm\{poly\}(n){\textbackslash}) additive error. {\textbackslash}({\textbackslash}bullet{\textbackslash}) If {\textbackslash}(d = O({\textbackslash}log n){\textbackslash}) and {\textbackslash}(B = {\textbackslash}Theta ({\textbackslash}sqrt\{{\textbackslash}log n\}){\textbackslash}), assuming the Strong Exponential Time Hypothesis from fine-grained complexity theory, it is impossible to approximate {\textbackslash}({\textbackslash}mathrm\{Att\}(Q,K,V){\textbackslash}) up to {\textbackslash}(1/{\textbackslash}mathrm\{poly\}(n){\textbackslash}) additive error in truly subquadratic time {\textbackslash}(n{\textasciicircum}\{2 - {\textbackslash}Omega(1)\}{\textbackslash}). This gives a theoretical explanation for the phenomenon observed in practice that attention computation is much more efficient when the input matrices have smaller entries.},
language = {English},
journal = {arXiv.org},
author = {Alman, Josh and Zhao, Song},
month = feb,
year = {2023},
note = {Place: Ithaca
Publisher: Cornell University Library, arXiv.org},
keywords = {Machine learning, Machine Learning, Business And Economics--Banking And Finance, Algorithms, Complexity theory, Computational Complexity, Data Structures and Algorithms},
annote = {Copyright - © 2023. This work is published under http://creativecommons.org/licenses/by-nc-sa/4.0/ (the “License”). Notwithstanding the ProQuest Terms and Conditions, you may use this content in accordance with the terms of the License.},
annote = {Última actualización - 2023-03-08},
}
Downloads: 0
{"_id":"hFKogSBQ53yoaR77o","bibbaseid":"alman-zhao-fastattentionrequiresboundedentries-2023","author_short":["Alman, J.","Zhao, S."],"bibdata":{"bibtype":"article","type":"article","title":"Fast Attention Requires Bounded Entries","url":"https://www.proquest.com/working-papers/fast-attention-requires-bounded-entries/docview/2780572824/se-2","abstract":"In modern machine learning, inner product attention computation is a fundamental task for training large language models such as Transformer, GPT-1, BERT, GPT-2, GPT-3 and ChatGPT. Formally, in this problem, one is given as input three matrices \\(Q, K, V \\in [-B,B]\\textasciicircum\\n \\times d\\\\), and the goal is to construct the matrix \\(\\mathrm\\Att\\(Q,K,V) := \\mathrm\\diag\\(A \\\\bf 1\\_n)\\textasciicircum\\-1\\ A V \\in \\mathbb\\R\\\\textasciicircum\\n \\times d\\\\), where \\(A = \\exp(QK\\textasciicircum\\top/d)\\) is the `attention matrix', and \\(\\exp\\) is applied entry-wise. Straightforward methods for this problem explicitly compute the \\(n \\times n\\) attention matrix \\(A\\), and hence require time \\(\\Omega(n\\textasciicircum2)\\) even when \\(d = n\\textasciicircum\\o(1)\\\\) is small. In this paper, we investigate whether faster algorithms are possible by implicitly making use of the matrix \\(A\\). We present two results, showing that there is a sharp transition at \\(B = \\Theta(\\sqrt\\\\log n\\)\\). \\(\\bullet\\) If \\(d = O(\\log n)\\) and \\(B = o(\\sqrt\\\\log n\\)\\), there is an \\(n\\textasciicircum\\1+o(1)\\\\) time algorithm to approximate \\(\\mathrm\\Att\\(Q,K,V)\\) up to \\(1/\\mathrm\\poly\\(n)\\) additive error. \\(\\bullet\\) If \\(d = O(\\log n)\\) and \\(B = \\Theta (\\sqrt\\\\log n\\)\\), assuming the Strong Exponential Time Hypothesis from fine-grained complexity theory, it is impossible to approximate \\(\\mathrm\\Att\\(Q,K,V)\\) up to \\(1/\\mathrm\\poly\\(n)\\) additive error in truly subquadratic time \\(n\\textasciicircum\\2 - \\Omega(1)\\\\). This gives a theoretical explanation for the phenomenon observed in practice that attention computation is much more efficient when the input matrices have smaller entries.","language":"English","journal":"arXiv.org","author":[{"propositions":[],"lastnames":["Alman"],"firstnames":["Josh"],"suffixes":[]},{"propositions":[],"lastnames":["Zhao"],"firstnames":["Song"],"suffixes":[]}],"month":"February","year":"2023","note":"Place: Ithaca Publisher: Cornell University Library, arXiv.org","keywords":"Machine learning, Machine Learning, Business And Economics–Banking And Finance, Algorithms, Complexity theory, Computational Complexity, Data Structures and Algorithms","annote":"Última actualización - 2023-03-08","bibtex":"@article{alman_fast_2023,\n\ttitle = {Fast {Attention} {Requires} {Bounded} {Entries}},\n\turl = {https://www.proquest.com/working-papers/fast-attention-requires-bounded-entries/docview/2780572824/se-2},\n\tabstract = {In modern machine learning, inner product attention computation is a fundamental task for training large language models such as Transformer, GPT-1, BERT, GPT-2, GPT-3 and ChatGPT. Formally, in this problem, one is given as input three matrices {\\textbackslash}(Q, K, V {\\textbackslash}in [-B,B]{\\textasciicircum}\\{n {\\textbackslash}times d\\}{\\textbackslash}), and the goal is to construct the matrix {\\textbackslash}({\\textbackslash}mathrm\\{Att\\}(Q,K,V) := {\\textbackslash}mathrm\\{diag\\}(A \\{{\\textbackslash}bf 1\\}\\_n){\\textasciicircum}\\{-1\\} A V {\\textbackslash}in {\\textbackslash}mathbb\\{R\\}{\\textasciicircum}\\{n {\\textbackslash}times d\\}{\\textbackslash}), where {\\textbackslash}(A = {\\textbackslash}exp(QK{\\textasciicircum}{\\textbackslash}top/d){\\textbackslash}) is the `attention matrix', and {\\textbackslash}({\\textbackslash}exp{\\textbackslash}) is applied entry-wise. Straightforward methods for this problem explicitly compute the {\\textbackslash}(n {\\textbackslash}times n{\\textbackslash}) attention matrix {\\textbackslash}(A{\\textbackslash}), and hence require time {\\textbackslash}({\\textbackslash}Omega(n{\\textasciicircum}2){\\textbackslash}) even when {\\textbackslash}(d = n{\\textasciicircum}\\{o(1)\\}{\\textbackslash}) is small. In this paper, we investigate whether faster algorithms are possible by implicitly making use of the matrix {\\textbackslash}(A{\\textbackslash}). We present two results, showing that there is a sharp transition at {\\textbackslash}(B = {\\textbackslash}Theta({\\textbackslash}sqrt\\{{\\textbackslash}log n\\}){\\textbackslash}). {\\textbackslash}({\\textbackslash}bullet{\\textbackslash}) If {\\textbackslash}(d = O({\\textbackslash}log n){\\textbackslash}) and {\\textbackslash}(B = o({\\textbackslash}sqrt\\{{\\textbackslash}log n\\}){\\textbackslash}), there is an {\\textbackslash}(n{\\textasciicircum}\\{1+o(1)\\}{\\textbackslash}) time algorithm to approximate {\\textbackslash}({\\textbackslash}mathrm\\{Att\\}(Q,K,V){\\textbackslash}) up to {\\textbackslash}(1/{\\textbackslash}mathrm\\{poly\\}(n){\\textbackslash}) additive error. {\\textbackslash}({\\textbackslash}bullet{\\textbackslash}) If {\\textbackslash}(d = O({\\textbackslash}log n){\\textbackslash}) and {\\textbackslash}(B = {\\textbackslash}Theta ({\\textbackslash}sqrt\\{{\\textbackslash}log n\\}){\\textbackslash}), assuming the Strong Exponential Time Hypothesis from fine-grained complexity theory, it is impossible to approximate {\\textbackslash}({\\textbackslash}mathrm\\{Att\\}(Q,K,V){\\textbackslash}) up to {\\textbackslash}(1/{\\textbackslash}mathrm\\{poly\\}(n){\\textbackslash}) additive error in truly subquadratic time {\\textbackslash}(n{\\textasciicircum}\\{2 - {\\textbackslash}Omega(1)\\}{\\textbackslash}). This gives a theoretical explanation for the phenomenon observed in practice that attention computation is much more efficient when the input matrices have smaller entries.},\n\tlanguage = {English},\n\tjournal = {arXiv.org},\n\tauthor = {Alman, Josh and Zhao, Song},\n\tmonth = feb,\n\tyear = {2023},\n\tnote = {Place: Ithaca\nPublisher: Cornell University Library, arXiv.org},\n\tkeywords = {Machine learning, Machine Learning, Business And Economics--Banking And Finance, Algorithms, Complexity theory, Computational Complexity, Data Structures and Algorithms},\n\tannote = {Copyright - © 2023. This work is published under http://creativecommons.org/licenses/by-nc-sa/4.0/ (the “License”). Notwithstanding the ProQuest Terms and Conditions, you may use this content in accordance with the terms of the License.},\n\tannote = {Última actualización - 2023-03-08},\n}\n\n","author_short":["Alman, J.","Zhao, S."],"key":"alman_fast_2023","id":"alman_fast_2023","bibbaseid":"alman-zhao-fastattentionrequiresboundedentries-2023","role":"author","urls":{"Paper":"https://www.proquest.com/working-papers/fast-attention-requires-bounded-entries/docview/2780572824/se-2"},"keyword":["Machine learning","Machine Learning","Business And Economics–Banking And Finance","Algorithms","Complexity theory","Computational Complexity","Data Structures and Algorithms"],"metadata":{"authorlinks":{}}},"bibtype":"article","biburl":"https://bibbase.org/network/files/22WYpzbBvi3hDHX7Y","dataSources":["cYu6uhMkeFHgRrEty","hLMh7bwHyFsPNWAEL","LKW3iRvnztCpLNTW7","TLD9JxqHfSQQ4r268","X9BvByJrC3kGJexn8","iovNvcnNYDGJcuMq2","NjZJ5ZmWhTtMZBfje"],"keywords":["machine learning","machine learning","business and economics–banking and finance","algorithms","complexity theory","computational complexity","data structures and algorithms"],"search_terms":["fast","attention","requires","bounded","entries","alman","zhao"],"title":"Fast Attention Requires Bounded Entries","year":2023}