@@ -162,7 +168,7 @@ class AMCTaskGenerator(TaskGenerator):
classAMCPruner(IterativePruner):
r"""
__doc__=r"""
AMC pruner leverages reinforcement learning to provide the model compression policy.
According to the author, this learning-based compression policy outperforms conventional rule-based compression policy by having a higher compression ratio,
better preserving the accuracy and freeing human labor.
...
...
@@ -186,10 +192,11 @@ class AMCPruner(IterativePruner):
- op_names : Operation name to be pruned.
- op_partial_names: Operation partial names to be pruned, will be autocompleted by NNI.
- exclude : Set True then the layers setting by op_types and op_names will be excluded from pruning.
dummy_input : torch.Tensor
`dummy_input` is required for speedup and tracing the model in RL environment.
evaluator : Callable[[Module], float]
Evaluate the pruned model and give a score.
evaluator
``evaluator`` is used to replace the previous ``finetuner``, ``dummy_input`` and old ``evaluator`` API.
{evaluator_docstring}
The old API (``finetuner``, ``dummy_input`` and old ``evaluator``) is still supported and will be deprecated in v3.0.
If you want to consult the old API, please refer to `v2.8 pruner API <https://nni.readthedocs.io/en/v2.8/reference/compression/pruner.html>`__.
_logger.warning('Only `total_sparsity` can be differentially allocated sparse ratio to each layer, `sparsity` or `sparsity_per_layer` will allocate fixed sparse ratio to layers. Make sure you know what this will lead to, otherwise please use `total_sparsity`.')
warn_msg='Only `total_sparsity` can be differentially allocated sparse ratio to each layer, '+ \
'`sparsity` or `sparsity_per_layer` will allocate fixed sparse ratio to layers. '+ \
'Make sure you know what this will lead to, otherwise please use `total_sparsity`.'
@@ -53,8 +60,9 @@ class AutoCompressTaskGenerator(LotteryTicketTaskGenerator):
classAutoCompressPruner(IterativePruner):
r"""
__doc__=r"""
For total iteration number :math:`N`, AutoCompressPruner prune the model that survive the previous iteration for a fixed sparsity ratio (e.g., :math:`1-{(1-0.8)}^{(1/N)}`) to achieve the overall sparsity (e.g., :math:`0.8`):
"""+r"""
.. code-block:: bash
...
...
@@ -65,35 +73,27 @@ class AutoCompressPruner(IterativePruner):
For detailed example please refer to :githublink:`examples/model_compress/pruning/movement_pruning_glue.py <examples/model_compress/pruning/movement_pruning_glue.py>`
_logger.debug('\nTask %s total real sparsity compared with original model is:\n%s',str(task_result.task_id),json_tricks.dumps(current2origin_sparsity,indent=4))
_logger.warning('Only `total_sparsity` can be differentially allocated sparse ratio to each layer, `sparsity` or `sparsity_per_layer` will allocate fixed sparse ratio to layers. Make sure you know what this will lead to, otherwise please use `total_sparsity`.')
warn_msg='Only `total_sparsity` can be differentially allocated sparse ratio to each layer, '+ \
'`sparsity` or `sparsity_per_layer` will allocate fixed sparse ratio to layers. '+ \
'Make sure you know what this will lead to, otherwise please use `total_sparsity`.'