Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
119 commits
Select commit Hold shift + click to select a range
9e900d5
decouple criterias from pruner
WeiweiZhang1 Nov 23, 2022
9cd602b
remove development code
WeiweiZhang1 Nov 24, 2022
e7d76ef
add docstring, reorg progressive pruner
WeiweiZhang1 Nov 30, 2022
847f75a
fix typo
WeiweiZhang1 Dec 1, 2022
1868294
add yolov5 example
WeiweiZhang1 Dec 1, 2022
a93ecb5
modify docstring and formatting errors, add copyright description
WeiweiZhang1 Dec 1, 2022
e4eca40
rm useless function, bugfix
WeiweiZhang1 Dec 2, 2022
c698b02
bugfixs2
WeiweiZhang1 Dec 2, 2022
c4568d8
fix typos
WeiweiZhang1 Dec 5, 2022
1372b78
add dictionary
WeiweiZhang1 Dec 5, 2022
12a27e6
fix typos about criterion
WeiweiZhang1 Dec 5, 2022
c9970ff
modify pruning config, add progressive test-case
WeiweiZhang1 Dec 6, 2022
08c6b8d
Merged new-developed pruning API to old one.
YIYANGCAI Dec 7, 2022
73edbef
test
Dec 7, 2022
08b9924
adjust pruning location
Dec 7, 2022
110111f
adjust pruning location
Dec 7, 2022
77095d5
fix typo
Dec 7, 2022
86464c0
1 change name due to name conflict, 2 change locations
Dec 7, 2022
16800d4
1 change name 2 change location
Dec 7, 2022
568bb3a
reformat code
Dec 7, 2022
aa321cb
Merged new-developed pruning API to old one.
YIYANGCAI Dec 7, 2022
5e5caa0
test
Dec 7, 2022
ed4276d
adjust pruning location
Dec 7, 2022
d6d6644
adjust pruning location
Dec 7, 2022
5402063
fix typo
Dec 7, 2022
a9ee475
1 change name due to name conflict, 2 change locations
Dec 7, 2022
47ceec0
1 change name 2 change location
Dec 7, 2022
84aeb6a
reformat code
Dec 7, 2022
10a00fa
RCeorg API, add test codes.
YIYANGCAI Dec 7, 2022
bded726
merge
wenhuach21 Dec 7, 2022
2963a48
merge
wenhuach21 Dec 7, 2022
ac368b4
merge weight_compression_pytorch, fixed some bugs
wenhuach21 Dec 7, 2022
0cf3f45
adjust pruning path
wenhuach21 Dec 7, 2022
70f9b76
replace nerualcompressor/pruning with new pruning
wenhuach21 Dec 7, 2022
cc2cc60
change update_items_for_all_pruner to update_config
wenhuach21 Dec 7, 2022
a19a455
fix not setting global config
wenhuach21 Dec 7, 2022
117076f
change names
wenhuach21 Dec 7, 2022
ce1aac2
merge two functions
wenhuach21 Dec 7, 2022
e6e5136
fix merging excluded names issue
wenhuach21 Dec 7, 2022
b112604
move files
wenhuach21 Dec 7, 2022
3e70319
mv sparsity_decay_type to global config, fix missing prune_layer_type
wenhuach21 Dec 7, 2022
dc09184
delete lots of legacy files, move new API files
wenhuach21 Dec 8, 2022
2508180
pruner README v1
yintong-lu Dec 8, 2022
c4d72c2
pruner README V1
yintong-lu Dec 8, 2022
1ec608b
Update README.md
yintong-lu Dec 8, 2022
e674eda
pruner README V_1
yintong-lu Dec 8, 2022
e82e95c
pruner README V1_
yintong-lu Dec 8, 2022
6dea88f
Merge branch 'cyy/pruning-api-merge' of https://github.com/intel/neur…
yintong-lu Dec 8, 2022
56acaeb
rename update_frequency to prune_frequncy, disable some unit test of
wenhuach21 Dec 8, 2022
db902c0
Merge branch 'cyy/pruning-api-merge' of https://github.com/intel/neur…
wenhuach21 Dec 8, 2022
2ac03c0
move folder
wenhuach21 Dec 8, 2022
b413763
delete imagenet pruning example
wenhuach21 Dec 8, 2022
6334e07
change pruning related configs of some examples
wenhuach21 Dec 8, 2022
5572284
fix a bug, add empty unit test file
wenhuach21 Dec 8, 2022
b1c0db0
fix typo
wenhuach21 Dec 8, 2022
d7887db
pruning doc v1.1
yintong-lu Dec 8, 2022
5898e95
Merge branch 'cyy/pruning-api-merge' of https://github.com/intel/neur…
yintong-lu Dec 8, 2022
c70d58b
pruning doc v1.1
yintong-lu Dec 8, 2022
6a4b6b9
fix a bug, add one unit test
wenhuach21 Dec 8, 2022
b5bd3e8
Merge branch 'cyy/pruning-api-merge' of https://github.com/intel/neur…
wenhuach21 Dec 8, 2022
263e85d
pruning doc v1.2
yintong-lu Dec 8, 2022
e6ccba3
pruning doc v1.2
yintong-lu Dec 8, 2022
1735112
Merge branch 'cyy/pruning-api-merge' of https://github.com/intel/neur…
yintong-lu Dec 8, 2022
6041a3a
pruningdoc v1.2
yintong-lu Dec 8, 2022
337629b
pruning doc v1.3
yintong-lu Dec 8, 2022
f5f1450
pruning doc v1.3
yintong-lu Dec 8, 2022
7fa6593
pruning doc v1.3
yintong-lu Dec 8, 2022
c3c7cfe
fix bug, add unit test
wenhuach21 Dec 8, 2022
30726ac
add test_pruning_config
WeiweiZhang1 Dec 8, 2022
e701b03
delete tensorflow pruning examples
wenhuach21 Dec 8, 2022
4d6aa73
pruning doc v1.5
yintong-lu Dec 8, 2022
cd723a0
Merge branch 'cyy/pruning-api-merge' of https://github.com/intel/neur…
yintong-lu Dec 8, 2022
67674e2
pruning doc v1.5
yintong-lu Dec 8, 2022
10ad8ad
pruning doc v1.5
yintong-lu Dec 8, 2022
a0f7ce7
pruning doc V1.5
yintong-lu Dec 8, 2022
1be82d7
pruning doc V1.5
yintong-lu Dec 8, 2022
06ecda5
pruning doc V1.5
yintong-lu Dec 8, 2022
0dd2d92
pruning doc V1.6
yintong-lu Dec 8, 2022
2f71f68
pruning doc V1.6
yintong-lu Dec 8, 2022
063ef19
pruning doc V1.6
yintong-lu Dec 8, 2022
4b07139
pruning doc V1.6
yintong-lu Dec 8, 2022
711a5bb
pruning doc V1.6
yintong-lu Dec 8, 2022
fdd1b4d
add unit test
wenhuach21 Dec 8, 2022
7b48f59
update unit test
wenhuach21 Dec 8, 2022
8884217
update unit test
wenhuach21 Dec 8, 2022
423b144
fix an issue in progressive pruning
wenhuach21 Dec 8, 2022
bcc68e0
Merge branch 'master' into cyy/pruning-api-merge
wenhuach21 Dec 8, 2022
5a99366
update unit test
wenhuach21 Dec 8, 2022
8efe8cb
fix issues based on preci
wenhuach21 Dec 8, 2022
b405c90
fix issue
wenhuach21 Dec 8, 2022
f8c5a04
lazy import torch
wenhuach21 Dec 8, 2022
633c2a9
lazy import torch
wenhuach21 Dec 8, 2022
8be9637
torch import issue
wenhuach21 Dec 8, 2022
d7fea68
torch import issue
wenhuach21 Dec 8, 2022
7a04c1d
fix update config issue, update unit test, fix example import issue
wenhuach21 Dec 8, 2022
140ddaa
update examples
WeiweiZhang1 Dec 8, 2022
b158da9
update examples 2
WeiweiZhang1 Dec 8, 2022
3eec738
bugfix
WeiweiZhang1 Dec 9, 2022
198f5c9
recover files in experimental folder
wenhuach21 Dec 9, 2022
fd42cae
Merge branch 'cyy/pruning-api-merge' of https://github.com/intel/neur…
wenhuach21 Dec 9, 2022
e692eca
support pruning_config in pruning
wenhuach21 Dec 9, 2022
47a7032
prune_domain to pruning_scope
wenhuach21 Dec 9, 2022
0b280d8
reformat code
wenhuach21 Dec 9, 2022
9308000
update README
WeiweiZhang1 Dec 9, 2022
34d898c
change configs, not finished
wenhuach21 Dec 9, 2022
2201f55
partly update
wenhuach21 Dec 9, 2022
07f1fcc
Merge branch 'cyy/pruning-api-merge' of https://github.com/intel/neur…
wenhuach21 Dec 9, 2022
71c0e53
add support for weight_compresssion_config
wenhuach21 Dec 9, 2022
4da7634
cyy:update unitest files for new api.
YIYANGCAI Dec 9, 2022
b1e1654
update unittests 2
WeiweiZhang1 Dec 9, 2022
aba1b23
update tests
WeiweiZhang1 Dec 9, 2022
c6f79d5
INC prune doc v2
yintong-lu Dec 9, 2022
6ffa816
try to fix init conflict
wenhuach21 Dec 9, 2022
2424ff4
trying to solve conflict
wenhuach21 Dec 9, 2022
685ff2d
trying to solve conflict issue
wenhuach21 Dec 9, 2022
3588322
INC prune doc v2.0
yintong-lu Dec 9, 2022
7b3f5f7
Merge branch 'cyy/pruning-api-merge' of https://github.com/intel/neur…
yintong-lu Dec 9, 2022
ed7cafe
Removed redundant yaml configs in ut code.
YIYANGCAI Dec 9, 2022
cbf24e5
pruning README v2
yintong-lu Dec 12, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .azure-pipelines/scripts/codeScan/pyspelling/inc_dict.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ berts
bertsquad
BertTokenizer
bfloat
blockwise
BFP
BGR
Bianchi
Expand Down Expand Up @@ -327,6 +328,7 @@ convolutional
Convolutional
ConvPerStage
ConvReLU
cooldown
copt
coreml
CoreML
Expand Down Expand Up @@ -741,6 +743,7 @@ horovodrun
hostfile
Hounsfield
howpublished
hyp
HqEgzS
href
html
Expand Down Expand Up @@ -1179,6 +1182,7 @@ ngatang
NGPUS
ngram
NHWC
ni
NIC
nifti
niftis
Expand Down Expand Up @@ -1240,8 +1244,11 @@ nvidia
NVIDIA
NVIDIA's
nvme
nw
Nx
NxM
nyu
oc
ok
ol
Omer
Expand All @@ -1251,6 +1258,7 @@ oneapi
oneAPI
onednn
oneDNN
oneshot
onlinedocs
onnx
ONNX
Expand Down Expand Up @@ -1885,6 +1893,7 @@ UI
UID
uint
uk
ultralytics
un
uncomment
uncompress
Expand All @@ -1895,6 +1904,7 @@ unidecode
uniq
unittest
unref
unscale
unsqueeze
unstack
upenn
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/imgs/pruning/pruning.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/source/_static/imgs/pruning/pruning_patterns.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
183 changes: 183 additions & 0 deletions docs/source/pruning_details.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
Pruning details
============



1. [Introduction](#introduction)



>>>[Neural Network Pruning](#neural-network-pruning)



>>>[Pruning Patterns](#pruning-patterns)



>>>[Pruning Criteria](#pruning-criteria)



>>>[Pruning Schedule](#pruning-schedule)



>>>[Pruning Type](#pruning-type)



>>>[Regularization](#regularization)





2. [Pruning examples](#examples)



3. [Reference](#reference)



## Introduction



### Neural Network Pruning
Neural network pruning is a promising model compression technique that removes the least important parameters in the network and achieves compact architectures with minimal accuracy drop and maximal inference acceleration. As state-of-the-art model sizes have grown at an unprecedented speed, pruning has become increasingly crucial for reducing the computational and memory footprint that huge neural networks require.




### Pruning Patterns


- Unstructured Pruning


Unstructured pruning means pruning the least salient connections in the model. The nonzero patterns are irregular and could be anywhere in the matrix.


- Structured Pruning


Structured pruning means pruning parameters in groups and deleting entire blocks, filters, or channels according to some pruning criterions. In general, structured pruning leads to lower accuracy due to restrictive structure compared to unstructured pruning but it can significantly accelerate the model execution as it fits better with hardware designs.






### Pruning Criteria



Pruning criteria determines how should the weights of a neural network be scored and pruned. The magnitude and gradient are widely used to score the weights.


- Magnitude


The algorithm prunes the weight by the lowest absolute value at each layer with given sparsity target.


- Gradient

The algorithm prunes the weight by the lowest gradient value at each layer with given sparsity target.

- SNIP


The algorithm prunes the dense model at its initialization, by analyzing the weights' effect to the loss function when they are masked. Please refer to the original [paper](https://arxiv.org/abs/1810.02340) for details


- SNIP with momentum


The algorithm improves original SNIP algorithms and introduces weights' score maps which updates in a momentum way.\
In the following formula, $n$ is the pruning step and $W$ and $G$ are model's weights and gradients respectively.
$$Score_{n} = 1.0 \times Score_{n-1} + 0.9 \times |W_{n} \times G_{n}|$$



### Pruning Schedule


Pruning schedule defines the way the model reach the target sparsity (the ratio of pruned weights).


- One-shot Pruning


One-shot pruning means the model is pruned to its target sparsity with one single step. This pruning method often works at model's initialization step. It can easily cause accuracy drop, but save much training time.



- Iterative Pruning


Iterative pruning means the model is gradually pruned to its target sparsity during a training process. The pruning process contains several pruning steps, and each step raises model's sparsity to a higher value. In the final pruning step, the model reaches target sparsity and the pruning process ends.




### Pruning Type



- Pattern_lock Pruning


Pattern_lock pruning type uses masks of a fixed pattern during the pruning process.


- Progressive Pruning


Progressive pruning aims at smoothing the structured pruning by automatically interpolating a group of interval masks during the pruning process. In this method, a sequence of masks are generated to enable a more flexible pruning process and those masks would gradually change into ones to fit the target pruning structure.


### Regularization


Regularization is a technique that discourages learning a more complex model and therefore performs variable-selection.


- Group Lasso


The Group-lasso algorithm is used to prune entire rows, columns or blocks of parameters that result in a smaller dense network.




## Pruning Examples



We validate the pruning technique on typical models across various domains (including CV, NLP, and Recommendation System) and the examples are listed below.


<table>
<thead>
<tr>
<th>Model</th>
<th>Dataset</th>
<th>Pruning Algorithm</th>
<th>Framework</th>
</tr>
</thead>



## Reference

[1] Namhoon Lee, Thalaiyasingam Ajanthan, and Philip Torr. SNIP: SINGLE-SHOT NETWORK
PRUNING BASED ON CONNECTION SENSITIVITY. In International Conference on
Learning Representations, 2019.




16 changes: 6 additions & 10 deletions docs/source/pythonic_style.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,14 @@ distiller = Distillation(config)
To specify pruning configurations, users can assign values to the corresponding attributes.
```python
from neural_compressor import config
config.pruning.weight_compression.initial_sparsity = 0.0
config.pruning.weight_compression.target_sparsity = 0.9
config.pruning.weight_compression.max_sparsity_ratio_per_layer = 0.98
config.pruning.weight_compression.prune_type = "basic_magnitude"
config.pruning.weight_compression.start_epoch = 0
config.pruning.weight_compression.end_epoch = 3
config.pruning.weight_compression.max_sparsity_ratio_per_op = 0.98
config.pruning.weight_compression.pruning_type = "snip_momentum"
config.pruning.weight_compression.start_step = 0
config.pruning.weight_compression.end_step = 0
config.pruning.weight_compression.update_frequency = 1.0
config.pruning.weight_compression.update_frequency_on_step = 1
config.pruning.weight_compression.prune_domain = "global"
config.pruning.weight_compression.pattern = "tile_pattern_1x1"
config.pruning.weight_compression.end_step = 3
config.pruning.weight_compression.pruning_frequency = 1
config.pruning.weight_compression.pruning_scope = "global"
config.pruning.weight_compression.pattern = "4x1"

from neural_compressor.experimental import Pruning
prune = Pruning(config)
Expand Down
2 changes: 1 addition & 1 deletion docs/source/user_yaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pruning:
- !Pruner
start_epoch: 0
end_epoch: 19
prune_type: basic_magnitude
pruning_type: basic_magnitude
```
* ***distillation***: The distillation specifications define distillation's tuning
space. Similar to pruning, to define the training behavior, users can use the
Expand Down
4 changes: 2 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -609,14 +609,14 @@ Intel® Neural Compressor validated examples with multiple compression technique
<td>Natural Language Processing (text classification)</td>
<td>Structured (4x1, 2in4), Unstructured</td>
<td>Snip-momentum</td>
<td><a href="./pytorch/nlp/huggingface_models/text-classification/pruning/pytorch_pruner/eager">eager</a></td>
<td><a href="pytorch/nlp/huggingface_models/text-classification/pruning/eager">eager</a></td>
</tr>
<tr>
<td>Bert-mini</td>
<td>Natural Language Processing (question answering)</td>
<td>Structured (4x1, 2in4), Unstructured</td>
<td>Snip-momentum</td>
<td><a href="./pytorch/nlp/huggingface_models/question-answering/pruning/pytorch_pruner/eager">eager</a></td>
<td><a href="pytorch/nlp/huggingface_models/question-answering/pruning/eager">eager</a></td>
</tr>
</tbody>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,15 @@ pruning:
CrossEntropyLoss:
approach:
weight_compression:
initial_sparsity: 0.0
target_sparsity: 0.3
start_epoch: 0
end_epoch: 4
start_step: 0
end_step: 1000
pruners:
- !Pruner
start_epoch: 0
end_epoch: 4
update_frequency: 1
prune_type: basic_magnitude
start_step: 0
end_step: 1000
pruning_frequency: 10
pruning_type: magnitude
names: ['layer1.0.conv1.weight', 'layer1.0.conv2.weight']

evaluation: # optional. required if user doesn't provide eval_func in neural_compressor.Quantization.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,15 @@ pruning:
CrossEntropyLoss:
approach:
weight_compression:
initial_sparsity: 0.0
target_sparsity: 0.3
start_epoch: 0
end_epoch: 4
start_step: 0
end_step: 2000
pruners:
- !Pruner
start_epoch: 0
end_epoch: 4
update_frequency: 1
prune_type: basic_magnitude
start_step: 0
end_step: 4
pruning_frequency: 100
pruning_type: "snip_momentum"
names: ['layer1.0.conv1.weight', 'layer1.0.conv2.weight']

evaluation: # optional. required if user doesn't provide eval_func in neural_compressor.Quantization.
Expand Down

This file was deleted.

Loading