Long Sequence Modeling with Attention Tensorization: From Sequence to Tensor Learning
Aosong Feng, Rex Ying, Leandros Tassiulas
TL;DR
Long-context processing in LLMs is challenged by quadratic attention and fixed training context lengths. The authors introduce Tensorized Attention, which folds sequences into a higher-order tensor and performs attention along each dimension, enabling exponential length extrapolation and efficient computation with a Triton kernel. They formalize a tensor-space attention framework, analyze its low-rank properties via CP decomposition, and demonstrate substantial empirical gains, including up to an $11\times$ speedup over full attention and improved perplexity on long-context benchmarks, by continuing pretraining of OpenLlama-3B, Mistral-7B, and Llama-8B to context lengths of $32{,}768$ and beyond to $128{,}k$. The approach shows strong performance on downstream tasks that benefit from longer context and provides a practical path to scalable long-sequence modeling for pretrained LLMs and beyond. Overall, tensorized attention offers a principled, efficient alternative to full attention for long sequences, with potential applicability to time-series and other sequence-modelling domains.
Abstract
As the demand for processing extended textual data grows, the ability to handle long-range dependencies and maintain computational efficiency is more critical than ever. One of the key issues for long-sequence modeling using attention-based model is the mismatch between the limited-range modeling power of full attention and the long-range token dependency in the input sequence. In this work, we propose to scale up the attention receptive field by tensorizing long input sequences into compact tensor representations followed by attention on each transformed dimension. The resulting Tensorized Attention can be adopted as efficient transformer backbones to extend input context length with improved memory and time efficiency. We show that the proposed attention tensorization encodes token dependencies as a multi-hop attention process, and is equivalent to Kronecker decomposition of full attention. Extensive experiments show that tensorized attention can be used to adapt pretrained LLMs with improved efficiency. Notably, Llama-8B with tensorization is trained under 32,768 context length and can steadily extrapolate to 128k length during inference with $11\times$ speedup, compared to full attention with FlashAttention-2.
