neulab/docprompting-conala huggingface dataset:
class torch.nn.utils.prune.CustomFromMask(mask) [source]
 
 
classmethod apply(module, name, mask) [source]
 
Adds the forward pre-hook that enables pruning on the fly and the reparametrization of a tensor in terms of the original tensor and the pruning mask.  Parameters 
 
module (nn.Module) – module containing the tensor to prune 
name (str) – parameter name within module on which pruning will act.    
  
apply_mask(module)  
Simply handles the multiplication between the parameter being pruned and the generated mask. Fetches the mask and the original tensor from the module and returns the pruned version of the tensor.  Parameters 
module (nn.Module) – module containing the tensor to prune  Returns 
pruned version of the input tensor  Return type 
pruned_tensor (torch.Tensor)   
  
prune(t, default_mask=None, importance_scores=None)  
Computes and returns a pruned version of input tensor t according to the pruning rule specified in compute_mask().  Parameters 
 
t (torch.Tensor) – tensor to prune (of same dimensions as default_mask). 
importance_scores (torch.Tensor) – tensor of importance scores (of same shape as t) used to compute mask for pruning t. The values in this tensor indicate the importance of the corresponding elements in the t that is being pruned. If unspecified or None, the tensor t will be used in its place. 
default_mask (torch.Tensor, optional) – mask from previous pruning iteration, if any. To be considered when determining what portion of the tensor that pruning should act on. If None, default to a mask of ones.   Returns 
pruned version of tensor t.   
  
remove(module)  
Removes the pruning reparameterization from a module. The pruned parameter named name remains permanently pruned, and the parameter named name+'_orig' is removed from the parameter list. Similarly, the buffer named name+'_mask' is removed from the buffers.  Note Pruning itself is NOT undone or reversed!
classmethod apply(module, name, mask) [source]
 
Adds the forward pre-hook that enables pruning on the fly and the reparametrization of a tensor in terms of the original tensor and the pruning mask.  Parameters 
 
module (nn.Module) – module containing the tensor to prune 
name (str) – parameter name within module on which pruning will act.
apply_mask(module)  
Simply handles the multiplication between the parameter being pruned and the generated mask. Fetches the mask and the original tensor from the module and returns the pruned version of the tensor.  Parameters 
module (nn.Module) – module containing the tensor to prune  Returns 
pruned version of the input tensor  Return type 
pruned_tensor (torch.Tensor)
prune(t, default_mask=None, importance_scores=None)  
Computes and returns a pruned version of input tensor t according to the pruning rule specified in compute_mask().  Parameters 
 
t (torch.Tensor) – tensor to prune (of same dimensions as default_mask). 
importance_scores (torch.Tensor) – tensor of importance scores (of same shape as t) used to compute mask for pruning t. The values in this tensor indicate the importance of the corresponding elements in the t that is being pruned. If unspecified or None, the tensor t will be used in its place. 
default_mask (torch.Tensor, optional) – mask from previous pruning iteration, if any. To be considered when determining what portion of the tensor that pruning should act on. If None, default to a mask of ones.   Returns 
pruned version of tensor t.
remove(module)  
Removes the pruning reparameterization from a module. The pruned parameter named name remains permanently pruned, and the parameter named name+'_orig' is removed from the parameter list. Similarly, the buffer named name+'_mask' is removed from the buffers.  Note Pruning itself is NOT undone or reversed!
torch.nn.utils.prune.custom_from_mask(module, name, mask) [source]
 
Prunes tensor corresponding to parameter called name in module by applying the pre-computed mask in mask. Modifies module in place (and also return the modified module) by: 1) adding a named buffer called name+'_mask' corresponding to the binary mask applied to the parameter name by the pruning method. 2) replacing the parameter name by its pruned version, while the original (unpruned) parameter is stored in a new parameter named name+'_orig'.  Parameters 
 
module (nn.Module) – module containing the tensor to prune 
name (str) – parameter name within module on which pruning will act. 
mask (Tensor) – binary mask to be applied to the parameter.   Returns 
modified (i.e. pruned) version of the input module  Return type 
module (nn.Module)   Examples >>> m = prune.custom_from_mask(
        nn.Linear(5, 3), name='bias', mask=torch.Tensor([0, 1, 0])
    )
>>> print(m.bias_mask)
tensor([0., 1., 0.])
torch.nn.utils.prune.global_unstructured(parameters, pruning_method, importance_scores=None, **kwargs) [source]
 
Globally prunes tensors corresponding to all parameters in parameters by applying the specified pruning_method. Modifies modules in place by: 1) adding a named buffer called name+'_mask' corresponding to the binary mask applied to the parameter name by the pruning method. 2) replacing the parameter name by its pruned version, while the original (unpruned) parameter is stored in a new parameter named name+'_orig'.  Parameters 
 
parameters (Iterable of (module, name) tuples) – parameters of the model to prune in a global fashion, i.e. by aggregating all weights prior to deciding which ones to prune. module must be of type nn.Module, and name must be a string. 
pruning_method (function) – a valid pruning function from this module, or a custom one implemented by the user that satisfies the implementation guidelines and has PRUNING_TYPE='unstructured'. 
importance_scores (dict) – a dictionary mapping (module, name) tuples to the corresponding parameter’s importance scores tensor. The tensor should be the same shape as the parameter, and is used for computing mask for pruning. If unspecified or None, the parameter will be used in place of its importance scores. 
kwargs – other keyword arguments such as: amount (int or float): quantity of parameters to prune across the specified parameters. If float, should be between 0.0 and 1.0 and represent the fraction of parameters to prune. If int, it represents the absolute number of parameters to prune.   Raises 
TypeError – if PRUNING_TYPE != 'unstructured'    Note Since global structured pruning doesn’t make much sense unless the norm is normalized by the size of the parameter, we now limit the scope of global pruning to unstructured methods.  Examples >>> net = nn.Sequential(OrderedDict([
        ('first', nn.Linear(10, 4)),
        ('second', nn.Linear(4, 1)),
    ]))
>>> parameters_to_prune = (
        (net.first, 'weight'),
        (net.second, 'weight'),
    )
>>> prune.global_unstructured(
        parameters_to_prune,
        pruning_method=prune.L1Unstructured,
        amount=10,
    )
>>> print(sum(torch.nn.utils.parameters_to_vector(net.buffers()) == 0))
tensor(10, dtype=torch.uint8)
class torch.nn.utils.prune.Identity [source]
 
Utility pruning method that does not prune any units but generates the pruning parametrization with a mask of ones.  
classmethod apply(module, name) [source]
 
Adds the forward pre-hook that enables pruning on the fly and the reparametrization of a tensor in terms of the original tensor and the pruning mask.  Parameters 
 
module (nn.Module) – module containing the tensor to prune 
name (str) – parameter name within module on which pruning will act.    
  
apply_mask(module)  
Simply handles the multiplication between the parameter being pruned and the generated mask. Fetches the mask and the original tensor from the module and returns the pruned version of the tensor.  Parameters 
module (nn.Module) – module containing the tensor to prune  Returns 
pruned version of the input tensor  Return type 
pruned_tensor (torch.Tensor)   
  
prune(t, default_mask=None, importance_scores=None)  
Computes and returns a pruned version of input tensor t according to the pruning rule specified in compute_mask().  Parameters 
 
t (torch.Tensor) – tensor to prune (of same dimensions as default_mask). 
importance_scores (torch.Tensor) – tensor of importance scores (of same shape as t) used to compute mask for pruning t. The values in this tensor indicate the importance of the corresponding elements in the t that is being pruned. If unspecified or None, the tensor t will be used in its place. 
default_mask (torch.Tensor, optional) – mask from previous pruning iteration, if any. To be considered when determining what portion of the tensor that pruning should act on. If None, default to a mask of ones.   Returns 
pruned version of tensor t.   
  
remove(module)  
Removes the pruning reparameterization from a module. The pruned parameter named name remains permanently pruned, and the parameter named name+'_orig' is removed from the parameter list. Similarly, the buffer named name+'_mask' is removed from the buffers.  Note Pruning itself is NOT undone or reversed!
classmethod apply(module, name) [source]
 
Adds the forward pre-hook that enables pruning on the fly and the reparametrization of a tensor in terms of the original tensor and the pruning mask.  Parameters 
 
module (nn.Module) – module containing the tensor to prune 
name (str) – parameter name within module on which pruning will act.
torch.nn.utils.prune.is_pruned(module) [source]
 
Check whether module is pruned by looking for forward_pre_hooks in its modules that inherit from the BasePruningMethod.  Parameters 
module (nn.Module) – object that is either pruned or unpruned  Returns 
binary answer to whether module is pruned.   Examples >>> m = nn.Linear(5, 7)
>>> print(prune.is_pruned(m))
False
>>> prune.random_unstructured(m, name='weight', amount=0.2)
>>> print(prune.is_pruned(m))
True
class torch.nn.utils.prune.L1Unstructured(amount) [source]
 
Prune (currently unpruned) units in a tensor by zeroing out the ones with the lowest L1-norm.  Parameters 
amount (int or float) – quantity of parameters to prune. If float, should be between 0.0 and 1.0 and represent the fraction of parameters to prune. If int, it represents the absolute number of parameters to prune.    
classmethod apply(module, name, amount, importance_scores=None) [source]
 
Adds the forward pre-hook that enables pruning on the fly and the reparametrization of a tensor in terms of the original tensor and the pruning mask.  Parameters 
 
module (nn.Module) – module containing the tensor to prune 
name (str) – parameter name within module on which pruning will act. 
amount (int or float) – quantity of parameters to prune. If float, should be between 0.0 and 1.0 and represent the fraction of parameters to prune. If int, it represents the absolute number of parameters to prune. 
importance_scores (torch.Tensor) – tensor of importance scores (of same shape as module parameter) used to compute mask for pruning. The values in this tensor indicate the importance of the corresponding elements in the parameter being pruned. If unspecified or None, the module parameter will be used in its place.    
  
apply_mask(module)  
Simply handles the multiplication between the parameter being pruned and the generated mask. Fetches the mask and the original tensor from the module and returns the pruned version of the tensor.  Parameters 
module (nn.Module) – module containing the tensor to prune  Returns 
pruned version of the input tensor  Return type 
pruned_tensor (torch.Tensor)   
  
prune(t, default_mask=None, importance_scores=None)  
Computes and returns a pruned version of input tensor t according to the pruning rule specified in compute_mask().  Parameters 
 
t (torch.Tensor) – tensor to prune (of same dimensions as default_mask). 
importance_scores (torch.Tensor) – tensor of importance scores (of same shape as t) used to compute mask for pruning t. The values in this tensor indicate the importance of the corresponding elements in the t that is being pruned. If unspecified or None, the tensor t will be used in its place. 
default_mask (torch.Tensor, optional) – mask from previous pruning iteration, if any. To be considered when determining what portion of the tensor that pruning should act on. If None, default to a mask of ones.   Returns 
pruned version of tensor t.   
  
remove(module)  
Removes the pruning reparameterization from a module. The pruned parameter named name remains permanently pruned, and the parameter named name+'_orig' is removed from the parameter list. Similarly, the buffer named name+'_mask' is removed from the buffers.  Note Pruning itself is NOT undone or reversed!
classmethod apply(module, name, amount, importance_scores=None) [source]
 
Adds the forward pre-hook that enables pruning on the fly and the reparametrization of a tensor in terms of the original tensor and the pruning mask.  Parameters 
 
module (nn.Module) – module containing the tensor to prune 
name (str) – parameter name within module on which pruning will act. 
amount (int or float) – quantity of parameters to prune. If float, should be between 0.0 and 1.0 and represent the fraction of parameters to prune. If int, it represents the absolute number of parameters to prune. 
importance_scores (torch.Tensor) – tensor of importance scores (of same shape as module parameter) used to compute mask for pruning. The values in this tensor indicate the importance of the corresponding elements in the parameter being pruned. If unspecified or None, the module parameter will be used in its place.
torch.nn.utils.prune.l1_unstructured(module, name, amount, importance_scores=None) [source]
 
Prunes tensor corresponding to parameter called name in module by removing the specified amount of (currently unpruned) units with the lowest L1-norm. Modifies module in place (and also return the modified module) by: 1) adding a named buffer called name+'_mask' corresponding to the binary mask applied to the parameter name by the pruning method. 2) replacing the parameter name by its pruned version, while the original (unpruned) parameter is stored in a new parameter named name+'_orig'.  Parameters 
 
module (nn.Module) – module containing the tensor to prune 
name (str) – parameter name within module on which pruning will act. 
amount (int or float) – quantity of parameters to prune. If float, should be between 0.0 and 1.0 and represent the fraction of parameters to prune. If int, it represents the absolute number of parameters to prune. 
importance_scores (torch.Tensor) – tensor of importance scores (of same shape as module parameter) used to compute mask for pruning. The values in this tensor indicate the importance of the corresponding elements 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'])
classmethod apply(module, name, amount, n, dim, importance_scores=None) [source]
 
Adds the forward pre-hook that enables pruning on the fly and the reparametrization of a tensor in terms of the original tensor and the pruning mask.  Parameters 
 
module (nn.Module) – module containing the tensor to prune 
name (str) – parameter name within module on which pruning will act. 
amount (int or float) – quantity of parameters to prune. If float, should be between 0.0 and 1.0 and represent the fraction of parameters to prune. If int, it represents the absolute number of parameters to prune. 
n (int, float, inf, -inf, 'fro', 'nuc') – See documentation of valid entries for argument p in torch.norm(). 
dim (int) – index of the dim along which we define channels to prune. 
importance_scores (torch.Tensor) – tensor of importance scores (of same shape as module parameter) used to compute mask for pruning. The values in this tensor indicate the importance of the corresponding elements in the parameter being pruned. If unspecified or None, the module parameter will be used in its place.
compute_mask(t, default_mask) [source]
 
Computes and returns a mask for the input tensor t. Starting from a base default_mask (which should be a mask of ones if the tensor has not been pruned yet), generate a mask to apply on top of the default_mask by zeroing out the channels along the specified dim with the lowest Ln-norm.  Parameters 
 
t (torch.Tensor) – tensor representing the parameter to prune 
default_mask (torch.Tensor) – Base mask from previous pruning iterations, that need to be respected after the new mask is applied. Same dims as t.   Returns 
mask to apply to t, of same dims as t  Return type 
mask (torch.Tensor)  Raises 
IndexError – if self.dim >= len(t.shape)
torch.nn.utils.prune.ln_structured(module, name, amount, n, dim, importance_scores=None) [source]
 
Prunes tensor corresponding to parameter called name in module by removing the specified amount of (currently unpruned) channels along the specified dim with the lowest L``n``-norm. Modifies module in place (and also return the modified module) by: 1) adding a named buffer called name+'_mask' corresponding to the binary mask applied to the parameter name by the pruning method. 2) replacing the parameter name by its pruned version, while the original (unpruned) parameter is stored in a new parameter named name+'_orig'.  Parameters 
 
module (nn.Module) – module containing the tensor to prune 
name (str) – parameter name within module on which pruning will act. 
amount (int or float) – quantity of parameters to prune. If float, should be between 0.0 and 1.0 and represent the fraction of parameters to prune. If int, it represents the absolute number of parameters to prune. 
n (int, float, inf, -inf, 'fro', 'nuc') – See documentation of valid entries for argument p in torch.norm(). 
dim (int) – index of the dim along which we define channels to prune. 
importance_scores (torch.Tensor) – tensor of importance scores (of same shape as module parameter) used to compute mask for pruning. The values in this tensor indicate the importance of the corresponding elements 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.ln_structured(
       nn.Conv2d(5, 3, 2), 'weight', amount=0.3, dim=1, n=float('-inf')
    )
add_pruning_method(method) [source]
 
Adds a child pruning method to the container.  Parameters 
method (subclass of BasePruningMethod) – child pruning method to be added to the container.
classmethod apply(module, name, *args, importance_scores=None, **kwargs)  
Adds the forward pre-hook that enables pruning on the fly and the reparametrization of a tensor in terms of the original tensor and the pruning mask.  Parameters 
 
module (nn.Module) – module containing the tensor to prune 
name (str) – parameter name within module on which pruning will act. 
args – arguments passed on to a subclass of BasePruningMethod
 
importance_scores (torch.Tensor) – tensor of importance scores (of same shape as module parameter) used to compute mask for pruning. The values in this tensor indicate the importance of the corresponding elements in the parameter being pruned. If unspecified or None, the parameter will be used in its place. 
kwargs – keyword arguments passed on to a subclass of a BasePruningMethod
compute_mask(t, default_mask) [source]
 
Applies the latest method by computing the new partial masks and returning its combination with the default_mask. The new partial mask should be computed on the entries or channels that were not zeroed out by the default_mask. Which portions of the tensor t the new mask will be calculated from depends on the PRUNING_TYPE (handled by the type handler):  for ‘unstructured’, the mask will be computed from the raveled list of nonmasked entries; for ‘structured’, the mask will be computed from the nonmasked channels in the tensor; for ‘global’, the mask will be computed across all entries.   Parameters 
 
t (torch.Tensor) – tensor representing the parameter to prune (of same dimensions as default_mask). 
default_mask (torch.Tensor) – mask from previous pruning iteration.   Returns 
new mask that combines the effects of the default_mask and the new mask from the current pruning method (of same dimensions as default_mask and t).  Return type 
mask (torch.Tensor)
classmethod apply(module, name, amount, dim=-1) [source]
 
Adds the forward pre-hook that enables pruning on the fly and the reparametrization of a tensor in terms of the original tensor and the pruning mask.  Parameters 
 
module (nn.Module) – module containing the tensor to prune 
name (str) – parameter name within module on which pruning will act. 
amount (int or float) – quantity of parameters to prune. If float, should be between 0.0 and 1.0 and represent the fraction of parameters to prune. If int, it represents the absolute number of parameters to prune. 
dim (int, optional) – index of the dim along which we define channels to prune. Default: -1.
compute_mask(t, default_mask) [source]
 
Computes and returns a mask for the input tensor t. Starting from a base default_mask (which should be a mask of ones if the tensor has not been pruned yet), generate a random mask to apply on top of the default_mask by randomly zeroing out channels along the specified dim of the tensor.  Parameters 
 
t (torch.Tensor) – tensor representing the parameter to prune 
default_mask (torch.Tensor) – Base mask from previous pruning iterations, that need to be respected after the new mask is applied. Same dims as t.   Returns 
mask to apply to t, of same dims as t  Return type 
mask (torch.Tensor)  Raises 
IndexError – if self.dim >= len(t.shape)
class torch.nn.utils.prune.RandomUnstructured(amount) [source]
 
Prune (currently unpruned) units in a tensor at random.  Parameters 
 
name (str) – parameter name within module on which pruning will act. 
amount (int or float) – quantity of parameters to prune. If float, should be between 0.0 and 1.0 and represent the fraction of parameters to prune. If int, it represents the absolute number of parameters to prune.     
classmethod apply(module, name, amount) [source]
 
Adds the forward pre-hook that enables pruning on the fly and the reparametrization of a tensor in terms of the original tensor and the pruning mask.  Parameters 
 
module (nn.Module) – module containing the tensor to prune 
name (str) – parameter name within module on which pruning will act. 
amount (int or float) – quantity of parameters to prune. If float, should be between 0.0 and 1.0 and represent the fraction of parameters to prune. If int, it represents the absolute number of parameters to prune.    
  
apply_mask(module)  
Simply handles the multiplication between the parameter being pruned and the generated mask. Fetches the mask and the original tensor from the module and returns the pruned version of the tensor.  Parameters 
module (nn.Module) – module containing the tensor to prune  Returns 
pruned version of the input tensor  Return type 
pruned_tensor (torch.Tensor)   
  
prune(t, default_mask=None, importance_scores=None)  
Computes and returns a pruned version of input tensor t according to the pruning rule specified in compute_mask().  Parameters 
 
t (torch.Tensor) – tensor to prune (of same dimensions as default_mask). 
importance_scores (torch.Tensor) – tensor of importance scores (of same shape as t) used to compute mask for pruning t. The values in this tensor indicate the importance of the corresponding elements in the t that is being pruned. If unspecified or None, the tensor t will be used in its place. 
default_mask (torch.Tensor, optional) – mask from previous pruning iteration, if any. To be considered when determining what portion of the tensor that pruning should act on. If None, default to a mask of ones.   Returns 
pruned version of tensor t.   
  
remove(module)  
Removes the pruning reparameterization from a module. The pruned parameter named name remains permanently pruned, and the parameter named name+'_orig' is removed from the parameter list. Similarly, the buffer named name+'_mask' is removed from the buffers.  Note Pruning itself is NOT undone or reversed!