Transformers achieve remarkable performance in several tasks but due to their quadratic complexity, with respect to the input's length, they are prohibitively slow for very long sequences. To address this limitation, we express the self-attention as a linear dot-product of kernel feature maps and make use of the associativity property of matrix products to reduce the complexity from $\mathcal{O}\left(N^2\right)$ to $\mathcal{O}\left(N\right)$, where $N$ is the sequence length. We show that this formulation permits an iterative implementation that dramatically accelerates autoregressive transformers and reveals their relationship to recurrent neural networks. Our linear transformers achieve similar performance to vanilla transformers and they are up to 4000x faster on autoregressive prediction of very long sequences.
核心贡献 · Key contributions
提出通过核特征图实现线性注意力,将复杂度从 O(N^2) 降至 O(N)。 Proposes linear attention via kernel feature maps, reducing complexity from O(N^2) to O(N).
推导出自回归 Transformer 的因果掩码,实现线性时间和恒定内存。 Derives causal masking with linear time and constant memory for autoregressive transformers.
揭示 Transformer 可视为循环神经网络,实现每步恒定时间推理。 Reveals transformers as recurrent neural networks, enabling constant-time inference per step.
在长序列自回归推理上实现高达 4000 倍加速,性能与原始 Transformer 相当。 Achieves up to 4000x faster autoregressive inference on long sequences with comparable performance.
通过累积和提供因果线性注意力的恒定内存梯度计算。 Provides constant-memory gradient computation for causal linear attention via cumulative sums.
在图像生成和语音识别上验证,展示线性缩放和竞争性精度。 Validates on image generation and speech recognition, showing linear scaling and competitive accuracy.
局限 · Limitations
特征图选择(如 elu)可能在某些任务中不如 softmax 注意力。 Feature map choice (e.g., elu) may not match softmax attention in all tasks.