Abstract
Training large language models (LLMs) on million-token sequences typically necessitates massive GPU clusters to accommodate activation memory. This paper presents Sequence Accumulation (SA) and its parallel extension SAPP, which exploit the recurrent properties of linear sequence models to enable training on virtually infinite context lengths with constant memory overhead. We demonstrate that SA allows a 1B parameter model to be trained on 1 million tokens on a single GPU, maintaining a fixed memory footprint without compromising model performance.
Introduction
While standard Transformers face $O(N^2)$ complexity challenges with long sequences, modern "linear" models—such as Mamba, RWKV, and Linear Attention—offer $O(N)$ scaling. However, training these models still encounters memory bottlenecks because intermediate activations must be stored for gradient calculation during the backward pass. For a sequence of 1 million tokens, even linear scaling eventually leads to Out-of-Memory (OOM) errors on single devices. Existing solutions like Sequence Parallelism (SP) or Context Parallelism (CP) mitigate this by distributing data across multiple GPUs, but they introduce significant communication overhead and require expensive hardware. This work addresses the challenge of training on extremely long sequences using minimal hardware without sacrificing efficiency.
Methodology: Sequence Accumulation (SA) and SAPP
The core innovation lies in the unified recurrence formulation shared by many modern linear models. The authors propose two primary techniques:
Sequence Accumulation (SA)
SA decomposes a massive sequence into smaller, fixed-length "sub-sequences" processed sequentially on a single GPU. Instead of storing activations for the entire sequence, SA only carries over a fixed-size "memory state" (a matrix whose size depends on the hidden dimension, not sequence length) between chunks. This ensures the memory footprint remains constant regardless of total sequence length.
Sequence Accumulation Pipeline Parallelism (SAPP)
To scale to larger models (e.g., 7B+ parameters), SA is integrated with Pipeline Parallelism. In SAPP, model layers are distributed across GPUs, and sub-sequences are pipelined through the devices. Unlike traditional sequence parallelism, SAPP avoids additional synchronization across the sequence dimension, maintaining high efficiency.
Experimental Evaluation
The methods were validated using The Pile (825 GB text dataset) for pre-training and evaluated on downstream benchmarks including PIQA, HellaSwag, WinoGrande, and ARC.
Key Results
Empirical results confirm the effectiveness of SA and SAPP:
- Constant Memory Usage: On a single A100 (80GB) GPU, SA maintained a flat memory usage of approximately 34GB for a 1B parameter model across context lengths from 2K to 1024K (1 million) tokens.
- Throughput and Scaling: As context length increases, throughput (tokens per second) remains stable or improves slightly as the relative overhead of the pipeline bubble decreases.
- Model Integrity: Models trained with SA/SAPP achieved downstream accuracy and loss metrics virtually identical to baseline models, proving that the chunking process does not degrade learning.
Discussion and Limitations
The "Recurrence Trick" allows for "infinite" context length in theory, limited only by numerical precision and compute time rather than VRAM. However, this technique is currently restricted to linear sequence models (e.g., Mamba2, RWKV-6, RetNet, GLA). It cannot be directly applied to standard Softmax Attention (e.g., GPT-4), which requires access to all previous keys and values. Additionally, while SA saves memory, it does not reduce the total FLOPs required for training.
Future work will focus on optimizing CUDA kernels to further enhance the speed of the accumulation process and addressing the inherent "high-recall" limitations of linear architectures compared to traditional attention mechanisms.
Summary updated