GTFormer: A Syntax-Free Graph Network Alternative to Transformers for 8192 Length Extrapolation in Linear Time
Organizations: Middlesex University, Department of Computer Science The Burroughs, Hendon, London NW4 4BT, UK.
Abstract
Self-attention mechanisms have established the Transformer as the dominant backbone across natural language processing, source code intelligence, and automated theorem proving. However, all-to-all pairwise token comparison enforces a quadratic compute and memory barrier alongside severe softmax attention dilution as sequence length scales beyond the training horizon. Inspired by recent advances in algebraic graph learning (WPNet), this work introduces GTFormer, a syntax-free hierarchical Graph Neural Network (GNN) that replaces flat self-attention for general long-context sequence modeling. GTFormer organizes raw token streams into a bounded-degree hierarchy combining a balanced binary reduction tree ( depth), horizontal boundary-bridging shift edges, random expander shortcuts, multi-channel convex highway gating, and a top-down broadcast pass. Across eight long-context code, log, and multi-hop retrieval benchmarks trained exclusively on sequences of length , GTFormer extrapolates zero-shot to () on a single commodity GPU in linear memory, maintaining near-perfect accuracy where standard and RoPE Transformers suffer from out-of-distribution attention collapse and out-of-memory exhaustion.
Figures & tables
| Task Name | Input Token Sequence ( ) | Event Progression / Semantics | Target Class |
|---|---|---|---|
| override_qa | [42, 203, 118, 207, 12, 201, 88, 206, 91, 155, 202, 33, 200, 77, 94, 18] | . Final state: | 25 |
| unaligned_kv | [42, 118, 12, 200 , 205 , 88, 201 , 203 , 91, 155, 202 , 206 , 33, 200 , 204 , 77] | Odd-boundary pairs: . Final state: | 19 |
| pointer_hop_triple | [14, 213 , 83, 212 , 90, 214 , 111, 200 , 211 , 49, 201 , 208 , 170, 202 , 210 , 88] | , , ; Dereference , , final values = [0, 3, 2] | 14 |
| intrusion_fsm | [81, 203 , 45, 207 , 19, 250 , 99, 110, 202 , 130, 14, 66, 92, 140, 50, 12] | Final state: | 32 |
| code_scope_shadow | [ 202 , 41, 260 , 12, 203 , 89, 261 , 73, 99, 102, 18, 45, 160, 11, 82, 39] | Global revert to 2 Final state: [2,0,0] | 32 |
| multi_needle_rag | [18, 201 , 207 , 44, 210 , 92, 200 , 206 , 11, 145, 202 , 209 , 67, 83, 104, 5] | Query ; Bindings: Retrieved slots: | 7 |
| Model Variant | Topology | Local Shift | Expander | Convex Gate | Top-Down | Primary Role / Ablation Target |
| ( use_local_shift ) | ( use_expander ) | ( use_convex_gate ) | ( use_top_down ) | |||
| GTFormer_Bidirectional | Hierarchical | ✓ | ✓ | ✓ | ✓ | Full proposed architecture |
| GTFormer_BottomUp | Hierarchical | ✓ | ✓ | ✓ | ✗ | Feed-forward root readout only |
| GTFormer_NoExpander | Hierarchical | ✓ | ✗ | ✓ | ✓ | Ablates horizontal peer shortcuts ( ) |
| Pure_Binary_Tree | Hierarchical | ✗ | ✗ | ✓ | ✓ | No horizontal edges; tests odd-index splitting |
| Unbounded_Tree_MLP | Hierarchical | ✓ | ✓ | ✗ | ✓ | Unconstrained MLP merge; tests depth drift |
| Architecture | Time | Memory | Graph | Max | Odd-Split | 2-Hop Ptr |
|---|---|---|---|---|---|---|
| Diam. | Fan-In | Safe | Safe | |||
| Flat Transformer (Sin / RoPE) | Yes | Yes (ID) | ||||
| Pure Binary Tree-GNN | No | No | ||||
| Unbounded Tree-MLP | Yes | No | ||||
| GraphTree (Bottom-Up) | Yes | Partial | ||||
| GraphTree (Bidirectional) | Yes | Yes ( ) |
| Architecture | (ID) | (ID) | (ID) | |||
|---|---|---|---|---|---|---|
| GraphTree (Bidirectional: Up + Down) | ||||||
| GraphTree (Bottom-Up + Shortcuts) | ||||||
| GraphTree (Local Shift, No Expander) | ||||||
| Pure Binary Tree-GNN (No Shortcuts) | ||||||
| Unbounded Tree-GNN (No Convex Gate) | ||||||
| Flat Transformer (Sinusoidal) | OOM |
| Architecture | ||||||
|---|---|---|---|---|---|---|
| GraphTree (Local Shift, No Expander) | 31 MB | 64 MB | 108 MB | 196 MB | 373 MB | 725 MB |
| GraphTree (Bottom-Up + Shortcuts) | 32 MB | 65 MB | 109 MB | 197 MB | 373 MB | 726 MB |
| GraphTree (Bidirectional: Up + Down) | 34 MB | 66 MB | 111 MB | 199 MB | 375 MB | 728 MB |
| Pure Binary Tree-GNN | 24 MB | 36 MB | 54 MB | 88 MB | 156 MB | 292 MB |
| Unbounded Tree-GNN | 32 MB | 64 MB | 109 MB | 197 MB | 373 MB | 726 MB |
| Flat Transformer (Sinusoidal) | 27 MB | 45 MB | 69 MB | 117 MB | 213 MB | OOM |
| Architecture | ||||||
|---|---|---|---|---|---|---|
| GraphTree (Local Shift, No Expander) | 0.17 ms | 0.23 ms | 0.29 ms | 0.38 ms | 1.12 ms | 3.65 ms |
| GraphTree (Bottom-Up + Shortcuts) | 0.24 ms | 0.34 ms | 0.40 ms | 0.51 ms | 1.57 ms | 5.38 ms |
| GraphTree (Bidirectional: Up + Down) | 0.34 ms | 0.42 ms | 0.49 ms | 0.60 ms | 1.69 ms | 5.57 ms |
| Pure Binary Tree-GNN | 0.16 ms | 0.19 ms | 0.21 ms | 0.30 ms | 0.75 ms | 2.33 ms |
| Unbounded Tree-GNN | 0.12 ms | 0.17 ms | 0.21 ms | 0.29 ms | 0.89 ms | 2.79 ms |
| Flat Transformer (Sinusoidal) | 0.13 ms | 0.12 ms | 0.17 ms | 0.36 ms | 2.10 ms | OOM |
Appendix figures & tables16 assets
Supplementary material from the paper’s appendix.
Appendix
| Architecture | (ID) | (ID) | (ID) | (OOD) | (OOD) | (OOD) |
|---|---|---|---|---|---|---|
| GraphTree (Bidirectional: Up + Down) | ||||||
| GraphTree (Bottom-Up + Shortcuts) | ||||||
| GraphTree (Local Shift, No Expander) | ||||||
| Pure Binary Tree-GNN (No Shortcuts) | ||||||
| Unbounded Tree-GNN (No Convex Gate) | ||||||
| Flat Transformer (Sinusoidal) | OOM |
| Architecture | ||||||
| GraphTree (Bidirectional: Up + Down) | ||||||
| GraphTree (Bottom-Up + Shortcuts) | ||||||
| GraphTree (Local Shift, No Expander) | ||||||
| Pure Binary Tree-GNN (No Shortcuts) | ||||||
| Unbounded Tree-GNN (No Convex Gate) | ||||||
| Flat Transformer (Sinusoidal) | OOM | OOM | OOM | OOM | OOM | OOM |
| Architecture | (ID) | (ID) | (ID) | (OOD) | (OOD) | (OOD) |
|---|---|---|---|---|---|---|
| GraphTree (Bidirectional: Up + Down) | ||||||
| GraphTree (Bottom-Up + Shortcuts) | ||||||
| GraphTree (Local Shift, No Expander) | ||||||
| Pure Binary Tree-GNN (No Shortcuts) | ||||||
| Unbounded Tree-GNN (No Convex Gate) | ||||||
| Flat Transformer (Sinusoidal) | OOM |
| Architecture | ||||||
|---|---|---|---|---|---|---|
| GraphTree (Bidirectional: Up + Down) | ||||||
| GraphTree (Bottom-Up + Shortcuts) | ||||||
| GraphTree (Local Shift, No Expander) | ||||||
| Pure Binary Tree-GNN (No Shortcuts) | ||||||
| Unbounded Tree-GNN (No Convex Gate) | ||||||
| Flat Transformer (Sinusoidal) | OOM | OOM | OOM | OOM | OOM | OOM |
| Architecture | (ID) | (ID) | (ID) | (OOD) | (OOD) | (OOD) |
|---|---|---|---|---|---|---|
| GraphTree (Bidirectional: Up + Down) | ||||||
| GraphTree (Bottom-Up + Shortcuts) | ||||||
| GraphTree (Local Shift, No Expander) | ||||||
| Pure Binary Tree-GNN (No Shortcuts) | ||||||
| Unbounded Tree-GNN (No Convex Gate) | ||||||
| Flat Transformer (Sinusoidal) | OOM |
| Architecture | ||||||
| GraphTree (Bidirectional: Up + Down) | ||||||
| GraphTree (Bottom-Up + Shortcuts) | ||||||
| GraphTree (Local Shift, No Expander) | ||||||
| Pure Binary Tree-GNN (No Shortcuts) | ||||||
| Unbounded Tree-GNN (No Convex Gate) | ||||||
| Flat Transformer (Sinusoidal) | OOM | OOM | OOM | OOM | OOM | OOM |
| Architecture | (ID) | (ID) | (ID) | (OOD) | (OOD) | (OOD) |
|---|---|---|---|---|---|---|
| GraphTree (Bidirectional: Up + Down) | ||||||
| GraphTree (Bottom-Up + Shortcuts) | ||||||
| GraphTree (Local Shift, No Expander) | ||||||
| Pure Binary Tree-GNN (No Shortcuts) | ||||||
| Unbounded Tree-GNN (No Convex Gate) | ||||||
| Flat Transformer (Sinusoidal) | OOM |
| Architecture | ||||||
| GraphTree (Bidirectional: Up + Down) | ||||||
| GraphTree (Bottom-Up + Shortcuts) | ||||||
| GraphTree (Local Shift, No Expander) | ||||||
| Pure Binary Tree-GNN (No Shortcuts) | ||||||
| Unbounded Tree-GNN (No Convex Gate) | ||||||
| Flat Transformer (Sinusoidal) | OOM | OOM | OOM | OOM | OOM | OOM |
| Architecture | (ID) | (ID) | (ID) | (OOD) | (OOD) | (OOD) |
|---|---|---|---|---|---|---|
| GraphTree (Bidirectional: Up + Down) | ||||||
| GraphTree (Bottom-Up + Shortcuts) | ||||||
| GraphTree (Local Shift, No Expander) | ||||||
| Pure Binary Tree-GNN (No Shortcuts) | ||||||
| Unbounded Tree-GNN (No Convex Gate) | ||||||
| Flat Transformer (Sinusoidal) | OOM |
| Architecture | ||||||
| GraphTree (Bidirectional: Up + Down) | ||||||
| GraphTree (Bottom-Up + Shortcuts) | ||||||
| GraphTree (Local Shift, No Expander) | ||||||
| Pure Binary Tree-GNN (No Shortcuts) | ||||||
| Unbounded Tree-GNN (No Convex Gate) | ||||||
| Flat Transformer (Sinusoidal) | OOM | OOM | OOM | OOM | OOM | OOM |
| Architecture | (ID) | (ID) | (ID) | (OOD) | (OOD) | (OOD) |
|---|---|---|---|---|---|---|
| GraphTree (Bidirectional: Up + Down) | ||||||
| GraphTree (Bottom-Up + Shortcuts) | ||||||
| GraphTree (Local Shift, No Expander) | ||||||
| Pure Binary Tree-GNN (No Shortcuts) | ||||||
| Unbounded Tree-GNN (No Convex Gate) | ||||||
| Flat Transformer (Sinusoidal) | OOM |
| Architecture | ||||||
| GraphTree (Bidirectional: Up + Down) | ||||||
| GraphTree (Bottom-Up + Shortcuts) | ||||||
| GraphTree (Local Shift, No Expander) | ||||||
| Pure Binary Tree-GNN (No Shortcuts) | ||||||
| Unbounded Tree-GNN (No Convex Gate) | ||||||
| Flat Transformer (Sinusoidal) | OOM | OOM | OOM | OOM | OOM | OOM |
| Architecture | (ID) | (ID) | (ID) | (OOD) | (OOD) | (OOD) |
|---|---|---|---|---|---|---|
| GraphTree (Bidirectional: Up + Down) | ||||||
| GraphTree (Bottom-Up + Shortcuts) | ||||||
| GraphTree (Local Shift, No Expander) | ||||||
| Pure Binary Tree-GNN (No Shortcuts) | ||||||
| Unbounded Tree-GNN (No Convex Gate) | ||||||
| Flat Transformer (Sinusoidal) | OOM |
| Architecture | ||||||
|---|---|---|---|---|---|---|
| GraphTree (Bidirectional: Up + Down) | ||||||
| GraphTree (Bottom-Up + Shortcuts) | ||||||
| GraphTree (Local Shift, No Expander) | ||||||
| Pure Binary Tree-GNN (No Shortcuts) | ||||||
| Unbounded Tree-GNN (No Convex Gate) | ||||||
| Flat Transformer (Sinusoidal) | OOM | OOM | OOM | OOM | OOM | OOM |
| Architecture | (ID) | (ID) | (ID) | (OOD) | (OOD) | (OOD) |
|---|---|---|---|---|---|---|
| GraphTree (Bidirectional: Up + Down) | ||||||
| GraphTree (Bottom-Up + Shortcuts) | ||||||
| GraphTree (Local Shift, No Expander) | ||||||
| Pure Binary Tree-GNN (No Shortcuts) | ||||||
| Unbounded Tree-GNN (No Convex Gate) | ||||||
| Flat Transformer (Sinusoidal) | OOM |
| Architecture | ||||||
| GraphTree (Bidirectional: Up + Down) | ||||||
| GraphTree (Bottom-Up + Shortcuts) | ||||||
| GraphTree (Local Shift, No Expander) | ||||||
| Pure Binary Tree-GNN (No Shortcuts) | ||||||
| Unbounded Tree-GNN (No Convex Gate) | ||||||
| Flat Transformer (Sinusoidal) | OOM | OOM | OOM | OOM | OOM | OOM |
Long-Context Modeling
Long-context modeling studies how AI systems process, retrieve, and reason over sequences that exceed ordinary context windows.
See all 136 papers