We present a very simple algorithm for attention that requires $O(1)$ memory with respect to sequence length and an extension to self-attention that requires $O(\log n)$ memory. This is in contrast with the frequently stated belief that self-attention requires $O(n^2)$ memory. While the time complexity is still $O(n^2)$, device memory rather than compute capability is often the limiting factor on modern accelerators. Thus, reducing the memory requirements of attention allows processing of longer sequences than might otherwise be feasible. We provide a practical implementation for accelerators that requires $O(\sqrt{n})$ memory, is numerically stable, and is within a few percent of the runtime of the standard implementation of attention. We also demonstrate how to differentiate the function while remaining memory-efficient. For sequence length 16384, the memory overhead of self-attention is reduced by 59X for inference and by 32X for differentiation.


翻译:我们提出了一个非常简单的注意算法,在序列长度方面需要O(1)美元内存,自我注意的延伸需要O(log n)美元内存。这与经常表示的自留需要O(n)2美元内存的信念形成对照。虽然时间复杂性仍然是$(n)2美元,但设备内存而不是计算能力往往是现代加速器的限制因素。因此,减少对注意的内存要求使得对注意序列的处理比其他可能可行时要长。我们为需要O(sqrt{n})内存的加速器提供实际操作,因为需要O(sqrt{n)美元内存,数字稳定,在标准关注执行的运行时间的一小部分之内。我们还演示了如何在保持记忆效率的同时区分功能。对于第16384号序列,自留的内存管理费减少59X,用于推断的减少32X。

0
下载
关闭预览

相关内容

专知会员服务
50+阅读 · 2020年12月14日
Linux导论,Introduction to Linux,96页ppt
专知会员服务
77+阅读 · 2020年7月26日
基于多头注意力胶囊网络的文本分类模型
专知会员服务
76+阅读 · 2020年5月24日
Python分布式计算,171页pdf,Distributed Computing with Python
专知会员服务
106+阅读 · 2020年5月3日
强化学习最新教程,17页pdf
专知会员服务
174+阅读 · 2019年10月11日
2019年机器学习框架回顾
专知会员服务
35+阅读 · 2019年10月11日
一文读懂Attention机制
机器学习与推荐算法
63+阅读 · 2020年6月9日
Hierarchically Structured Meta-learning
CreateAMind
24+阅读 · 2019年5月22日
逆强化学习-学习人先验的动机
CreateAMind
15+阅读 · 2019年1月18日
强化学习的Unsupervised Meta-Learning
CreateAMind
17+阅读 · 2019年1月7日
Unsupervised Learning via Meta-Learning
CreateAMind
41+阅读 · 2019年1月3日
从Seq2seq到Attention模型到Self Attention(二)
量化投资与机器学习
23+阅读 · 2018年10月9日
计算机视觉近一年进展综述
机器学习研究会
9+阅读 · 2017年11月25日
【学习】Hierarchical Softmax
机器学习研究会
4+阅读 · 2017年8月6日
Arxiv
0+阅读 · 2022年2月17日
Arxiv
9+阅读 · 2021年4月8日
Meta-Learning with Implicit Gradients
Arxiv
13+阅读 · 2019年9月10日
Arxiv
4+阅读 · 2018年10月31日
VIP会员
相关VIP内容
专知会员服务
50+阅读 · 2020年12月14日
Linux导论,Introduction to Linux,96页ppt
专知会员服务
77+阅读 · 2020年7月26日
基于多头注意力胶囊网络的文本分类模型
专知会员服务
76+阅读 · 2020年5月24日
Python分布式计算,171页pdf,Distributed Computing with Python
专知会员服务
106+阅读 · 2020年5月3日
强化学习最新教程,17页pdf
专知会员服务
174+阅读 · 2019年10月11日
2019年机器学习框架回顾
专知会员服务
35+阅读 · 2019年10月11日
相关资讯
一文读懂Attention机制
机器学习与推荐算法
63+阅读 · 2020年6月9日
Hierarchically Structured Meta-learning
CreateAMind
24+阅读 · 2019年5月22日
逆强化学习-学习人先验的动机
CreateAMind
15+阅读 · 2019年1月18日
强化学习的Unsupervised Meta-Learning
CreateAMind
17+阅读 · 2019年1月7日
Unsupervised Learning via Meta-Learning
CreateAMind
41+阅读 · 2019年1月3日
从Seq2seq到Attention模型到Self Attention(二)
量化投资与机器学习
23+阅读 · 2018年10月9日
计算机视觉近一年进展综述
机器学习研究会
9+阅读 · 2017年11月25日
【学习】Hierarchical Softmax
机器学习研究会
4+阅读 · 2017年8月6日
Top
微信扫码咨询专知VIP会员