108 Star 864 Fork 1.5K

MindSpore/models

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

Contents

AdderQuant Description

Existing AdderNet quantization techniques propose to use only one shared scale to quantize both the weights and activations simultaneously.
We propos a new quantization algorithm by redistributing the weights and the activations. Specifically, the pre-trained full-precision weights in different kernels are clustered into different groups, then the intra-group sharing and inter-group independent scales can be adopted. To further compensate the accuracy drop caused by the distribution difference, we then develop a lossless range clamp scheme for weights and a simple yet effective outliers clamp strategy for activations. Thus, the functionality of full-precision weights and the representation ability of full-precision activations can be fully preserved.

Paper: Redistribution of Weights and Activations for AdderNet Quantization. Ying Nie, Kai Han1, Haikang Diao, Chuanjian Liu, Enhua Wu, Yunhe Wang

Quantization Algorithm

img_1.png The illustration of the proposed quantization method for AdderNet (symmetric 4-bit as an example). The pre-trained full-precision weights are clustered into different groups. Then the clamp scheme for weights and activations are explored respectively to make efficient use of the precious bits and eliminate the negative impact of outliers.

Dataset

Note that you can run the scripts based on the dataset mentioned in original paper or widely used in relevant domain/network architecture. In the following sections, we will introduce how to run the scripts using the related dataset below.

Dataset used: CIFAR-10

  • Dataset size:175M,60,000 32*32 colorful images in 10 classes
    • Train:146M,50,000 images
    • Test:29.3M,10,000 images
  • Data format:binary files
    • Note:Data will be processed in dataset.py
  • Download the dataset, the directory structure is as follows:
├─cifar-10-batches-bin
│
└─cifar-10-verify-bin

Environment Requirements

Script description

Script and sample code

AdderQuant
.
├── README.md                 # Readme file
├── adder_quant.py            # AdderNet with Quantization Algorithm
├── eval.py                   # Evaluation
├── requirements.txt          # requirements
└── res20_adder.py            # Resnet with Addernet Conv

Eval process

Usage

After installing MindSpore via the official website, you can start evaluation as follows:

Launch

# infer example
  # python
  GPU: python eval.py --checkpoint_file_path path/to/ckpt --train_dataset_path path/to/cifar-10-batches-bin --eval_dataset_path path/to/cifar-10-verify-bin

checkpoint can be downloaded at https://download.mindspore.cn/model_zoo/research/cv/AdderQuant/

Result

Quantization results of AdderNets(ResNet-20 with 90.44full-precision) on CIFAR-10:

Bits PTQ(%)
8 91.36
6 91.21
5 90.86
4 90.27

ModelZoo Homepage

Please check the official homepage.

马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mindspore/models.git
git@gitee.com:mindspore/models.git
mindspore
models
models
master

搜索帮助