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
下载
关闭预览

相关内容

专知会员服务
52+阅读 · 2020年12月14日
Linux导论,Introduction to Linux,96页ppt
专知会员服务
82+阅读 · 2020年7月26日
基于多头注意力胶囊网络的文本分类模型
专知会员服务
79+阅读 · 2020年5月24日
Python分布式计算,171页pdf,Distributed Computing with Python
专知会员服务
108+阅读 · 2020年5月3日
强化学习最新教程,17页pdf
专知会员服务
182+阅读 · 2019年10月11日
2019年机器学习框架回顾
专知会员服务
36+阅读 · 2019年10月11日
一文读懂Attention机制
机器学习与推荐算法
63+阅读 · 2020年6月9日
Hierarchically Structured Meta-learning
CreateAMind
27+阅读 · 2019年5月22日
逆强化学习-学习人先验的动机
CreateAMind
16+阅读 · 2019年1月18日
强化学习的Unsupervised Meta-Learning
CreateAMind
18+阅读 · 2019年1月7日
Unsupervised Learning via Meta-Learning
CreateAMind
44+阅读 · 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会员
最新内容
2025年大语言模型进展报告
专知会员服务
1+阅读 · 今天13:30
多智能体协作机制
专知会员服务
1+阅读 · 今天13:26
非对称优势:美海军开发低成本反无人机技术
专知会员服务
4+阅读 · 今天4:39
《美战争部小企业创新研究(SBIR)计划》
专知会员服务
6+阅读 · 今天2:48
《军事模拟:将军事条令与目标融入AI智能体》
专知会员服务
9+阅读 · 今天2:43
【NTU博士论文】3D人体动作生成
专知会员服务
7+阅读 · 4月24日
以色列军事技术对美国军力发展的持续性赋能
专知会员服务
8+阅读 · 4月24日
《深度强化学习在兵棋推演中的应用》40页报告
专知会员服务
14+阅读 · 4月24日
《多域作战面临复杂现实》
专知会员服务
10+阅读 · 4月24日
《印度的多域作战:条令与能力发展》报告
专知会员服务
5+阅读 · 4月24日
相关VIP内容
专知会员服务
52+阅读 · 2020年12月14日
Linux导论,Introduction to Linux,96页ppt
专知会员服务
82+阅读 · 2020年7月26日
基于多头注意力胶囊网络的文本分类模型
专知会员服务
79+阅读 · 2020年5月24日
Python分布式计算,171页pdf,Distributed Computing with Python
专知会员服务
108+阅读 · 2020年5月3日
强化学习最新教程,17页pdf
专知会员服务
182+阅读 · 2019年10月11日
2019年机器学习框架回顾
专知会员服务
36+阅读 · 2019年10月11日
相关资讯
一文读懂Attention机制
机器学习与推荐算法
63+阅读 · 2020年6月9日
Hierarchically Structured Meta-learning
CreateAMind
27+阅读 · 2019年5月22日
逆强化学习-学习人先验的动机
CreateAMind
16+阅读 · 2019年1月18日
强化学习的Unsupervised Meta-Learning
CreateAMind
18+阅读 · 2019年1月7日
Unsupervised Learning via Meta-Learning
CreateAMind
44+阅读 · 2019年1月3日
从Seq2seq到Attention模型到Self Attention(二)
量化投资与机器学习
23+阅读 · 2018年10月9日
计算机视觉近一年进展综述
机器学习研究会
9+阅读 · 2017年11月25日
【学习】Hierarchical Softmax
机器学习研究会
4+阅读 · 2017年8月6日
Top
微信扫码咨询专知VIP会员