This repository contains implementation of various PyTorch models using the gradient checkpointing[1] which allows trading compute for memory and hence allows training bigger/wider models and use large minibatch sizes.
The application of checkpointing is showcased on various models:
- ResNet
- DenseNet
- LSTM model from pytorch examples here
- VNet model which is used in medical imaging applications, available here
Results of checkpointing on these models are showcased below:
In order to use the models, you need to install PyTorch master following instructions from here
To run checkpointed models and their baseline tests, follow the commands below:
# for checkpointed
python test_memory_optimized.py
# for baseline
python test_memory_optimized.py
We provide a tutorial to describe how to use checkpointing for various kinds of models.
There are few special kinds of layers like Batch normalization, dropout that should be handled carefully. The details for handling those are also available in the tutorial
GPU Mem | Batchsize | Training Time (20 iters) | |
---|---|---|---|
base | 2.6G | 4 | 38.9s |
checkpointed | 1.8G | 4 | 18.9s/38.9s |
base | 5.6G + 4.1G | 16 | 66.5s |
checkpointed | 5.1G + 5.1G | 32 | 67.5s |
base | 5.5G + 5.7G | 20 | 84.5s |
checkpointed | 6.0G + 5.7G | 36 | 74.5s |
base TSN Resnet50 | 3.9G | 4 | 0.41s |
checkpointed TSN Resnet50 | 4.5G | 32 | 1.4s |
[1]. Siskind, Jeffrey Mark, and Barak A. Pearlmutter. "Divide-and-Conquer Checkpointing for Arbitrary Programs with No User Annotation." arXiv preprint arXiv:1708.06799 (2017).