parser.add_argument('--sparse_block',nargs='+',type=int,default=[1,1],help="There must be two integers inside this array. The array defines the shape of the block, the values within which are either sparsified to all zeros or kept original. [1, 1] means unstructured pruning. Default: [1, 1]")
add_arg('data',str,"imagenet","Which data to use. 'cifar10' or 'imagenet'. Default: imagenet")
add_arg('data',str,"imagenet","Which data to use. 'cifar10' or 'imagenet'. Default: imagenet")
add_arg('log_period',int,100,"Log period in batches. Default: 100")
add_arg('log_period',int,100,"Log period in batches. Default: 100")
add_arg('test_period',int,5,"Test period in epoches. Default: 5")
add_arg('test_period',int,5,"Test period in epoches. Default: 5")
parser.add_argument('--sparse_block',nargs='+',type=int,default=[1,1],help="There must be two integers inside this array. The array defines the shape of the block, the values within which are either sparsified to all zeros or kept original. [1, 1] means unstructured pruning. Default: [1, 1]")
add_arg('data',str,"imagenet","Which data to use. 'mnist', 'cifar10' or 'imagenet'. Default: imagenet")
add_arg('data',str,"imagenet","Which data to use. 'mnist', 'cifar10' or 'imagenet'. Default: imagenet")
add_arg('log_period',int,100,"Log period in batches. Default: 100")
add_arg('log_period',int,100,"Log period in batches. Default: 100")
add_arg('test_period',int,5,"Test period in epoches. Default: 5")
add_arg('test_period',int,5,"Test period in epoches. Default: 5")
- 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
- 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
- sparse_block(Array<Integer>): There must be two integers inside this array. The array defines the shape of the block, the values within which are either sparsified to all zeros or kept original. [1, 1] means unstructured pruning. Default: [1,1]
"""
"""
def__init__(self,
def__init__(self,
...
@@ -34,18 +37,28 @@ class UnstructuredPruner():
...
@@ -34,18 +37,28 @@ class 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):
local_sparsity=False,
sparse_block=[1,1]):
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:
iflocal_sparsity:
assertmode=='ratio',"We don't support local_sparsity==True and mode=='threshold' at the same time, please change the inputs accordingly."
assertmode=='ratio',"We don't support local_sparsity==True and mode=='threshold' at the same time, please change the inputs accordingly."
"Your sparse block size {} might be too large for the param {} with shape {}, the sparsity of this param might not be precise. Please decrease your sparse block size if possible. Currently, sparse_block[0] ({}) X sparse_block[1] ({}) / weight_count ({}) >= {}".
@@ -275,6 +306,7 @@ class GMPUnstructuredPruner(UnstructuredPruner):
...
@@ -275,6 +306,7 @@ class GMPUnstructuredPruner(UnstructuredPruner):
- 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
- 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
- sparse_block(Array<Integer>): There must be two integers inside this array. The array defines a block, the values within which are either sparsified to all zeros or kept original. [1, 1] means unstructured pruning. Default: [1,1]
- 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
...
@@ -296,12 +328,13 @@ class GMPUnstructuredPruner(UnstructuredPruner):
...
@@ -296,12 +328,13 @@ class GMPUnstructuredPruner(UnstructuredPruner):
prune_params_type=None,
prune_params_type=None,
skip_params_func=None,
skip_params_func=None,
local_sparsity=False,
local_sparsity=False,
sparse_block=[1,1],
configs=None):
configs=None):
assertconfigsisnotNone,"Configs must be passed in for GMP pruner."
assertconfigsisnotNone,"Configs must be passed in for GMP pruner."
- scope(paddle.static.Scope): The scope storing values of all variables. None means paddle.static.global_scope. Default: None.
- scope(paddle.static.Scope): The scope storing values of all variables. None means paddle.static.global_scope. Default: None.
- 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 and bias. 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
- 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
- sparse_block(Array<Integer>): There must be two integers inside this array. The array defines the shape of the block, the values within which are either sparsified to all zeros or kept original. [1, 1] means unstructured pruning. Default: [1,1]
"""
"""
def__init__(self,
def__init__(self,
...
@@ -32,18 +34,28 @@ class UnstructuredPruner():
...
@@ -32,18 +34,28 @@ class UnstructuredPruner():
place=None,
place=None,
prune_params_type=None,
prune_params_type=None,
skip_params_func=None,
skip_params_func=None,
local_sparsity=False):
local_sparsity=False,
sparse_block=[1,1]):
self.mode=mode
self.mode=mode
self.ratio=ratio
self.ratio=ratio
self.threshold=threshold
self.threshold=threshold
self.local_sparsity=local_sparsity
self.local_sparsity=local_sparsity
self.thresholds={}
self.thresholds={}
self.sparse_block=sparse_block
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:
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."
assertself.mode=='ratio',"We don't support local_sparsity==True and mode=='threshold' at the same time, please change the inputs accordingly."
"Your sparse block size {} might be too large for the param {} with shape {}, the sparsity of this param might not be precise. Please decrease your sparse block size if possible. Currently, sparse_block[0] ({}) X sparse_block[1] ({}) / weight_count ({}) >= {}".
@@ -322,6 +352,7 @@ class GMPUnstructuredPruner(UnstructuredPruner):
...
@@ -322,6 +352,7 @@ class GMPUnstructuredPruner(UnstructuredPruner):
- 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
- 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
- sparse_block(Array<Integer>): There must be two integers inside this array. The array defines the shape of the block, the values within which are either sparsified to all zeros or kept original. [1, 1] means unstructured pruning. Default: [1,1]
- 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
...
@@ -344,12 +375,13 @@ class GMPUnstructuredPruner(UnstructuredPruner):
...
@@ -344,12 +375,13 @@ class GMPUnstructuredPruner(UnstructuredPruner):
prune_params_type=None,
prune_params_type=None,
skip_params_func=None,
skip_params_func=None,
local_sparsity=False,
local_sparsity=False,
sparse_block=[1,1],
configs=None):
configs=None):
assertconfigsisnotNone,"Please pass in a valid config dictionary."
assertconfigsisnotNone,"Please pass in a valid config dictionary."