arXiv:2605.09472cs.LGcs.DS2026-05

用局部敏感哈希解释注意力中的位置偏置,实现高效长序列建模。

Positional LSH: Binary Block Matrix Approximation for Attention with Linear Biases

论文配图:Positional LSH: Binary Block Matrix Approximation for Attention with Linear Biases
图 1 · 摘自论文原文
  • 基于位置LSH构造二值掩码,推导出线性偏置的数学本质
  • 采样掩码可近似原注意力,误差有理论保证且计算接近线性
  • 适合需要长上下文、追求高效推理的大模型应用

Transformer中的位置编码通常通过位置嵌入、注意力掩码或偏置项实现,但这些机制间的理论联系尚不明确。本文从局部敏感哈希(LSH)视角研究带有线性偏置(ALiBi)的注意力机制,证明其偏置矩阵是某种‘位置LSH’方案产生的连续分块对角二值掩码的期望。从该方案中采样的掩码经验均值,在高概率下对谱范数和最大范数提供逼近保证,且块大小有界。这一结构定理表明:在高概率下,采样掩码能统一逼近所有查询-键-值输入的ALiBi注意力输出,且可在近线性时间内完成,将长序列ALiBi注意力转化为一组随机化的短序列常规注意力操作。该结果在大型语言模型实验中得到验证,为位置偏置、掩码与位置嵌入提供了统一形式框架,并提出一种高效实现路径。

原文摘要 · Abstract (English)

Positional encoding in transformers is commonly implemented through positional embeddings, attention masks, or bias terms, but formal connections between these mechanisms remain limited. We study attention with positional bias through the lens of locality-sensitive hashing (LSH), focusing on Attention with Linear Biases (ALiBi). We show that the ALiBi bias matrix is the expectation of contiguous block-diagonal binary masks induced by a ``positional LSH'' scheme. The empirical mean of masks sampled from this scheme yields spectral norm and max-norm approximation guarantees with bounded block sizes with high probability. This structural theorem implies a uniform approximation theorem for ALiBi-biased attention: with high probability over the sampled masks, the approximate attention output is accurate simultaneously for all query-key-value inputs and can be computed in near-linear time in the context length, reducing long-context ALiBi to a collection of randomized short-context regular (positionally unbiased) attention operations. Conceptually, this connects positional bias, masks, and positional embeddings in a single formal framework and suggests an approach to efficient ALiBi-biased attention. Experiments on large language models validate our theoretical findings.

注意力机制位置编码高效计算线性偏置

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。