2020-12-23 10:47:58 -08:00
2022-05-08 20:01:53 +02:00
2023-02-26 08:58:24 +08:00
2023-05-17 16:37:09 +00:00
2022-05-30 10:08:18 +02:00
2022-02-06 10:15:05 +09:00
2022-09-22 11:27:03 +09:00
2021-12-29 16:30:55 +01:00
2021-01-08 10:51:58 +01:00
2022-07-28 09:35:02 +02:00
2023-02-23 15:33:23 +08:00
2020-12-23 10:47:58 -08:00
2022-02-06 10:15:05 +09:00
2022-01-07 13:49:43 +01:00
2020-12-23 10:47:58 -08:00
2022-07-13 20:01:42 +02:00

Sparsity Research on ViT

This reposity contains the PyTorch training code for the original DeiT models. Currently the code base are forked from the official DeiT repo

Here, I have build an interface and add some naive methods for add sparsity into the ViT.

Support Sparsity Searching Algorithm

Currently, we support the following sparsity strategy:

  • lamp : pruning via lamp score paper
  • glob : global pruning
  • unif : uniform pruning
  • unifplus : uniform pruning with some specific modificaiton (i.e. no pruning the first and last layer)
  • erk : Erdos-Renyi-Kernel paper

All of the support sparsity algorithm can be found in ./sparsity_factory/pruners.py.

The abovementioned methods will calculate the layer wise sparsity automatically once given the global target sparsity. In the following section, we will demonstrate how to use a custom designed sparsity level to sparsify the model

Use custom layer-wise Sparsity

We can provide a custom config that define the target sparsity of each layer. Currently, we support two kind of sparsity including nxm and unstructuted. User can create a yaml file the descibe the detail and pass into the main function by add the --custom-config [path to config file] argument when you call the main.py

Example Usage

To run a DeiT-S with custom configuration and eval the accuracy before finetuning

python main.py \ 
--model deit_small_patch16_224 \
--data-path [Path to imagenet] \
--output_dir [Path to output directory] \
--eval  \
--pruner custom \
--custom-config configs/deit_small_nxm.yaml

To finetune the DeiT-S with custom configuration

python main.py \ 
--model deit_small_patch16_224 \
--data-path [Path to imagenet] \
--output_dir [Path to output directory] \
--pruner custom \
--custom-config configs/deit_small_nxm.yaml

To use the algorithm to calculate the layer-sparsity and finetune given the global target sparsity to be 65%

python main.py \ 
--model deit_small_patch16_224 \
--data-path [Path to imagenet] \
--output_dir [Path to output directory] \
--pruner lamp \
--sparsity 0.65
Description
Official DeiT repository
Readme Apache-2.0 9.1 MiB
Languages
Python 100%