arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2310.01655cs.LG
收藏

PolySketchFormer:通过草图化多项式核实现快速Transformer

PolySketchFormer: Fast Transformers via Sketching Polynomial Kernels

Carnegie Mellon University(卡内基梅隆大学);Google Research(谷歌研究院)

Praneeth Kacham, Vahab Mirrokni, Peilin Zhong

AI总结:

针对自注意力二次复杂度瓶颈,提出用高次多项式核替代softmax并采用数值线性代数的草图化技术,实现带逼近保证的线性时间Transformer架构PolySketchFormer,在长上下文训练中较FlashAttention提速2.5-4倍且质量无损。

摘要:

自注意力机制固有的关于序列长度的二次时间和内存复杂度,对大规模基于Transformer的语言模型的训练和部署构成了关键的计算瓶颈。最近的理论结果表明,在合理的复杂度假设下,次二次softmax注意力逼近是不可解的。本文通过首先证明高次多项式注意力可以在不牺牲模型质量的情况下有效替代softmax来解决这一挑战。接下来,我们开发了来自数值线性代数的多项式草图化技术,以实现具有逼近保证的线性时间多项式注意力。关键的是,我们的方法在实现这一加速时不需要注意力矩阵的稀疏化。我们还提出了一种基于块的算法来高效地应用因果掩码。结合这些技术,我们提供了PolySketchFormer,一种实用的线性时间Transformer架构,用于语言建模,并提供可证明的保证。我们通过训练能够处理长上下文的语言模型来实证验证PolySketchFormer。这些实验在Google Cloud TPU上使用了合成和真实世界数据集(PG19、Wikipedia和C4)。对于32k的上下文长度和GPT-2风格的模型,与FlashAttention相比,我们的模型在训练中实现了2.5-4倍的加速,并且在我们的所有实验中未观察到质量下降。

英文摘要:

The quadratic time and memory complexity inherent to self-attention mechanisms, with respect to sequence length, presents a critical computational bottleneck in the training and deployment of large-scale Transformer-based language models. Recent theoretical results indicate the intractability of sub-quadratic softmax attention approximation under reasonable complexity assumptions. This paper addresses this challenge by first demonstrating that polynomial attention with high degree can effectively replace softmax without sacrificing model quality. Next, we develop polynomial sketching techniques from numerical linear algebra to achieve linear-time polynomial attention with approximation guarantees. Crucially, our approach achieves this speedup without requiring the sparsification of attention matrices. We also present a block-based algorithm to apply causal masking efficiently. Combining these techniques, we provide \emph{PolySketchFormer}, a practical linear-time Transformer architecture for language modeling that offers provable guarantees. We validate PolySketchFormer empirically by training language models capable of handling long contexts. These experiments utilize both synthetic and real-world datasets (PG19, Wikipedia and C4) on Google Cloud TPUs. For context lengths of 32k and GPT-2 style models, our model achieves a 2.5-4x speedup in training compared to FlashAttention, with no observed degradation in quality across our experiments.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑