arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2604.23798cs.LGcs.CV
收藏

ELSA:精确线性扫描注意力用于快速且内存高效的视觉Transformer

ELSA: Exact Linear-Scan Attention for Fast and Memory-Light Vision Transformers

Advanced Computer Vision Laboratory, National Yang Ming Chiao Tung University(国家阳明交通大学先进计算机视觉实验室)

Chih-Chung Hsu, Xin-Di Ma, Wo-Ting Liao, Chia-Ming Lee

AI总结:

ELSA通过算法重构在线softmax注意力,在保持精确softmax语义的同时,实现O(log n)的并行深度和O(n)的额外内存,适用于多种硬件平台的高精度推理。

摘要:

现有注意力加速器常在精确softmax语义、依赖融合张量核心内核或引入序列深度限制FP32在长序列中的吞吐量。我们提出ELSA,一种在线softmax注意力的算法重构,(i)在实数运算中保持精确softmax语义,具有可证明的O(u log n) FP32相对误差界;(ii)将在线softmax更新视为一个关联单oid(m,S,W)的前缀扫描,产生O(n)额外内存和O(log n)并行深度;(iii)独立于Tensor-Core,使用Triton和CUDA C++实现,并可作为drop-in replacement部署,无需重新训练或权重修改。与FlashAttention-2/3不同,ELSA在A100和资源受限的边缘设备如Jetson TX2上运行相同,使其成为唯一硬件无关的精确注意力内核,将并行深度减少到O(log n)在全精度下。在A100 FP32基准测试(1K-16K tokens)上,ELSA在内存高效SDPA上实现1.3-3.5倍的速度提升,在BERT上实现1.97-2.27倍的提升;在Jetson TX2上,ELSA在Math(64-900 tokens)上实现1.5-1.6倍的提升,具有17.8-20.2%的吞吐量增益在LLaMA-13B卸载时≥32K。在FP16中,ELSA在长序列中接近硬件融合基线,同时保留完整的FP32能力,提供一个统一的内核用于跨平台的高精度推理。我们的代码和实现可在https://github.com/ming053l/ELSA获取。

英文摘要:

Existing attention accelerators often trade exact softmax semantics, depend on fused Tensor Core kernels, or incur sequential depth that limits FP32 throughput on long sequences. We present \textbf{ELSA}, an algorithmic reformulation of online softmax attention that (i)~preserves exact softmax semantics in real arithmetic with a \emph{provable} $\mathcal{O}(u\log n)$ FP32 relative error bound; (ii)~casts the online softmax update as a prefix scan over an associative monoid $(m,S,W)$, yielding $O(n)$ extra memory and $O(\log n)$ parallel depth; and (iii)~is Tensor-Core independent, implemented in Triton and CUDA C++, and deployable as a \emph{drop-in replacement} requiring no retraining or weight modification. Unlike FlashAttention-2/3, which rely on HMMA/GMMA Tensor Core instructions and provide no compatible FP32 path, ELSA operates identically on A100s and resource-constrained edge devices such as Jetson TX2 -- making it the only hardware-agnostic exact-attention kernel that reduces parallel depth to $O(\log n)$ at full precision. On A100 FP32 benchmarks (1K--16K tokens), ELSA delivers $1.3$--$3.5\times$ speedup over memory-efficient SDPA and $1.97$--$2.27\times$ on BERT; on Jetson TX2, ELSA achieves $1.5$--$1.6\times$ over Math (64--900 tokens), with $17.8$--$20.2\%$ throughput gains under LLaMA-13B offloading at $\ge$32K. In FP16, ELSA approaches hardware-fused baselines at long sequences while retaining full FP32 capability, offering a unified kernel for high-precision inference across platforms. Our code and implementation are available at https://github.com/ming053l/ELSA.

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

↑