Papers
Topics
Authors
Recent
Search
2000 character limit reached

Hyperbolic Relative Bias (HyPE) in Transformers

Updated 31 January 2026
  • Hyperbolic Relative Bias (HyPE) is a relative positional encoding method that uses hyperbolic functions to dynamically inject biases into Transformer attention mechanisms.
  • It integrates auxiliary hyperbolic embeddings into queries and keys, ensuring memory efficiency and compatibility with advanced kernels like FlashAttention-2.
  • Its analytic formulation allows seamless long-context extrapolation, approximating linear biases such as ALiBi and generalizing beyond pretraining lengths.

Hyperbolic Relative Bias (HyPE) is a relative positional encoding scheme for Transformer-based architectures that leverages hyperbolic functions to encode token relationships, enabling efficient context-length extrapolation and seamless integration with advanced attention mechanisms. Unlike traditional methods for sequential order imposition—such as absolute positional embeddings or dense relative-bias masks—HyPE introduces a fully differentiable, memory-efficient formulation where the positional bias is indirectly injected into the attention computation using hyperbolic embeddings. HyPE is compatible with state-of-the-art fused attention kernels, supports gradient propagation for all learnable parameters, and analytically approximates linear biases such as the ALiBi method, facilitating extrapolation well beyond pretraining context lengths (Angelotti, 2023).

1. Mathematical Formulation of Hyperbolic Bias

HyPE constructs a relative-position bias matrix BB parameterized by the sequence length LL and the hidden dimension dd of each attention head. The matrix is defined by

B=[Bi,j]0i,j<LwhereBi,j=τsinh(μ(ji))B = [B_{i,j}]_{0 \leq i,j < L} \quad \text{where} \quad B_{i,j} = -\tau\,\sinh(\mu\,(j-i))

with μR\mu \in \mathbb{R} as the slope and τ>0\tau > 0 as the amplitude. The hyperbolic identity

2sinh(x)=exex2\sinh(x) = e^{x} - e^{-x}

implies

Bi,j=τ2(eμ(ji)eμ(ji)).B_{i,j} = -\frac{\tau}{2}(e^{\mu(j-i)} - e^{-\mu(j-i)}).

This bias function translates relative token distances Δ=ji\Delta = j-i into soft positional biases, which can be tuned by the μ\mu and LL0 hyperparameters.

2. Integration into Transformer Attention

HyPE modifies the attention computation pipeline by introducing two hyperbolic embedding matrices per head,

LL1

with entries

LL2

for LL3. These embeddings are concatenated as additional channels to the usual query and key matrices,

LL4

The attention logits are then

LL5

where the bias LL6 arises via hyperbolic identity. The final output is computed as

LL7

and the explicit bias matrix LL8 is never materialized, ensuring efficient computation.

3. Computational Complexity and Memory Footprint

Standard relative-position bias approaches incur LL9 memory cost for storing a dense bias mask. HyPE requires only two dd0 side-channel matrices per attention head (dd1 scalars), or dd2 overall for dd3 heads. The runtime involves a single dd4 matrix multiplication per head and the usual dd5 cost, with no additional dd6 operations. The overall time complexity remains dd7 per head, and memory footprint for embeddings is dd8, matching standard Transformer attention efficiency.

4. Compatibility with FlashAttention-2 and Backpropagation

HyPE's bias injection via concatenation of auxiliary channels into dd9 and B=[Bi,j]0i,j<LwhereBi,j=τsinh(μ(ji))B = [B_{i,j}]_{0 \leq i,j < L} \quad \text{where} \quad B_{i,j} = -\tau\,\sinh(\mu\,(j-i))0 renders it fully compatible with FlashAttention-2's fused, IO-aware attention kernels. The two added channels are managed as ordinary feature dimensions and all gradients propagate through B=[Bi,j]0i,j<LwhereBi,j=τsinh(μ(ji))B = [B_{i,j}]_{0 \leq i,j < L} \quad \text{where} \quad B_{i,j} = -\tau\,\sinh(\mu\,(j-i))1 and B=[Bi,j]0i,j<LwhereBi,j=τsinh(μ(ji))B = [B_{i,j}]_{0 \leq i,j < L} \quad \text{where} \quad B_{i,j} = -\tau\,\sinh(\mu\,(j-i))2 under standard automatic differentiation. Any learnable parameters, such as per-head B=[Bi,j]0i,j<LwhereBi,j=τsinh(μ(ji))B = [B_{i,j}]_{0 \leq i,j < L} \quad \text{where} \quad B_{i,j} = -\tau\,\sinh(\mu\,(j-i))3 or amplitude B=[Bi,j]0i,j<LwhereBi,j=τsinh(μ(ji))B = [B_{i,j}]_{0 \leq i,j < L} \quad \text{where} \quad B_{i,j} = -\tau\,\sinh(\mu\,(j-i))4, are updated by the established backward pass without need for special handling or code modifications at the kernel level.

5. Hyperparameter Selection and ALiBi Approximation

The ALiBi method employs a linear bias B=[Bi,j]0i,j<LwhereBi,j=τsinh(μ(ji))B = [B_{i,j}]_{0 \leq i,j < L} \quad \text{where} \quad B_{i,j} = -\tau\,\sinh(\mu\,(j-i))5. For HyPE, the Taylor expansion

B=[Bi,j]0i,j<LwhereBi,j=τsinh(μ(ji))B = [B_{i,j}]_{0 \leq i,j < L} \quad \text{where} \quad B_{i,j} = -\tau\,\sinh(\mu\,(j-i))6

implies

B=[Bi,j]0i,j<LwhereBi,j=τsinh(μ(ji))B = [B_{i,j}]_{0 \leq i,j < L} \quad \text{where} \quad B_{i,j} = -\tau\,\sinh(\mu\,(j-i))7

Setting B=[Bi,j]0i,j<LwhereBi,j=τsinh(μ(ji))B = [B_{i,j}]_{0 \leq i,j < L} \quad \text{where} \quad B_{i,j} = -\tau\,\sinh(\mu\,(j-i))8 and B=[Bi,j]0i,j<LwhereBi,j=τsinh(μ(ji))B = [B_{i,j}]_{0 \leq i,j < L} \quad \text{where} \quad B_{i,j} = -\tau\,\sinh(\mu\,(j-i))9 yields

μR\mu \in \mathbb{R}0

so the cubic remainder is negligible for μR\mu \in \mathbb{R}1 if μR\mu \in \mathbb{R}2, where μR\mu \in \mathbb{R}3 is the context length for extrapolation. Promoting μR\mu \in \mathbb{R}4, or using per-head μR\mu \in \mathbb{R}5, enables fine control over overall bias magnitude during training.

6. Generalization Beyond Pretraining Lengths

HyPE supports input-length extrapolation due to its analytic design. With μR\mu \in \mathbb{R}6, the hyperbolic bias grows almost linearly up to μR\mu \in \mathbb{R}7 before saturating, preventing divergence. As HyPE relies on no fixed-size sinusoidal tables or learned absolute embeddings, it generalizes without modification to arbitrary sequence lengths at inference. The bound on approximation error to linear bias, derived from Taylor expansion, further supports its theoretical robustness. While large-scale empirical results are deferred, HyPE offers a compact, differentiable framework for positional bias injection, achieving extrapolation benefits analogous to ALiBi, trainability, and compatibility with advanced attention mechanisms at minimal memory and computational cost (Angelotti, 2023).

Definition Search Book Streamline Icon: https://streamlinehq.com
References (1)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Hyperbolic Relative Bias (HyPE).