Abstract
Training Large Language Models (LLMs) on long contexts is severely constrained by prohibitive GPU memory overhead, not training time. The primary culprits are the activations, whose memory footprints scale linearly with sequence length. We introduce OOMB, a highly memory-efficient training system that directly confronts this barrier. Our approach employs a chunk-recurrent training framework with on-the-fly activation recomputation, which maintains a constant activation memory footprint ($O(1)$) and shifts the primary bottleneck to the growing KV cache. To manage the KV cache, OOMB integrates a suite of synergistic optimizations: a paged memory manager for both the KV cache and its gradients to eliminate fragmentation, asynchronous CPU offloading to hide data transfer latency, and page-level sparse attention to reduce both computational complexity and communication overhead. The synergy of these techniques yields exceptional efficiency. Our empirical results show that for every additional 10K tokens of context, the end-to-end training memory overhead increases by a mere 10MB for Qwen2.5-7B. This allows training Qwen2.5-7B with a 4M-token context on a single H200 GPU, a feat that would otherwise require a large cluster using context parallelism. This work represents a substantial advance in resource efficiency for long-context LLM training.
Introduction
The "context window" has become a critical frontier in Large Language Model (LLM) development. However, training models to handle millions of tokens is a significant memory challenge. Standard training methods suffer from linear growth in memory usage: as the sequence length ($N$) increases, the memory required for activations and the Key-Value (KV) cache also increases ($O(N)$).
Even with high-end hardware like an H100 or H200, a single GPU typically hits a "memory wall" at around 32K tokens. To extend this, researchers often rely on Context Parallelism (CP), which distributes a single sequence across multiple GPUs. However, CP requires expensive, high-bandwidth interconnects and substantial hardware resources, making it inaccessible for many. OOMB (Out Of the Memory Barrier) aims to break this barrier, enabling resource-efficient long-context training on a single device.
Methodology
OOMB introduces a synergistic architecture that addresses memory constraints through several key innovations:
Chunk-Recurrent Training with Recomputation
Instead of processing a million-token sequence in its entirety, OOMB partitions it into smaller "chunks." The system computes the forward pass for a chunk, stores the KV cache, and discards intermediate activations. During the backward pass, these activations are recomputed on-the-fly. This strategy maintains a constant activation memory footprint ($O(1)$), regardless of total sequence length.
Paged KV Cache and Gradient Management
Inspired by inference engines like vLLM, OOMB utilizes a paged memory manager to prevent fragmentation and facilitate efficient token appending. Custom Triton kernels were developed to manage both the KV cache and its gradients, bypassing PyTorch’s autograd to perform in-place updates and minimize overhead.
Asynchronous CPU Offloading and Sparse Attention
To manage the growing KV cache, OOMB offloads it to CPU RAM. A pre-fetching strategy overlaps data transfer with GPU computation to hide latency. Furthermore, a page-level sparse attention mechanism uses Top-K retrieval to identify relevant KV cache pages, reducing both computation and communication costs.
Experimental Setup
The system was evaluated using the Qwen2.5-7B model. Benchmarks were conducted on the arXiv dataset, with samples concatenated to reach million-token lengths. SlimPajama was also used to assess long-range modeling capabilities.
Key Results and Discussion
OOMB demonstrates remarkable scalability and efficiency as shown in the performance benchmarks:
- Single-GPU Scalability: OOMB successfully trained Qwen2.5-7B with a 4-million-token context on a single H200 GPU. The memory overhead increases by only 10MB for every 10,000 additional tokens.
- Throughput and Speedup: OOMB outperformed Ring Flash Attention (RFA) in per-device throughput. On 256K token sequences, the sparse attention variant achieved a 13.5x speedup over dense attention baselines.
- Accuracy: Validation runs at 1M contexts showed that sparse attention converged with loss curves nearly identical to dense training, indicating no loss in model quality.
Limitations
Despite these gains, OOMB faces some trade-offs. Serial chunk processing increases total iteration time compared to fully parallel methods. Additionally, the effectiveness of sparse attention on tasks requiring dense global context requires further investigation. Finally, performance is partially dependent on the CPU-GPU interconnect bandwidth (PCIe).
Conclusion
OOMB represents a significant step toward making long-context LLM training accessible. By shifting the memory bottleneck from activations to the KV cache and managing the latter with paging, offloading, and sparsity, OOMB enables million-token training on commodity-grade single-GPU setups.
Summary updated