ROAM: memory-efficient large DNN training via optimized operator ordering and memory layout

Huiyao Shu, Ang Wang, Ziji Shi, Hanyu Zhao, Yong Li, Lu LuarXiv 2023

TL;DR

This paper introduces ROAM, a novel framework that optimizes deep learning model training by intelligently reordering operations and managing memory layouts. By tackling memory bottlenecks at the computation graph level, ROAM significantly reduces memory usage and speeds up training without introducing overheads, making large model training more accessible.

What Problem Does This Paper Address?

The ever-increasing size of deep learning models, particularly in areas like machine translation and high-resolution image processing, has led to a surge in memory requirements during training. While existing techniques like offloading, recomputation, and compression can alleviate memory pressure, they often introduce significant computational overheads and can sometimes impact model accuracy. The core problem ROAM addresses is the inefficiency in current deep learning frameworks' handling of memory during training. Standard frameworks often rely on basic topological ordering and simple memory allocation strategies that don't account for the complex interplay of operator execution order and tensor memory layouts, leading to suboptimal memory usage and the need for more aggressive, overhead-inducing mitigation techniques.

Methods

ROAM tackles memory efficiency by operating at the computation graph level, focusing on two key areas:

  • Optimized Operator Ordering: ROAM introduces the concept of "Memory-Insensitive Operators" which act as natural breakpoints in the computation graph, dividing it into "Independent Segments." The optimization problem is then decomposed to find the most memory-efficient execution order within each segment. For training graphs, a novel scheduler is proposed to intelligently decide when to schedule weight update operations, balancing immediate execution with the need to preserve gradients.
  • Memory Layout Management: ROAM analyzes tensor lifetimes and sizes to optimize memory layouts, aiming to maximize memory reuse and minimize fragmentation. It categorizes shared tensors (e.g., activations, temporary buffers) and applies specific optimization strategies based on their creation and destruction within subgraphs. A tree-based algorithm is used to recursively split large graphs into smaller, manageable subgraphs for optimization, leveraging Integer Linear Programming (ILP) for near-optimal solutions within these subgraphs.

Datasets

The paper evaluates ROAM on a variety of standard deep learning models, including:

  • CNN models: AlexNet, VGG, MnasNet, MobileNet, EfficientNet
  • Transformer-based models: VIT, BERT
  • Large Language Models: GPT2-XL

These models are evaluated across different batch sizes (1 and 32) to demonstrate performance under varying memory constraints.

Key Insights and Ideas

  • Operator Order and Memory Layout are Intertwined: The paper highlights that optimizing either operator order or memory layout in isolation is insufficient. ROAM's strength lies in jointly optimizing both aspects.
  • Memory-Insensitive Operators as Graph Dividers: Identifying operators that have fixed scheduling points is crucial for breaking down complex graphs into manageable, independently optimizable segments.
  • Intelligent Weight Update Scheduling: The decision of when to perform weight updates significantly impacts peak memory. ROAM's scheduler dynamically decides this to avoid unnecessary memory pressure.
  • Tensor Lifetime is Key for Memory Layout: Simply allocating memory based on creation time is inefficient. Considering tensor lifetimes allows for more effective memory reuse and reduced fragmentation.
  • Hierarchical Optimization with Subgraphs: For very large models, a recursive approach of splitting the graph into independent and dependent subgraphs, and then optimizing these smaller units, is essential for scalability.

Key Results

ROAM demonstrates significant improvements in memory efficiency and training speed:

  • Memory Reduction: ROAM achieved an average memory reduction of 35.7% compared to PyTorch, 13.3% compared to a heuristic baseline (LESCEA+LLFB), and 27.2% compared to MODEL-Multi-Streaming.
  • Speedup: ROAM offers a remarkable average speedup of 53.7x compared to the ILP state-of-the-art method in optimization time.
  • Fragmentation Reduction: ROAM effectively reduces fragmentation to less than 1% on average, compared to PyTorch's 23.0% and the heuristic's unpredictable performance.
  • Scalability: The framework scales well to large models, successfully optimizing GPT2-XL (over 10,000 operators), a task that was unsupported by the MODEL baseline due to its complexity.

Limitations and Future Work

  • ILP Complexity: While ROAM uses ILP for subgraph optimization, the inherent complexity of ILP can still lead to longer optimization times for very large or complex subgraphs. The paper addresses this by introducing a node_limit parameter to constrain subgraph size.
  • Heuristic vs. ROAM Speed: ROAM's execution is noted to be slower than heuristic methods in some single-streaming scenarios, though it achieves better solutions. The paper suggests that the trade-off is acceptable given the superior memory savings.
  • Future Work: The paper suggests that further research could explore more advanced techniques for handling complex graph structures and optimizing for scenarios with extremely limited memory. The framework's modularity also allows for integration with other high-level optimization techniques.

Summary updated

Abstract

As deep learning models continue to increase in size, the memory requirements for training have surged. While high-level techniques like offloading, recomputation, and compression can alleviate memory pressure, they also introduce overheads. However, a memory-efficient execution plan that includes a reasonable operator execution order and tensor memory layout can significantly increase the models' memory efficiency and reduce overheads from high-level techniques. In this paper, we propose ROAM which operates on computation graph level to derive memory-efficient execution plan with optimized operator order and tensor memory layout for models. We first propose sophisticated theories that carefully consider model structure and training memory load to support optimization for large complex graphs that have not been well supported in the past. An efficient tree-based algorithm is further proposed to search task divisions automatically, along with delivering high performance and effectiveness to solve the problem. Experiments show that ROAM achieves a substantial memory reduction of 35.7%, 13.3%, and 27.2% compared to Pytorch and two state-of-the-art methods and offers a remarkable 53.7x speedup. The evaluation conducted on the expansive GPT2-XL further validates ROAM's scalability.

Empirical ResultsBrowse all benchmarks →

BenchmarkMethodMetricScoreProtocol / Evidence
Evaluated DNN models · Overall memory evaluation on AlexNet, VGG, MnasNet, MobiROAMmemory usage reduction13.3%optimizer=Adam · batch_size=1, 32
Source quote
L300: To evaluate the effectiveness of our methodology, we compared the overall memory requirements of various neural networks against four baseline approaches. \autoref{fig:overall_memory_saving} illustrates the memory-saving ratio of our approach in comparison to PyTorch, Heuristics (LESCEA+LLFB) and MODeL-Multi-Streaming. The results demonstrate that ROAM\xspace achieves a remarkable 35.7%, and 13.3% reduction in memory usage as compared to PyTorch and heuristics respectively.
Evaluated DNN models · Overall memory evaluation on the evaluated DNN modelsROAMmemory reduction27.2%multi-streaming · optimization_time_limit=1 hour
Source quote
L347: In the case of multi-streaming, as shown in Figure\autoref{fig:MODeL_e2e_saving}, our approach achieves an impressive 27.2% memory reduction on average when given a time limit 1h.
GPT2-XLROAMoptimization-time speedup19.2x ×optimizer=Adam · comparison=LESCEA+LLFB
Source quote
L385: \autoref{fig:LLM_time} illustrates the comparison of time consumption between ROAM\xspace and heuristics. We see that ROAM\xspace can optimize GPT2-XL in a similar amount of time as other cases as illustrated in \autoref{fig:Optimization time}, while the optimization time for heuristics significantly increases, leading to reduced usability. It is evident that ROAM\xspace achieves significantly higher speedup than heuristics for the large case, GPT2-XL. On average, ROAM\xspace achieves a speedup of 19.2x, which confirms the excellent scalability of ROAM\xspace. Furthermore, it is noteworthy that ROAM\xspace can support the large case that is unsupported in other ILP-based methods. We have attempted to obtain the solutions of MODeL. However, MODeL fails to solve the large ILP model with more than 22 million integer decision variables.
BibTeX
@misc{shu2023roam,
  author = {Huiyao Shu and Ang Wang and Ziji Shi and Hanyu Zhao and Yong Li and Lu Lu},
  title = {{ROAM: memory-efficient large DNN training via optimized operator ordering and memory layout}},
  year = {2023},
  eprint = {2310.19295},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2310.19295},
}

Loading related content...

Figure