Abstract
As Large Language Models (LLMs) continue to scale, GPU memory capacity has become a critical bottleneck for training efficiency. While techniques like recomputation and virtual pipelining reduce theoretical memory requirements, they introduce significant memory fragmentation, often wasting up to 43% of available resources. We present STAlloc, a novel GPU memory allocator that leverages the inherent regularity of deep learning training to perform offline spatio-temporal planning. By grouping tensors with similar lifespans and sizes, STAlloc reduces fragmentation by an average of 85.1% and improves training throughput by up to 32.5%, enabling the use of larger, more efficient training configurations.
Introduction: The Fragmentation Bottleneck
The training of modern LLMs relies on complex memory management strategies to fit massive models into limited GPU memory. Standard allocators, such as the one used in PyTorch, operate on an "online" basis, making immediate allocation decisions without knowledge of future requests or tensor lifespans.
In large-scale training, optimizations like recomputation (where activations are discarded and recalculated) and virtual pipelining create interleaved allocation and deallocation patterns. This leads to severe memory fragmentation—a state where the GPU memory is filled with small, non-contiguous "holes" that cannot accommodate large tensor requests. This "Swiss cheese" effect often results in Out-of-Memory (OOM) errors even when total free memory is technically sufficient, forcing researchers to adopt slower, sub-optimal training setups.
Methodology: STAlloc's Spatio-Temporal Planning
STAlloc addresses fragmentation by shifting from reactive allocation to proactive Spatio-Temporal Planning. The system operates in three distinct phases:
- Allocation Profiler: During initial "warm-up" iterations, STAlloc records the size, lifespan, and sequence of every memory request.
- Plan Synthesizer: Using the profiled data, STAlloc organizes requests into HomoPhase Groups (tensors with overlapping lifespans) and HomoSize Groups (tensors of identical size). It then solves a 2D packing problem (Address vs. Time) to create a "Static Allocation Plan" that minimizes gaps.
- Runtime Allocator: During training, the Static Allocator executes the pre-defined plan. For dynamic architectures like Mixture-of-Experts (MoE), a specialized Dynamic Allocator identifies "idle holes" within the static plan to safely reuse memory for variable-sized tensors without risk of memory corruption.
Key Insights: Exploiting Regularity
The core innovation of STAlloc lies in the observation of "spatial and temporal regularity" in deep learning workloads. Despite the thousands of allocations per iteration, the number of unique tensor sizes is remarkably small.
As shown in the figure above, tensor sizes follow a highly concentrated distribution. STAlloc exploits this regularity to make the NP-hard problem of optimal memory layout tractable. By treating memory as a 2D space-time grid, the system can "fuse" adjacent memory groups to eliminate bubbles where memory would otherwise sit idle.
Evaluation and Results
STAlloc was evaluated across a variety of dense and sparse models, including Llama2-7B, Qwen2.5-72B, and Qwen1.5-MoE, on hardware ranging from NVIDIA A800 to AMD MI210 GPUs.
The results demonstrate significant improvements across all metrics:
- Fragmentation Reduction: STAlloc reduced the fragmentation ratio by an average of 85.1%, achieving 100% reduction in several dense model scenarios.
- Memory Efficiency: The system saved up to 56.3GB of GPU memory, allowing for larger batch sizes.
- Throughput Gains: By enabling more aggressive training configurations, STAlloc improved training throughput by an average of 32.5% compared to the default PyTorch allocator.
- Low Overhead: The offline planning phase typically completes within minutes, and the runtime overhead is negligible (less than 0.05%).
Conclusion
STAlloc demonstrates that the repetitive nature of deep learning training can be harnessed to solve the long-standing problem of GPU memory fragmentation. By moving memory management from the runtime to a planning phase, STAlloc provides a "free lunch" for large-scale model training, offering substantial performance gains with minimal integration effort. Future work will explore extending these spatio-temporal techniques to multi-GPU memory management and deeper integration with machine learning compilers.
Summary updated