Giter Club home page Giter Club logo

shiftaddnet's Introduction

ShiftAddNet

License: MIT

This is a PyTorch implementation of ShiftAddNet: A Hardware-Inspired Deep Network published on the NeurIPS 2020


Prerequisite

  • GCC >= 5.4.0
  • PyTorch == 1.4
  • Other common library are included in requirements.txt

Compile Adder Cuda Kernal

The original AdderNet Repo considers using PyTorch for implementing add absed convolution, however it remains slow and requires much more runtime memory costs as compared to the variant with CUDA acceleration.

We here provide one kind of CUDA implementation, please follow the intruction below to compile and check that the forwad/backward results are consistent with the original version.

Step 1: modify PyTorch before launch (for solving compiling issue)

Change lines:57-64 in anaconda3/lib/python3.7/site-packages/torch/include/THC/THCTensor.hpp from:

#include <THC/generic/THCTensor.hpp>
#include <THC/THCGenerateAllTypes.h>

#include <THC/generic/THCTensor.hpp>
#include <THC/THCGenerateBoolType.h>

#include <THC/generic/THCTensor.hpp>
#include <THC/THCGenerateBFloat16Type.h>

to:

#include <THC/generic/THCTensor.h>
#include <THC/THCGenerateAllTypes.h>

#include <THC/generic/THCTensor.h>
#include <THC/THCGenerateBoolType.h>

#include <THC/generic/THCTensor.h>
#include <THC/THCGenerateBFloat16Type.h>

Step 2: launch command to make sure you can successfully compile

python check.py

You should be able to successfully compile and see the runtime speed comparisons in the toy cases.

Reproduce Results in Paper

We release the pretrained checkpoints in Google Drive. To evaluate the inference accuracy of test set, we provide evaluation scripts shown below for your convenience. If you want to train your own model, the only change should be removing --eval_only option in the commands.

  • Examples for training of AdderNet
# CIFAR-10
    bash ./scripts/addernet/cifar10/FP32.sh
    bash ./scripts/addernet/cifar10/FIX8.sh

# CIFAR-100
    bash ./scripts/addernet/cifar100/FP32.sh
    bash ./scripts/addernet/cifar100/FIX8.sh
  • Examples for training of DeepShift
# CIFAR-10
    bash ./scripts/deepshift/cifar10.sh

# CIFAR-100
    bash ./scripts/deepshift/cifar100.sh
  • Examples for training of ShiftAddNet
# CIFAR-10
    bash ./scripts/shiftaddnet/cifar10/FP32.sh
    bash ./scripts/shiftaddnet/cifar10/FIX8.sh

# CIFAR-100
    bash ./scripts/shiftaddnet/cifar100/FP32.sh
    bash ./scripts/shiftaddnet/cifar100/FIX8.sh
  • Examples for training of ShiftAddNet (Fixed shift variant)
# CIFAR-10
    bash ./scripts/shiftaddnet_fix/cifar10/FP32.sh
    bash ./scripts/shiftaddnet_fix/cifar10/FIX8.sh

# CIFAR-100
    bash ./scripts/shiftaddnet_fix/cifar100/FP32.sh
    bash ./scripts/shiftaddnet_fix/cifar100/FIX8.sh

ShiftAddNet on IoT

Please refer to ./IoT directory for detailed description.

T-SNE Visualization

Reproduce the T-SNE visualization of the class divergences in AdderNet, and the proposed ShiftAddNet, using ResNet-20 on CIFAR-10 as an example.

bash ./scripts/gen_feat.sh # generate the features that will be used for visualization

cd tsne_vis &&
python visual_tsne.py --save_dir resnet20_add_FP32 --scratch
python visual_tsne.py --save_dir resnet20_add_FIX8 --scratch
python visual_tsne.py --save_dir resnet20_shiftadd_FP32 --scratch
python visual_tsne.py --save_dir resnet20_shiftadd_FIX8 --scratch

python visual_tsne.py --save_dir resnet20_add_FP32 --scratch --dim_3d
python visual_tsne.py --save_dir resnet20_add_FIX8 --scratch --dim_3d
python visual_tsne.py --save_dir resnet20_shiftadd_FP32 --scratch --dim_3d
python visual_tsne.py --save_dir resnet20_shiftadd_FIX8 --scratch --dim_3d

The output figure should look like below:

Citation

If you find this codebase is useful for your research, please cite:

@inproceedings{ShiftAddNet,
title={ShiftAddNet: A Hardware-Inspired Deep Network},
author={Haoran You, Xiaohan Chen, Yongan Zhang, Chaojian Li, Sicheng Li, Zihao Liu, Zhangyang Wang, Yingyan Lin},
booktitle={Thirty-fourth Conference on Neural Information Processing Systems},
year={2020},
}

shiftaddnet's People

Contributors

dependabot[bot] avatar ranery 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.