torch.nn.utils.prune.l1_unstructured#
- torch.nn.utils.prune.l1_unstructured(module,name,amount,importance_scores=None)[source]#
Prune tensor by removing units with the lowest L1-norm.
Prunes tensor corresponding to parameter called
nameinmoduleby removing the specifiedamount of (currently unpruned) units with thelowest L1-norm.Modifies module in place (and also return the modified module)by:adding a named buffer called
name+'_mask'corresponding to thebinary mask applied to the parameternameby the pruning method.replacing the parameter
nameby its pruned version, while theoriginal (unpruned) parameter is stored in a new parameter namedname+'_orig'.
- Parameters
module (nn.Module) – module containing the tensor to prune
name (str) – parameter name within
moduleon which pruningwill act.amount (int orfloat) – quantity of parameters to prune.If
float, should be between 0.0 and 1.0 and represent thefraction of parameters to prune. Ifint, it represents theabsolute number of parameters to prune.importance_scores (torch.Tensor) – tensor of importance scores (of sameshape as module parameter) used to compute mask for pruning.The values in this tensor indicate the importance of the correspondingelements in the parameter being pruned.If unspecified or None, the module parameter will be used in its place.
- Returns
modified (i.e. pruned) version of the input module
- Return type
module (nn.Module)
Examples
>>>m=prune.l1_unstructured(nn.Linear(2,3),"weight",amount=0.2)>>>m.state_dict().keys()odict_keys(['bias', 'weight_orig', 'weight_mask'])