Code Monkey home page Code Monkey logo

binnet-pytorch's Introduction

Binnet CUDA

Experiments with Binarized Neural Networks in Pytorch.

The code provides a clean implementation of Binned Neural Networks with a custom CUDA kernel for the forward pass. It incorporates the main ideas introduced in Binarized Neural Networks paper.

The only layer available at the moment is BinaryLinear, which is a binarized version of torch.nn.Linear. The optimized forward pass kernel is available via the use_xnor_kernel argument.

Installation

The code requires CUDA 10.2+.

  1. Install the Python dependencies:
pip install -r requirements.txt
  1. Install the optimized forward pass CUDA kernel for the BinaryLinear:
cd cuda && pip install .

If this fails, you can try to explicitly specify the compiler you want to use via the CXX environment variable:

CXX=g++ pip install .

Examples

experiments/mnist_mlp.py contains an example experiment with an MLP network on the MNIST dataset.

Benchmarks

Benchmarks were run on Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz / GeForce GTX 1650 Mobile. The custom CUDA XNOR kernel was compared to the cuBLAS kernel on the following problems:

  • (8196, 8916) x (8196, 8916) matrix multiplication
  • MLP ((4096, 4096, 4096) hidden units) inference on the MNIST test set (batch size = 100); first layer and softmax projection layers were not binarized

Each experiment was repeated 100 times with torch.utils.benchmark.

Problem cuBLAS XNOR
Matrix Multiplication 425.21 ms 155.33 ms
MLP on MNIST test 772.96 ms 690.84 ms

The full report is available in the experiments folder.

Benchmarks were created using experiments/benchmark.py.

binnet-pytorch's People

Contributors

mszulc913 avatar

Stargazers

 avatar

Watchers

 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.