- ratio(float): The parameters whose absolute values are in the smaller part decided by the ratio will be zeros. Default: 0.55
- ratio(float): The parameters whose absolute values are in the smaller part decided by the ratio will be zeros. Default: 0.55
- prune_params_type(str): The argument to control which type of ops will be pruned. Currently we only support None (all but norms) or conv1x1_only as input. It acts as a straightforward call to conv1x1 pruning. Default: None
- prune_params_type(str): The argument to control which type of ops will be pruned. Currently we only support None (all but norms) or conv1x1_only as input. It acts as a straightforward call to conv1x1 pruning. Default: None
- skip_params_func(function): The function used to select the parameters which should be skipped when performing pruning. Default: normalization-related params.
- skip_params_func(function): The function used to select the parameters which should be skipped when performing pruning. Default: normalization-related params.
- local_sparsity(bool): Whether to enable local sparsity. Local sparsity means all the weight matrices have the same sparsity. And the global sparsity only ensures the whole model's sparsity is equal to the passed-in 'ratio'. Default: False
"""
"""
def__init__(self,
def__init__(self,
...
@@ -32,14 +33,19 @@ class UnstructuredPruner():
...
@@ -32,14 +33,19 @@ class UnstructuredPruner():
threshold=0.01,
threshold=0.01,
ratio=0.55,
ratio=0.55,
prune_params_type=None,
prune_params_type=None,
skip_params_func=None):
skip_params_func=None,
local_sparsity=False):
assertmodein('ratio','threshold'
assertmodein('ratio','threshold'
),"mode must be selected from 'ratio' and 'threshold'"
),"mode must be selected from 'ratio' and 'threshold'"
assertprune_params_typeisNoneorprune_params_type=='conv1x1_only',"prune_params_type only supports None or conv1x1_only for now."
assertprune_params_typeisNoneorprune_params_type=='conv1x1_only',"prune_params_type only supports None or conv1x1_only for now."
iflocal_sparsity:
assertmode=='ratio',"We don't support local_sparsity==True and mode=='threshold' at the same time, please change the inputs accordingly."
@@ -243,6 +261,7 @@ class GMPUnstructuredPruner(UnstructuredPruner):
...
@@ -243,6 +261,7 @@ class GMPUnstructuredPruner(UnstructuredPruner):
- ratio(float): The parameters whose absolute values are in the smaller part decided by the ratio will be zeros. Default: 0.55
- ratio(float): The parameters whose absolute values are in the smaller part decided by the ratio will be zeros. Default: 0.55
- prune_params_type(str): The argument to control which type of ops will be pruned. Currently we only support None (all but norms) or conv1x1_only as input. It acts as a straightforward call to conv1x1 pruning. Default: None
- prune_params_type(str): The argument to control which type of ops will be pruned. Currently we only support None (all but norms) or conv1x1_only as input. It acts as a straightforward call to conv1x1 pruning. Default: None
- skip_params_func(function): The function used to select the parameters which should be skipped when performing pruning. Default: normalization-related params.
- skip_params_func(function): The function used to select the parameters which should be skipped when performing pruning. Default: normalization-related params.
- local_sparsity(bool): Whether to enable local sparsity. Local sparsity means all the weight matrices have the same sparsity. And the global sparsity only ensures the whole model's sparsity is equal to the passed-in 'ratio'. Default: False
- configs(Dict): The dictionary contains all the configs for GMP pruner. Default: None
- configs(Dict): The dictionary contains all the configs for GMP pruner. Default: None
.. code-block:: python
.. code-block:: python
...
@@ -263,11 +282,13 @@ class GMPUnstructuredPruner(UnstructuredPruner):
...
@@ -263,11 +282,13 @@ class GMPUnstructuredPruner(UnstructuredPruner):
ratio=0.55,
ratio=0.55,
prune_params_type=None,
prune_params_type=None,
skip_params_func=None,
skip_params_func=None,
local_sparsity=False,
configs=None):
configs=None):
assertconfigsisnotNone,"Configs must be passed in for GMP pruner."
assertconfigsisnotNone,"Configs must be passed in for GMP pruner."
- place(CPUPlace | CUDAPlace): The device place used to execute model. None means CPUPlace. Default: None.
- place(CPUPlace | CUDAPlace): The device place used to execute model. None means CPUPlace. Default: None.
- prune_params_type(str): The argument to control which type of ops will be pruned. Currently we only support None (all but norms) or conv1x1_only as input. It acts as a straightforward call to conv1x1 pruning. Default: None
- prune_params_type(str): The argument to control which type of ops will be pruned. Currently we only support None (all but norms) or conv1x1_only as input. It acts as a straightforward call to conv1x1 pruning. Default: None
- skip_params_func(function): The function used to select the parameters which should be skipped when performing pruning. Default: normalization-related params. Default: None
- skip_params_func(function): The function used to select the parameters which should be skipped when performing pruning. Default: normalization-related params. Default: None
- local_sparsity(bool): Whether to enable local sparsity. Local sparsity means all the weight matrices have the same sparsity. And the global sparsity only ensures the whole model's sparsity is equal to the passed-in 'ratio'. Default: False
"""
"""
def__init__(self,
def__init__(self,
...
@@ -30,15 +31,19 @@ class UnstructuredPruner():
...
@@ -30,15 +31,19 @@ class UnstructuredPruner():
scope=None,
scope=None,
place=None,
place=None,
prune_params_type=None,
prune_params_type=None,
skip_params_func=None):
skip_params_func=None,
local_sparsity=False):
self.mode=mode
self.mode=mode
self.ratio=ratio
self.ratio=ratio
self.threshold=threshold
self.threshold=threshold
self.local_sparsity=local_sparsity
self.thresholds={}
assertself.modein[
assertself.modein[
'ratio','threshold'
'ratio','threshold'
],"mode must be selected from 'ratio' and 'threshold'"
],"mode must be selected from 'ratio' and 'threshold'"
assertprune_params_typeisNoneorprune_params_type=='conv1x1_only',"prune_params_type only supports None or conv1x1_only for now."
assertprune_params_typeisNoneorprune_params_type=='conv1x1_only',"prune_params_type only supports None or conv1x1_only for now."
ifself.local_sparsity:
assertself.mode=='ratio',"We don't support local_sparsity==True and mode=='threshold' at the same time, please change the inputs accordingly."
@@ -296,6 +311,7 @@ class GMPUnstructuredPruner(UnstructuredPruner):
...
@@ -296,6 +311,7 @@ class GMPUnstructuredPruner(UnstructuredPruner):
- place(CPUPlace | CUDAPlace): The device place used to execute model. None means CPUPlace. Default: None.
- place(CPUPlace | CUDAPlace): The device place used to execute model. None means CPUPlace. Default: None.
- prune_params_type(str): The argument to control which type of ops will be pruned. Currently we only support None (all but norms) or conv1x1_only as input. It acts as a straightforward call to conv1x1 pruning. Default: None
- prune_params_type(str): The argument to control which type of ops will be pruned. Currently we only support None (all but norms) or conv1x1_only as input. It acts as a straightforward call to conv1x1 pruning. Default: None
- skip_params_func(function): The function used to select the parameters which should be skipped when performing pruning. Default: normalization-related params. Default: None
- skip_params_func(function): The function used to select the parameters which should be skipped when performing pruning. Default: normalization-related params. Default: None
- local_sparsity(bool): Whether to enable local sparsity. Local sparsity means all the weight matrices have the same sparsity. And the global sparsity only ensures the whole model's sparsity is equal to the passed-in 'ratio'. Default: False
- configs(Dict): The dictionary contains all the configs for GMP pruner. Default: None. The detailed description is as below:
- configs(Dict): The dictionary contains all the configs for GMP pruner. Default: None. The detailed description is as below:
.. code-block:: python
.. code-block:: python
...
@@ -317,12 +333,13 @@ class GMPUnstructuredPruner(UnstructuredPruner):
...
@@ -317,12 +333,13 @@ class GMPUnstructuredPruner(UnstructuredPruner):
place=None,
place=None,
prune_params_type=None,
prune_params_type=None,
skip_params_func=None,
skip_params_func=None,
local_sparsity=False,
configs=None):
configs=None):
assertconfigsisnotNone,"Please pass in a valid config dictionary."
assertconfigsisnotNone,"Please pass in a valid config dictionary."