Table of Contents
Fetching ...

Out of the Memory Barrier: A Highly Memory Efficient Training System for LLMs with Million-Token Contexts

Wenhao Li, Daohai Yu, Gen Luo, Yuxin Zhang, Fei Chao, Rongrong Ji, Yifan Wu, Jiaxin Liu, Ziyang Gong, Zimu Liao

TL;DR

This paper addresses the memory barrier in training LLMs with extremely long contexts by proposing OOMB, a chunk-recurrent training system that preserves a constant activation memory footprint through activation recomputation. It combines four interdependent components: chunk-wise training, a paged KV cache with in-place gradient handling, page-level sparse attention, and asynchronous KV-cache offloading to CPU memory, achieving dramatic memory reductions and enabling million-token contexts on a single H200 GPU. Empirical results show minimal end-to-end memory growth (about 10 MB per 10K tokens) and substantial speedups from sparse attention, making ultra-long-context training feasible without large clusters. This work substantially lowers resource requirements for long-context LLM training and broadens accessibility for research and deployment, with open-source code provided.

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. The source code is available at https://github.com/wenhaoli-xmu/OOMB.

Out of the Memory Barrier: A Highly Memory Efficient Training System for LLMs with Million-Token Contexts

TL;DR

This paper addresses the memory barrier in training LLMs with extremely long contexts by proposing OOMB, a chunk-recurrent training system that preserves a constant activation memory footprint through activation recomputation. It combines four interdependent components: chunk-wise training, a paged KV cache with in-place gradient handling, page-level sparse attention, and asynchronous KV-cache offloading to CPU memory, achieving dramatic memory reductions and enabling million-token contexts on a single H200 GPU. Empirical results show minimal end-to-end memory growth (about 10 MB per 10K tokens) and substantial speedups from sparse attention, making ultra-long-context training feasible without large clusters. This work substantially lowers resource requirements for long-context LLM training and broadens accessibility for research and deployment, with open-source code provided.

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. The source code is available at https://github.com/wenhaoli-xmu/OOMB.
Paper Structure (15 sections, 4 equations, 9 figures, 4 tables)

This paper contains 15 sections, 4 equations, 9 figures, 4 tables.

Figures (9)

  • Figure 1: An overview of the OOMB training framework. (Left) OOMB processes sequences chunk-by-chunk with activation recomputation, maintaining a constant activation memory footprint ($\mathcal{O}(1)$) and shifting the bottleneck to the KV cache. (Center) The growing KV cache is managed through a combination of paged memory, asynchronous CPU offloading, and page-level sparse attention. (Right) Performance benchmarks show that the integrated system drastically reduces peak GPU memory, enabling efficient training on long contexts with minimal memory overhead.
  • Figure 2: The synergistic architecture of OOMB's efficient KV cache management relies on four deeply interdependent core components: chunk-wise training, paged key-value cache, sparse attention, and key-value cache offload. Each optimization enables and enhances the others, collectively resolving the memory bottleneck of long-context training.
  • Figure 3: Our paged KV cache management system for training. A custom kernel handles both forward and backward passes, updating gradients in-place to bypass the PyTorch autograd system for greater efficiency.
  • Figure 4: A non-paged implementation can result in memory usage nearly 3$\times$ higher than the theoretical requirement.
  • Figure 5: Visualization of the page-level sparse attention patterns for the Qwen2.5-7B model. Each subplot displays the retrieved key pages (x-axis) for each query page (y-axis) across the initial four layers at context lengths scaling from 32K to 256K.
  • ...and 4 more figures