Giter VIP home page Giter VIP logo

deep-compression-pytorch's Introduction

Deep-Compression-PyTorch

PyTorch implementation of 'Deep Compression: Compressing Deep Neural Networks with Pruning, Trained Quantization and Huffman Coding' by Song Han, Huizi Mao, William J. Dally

This implementation implements three core methods in the paper - Deep Compression

  • Pruning
  • Weight sharing
  • Huffman Encoding

Requirements

Following packages are required for this project

  • Python3.6+
  • tqdm
  • numpy
  • pytorch, torchvision
  • scipy
  • scikit-learn

or just use docker

$ docker pull tonyapplekim/deepcompressionpytorch

Usage

Pruning

$ python pruning.py

This command

  • trains LeNet-300-100 model with MNIST dataset
  • prunes weight values that has low absolute value
  • retrains the model with MNIST dataset
  • prints out non-zero statistics for each weights in the layer

You can control other values such as

  • random seed
  • epochs
  • sensitivity
  • batch size
  • learning rate
  • and others For more, type python pruning.py --help

Weight sharing

$ python weight_share.py saves/model_after_retraining.ptmodel

This command

  • Applies K-means clustering algorithm for the data portion of CSC or CSR matrix representation for each weight
  • Then, every non-zero weight is now clustered into (2**bits) groups. (Default is 32 groups - using 5 bits)
  • This modified model is saved to saves/model_after_weight_sharing.ptmodel

Huffman coding

$ python huffman_encode.py saves/model_after_weight_sharing.ptmodel

This command

  • Applies Huffman coding algorithm for each of the weights in the network
  • Saves each weight to encodings/ folder
  • Prints statistics for improvement

Note

Note that I didn’t apply pruning nor weight sharing nor Huffman coding for bias values. Maybe it’s better if I apply those to the biases as well, I haven’t try this out yet.

Note that this work was done when I was employed at http://nota.ai

deep-compression-pytorch's People

Contributors

mightydeveloper avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.