torch / nn / torch.nn
torch.nn.utils.prune.ln_structured¶
-
torch.nn.utils.prune.
ln_structured
(module, name, amount, n, dim)[source]¶ Prunes tensor corresponding to parameter called
name
inmodule
by removing the specifiedamount
of (currently unpruned) channels along the specifieddim
with the lowest L``n``-norm. Modifies module in place (and also return the modified module) by: 1) adding a named buffer calledname+'_mask'
corresponding to the binary mask applied to the parametername
by the pruning method. 2) replacing the parametername
by its pruned version, while the original (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
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. Ifint
, it represents the absolute number of parameters to prune.n (int, float, inf, -inf, 'fro', 'nuc') – See documentation of valid entries for argument
p
intorch.norm()
.dim (int) – index of the dim along which we define channels to prune.
- 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') )
此页内容是否对您有帮助