Giter Site home page Giter Site logo

vita-group / sfw-once-for-all-pruning Goto Github PK

View Code? Open in Web Editor NEW
28.0 7.0 1.0 320 KB

[ICLR 2022] "Learning Pruning-Friendly Networks via Frank-Wolfe: One-Shot, Any-Sparsity, and No Retraining" by Lu Miao*, Xiaolong Luo*, Tianlong Chen, Wuyang Chen, Dong Liu, Zhangyang Wang

License: MIT License

Python 100.00%
pruning stochastic-frank-wolfe once-and-for-all sparse-neural-networks

sfw-once-for-all-pruning's Introduction

Learning Pruning-Friendly Networks via Frank-Wolfe: One-Shot, Any-Sparsity, and No Retraining

License: MIT

Code used for paper: [ICLR 2022] Learning Pruning-Friendly Networks via Frank-Wolfe: One-Shot, Any-Sparsity, and No Retraining.

Lu Miao*, Xiaolong Luo*, Tianlong Chen, Wuyang Chen, Dong Liu, Zhangyang Wang

Overview

A novel framework to train a large deep neural network (DNN) for only once, which can then be pruned to any sparsity ratio to preserve competitive accuracy without any re-training. We propose a sparsity-aware one-shot pruning method based on K-sparse polytope constraint and Stochastic Frank-Wolfe (SFW) optimizer. We also present the first learning-based initialization scheme specifically for boosting SFW-based DNN training.

Reproduce

Preliminary

Required environment

  • pytorch >= 1.5.0
  • torchvision

Reproducing details

The following codes can reproduce the experiments involved in the paper.

SFW training for one-shot pruning

The following code is the training step in SFW-pruning framework.

python -u train_prune.py
					--data cifar10
					--arch ResNet18
					--optimizer SFW
					--constraint k_sparse_constraints
					--lr 1.0
					--lr_scheme dynamic_change
					--momentum 0.9
					--weight_decay 0
					--k_sparseness 10
					--k_frac 0.05
					--tau 15
					--mode initialization
					--rescale gradient
					--sfw_init 0 
					--train_batchsize 128
					--test_batchsize 128
					--epoch_num 180
					--color_channel 3
					--gpu -1

The log file is saved in /saved_logs/SFW_one_shot_prune/. The trained model is saved in /saved_models/.

Test pruning performance

The following code conducts (unstructured) pruning and tests the performance of the pruned DNN. Pruning ratios are 10%, 20%, 30%, 40%, 50%, 60%, 70%, 80%, 90%, 91%, 92%, 93%, 94%, 95%, 96%, 97%, 98%, 99%.

python -u test_prune.py
					--data cifar10
					--arch ResNet18
					--optimizer SFW
					--constraint k_sparse_constraints
					--lr 1.0
					--lr_scheme dynamic_change
					--momentum 0.9
					--weight_decay 0
					--k_sparseness 10
					--k_frac 0.05
					--tau 15
					--mode initialization
					--rescale gradient
					--sfw_init 0 
					--train_batchsize 128
					--test_batchsize 128
					--epoch_num 180
					--color_channel 3
					--gpu -1

The argument choices are parallel with those of train_prune.py. The log file is saved in /saved_logs/SFW_prune_test/.

Check DNN weight distribution

The following code checks out the weight distribution of the DNN.

python -u test_weight_distribution.py
					--data cifar10
					--arch ResNet18
					--optimizer SFW
					--constraint k_sparse_constraints
					--lr 1.0
					--lr_scheme dynamic_change
					--momentum 0.9
					--weight_decay 0
					--k_sparseness 10
					--k_frac 0.05
					--tau 15
					--mode initialization
					--rescale gradient
					--sfw_init 0 
					--train_batchsize 128
					--test_batchsize 128
					--epoch_num 180
					--color_channel 3
					--gpu -1

The argument choices are also parallel with those of train_prune.py. The log file is saved in /saved_logs/weight_distribution/.

Optional argument choices

Some optional argument choices are as follows.

optional arguments:
  				--data cifar10 | cifar100 | mnist | svhn | tiny
  				--arch ResNet18 | VGG16 | Mlp
      		--optimizer SFW |SGD
					--constraint k_sparse_constraints | l2_constraints | unconstraints
					--lr 1.0 (float between 0 and 1)
					--lr_scheme dynamic_change | decrease_3 | keep
					--momentum 0.9 (recommand)
					--weight_decay 0 (recommand)
					--k_sparseness 10 (equals to the number of labels)
					--k_frac 0.05 | 0.01 | 0.1
					--tau 15 | 5 | 10 | 20 
					--mode initialization | diameter | radius | None
					--rescale gradient | diameter | None
					--sfw_init 0 | 1
					--train_batchsize 128 
					--test_batchsize 128
					--epoch_num 180
					--color_channel 3
					--gpu -1 (GPU id to use)

If use the dataset 'Tiny-Imagenet', please download the dataset to /data/tiny_imagenet_200/.

Citation

TBD

sfw-once-for-all-pruning's People

Contributors

tianlong-chen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

sfw-once-for-all-pruning's Issues

function not defined

Could you provide the code of 'load_model_and_prune' and 'load_model' in test.py?

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.