• Stars
    star
    582
  • Rank 76,500 (Top 2 %)
  • Language
    Python
  • License
    MIT License
  • Created about 5 years ago
  • Updated almost 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Sublinear memory optimization for deep learning. https://arxiv.org/abs/1604.06174

pytorch-memonger

This is a re-implementation of Training Deep Nets with Sublinear Memory Cost. You may also want to have a look at the original mxnet implementation and OpenAI's tensorflow implementation.

Speed / Memory Comparision

Model (Batch size 16) Memory Speed
original resnet152 5459MiB 2.9258 iter/s
Checkpoint (Sublinear) 2455MiB 2.6273 iter/s

How to use

Different from TensorFlow and mxnet where the computation graph is static and known before actual computing, pytorch's philosophy is define-by-run and the graph details are not known until forward is finished. This implemention only supports Sequential models. By replacing nn.Sequential with memonger.SublinearSequential, the memory required for backward is reduced from O(N) to O(sqrt(N)).

# previous, O(N) memory footprint
import torch.nn as nn
net1 = nn.Sequential(
    nn.Conv2d(3, 16, kernel=3, padding=1),
    nn.BatchNorm2d(16),
    nn.ReLU(),
    nn.Conv2d(16, 16, kernel=3, padding=1),
    nn.BatchNorm2d(16),
    nn.ReLU(),
    nn.Conv2d(16, 16, kernel=3, padding=1),
    nn.BatchNorm2d(16),
    nn.ReLU(),
    ...
)

# optimized, O(sqrt(N)) memory footprint
from memonger import SublinearSequential
net2 = SublinearSequential(
    *list(net1.children())  
)

Caution

Since sublinear memory optimization requires re-forwarding, if your model contains layer with non-derministic behavior (e.g, BatchNorm, Dropout), you need to be careful when using the module. I have supported BatchNorm by re-scaling momentum , dropout by memorizing the random number generator (RNG).

More Repositories

1

pytorch-OpCounter

Count the MACs / FLOPs of your PyTorch model.
Python
4,761
star
2

Efficient-PyTorch

My best practice of training large dataset using PyTorch.
Python
1,081
star
3

SparseNet

[ECCV 2018] Sparsely Aggreagated Convolutional Networks https://arxiv.org/abs/1801.05895
Python
126
star
4

arXiv-stats

Python
49
star
5

hf-torrent

Python
33
star
6

mxbox

Simple, efficient and flexible vision toolbox for mxnet framework.
Python
31
star
7

Bayesian-Compression-for-Deep-Learning

Remplementation of paper https://arxiv.org/abs/1705.08665
Python
28
star
8

PyTorch-Template

A template for PyTorch projects.
Python
22
star
9

Colorize-Your-World

Let there be color!
Jupyter Notebook
19
star
10

Machine-Learning-for-Image-Colorization

(Torch + Tensorflow) A deep magic brings color to your monochrome image!
MATLAB
12
star
11

GroupNorm.pytorch

PyTorch implementation of Group Normalization https://arxiv.org/abs/1803.08494
Python
11
star
12

Colorizing-Color-Images

[HVEI 2018] Colorizing Color Images
Jupyter Notebook
11
star
13

Project-Page-Render

HTML
10
star
14

Echoo

Let your program echo to you.
Python
8
star
15

arch-viz

Python
5
star
16

hf-torrent-store

5
star
17

Deep-Learning-Live

From linear regression to multi-layer perceptron, an introductive tutorial for deep learning beginners.
4
star
18

MNasNet-TensorFlow

Implementation of MnasNet: Platform-Aware Neural Architecture Search for Mobile
Python
4
star
19

tvm-notes

Python
4
star
20

PyTorch-via-PyTorch

C++
4
star
21

FlashATM

3
star
22

HW-for-COMP

HTML
3
star
23

edge-cloud-train

Python
3
star
24

ffmpeg-cuda-docker

A docker container to launch GPU accelerated FFmpeg
Dockerfile
3
star
25

pi-tools

A repo includes some useful tools for raspberry pi farm setup. https://hub.docker.com/repository/docker/lyken/pi-tools
Dockerfile
2
star
26

EIE-pytorch

PyTorch implementation for EIE https://arxiv.org/abs/1602.01528
Jupyter Notebook
2
star
27

Colorize.PyTorch

Python
2
star
28

torch-mps-benchmark

Python
1
star
29

sample-video

1
star
30

micro23

1
star
31

GPU-Speed-Benchmark

Python
1
star
32

tvm-issue-07-12

Python
1
star
33

Docker-Horovod

Dockerfile
1
star
34

Deep-Learning-Framework-Popularity

Python
1
star
35

pythonLearn

Python
1
star
36

BeihangData

Python
1
star
37

tiny-whisper

Python
1
star
38

Neurips19-Statistics

1
star
39

gluon-multiple-gpu

Python
1
star
40

tvm-hack

Python
1
star
41

lith

Ligeng's extensions for PyTorch
Python
1
star
42

ubuntun-research

Common scripts I've used for setting up my ubuntu server
Shell
1
star
43

wandb-example

Python
1
star