Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

[Model Compression] Update api of iterative pruners #3507

Merged
merged 31 commits into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b039897
Update compression api (draft)
colorjam Apr 2, 2021
ebadd81
Merge branch 'master' of https://github.com/microsoft/nni into update…
colorjam Apr 29, 2021
0bd64b6
Add gitignore
colorjam Apr 30, 2021
9f48741
Update model definition in examples of compression
colorjam Apr 30, 2021
0002cfd
Update compressor
colorjam Apr 30, 2021
24402d6
Update iterative pruners
colorjam Apr 30, 2021
1a1b787
Update ut
colorjam Apr 30, 2021
b657744
Add trainer to pruner and update doc
colorjam May 6, 2021
e2314e1
Fix pipeline
colorjam May 7, 2021
a58acf8
Fix doc's warnings
colorjam May 7, 2021
c8a3367
Fix pipeline
colorjam May 7, 2021
f7ea6ab
Fix ut
colorjam May 7, 2021
56ee838
Left changes on ws10
colorjam May 18, 2021
4f4e943
Add DependencyAwarePruner
colorjam May 18, 2021
ab5a850
Update according to review's comments
colorjam May 18, 2021
e14be2c
Fix sphinx warning
colorjam May 18, 2021
749a28c
Remove agp pruner
colorjam May 18, 2021
9e17143
Update according to review's comments.
colorjam May 21, 2021
40c918b
Fix ut & update doc
colorjam May 21, 2021
8bf9965
Fix ut
colorjam May 21, 2021
7c322ce
Update according to reviews' comments
colorjam May 21, 2021
4a03ab9
Update according to reviews' comments
colorjam May 22, 2021
f52fcf7
Update example function
colorjam May 24, 2021
a6869a2
fix comments
J-shang May 24, 2021
17423f0
Merge branch 'master' into update-compression-api
J-shang May 24, 2021
182a034
fix ut
J-shang May 25, 2021
876c38a
Merge branch 'update-compression-api' of https://github.com/colorjam/…
J-shang May 25, 2021
c5c40bb
fix ut & example
J-shang May 25, 2021
6fb4eb8
fix ut & example
J-shang May 25, 2021
2eae6a5
fix ut
J-shang May 25, 2021
9fcc7a9
fix ut
J-shang May 25, 2021
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
22 changes: 11 additions & 11 deletions docs/en_US/Compression/CompressionReference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Weight Masker
.. autoclass:: nni.algorithms.compression.pytorch.pruning.weight_masker.WeightMasker
:members:

.. autoclass:: nni.algorithms.compression.pytorch.pruning.structured_pruning.StructuredWeightMasker
.. autoclass:: nni.algorithms.compression.pytorch.pruning.structured_pruning_masker.StructuredWeightMasker
:members:


Expand All @@ -43,37 +43,37 @@ Pruners
.. autoclass:: nni.algorithms.compression.pytorch.pruning.sensitivity_pruner.SensitivityPruner
:members:

.. autoclass:: nni.algorithms.compression.pytorch.pruning.one_shot.OneshotPruner
.. autoclass:: nni.algorithms.compression.pytorch.pruning.one_shot_pruner.OneshotPruner
:members:

.. autoclass:: nni.algorithms.compression.pytorch.pruning.one_shot.LevelPruner
.. autoclass:: nni.algorithms.compression.pytorch.pruning.one_shot_pruner.LevelPruner
:members:

.. autoclass:: nni.algorithms.compression.pytorch.pruning.one_shot.SlimPruner
.. autoclass:: nni.algorithms.compression.pytorch.pruning.one_shot_pruner.L1FilterPruner
:members:

.. autoclass:: nni.algorithms.compression.pytorch.pruning.one_shot.L1FilterPruner
.. autoclass:: nni.algorithms.compression.pytorch.pruning.one_shot_pruner.L2FilterPruner
:members:

.. autoclass:: nni.algorithms.compression.pytorch.pruning.one_shot.L2FilterPruner
.. autoclass:: nni.algorithms.compression.pytorch.pruning.one_shot_pruner.FPGMPruner
:members:

.. autoclass:: nni.algorithms.compression.pytorch.pruning.one_shot.FPGMPruner
.. autoclass:: nni.algorithms.compression.pytorch.pruning.iterative_pruner.SlimPruner
:members:

.. autoclass:: nni.algorithms.compression.pytorch.pruning.one_shot.TaylorFOWeightFilterPruner
.. autoclass:: nni.algorithms.compression.pytorch.pruning.iterative_pruner.TaylorFOWeightFilterPruner
:members:

.. autoclass:: nni.algorithms.compression.pytorch.pruning.one_shot.ActivationAPoZRankFilterPruner
.. autoclass:: nni.algorithms.compression.pytorch.pruning.iterative_pruner.ActivationAPoZRankFilterPruner
:members:

.. autoclass:: nni.algorithms.compression.pytorch.pruning.one_shot.ActivationMeanRankFilterPruner
.. autoclass:: nni.algorithms.compression.pytorch.pruning.iterative_pruner.ActivationMeanRankFilterPruner
:members:

.. autoclass:: nni.algorithms.compression.pytorch.pruning.lottery_ticket.LotteryTicketPruner
:members:

.. autoclass:: nni.algorithms.compression.pytorch.pruning.agp.AGPPruner
.. autoclass:: nni.algorithms.compression.pytorch.pruning.agp_pruner.AGPPruner
:members:

.. autoclass:: nni.algorithms.compression.pytorch.pruning.admm_pruner.ADMMPruner
Expand Down
4 changes: 2 additions & 2 deletions docs/en_US/Compression/CustomizeCompressor.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ An implementation of ``weight masker`` may look like this:
# mask = ...
return {'weight_mask': mask}

You can reference nni provided :githublink:`weight masker <nni/algorithms/compression/pytorch/pruning/structured_pruning.py>` implementations to implement your own weight masker.
You can reference nni provided :githublink:`weight masker <nni/algorithms/compression/pytorch/pruning/structured_pruning_maskerpy>` implementations to implement your own weight masker.
J-shang marked this conversation as resolved.
Show resolved Hide resolved

A basic ``pruner`` looks likes this:

Expand All @@ -52,7 +52,7 @@ A basic ``pruner`` looks likes this:
wrapper.if_calculated = True
return masks

Reference nni provided :githublink:`pruner <nni/algorithms/compression/pytorch/pruning/one_shot.py>` implementations to implement your own pruner class.
Reference nni provided :githublink:`pruner <nni/algorithms/compression/pytorch/pruning/one_shot_pruner.py>` implementations to implement your own pruner class.

----

Expand Down
15 changes: 12 additions & 3 deletions docs/en_US/Compression/Overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,19 @@ NNI provides a model compression toolkit to help user compress and speed up thei
* Provide friendly and easy-to-use compression utilities for users to dive into the compression process and results.
* Concise interface for users to customize their own compression algorithms.


Compression Pipeline
--------------------

.. image:: ../../img/compression_flow.jpg
:target: ../../img/compression_flow.jpg
:alt:

The overall compression pipeline in NNI. For compress a pretrained model, pruning and quantization can be used alone or in combination.
J-shang marked this conversation as resolved.
Show resolved Hide resolved

.. note::
Since NNI compression algorithms are not meant to compress model while NNI speedup tool can truly compress model and reduce latency. To obtain a truly compact model, users should conduct `model speedup <./ModelSpeedup.rst>`__. The interface and APIs are unified for both PyTorch and TensorFlow, currently only PyTorch version has been supported, TensorFlow version will be supported in future.


Supported Algorithms
--------------------

Expand All @@ -26,7 +35,7 @@ The algorithms include pruning algorithms and quantization algorithms.
Pruning Algorithms
^^^^^^^^^^^^^^^^^^

Pruning algorithms compress the original network by removing redundant weights or channels of layers, which can reduce model complexity and address the over-fitting issue.
Pruning algorithms compress the original network by removing redundant weights or channels of layers, which can reduce model complexity and address the over-fitting issue.
zheng-ningxin marked this conversation as resolved.
Show resolved Hide resolved

.. list-table::
:header-rows: 1
Expand Down Expand Up @@ -94,6 +103,7 @@ Model Speedup

The final goal of model compression is to reduce inference latency and model size. However, existing model compression algorithms mainly use simulation to check the performance (e.g., accuracy) of compressed model, for example, using masks for pruning algorithms, and storing quantized values still in float32 for quantization algorithms. Given the output masks and quantization bits produced by those algorithms, NNI can really speed up the model. The detailed tutorial of Masked Model Speedup can be found `here <./ModelSpeedup.rst>`__, The detailed tutorial of Mixed Precision Quantization Model Speedup can be found `here <./QuantizationSpeedup.rst>`__.


Compression Utilities
---------------------

Expand All @@ -108,7 +118,6 @@ NNI model compression leaves simple interface for users to customize a new compr
Reference and Feedback
----------------------


* To `report a bug <https://github.com/microsoft/nni/issues/new?template=bug-report.rst>`__ for this feature in GitHub;
* To `file a feature or improvement request <https://github.com/microsoft/nni/issues/new?template=enhancement.rst>`__ for this feature in GitHub;
* To know more about `Feature Engineering with NNI <../FeatureEngineering/Overview.rst>`__\ ;
Expand Down
10 changes: 4 additions & 6 deletions docs/en_US/Compression/Pruner.rst
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
Supported Pruning Algorithms on NNI
===================================

We provide several pruning algorithms that support fine-grained weight pruning and structural filter pruning. **Fine-grained Pruning** generally results in unstructured models, which need specialized hardware or software to speed up the sparse network. **Filter Pruning** achieves acceleration by removing the entire filter. Some pruning algorithms use one-shot method that prune weights at once based on an importance metric. Other pruning algorithms control the **pruning schedule** that prune weights during optimization, including some automatic pruning algorithms.
We provide several pruning algorithms that support fine-grained weight pruning and structural filter pruning. **Fine-grained Pruning** generally results in unstructured models, which need specialized hardware or software to speed up the sparse network. **Filter Pruning** achieves acceleration by removing the entire filter. Some pruning algorithms use one-shot method that prune weights at once based on an importance metric (It is necessary to finetune the model to compensate for the loss of accuracy). Other pruning algorithms **iteratively** prune weights during optimization, which control the pruning schedule, including some automatic pruning algorithms.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filter Pruning -> One-shot Pruning

Copy link
Contributor Author

@colorjam colorjam May 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filter Pruning and Fine-grained Pruning represent the alternative methods from the perspective of pruning granularity.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, so we have two categories, (Filter Pruning and Fine-grained Pruning), (Iteratively Pruning and One-shot Pruning)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the difference between "filter pruning" and "channel pruning"? "channel pruning" is also a type of "filter pruning"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the difference between "filter pruning" and "channel pruning"? "channel pruning" is also a type of "filter pruning"?

Their selection rules are different, one is based on the weight of the filter(out-channel), the other is based on the weight of the input-channel. Filter pruning prunes the output channel of the conv layers and the channel pruning prunes the input channel of the conv layers. The have the same effect after the propagation( pruning an input channel is equivalent to pruning a filter of the previous conv) .



**Fine-grained Pruning**

* `Level Pruner <#level-pruner>`__
J-shang marked this conversation as resolved.
Show resolved Hide resolved

**Filter Pruning**
**One-shot Pruning**

* `Slim Pruner <#slim-pruner>`__
* `FPGM Pruner <#fpgm-pruner>`__
Expand All @@ -18,18 +17,17 @@ We provide several pruning algorithms that support fine-grained weight pruning a
* `Activation Mean Rank Filter Pruner <#activationmeanrankfilter-pruner>`__
* `Taylor FO On Weight Pruner <#taylorfoweightfilter-pruner>`__

**Pruning Schedule**
**Iteratively Pruning**

* `AGP Pruner <#agp-pruner>`__
* `NetAdapt Pruner <#netadapt-pruner>`__
* `SimulatedAnnealing Pruner <#simulatedannealing-pruner>`__
* `AutoCompress Pruner <#autocompress-pruner>`__
* `AMC Pruner <#amc-pruner>`__
* `Sensitivity Pruner <#sensitivity-pruner>`__
* `ADMM Pruner <#admm-pruner>`__

**Others**

* `ADMM Pruner <#admm-pruner>`__
* `Lottery Ticket Hypothesis <#lottery-ticket-hypothesis>`__

Level Pruner
Expand Down
Binary file added docs/img/compression_flow.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/zh_CN/Compression/CompressionReference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module 的包装
.. autoclass:: nni.algorithms.compression.pytorch.pruning.weight_masker.WeightMasker
:members:

.. autoclass:: nni.algorithms.compression.pytorch.pruning.structured_pruning.StructuredWeightMasker
.. autoclass:: nni.algorithms.compression.pytorch.pruning.structured_pruning_maskerStructuredWeightMasker
J-shang marked this conversation as resolved.
Show resolved Hide resolved
:members:


Expand Down
2 changes: 1 addition & 1 deletion docs/zh_CN/Compression/CustomizeCompressor.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# mask = ...
return {'weight_mask': mask}

参考 NNI 提供的 :githublink:`权重掩码 <nni/algorithms/compression/pytorch/pruning/structured_pruning.py>` 来实现自己的权重掩码。
参考 NNI 提供的 :githublink:`权重掩码 <nni/algorithms/compression/pytorch/pruning/structured_pruning_maskerpy>` 来实现自己的权重掩码。
J-shang marked this conversation as resolved.
Show resolved Hide resolved

基础的 ``Pruner`` 如下所示:

Expand Down
6 changes: 6 additions & 0 deletions examples/model_compress/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.pth
.tar.gz
data/
MNIST/
cifar-10-batches-py/
experiment_data/
Loading