Standard Transformers face a fundamental scaling bottleneck: the self-attention mechanism is quadratic, $O(N^2)$, in relation to sequence length. While "Linear Transformers" solve this by using the associative property of matrix multiplication to achieve $O(N)$ complexity, they historically struggle with Relative Positional Encoding (RPE).
Traditional RPE methods, which allow a model to understand the distance between tokens rather than just their absolute coordinates, typically require adding a bias directly to the $N \times N$ attention matrix. Because linear models avoid ever calculating this full matrix, they were often forced to fall back on less effective absolute position embeddings.
A new wave of research has bridged this gap by developing decomposable transformations—mathematical operations applied directly to individual queries and keys that simulate relative distance without breaking the linear scaling of the model.
The Linear Attention Constraint
To understand why this is difficult, consider the core trick of linear attention. In standard attention, we compute $Softmax(QK^T)V$. In linear attention, we replace the softmax with a kernel function $\phi$, allowing us to rewrite the operation as: $$( \phi(Q) \phi(K)^T ) V = \phi(Q) ( \phi(K)^T V )$$ By computing $(\phi(K)^T V)$ first, we reduce the complexity from $O(N^2)$ to $O(N)$.
However, if you want to add a relative bias $B_{i,j}$ (representing the distance between token $i$ and $j$) to the attention score, you get $\phi(q_i)\phi(k_j)^T + B_{i,j}$. This $B_{i,j}$ term cannot be easily factored out of the summation, forcing the model back into quadratic territory.
Solution: Unitary and Rotary Transformations
The breakthrough, as articulated in Linearized Relative Positional Encoding by Zhen Qin and colleagues, is to move the positional information from an additive bias on the result to a multiplicative transformation on the inputs.
If we apply a transformation matrix $M$ to our queries and keys such that the transformation depends on the position $i$, the attention score becomes $(M_i q_i)^T (M_j k_j)$. For this to represent relative distance, the result must only depend on $i-j$. This is achieved if $M$ is a unitary or orthogonal matrix.
This mathematical framework generalizes several specific techniques:
- Rotary Embeddings (RoPE): Used in models like MLM-FG and RecGRELA by Juntao Hu, RoPE treats pairs of features as coordinates in a 2D plane and rotates them by an angle proportional to their position. The relative distance is captured by the difference in rotation angles.
- Permutations: Peng Chen introduced PermuteFormer, which uses position-dependent permutations of feature dimensions. Since permutations are a subset of orthogonal transformations, they preserve the inner product structure while encoding order with negligible overhead.
Beyond Sequences: Graphs and Stochastic Processes
The intuition of "position as transformation" is now being extended to non-linear data structures. In Rotary Position Encodings for Graphs, Isaac Reid and his team developed WIRE, which uses the spectral coordinates of a graph to determine rotation angles. This allows a Graph Transformer to remain linear in complexity while being sensitive to the graph's structural topology.
Alternatively, Antoine Liutkus and Ondřej Cífka proposed Stochastic Positional Encoding (SPE) in Relative Positional Encoding for Transformers with Linear Complexity. Instead of deterministic rotations, SPE frames the problem as a cross-covariance between random processes. By applying these stochastic transformations to queries and keys, the model learns to "sense" distance through the correlation of these random signals, maintaining the $O(N)$ efficiency required for massive sequences.
Why It Works
The common thread across these papers—from LMEC's learnable multiplicative embeddings to Zhen Qin's unitary framework—is the decoupling of content and space.
By transforming the query and key vectors before they interact, these methods ensure that the spatial relationship is baked into the vectors themselves. This preserves the associative property of the underlying linear attention mechanism, allowing the model to "see" the relative structure of a sequence or graph without ever having to build the expensive $N \times N$ map of how every token relates to every other.