Fast and Exact Relative-Position Attention via Structure-Aware Kernels

Delyan Boychev, Ivo Petrov, Dimitar I. Dimitrov

INSAIT, Sofia University

Published October 31, 2026 · on the feed November 9, 2026 · ▲ 22 · arXiv 2611.01182

Model architecture No code arXiv ↗Hugging Face ↗

The abstract

Relative-position attention mechanisms offer compelling alternatives to RoPE across various transformer architectures, delivering superior performance in domains such as audio. These mechanisms typically modify attention scores by adding content-position or bias-position terms. Unlike RoPE, which encodes position via per-token rotations directly on the queries and keys, relative-position terms generally require pairwise offset-dependent computation or lookups, complicating their integration into fused attention kernels and introducing severe memory, bandwidth, and compute overheads as sequences scale. To address this bottleneck, we propose an exact attention algorithm that incorporates additive relative-position terms into FlashAttention-style tiled computation. Our method (1) uses offset-aware tiling to avoid redundant indexing and memory accesses, (2) computes only the necessary key/query-relation products and reuses them across token pairs in both forward and backward passes, and (3) uses offset-based gradient sharding and aggregation, eliminating atomic contention. We provide a unified, efficient Triton implementation across diverse relative-position attention mechanisms and evaluate it against naive and specialized implementations. For 8K-token sequences, our method speeds up the forward (backward) pass by 1.8-6.4times (2.0-21times) and reduces peak memory up to 2.9-128times (1.4-54times) over the strongest baseline for each mechanism, enabling long-context end-to-end transcription that is 1.8times faster and uses 2.4times less memory. Our method thus provides a drop-in, hardware-efficient solution for scaling relative-position attention transformers.

The Brief

2:24

A short podcast summary of the paper. Written and voiced by AI.

Transcript

Fast and Exact Relative-Position Attention via Structure-Aware Kernels. By Delyan Boychev and two others, from INSAIT, Sofia University. Published on the thirty-first of October.

Relative-position attention mechanisms are a compelling alternative to RoPE across various transformer architectures, and in domains such as audio they deliver superior performance. They typically work by adding terms to the attention scores, either content-position or bias-position terms. That is where the trouble starts. RoPE encodes position with a rotation applied to each token, directly on the queries and keys. Relative-position terms instead generally need computation or lookups that depend on the offset between every pair of tokens. That makes them hard to integrate into fused attention kernels, and as sequences grow it brings severe overheads in memory, in bandwidth, and in compute.

The authors propose an exact attention algorithm that brings additive relative-position terms inside FlashAttention-style tiled computation. Nothing is approximated: the attention computed is the same, and the gain comes from exploiting the structure of the offsets.

Three ingredients do the work. First, offset-aware tiling, which avoids redundant indexing and redundant memory accesses. Second, the method computes only the key and query relation products that are actually needed, and reuses them across token pairs, in both the forward and the backward pass. Third, the gradients are sharded and aggregated by offset, which eliminates atomic contention. All of this comes as a single, unified implementation in Triton that covers diverse relative-position attention mechanisms, evaluated against both naive and specialized implementations.

The headline figures are for sequences of eight thousand tokens, measured against the strongest baseline for each mechanism. The forward pass speeds up by between one point eight and six point four times. The backward pass speeds up by between two and twenty-one times.

Peak memory falls as well. In the forward pass the reduction reaches between two point nine and one hundred and twenty-eight times. In the backward pass it reaches between one point four and fifty-four times. Carried through to a full system, this enables long-context end-to-end transcription that runs one point eight times faster and uses two point four times less memory.

Relative-position attention had a quality argument in its favour and an engineering argument against it. This work goes after the engineering side directly, without changing the mathematics, so that these mechanisms become a drop-in, hardware-efficient option for scaling transformers to long contexts.

More with an account

Listen to every day’s papers

Daily playlists, deep dives, quests for the papers, and quizzes on their key terms.

Join free
KipQuest: the day’s AI research, as podcasts and quests. All papers Android app Privacy Contact Episodes are written and voiced by AI from each paper. Summaries can contain mistakes: the paper is the source.