Equipping Transformer with Random-Access Reading for Long-Context Understanding
Chenghao Yang, Zi Yang, Nan Hua
TL;DR
The paper tackles the challenge of long-context understanding in transformers by addressing the quadratic cost of self-attention and length extrapolation from short pretraining. It introduces Random-Access Reading, a framework that uses a data server and a simple, confidence-driven skip policy to skip token blocks during reading, with an optional memory module (Attendre) to preserve coherence across skipped segments. The approach is validated through pretraining, finetuning, and long-context question answering on tasks like the C4 corpus and TriviaQA, demonstrating improved efficiency and performance, including near sublinear complexity when memory is included. These results imply that dynamic, query-driven reading strategies can substantially reduce computation for long-context tasks while enabling effective adaptation of short-context models to long contexts, with practical impact on interactive LLM systems and long-document understanding.
Abstract
Long-context modeling presents a significant challenge for transformer-based large language models (LLMs) due to the quadratic complexity of the self-attention mechanism and issues with length extrapolation caused by pretraining exclusively on short inputs. Existing methods address computational complexity through techniques such as text chunking, the kernel approach, and structured attention, and tackle length extrapolation problems through positional encoding, continued pretraining, and data engineering. These approaches typically require $\textbf{sequential access}$ to the document, necessitating reading from the first to the last token. We contend that for goal-oriented reading of long documents, such sequential access is not necessary, and a proficiently trained model can learn to omit hundreds of less pertinent tokens. Inspired by human reading behaviors and existing empirical observations, we propose $\textbf{random access}$, a novel reading strategy that enables transformers to efficiently process long documents without examining every token. Experimental results from pretraining, fine-tuning, and inference phases validate the efficacy of our method.
