Tree Rotary Positional Encoding for Extreme Length Extrapolation from Scratch

Qiuwu Chen, Ziteng Huang, Shuhai Zhang, Zimo Liu, Linxiao Li, Ying Sun, Yuchen Li, Yifan Zhang, Yaofo Chen, Mingkui TanNeurIPS 2026

TL;DR

Large language models usually fall apart when asked to read documents much longer than the snippets they saw during training, largely because they track word order using a single, endlessly climbing number. By replacing that single counter with a multi-digit, odometer-style tree coordinate system, Tree Rotary Positional Encoding (TPE) lets models extrapolate to dramatically longer contexts—up to $64\times$ their training window—without losing their place or slowing down.

What Problem Does This Paper Address?

Transformers are naturally blind to word order; without help, "the dog bit the man" looks identical to "the man bit the dog." Most modern LLMs solve this using Rotary Positional Encoding (RoPE), which encodes a token's position $m$ by rotating its feature vectors at various speeds (frequencies), much like the hands of a clock.

Because training on massive documents is expensive, we train on short sequences (say, 512 tokens) and hope the model generalizes to long ones (32,000 tokens). Here, RoPE hits a structural wall: all its dimensions are tied to one global scalar index. During short-context training, the "hour hand" (low-frequency dimensions) barely budges, leaving those features under-trained. Then, during long-context inference, the single index climbs into uncharted territory, pushing every dimension into unseen rotation angles and scrambling attention scores.

Methods

Instead of counting positions on an infinite number line, the authors treat position like a mechanical odometer—or a path down a tree—proposing two coupled techniques for training from scratch:

Figure 1: Comparisons between single-index rotary positional encoding (RoPE) and our Tree Rotary Positional Encoding (TPE). RoPE uses a single absolute index p, limiting the representation range within the training context. TPE decomposes positions into multiple components (e.g., p(0),p(1)) across scales and composes them to form position representations. This yields a large position space, enabling long-context positions to be represented by combining a small set of learned components.
  1. Tree Rotary Positional Encoding (TPE): TPE splits a token's feature vector into $L$ segments and decomposes its absolute position $p$ into $L$ digits in base-$B$ ($p^{(l)} = \lfloor p / B^l \rfloor \bmod B$). For example, with $L=2$ levels and radix $B=512$, position $600$ becomes $(88, 1)$. Each vector segment is rotated by its corresponding bounded digit, weighted by a scale factor $\alpha^l$ so coarse levels evolve appropriately alongside fine ones. Instead of extrapolating one giant number, long positions are built by recombining small, familiar digits $[0, B)$.
  2. Offset-based Positional Training (OPT): If you only ever train on positions $0$ to $511$, the "hundreds" digit in base-512 stays stuck at $0$. Inspired by position-simulation methods like PoSE, OPT splits each short training sequence of length $T$ in half: the first chunk gets normal indices $[0, T/2 - 1]$, and the second jumps by a random offset $\Delta$ up to a maximum range (e.g., 256K). This exposes the model to diverse combinations of coarse and fine digits without paying the compute cost of long-sequence training.
Figure 2: Illustration of offset-based positional training (OPT). (a) In standard training, absolute positions are assigned sequentially, thus many multi-scale index combinations in TPE remain under- trained (uncovered). (b) Our OPT splits each training sequence into two segments and applies a random offset to the second segment. As the offset varies across training samples, the model is exposed to diverse cross-scale positional combinations.For illustration, we use a toy radix B = 32.

Datasets

  • Pretraining: Models (60M, 0.3B, and 1.2B parameters using the OLMo architecture) were trained from scratch on a 10B-token subset of C4-en at a 512-token context length (plus an ablation at 2,048 tokens).
  • Evaluation: Next-token perplexity on long sequences (up to 32K tokens) and synthetic Passkey Retrieval (finding a hidden key in long text up to 32K tokens). No new benchmarks were introduced.

Key Insights and Ideas

  • Combinatorial coverage beats linear extrapolation: Rather than stretching continuous frequencies, TPE turns length extrapolation into compositional generalization. With $L=2$ and $B=512$, learning two sets of 512 states unlocks $512^2 = 262,144$ distinct positions.
  • Giving up exact shift-invariance actually helps: Standard RoPE guarantees that attention depends strictly on exact relative distance ($m - n$). TPE breaks this exact symmetry because digit rollovers depend on block boundaries. Surprisingly, the authors prove (Theorem 3) that this increases the variance of pre-softmax attention scores across distances—preventing attention from diluting into a flat soup over long contexts.
  • Shallow trees win: In ablations, a 2-level tree ($L=2$) beat deeper hierarchies ($L=4$ or $8$), which over-fragmented the feature dimensions and collapsed at long lengths.

Key Results

Trained at just 512 tokens and tested out to 32K tokens ($64\times$ extrapolation) on the 1.2B model:

  • Perplexity: TPE drops 32K perplexity from 4532.2 (RoPE) and 610.4 (FoPE, a strong recent baseline) down to 150.0 (149.96).
  • Passkey Retrieval: While RoPE and ALiBi collapse to ~0% accuracy past 1,024 tokens, TPE-1.2B achieves 58.4% at 8K and 38.1% at 16K. When pretrained at 2,048 tokens, TPE-0.3B hits 62.1% accuracy at 32K (vs. 0.0% for RoPE and FoPE).
  • Efficiency: TPE matches RoPE's exact memory footprint (6.6 GB at 8K on 1.2B) and inference speed (361.1 ms vs. 360.1 ms).
  • OPT alone isn't the magic: Applying OPT to RoPE or FoPE still yields 0.0% retrieval accuracy at 8K–16K, confirming the tree structure itself drives the gains.
Figure 3: Passkey retrieval accuracy (%) of different methods on 60M, 0.3B, and 1.2B models.

Limitations and Future Work

  • Designed for training from scratch: TPE alters the fundamental geometry of the positional subspaces, meaning it cannot be trivially dropped into existing RoPE-pretrained checkpoints without training.
  • Breaking shift invariance: TPE sacrifices exact translation invariance across radix reset boundaries.
  • Degradation at extreme retrieval: While vastly outperforming baselines, Passkey retrieval accuracy still noticeably decays at $16\times$–$32\times$ extrapolation (e.g., dropping to 38.1% at 16K on the 512-trained 1.2B model, and collapsing earlier on the tiny 60M model), and deeper trees ($L > 2$) suffer from instability. Explicit future work directions are not discussed in the main text.

Summary updated

Abstract

Large language models rely on positional representations for long context modeling, yet are trained on short sequences and evaluated at much longer lengths. Bridging this gap requires positional encodings remaining distinguishable at large distances while generalizing beyond the training length. In this paper, we identify a structural limitation of existing rotary-based positional encodings: all positional dimensions are controlled by a single global index, which couples training-time positional variation with long-range extrapolation. To address this, we propose Tree Rotary Positional Encoding (TPE), a structured multi-scale positional encoding designed for training from scratch that represents absolute positions through compositions of different components, avoiding single-index extrapolation. We further devise an Offset-based Positional Training (OPT) strategy to improve learning interactions across TPE components, enabling better generalization to longer contexts. We theoretically analyze how TPE’s multi-scale decomposition enables effective com-binatorial position coverage. On a 1.2B model trained from scratch at length 512, TPE reduces 32K perplexity from 4532.21 (RoPE) to 149.96, with comparable inference efficiency. This 64× extrapolation characterizes next-token likelihood; separately, Passkey retrieval accuracy is 58.4% at 8K and 38.1% at 16K.
BibTeX
@inproceedings{chen2026tree,
  author = {Qiuwu Chen and Ziteng Huang and Shuhai Zhang and Zimo Liu and Linxiao Li and Ying Sun and Yuchen Li and Yifan Zhang and Yaofo Chen and Mingkui Tan},
  title = {{Tree Rotary Positional Encoding for Extreme Length Extrapolation from Scratch}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=1NNDe1C284},
}
Figure