Giter VIP home page Giter VIP logo

hashed_nets's Introduction

HashedNets

This is a PyTorch implementation of HashedNets by Chen et al. (2015). The original authors have published a (Lua)Torch implementation here.

HashedNets implements parameter sharing by tying weights that collide in the same buckets given a hash function. The output dimensions of each layer remains the same, while the number of unique values in the weight matrices drop with the compression factor. The aim is to maintain performance as the model is compressed by making use of redundancy in the parameters. The benefit of using a hash function is that we only require the hash seed in order to record which parameters are tied, saving space.

Example results on MNIST

This is an approximate reproduction of a figure from the original paper (produced in example.ipynb). Note that the results will be slightly different from the original paper given the different implementations, and the fact that I have not run Bayesian hyperparameter optimisation which they do in the paper or averaged over multiple runs.

Example results

Dependencies

Tested with Python 3.6.8, PyTorch 1.0.1.post2, xxhash 1.3.0.

Usage

The main component of interest is probably the HashLinear layer in layers.py. See mnist.py for an example model using the layer.

To see possible arguments to the script, run:

python3 mnist.py --help

To run the MNIST example with default hyperparameters, with or without hashing:

python3 mnist.py --compress 0.015625  # No hashing -> Test accuracy: 94.09%
python3 mnist.py --compress 0.015625 --hashed  # With hashing -> Test accuracy: 96.83%

References

hashed_nets's People

Contributors

jfainberg 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.