All Projects → jacobkimmel → Pytorch_modelsize

jacobkimmel / Pytorch_modelsize

Licence: mit
Estimates the size of a PyTorch model in memory

Projects that are alternatives of or similar to Pytorch modelsize

Attentionexplanation
Stars: ✭ 247 (-0.8%)
Mutual labels:  jupyter-notebook
Wavegrad
Implementation of Google Brain's WaveGrad high-fidelity vocoder (paper: https://arxiv.org/pdf/2009.00713.pdf). First implementation on GitHub.
Stars: ✭ 245 (-1.61%)
Mutual labels:  jupyter-notebook
Mixture Density Networks For Distribution And Uncertainty Estimation
A generic Mixture Density Networks (MDN) implementation for distribution and uncertainty estimation by using Keras (TensorFlow)
Stars: ✭ 249 (+0%)
Mutual labels:  jupyter-notebook
Receptivefield
Gradient based receptive field estimation for Convolutional Neural Networks
Stars: ✭ 247 (-0.8%)
Mutual labels:  jupyter-notebook
Dl tutorial
Tutorials for deep learning
Stars: ✭ 247 (-0.8%)
Mutual labels:  jupyter-notebook
Pytorch Seq2seq
Tutorials on implementing a few sequence-to-sequence (seq2seq) models with PyTorch and TorchText.
Stars: ✭ 3,418 (+1272.69%)
Mutual labels:  jupyter-notebook
Ml finance codes
Machine Learning in Finance: From Theory to Practice Book
Stars: ✭ 245 (-1.61%)
Mutual labels:  jupyter-notebook
Cvpr2019 pyramid Feature Attention Network For Saliency Detection
code and model of Pyramid Feature Selective Network for Saliency detection
Stars: ✭ 249 (+0%)
Mutual labels:  jupyter-notebook
Talks
Stars: ✭ 247 (-0.8%)
Mutual labels:  jupyter-notebook
Nodebook
Repeatable analysis plugin for Jupyter notebook
Stars: ✭ 249 (+0%)
Mutual labels:  jupyter-notebook
Ts tutorial
Stars: ✭ 247 (-0.8%)
Mutual labels:  jupyter-notebook
Building Machine Learning Projects With Tensorflow
Building Machine Learning Projects with TensorFlow by Packt
Stars: ✭ 247 (-0.8%)
Mutual labels:  jupyter-notebook
Epipolar Transformers
Epipolar Transformers (CVPR 2020)
Stars: ✭ 245 (-1.61%)
Mutual labels:  jupyter-notebook
Keras Elmo
How to use ELMo embeddings in Keras with Tensorflow Hub
Stars: ✭ 247 (-0.8%)
Mutual labels:  jupyter-notebook
Stanford Cs231
Resources for students in the Udacity's Machine Learning Engineer Nanodegree to work through Stanford's Convolutional Neural Networks for Visual Recognition course (CS231n).
Stars: ✭ 249 (+0%)
Mutual labels:  jupyter-notebook
Neural Painters
Stars: ✭ 247 (-0.8%)
Mutual labels:  jupyter-notebook
Faiss note
faiss wiki in chinese.
Stars: ✭ 248 (-0.4%)
Mutual labels:  jupyter-notebook
Deep Learning Machine Learning Stock
Stock for Deep Learning and Machine Learning
Stars: ✭ 240 (-3.61%)
Mutual labels:  jupyter-notebook
Naucse.python.cz
Website with learning materials / Stránka s učebními materiály
Stars: ✭ 248 (-0.4%)
Mutual labels:  jupyter-notebook
Solt
Streaming over lightweight data transformations
Stars: ✭ 249 (+0%)
Mutual labels:  jupyter-notebook

PyTorch Model Size Estimator

This tool estimates the size of a PyTorch model in memory for a given input size.
Estimating the size of a model in memory is useful when trying to determine an appropriate batch size, or when making architectural decisions.

Note (1): SizeEstimator is only valid for models where dimensionality changes are exclusively carried out by modules in model.modules().

For example, use of nn.Functional.max_pool2d in the forward() method of a model prevents SizeEstimator from functioning properly. There is no direct means to access dimensionality changes carried out by arbitrary functions in the forward() method, such that tracking the size of inputs and gradients to be stored is non-trivial for such models.

Note (2): The size estimates provided by this tool are theoretical estimates only, and the total memory used will vary depending on implementation details. PyTorch utilizes a few hundred MB of memory for CUDA initialization, and the use of cuDNN alters memory usage in a manner that is difficult to predict. See this discussion on the PyTorch Forums for more detail.

See this blog post for an explanation of the size estimation logic.

Usage

To use the size estimator, simply import the SizeEstimator class, then provide a model and an input size for estimation.

# Define a model
import torch
import torch.nn as nn
from torch.autograd import Variable
import numpy as np

class Model(nn.Module):

    def __init__(self):
        super(Model,self).__init__()

        self.conv0 = nn.Conv2d(1, 16, kernel_size=3, padding=5)
        self.conv1 = nn.Conv2d(16, 32, kernel_size=3)

    def forward(self, x):
        h = self.conv0(x)
        h = self.conv1(h)
        return h

model = Model()

# Estimate Size
from pytorch_modelsize import SizeEstimator

se = SizeEstimator(model, input_size=(16,1,256,256))
print(se.estimate_size())

# Returns
# (size in megabytes, size in bits)
# (408.2833251953125, 3424928768)

print(se.param_bits) # bits taken up by parameters
print(se.forward_backward_bits) # bits stored for forward and backward
print(se.input_bits) # bits for input

Development

This tool is a product of the Laboratory of Cell Geometry at the University of California, San Francisco.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].