[Paper Review] TFLMS: Large Model Support in TensorFlow by Graph Rewriting
This paper proposes TFLMS, a graph rewriting approach in TensorFlow that enables training large deep neural networks by inserting swap-out and swap-in operations to offload intermediate activations to CPU memory, thereby overcoming GPU memory limitations. The method formally derives these operations using program transformation rules and achieves up to 4.7× and 2× larger batch sizes for ResNet-50 and 3DUnet, respectively, including enabling training of 3DUnet on full $192^3$ images without tiling.
While accelerators such as GPUs have limited memory, deep neural networks are becoming larger and will not fit with the memory limitation of accelerators for training. We propose an approach to tackle this problem by rewriting the computational graph of a neural network, in which swap-out and swap-in operations are inserted to temporarily store intermediate results on CPU memory. In particular, we first revise the concept of a computational graph by defining a concrete semantics for variables in a graph. We then formally show how to derive swap-out and swap-in operations from an existing graph and present rules to optimize the graph. To realize our approach, we developed a module in TensorFlow, named TFLMS. TFLMS is published as a pull request in the TensorFlow repository for contributing to the TensorFlow community. With TFLMS, we were able to train ResNet-50 and 3DUnet with 4.7x and 2x larger batch size, respectively. In particular, we were able to train 3DUNet using images of size of $192^3$ for image segmentation, which, without TFLMS, had been done only by dividing the images to smaller images, which affects the accuracy.
Motivation & Objective
- To address the challenge of training very large deep neural networks that exceed GPU memory capacity.
- To provide a formal, provably correct method for inserting swap-out and swap-in operations into computational graphs.
- To improve training efficiency and scalability for large models by optimizing memory usage through graph rewriting.
- To enable training of 3DUnet on full $192^3$ images, which previously required image tiling and compromised accuracy.
Proposed method
- Reformulate the computational graph by treating variables as first-class citizens with formal semantics, extending TensorFlow's graph model.
- Derive swap-out and swap-in operations using formal program transformation rules to ensure correctness and consistency.
- Introduce two strategies—chain_rule and direct_order—for statically identifying control dependencies to trigger optimal swap-in timing.
- Apply optimization rules such as fusing swap-in operations to reduce overhead and improve performance.
- Implement the approach as a pull request in the TensorFlow repository, named TFLMS, to enable community adoption.
- Use configurable parameters (n_tensors, lb, swap_branches) to control the trade-off between memory usage and training performance.
Experimental results
Research questions
- RQ1How can computational graphs be formally redefined to support first-class variables and enable correct graph rewriting for memory management?
- RQ2What formal rules can be used to derive swap-out and swap-in operations that preserve model correctness during training?
- RQ3How do different strategies for identifying control dependencies affect the performance of large model training?
- RQ4What is the optimal configuration of parameters (n_tensors, lb, swap_branches) for maximizing batch size and training throughput?
- RQ5Can TFLMS enable training of 3DUnet on full $192^3$ images without image tiling, and what performance is achieved?
Key findings
- TFLMS enabled training of ResNet-50 with a maximum batch size of 832, representing a 4.7× increase over the baseline of 176 without TFLMS.
- For 3DUnet, TFLMS allowed a 2× larger maximum batch size compared to the baseline, enabling training on full $192^3$ images without tiling.
- The highest training throughput was achieved with lb=5 and n_tensors=100 for ResNet-50, balancing memory usage and computation-communication overlap.
- Fusing swap-in operations improved performance but reduced the maximum batch size due to increased GPU memory retention of intermediate tensors.
- Enabling branch swapping with a threshold of 20 increased the maximum batch size for 3DUnet from 3 to 4, demonstrating its impact on scalability.
- With optimal configuration, 3DUnet achieved a training throughput of 0.17 images/sec on $192^3$ inputs, which was previously infeasible due to out-of-memory errors.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.